Exercise 7. Optimize a shape or behavior 

In this exercise, you yourself choose what the optimization goal will be. You will have access to the coordinates of the center of gravity of the structure and to the coordinates of all its elements (Parts) in each step of its simulation. Based on this information, your task is to define an objective function that will guide the evolution to the goal you specify.

The goal may be to evolve a particular shape or behavior. Shapes include, for example, stars, regular polyhedrons, tables, bridges, towers, etc. Behaviors include, for example, moving along a certain path, arriving at a certain location in a certain terrain (such as a maze) or, for example, climbing a mountain, "bulldozing" (pushing as far as possible through a barrier), "dancing," rolling (cf. "Rolling Wheel" from the walking.gen file), a certain way of moving/jumping/flying/swimming, moving fast in a hilly world, moving efficiently on land and in water (for evaluation, the environment can be periodically altered), diving, avoiding obstacles, jumping across chasms/jumping on columns, visiting predetermined places, the longest possible jump from the takeoff point, cooperation of individuals/coevolution etc. You can also use multi-criteria optimization – for example, specify two or three criteria. Consult your idea with the teacher before you start.

To get the recording of the coordinates of a simulated structure into the frams_evaluate() function in Python, use recording-body-coords.sim (i.e., provide this file name as the last one in the semicolon-separated list of files in the -sim argument). Have a look into recording-body-coords.sim and read the comment at the top of this file – you can limit the amount of collected and passed data to avoid recording what you do not need anyway, which will accelerate calculations. In the frams_evaluate() function, the default_evaluation_data dictionary will have the key named data->bodyrecording – its value is the list of lists (print it and verify) according to the specifications described in recording-body-coords.sim. Based on this data, design a fitness formula that reflects your idea so that it helps evolution achieve the goal you have chosen.

You can modify many aspects of the simulation according to your needs:

  • The ground surface shape and water level (class World) and the gravity force,
  • simulation time of a structure (Energy0) – if evolving a shape, one step is sufficient,
  • the location of its initial placement (changes in standard-eval.expdef, the onBorn() function and standard_placement.inc),
  • using (or not) the stabilization period,
  • custom sensor or effector (a new *.neuro file in the data/scripts directory).

The documentation of available classes and their fields is here; if in doubt, ask the lecturer.


For your experiments, create a new file called eval-allcriteria-mini.sim with the following contents:

sim_params:
expdef:standard-eval
creatwarnfail:1
p_nop:1.0
p_mut:0.0
p_xov:0.0
Energy0:10000.0
evalcount:2
evalplan:~
:numparts,numjoints,numneurons,numconnections,instances,lifespan,velocity,distance,vertvel,vertpos,fit,fit_stdev,time~
evalsavedata:evaluation
and use it instead of eval-allcriteria.sim in your sequence of .sim files.

In your answer below, include the following:

  • The goal of evolution in this simulation experiment is to ... (describe your objective).
    If the goal is to evolve behavior, think about and describe two issues:
    • Initial conditions (location and orientation in the world; the environment): constant/variable. How will this affect the outcome of evolution? ("overfitting").
    • Will the agent know where they are and what they are doing or not? (senses=sensors). In other words, can evolution sense/discover the relationship between the behavior and the objective function and thus create active control in the organism, or will the "blind" agent always behave independently of the environmental conditions and its own state?
  • The sequence of .sim files used.
  • The list of changed (from default) parameter values and script pieces. The stopping criterion used (can be, for example, based on the number of individuals evaluated, fitness values, fitness stagnation, etc.) – it is important to achieve convergence.
  • Examples of variants of the experiment for comparison: successive improvements in the definition of fitness, different values of parameters (weights in the objective function, population size, genetic representation f0/f1/f4/fH). Each variant should be repeated 10 times.
  • Compare at least two variants.
  • Plots – the same as in earlier labs (each variant is a separate category in the plots).
  • The characteristics of the fitness landscape – as a whole and in the area surrounding the location where evolution begins. You don't have to do a separate computational experiment here (although you can – as in this earlier exercise), just think about it and describe what the landscape looks like.
  • Quantitative conclusions (from evolutionary runs and box plots).
  • Qualitative conclusions: how do the best individuals behave? do they have any specific genotypes? are the results as expected? if not, why not? if the evolved individuals move or behave in a specific way – instead of including a series of screenshots in the answer, it is better to record a video (which can also demonstrate how their neural networks work) and publish it on youtube or somewhere online, then provide a link in your answer.

If you have made any improvements to the optimization algorithm itself, consider submitting it to the GECCO competition.

...