script: name:Evolve for speed vs gravity help:Evolve for speed in different gravity settings code:~ function main_args(gravity,min_evaluations) { Math.randomize(); World.wrldg=gravity; Populations[0].perfperiod=100000; //fitness: velocity serves as distance (because sampling period is longer than lifespan) ExpProperties.initialgen="XX[|,1:1][N,1:1,2:1][T][G]"; //custom fitness function: velocity minus small penalty for complexity (high number of parts, joints, neurons, connections) GenePools[0].fitness=""" function penalty(count) { var MAX_WITHOUT_PENALTY=50; var toomany=count-MAX_WITHOUT_PENALTY; if (toomany<=0) return 0; else return -toomany*0.001; } return this.velocity+penalty(this.numparts)+penalty(this.numjoints)+penalty(this.numneurons)+penalty(this.numconnections);"""; Simulator.init(); //Simulator.print(GenePools[0][0].genotype); //ensure the initialgen is in the gene pool Simulator.start(); while (Simulator.running) Simulator.step(); //runs until the experiment stops by itself (due to stagnation detected) var best=GenePools[0].best(); Simulator.print("Optimization ends, best: %g (x%g) %s" % best.fit % best.instances % best.genotype); // Now, since we have indeterminism (default settings used: random initialization of neural states and random placement of creatures), // we cannot trust fitness values that have not been confirmed (averaged) during multiple evaluations. // So we start another phase where we keep evaluating until the single best genotype is evaluated at least min_evaluations times. // No new genotypes are introduced in this phase. UserScripts.script_Find_best_genotype_on_average_args(min_evaluations,"best_%g_%u.expt" % gravity % int(Math.time)); } ~