script: name:Evolve for speed vs gravity help:Evolve for speed in different gravity settings code:~ function main(gravity,min_evaluations) { Math.randomize(); World.wrldg=gravity; Populations[0].perfperiod=100000; //fitness: velocity serves as distance (because sampling period is longer than lifespan) ExpParams.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=""" var MAX_WITHOUT_PENALTY=50; function penalty(count) { 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 var best=GenePools[0].best(); Simulator.print("%g (x%g) %s" % best.fit % best.popsiz % best.genotype); // Now, since we have indeterminism (default.sim 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 wait until the best genotype is evaluated at least min_evaluations times. // No new genotypes are introduced in this phase. ExpParams.stagnation=0; //turn off stagnation detection mechanism ExpParams.p_mut=0; //we don't want evolution and new genotypes anymore. We only want to evaluate existing genotypes multiple times ExpParams.p_xov=0; Simulator.start(); while (Simulator.running && best.popsiz0 && Simulator.running; t--) // simulate 'expected lifespan' steps after which 'best' may have changed. This helps avoid frequent unnecessary calls to best() Simulator.step(); best=GenePools[0].best(); } Simulator.stop(); Simulator.print("%g (x%g) %s" % best.fit % best.popsiz % best.genotype); GenePools[0].clear(); //remove all... best.moveTo(GenePools[0]); //...then restore best... Simulator.save("best_%g_%u.expt" % gravity % (0+Math.time)); //...and save it in a file just in case we want to see all of its data } ~