Changeset 1103


Ignore:
Timestamp:
03/11/21 19:51:11 (4 years ago)
Author:
Maciej Komosinski
Message:

Added an example of setting a different expdef (experiment definition)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/frams-test.py

    r1092 r1103  
    33For an introduction to Framsticks, its usage and scripting, see https://www.youtube.com/playlist?list=PLkPlXm7pOPatTl3_Gecx8ZaCVGeH4UV1L
    44For a list of available classes, objects, methods and fields, see http://www.framsticks.com/files/classdoc/
    5 For a number of examples of scripting, see the "scripts" directory in Framsticks distribution.
     5For a number of examples of scripting, see the "scripts" directory in the Framsticks distribution.
    66"""
    77
    88import sys
     9import json
    910import frams
    1011
     
    8081frams.Simulator.stop()
    8182
     83# changing expdef
     84testgenotype = "XrrX[G][-1:80][|,-1:0.9]X[|,-2:-21]"
     85evaluations = 100
     86print("\nLet's change the experiment definition (expdef) and evaluate genotype '%s' %d times." % (testgenotype, evaluations))
     87frams.Simulator.expdef = "standard-eval"
     88frams.ExpProperties.evalcount = evaluations
     89frams.ExpProperties.cr_v = 1
     90frams.ExpProperties.evalplan = ":velocity,vertpos,fit_stdev,time"
     91frams.GenePools[0].add(testgenotype)
     92frams.ExpProperties.evalsavefile = ""  # no need to store results in a file - we will get evaluations directly from Genotype's "data" field
     93frams.Simulator.init()
     94frams.Simulator.start()
     95step = frams.Simulator.step  # cache reference to avoid repeated lookup in the loop (just for performance)
     96while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
     97        step()
     98for g in frams.GenePools[0]:  # loop over all genotypes, even though we know we added only one
     99        serialized_dict = frams.String.serialize(g.data[frams.ExpProperties.evalsavedata._value()])
     100        print(json.loads(serialized_dict._string()))
     101
    82102# Note that implementing a complete expdef, especially a complex one, entirely in python may be inconvenient or impractical
    83103# because you do not have access to "event handlers" like you have in FramScript - onStep(), onBorn(), onDied(), onCollision() etc.,
Note: See TracChangeset for help on using the changeset viewer.