- Timestamp:
- 03/11/21 19:51:11 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/frams-test.py
r1092 r1103 3 3 For an introduction to Framsticks, its usage and scripting, see https://www.youtube.com/playlist?list=PLkPlXm7pOPatTl3_Gecx8ZaCVGeH4UV1L 4 4 For 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.5 For a number of examples of scripting, see the "scripts" directory in the Framsticks distribution. 6 6 """ 7 7 8 8 import sys 9 import json 9 10 import frams 10 11 … … 80 81 frams.Simulator.stop() 81 82 83 # changing expdef 84 testgenotype = "XrrX[G][-1:80][|,-1:0.9]X[|,-2:-21]" 85 evaluations = 100 86 print("\nLet's change the experiment definition (expdef) and evaluate genotype '%s' %d times." % (testgenotype, evaluations)) 87 frams.Simulator.expdef = "standard-eval" 88 frams.ExpProperties.evalcount = evaluations 89 frams.ExpProperties.cr_v = 1 90 frams.ExpProperties.evalplan = ":velocity,vertpos,fit_stdev,time" 91 frams.GenePools[0].add(testgenotype) 92 frams.ExpProperties.evalsavefile = "" # no need to store results in a file - we will get evaluations directly from Genotype's "data" field 93 frams.Simulator.init() 94 frams.Simulator.start() 95 step = frams.Simulator.step # cache reference to avoid repeated lookup in the loop (just for performance) 96 while frams.Simulator.running._int(): # standard-eval.expdef sets running to 0 when the evaluation is complete 97 step() 98 for 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 82 102 # Note that implementing a complete expdef, especially a complex one, entirely in python may be inconvenient or impractical 83 103 # 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.