Soda Race with Genetic Algorithms

Home

Soda Constructor and Soda Race

December 2003 (update in April 2005)

Soda constructor is an application used to build two-dimensional "creatures" using three simple components; springs, muscles and masses. Essentially the creatures are graph structures where some of the edges actuate given a configured heart beat, and other edges simply react by stretching and contracting. The soda play page contains  details of the soda constructor application and the various interesting creatures that have been constructed. Soda race is an extension of the soda constructor idea that permits fixed edges to be used to construct terrains in which the soda structures can race on. The soda race page contains details for preparing terrains and racing constructed soda creatures.

Here are direct links to the web star version of the soda race application, and the web start version of the soda constructor application. Here are links to describing the race application, and the soda race artificial intelligence forum.

Soda with Genetic Algorithms

I read somewhere that people were using global search techniques (simulated annealing and genetic algorithms) to both optimise existing soda structures and design new soda structures. Of course I became instantly interested. Using the open source genetic algorithm library ECJ and a Java decompiler I constructed a simple set of tools for optimising and designing competitive soda constructions.

I reverse engineered the soda race and soda constructor applications and reengineered them so that the fitness function of the genetic algorithm (running of a race) would be as fast as possible. All tools are similar in that they optimise a model for a terrain. The common process for all tools is as follows:

  1. Select an appropriate tool for whatever is being optimised
  2. Run tool to prepare ECJ gene definition (number of genes and variance on each gene)
  3. Paste generated gene definition into appropriate .params file for the tool
  4. Run the genetic algorithm tool, which operates on and outputs a vector of numbers
  5. Use the provided relevant tool to convert vectors to XML
  6. Copy and paste the XML into a race/terrain XML file
  7. Observe the race / upload race to soda race forum

A race is simply a terrain with a number of contenders. Contenders can be added to a race in an online mode by loading the model XML in the soda constructor then connecting the soda constructor to soda race. This is problematic for GA produced models. Thus, the best way of getting a produced model in the race is the copy-paste method prescribed above.

Essentially, the API and tools provided are nothing more than a problem definition for ECJ, and associated mechanics for converting between vector format and XML files. The three basic tools provided for each optimisation task are as follows;

  1. ECJ gene definition generator (for preparing the gene definition portion of the ECJ configuration files - needed for defining the scope/range of the variables being optimised). For each task, the tool takes a base model file and a percentage variance (0-1) for values of all genes. The tool for optimising model structures and parameters (tool 4) takes the number of masses and a variance rather than a base model.
  2. Tool for performing the genetic algorithm optimisation. Example: java -cp <...> ec.Evolve -file <parameter filename>
  3. Tool for converting the resulting vector into a model XML file. Requires that the vector be placed in a text file called vector.txt, the tool outputs a model XML file. The tools for optimising the parameters and parameters and structure of any model require the number of masses to be specified.

These tools can easily be extended and or used in alternative soda based applications. For example, it would be trivial to extend the tools to optimise a structure for multiple domains, or build a pretty user interface for optimising structures.

Tools

The four genetic algorithm based tools for optimising soda structures are as follows:

1. Eight Mass Amoeba Optimiser - The eight mass amoeba is a very efficient structure for moving across a terrain. The dynamics of the amoeba have been defined and hard coded .This tool allows the 14 parameters that control those rotation dynamics to be optimised by the algorithm. Like all tools, configuration is controlled by an ECJ parameters file. The additional (non ECJ standard parameters) required include the specification of a base amoeba XML file that defines the structure to optimise, and the terrain XML to optimise the amoeba for. An example one population and two population GA configuration is provided.

2. Variable Mass Amoeba Optimiser - This tool optimises the same 14 parameters as the eight mass amoeba as well as the number of masses used in the amoeba. The dynamics and connectivity of the model are fixed as in the case of the eight mass amoeba.

3. Any Model Parameter Optimiser - This tool requires that a terrain and model file be specified. The tool will optimise all parameters of the model. These include all environment parameters, all rest lengths and muscle amplitudes. The structure of the model is not adjusted, only the structures parameters.

4. Any Model Parameter and Structure Optimiser - This is probably the most interesting tool. The gene definition generator takes as a parameter the number of masses the model has. The genetic algorithm will then design a structure with the defined number of masses. The masses are static during the evolution, though all connections are dynamic both in type (mass or spring) and connectivity (connected or not connected) between all masses. Imagine a two-dimensional matrix with all nodes across the top and bottom and each cell represents a possible connection.

Naturally, the genetic algorithm parameter files can be adjusted  to configure the algorithm. For a full explanation of various GA modules, see the ECJ website and tutorials. It may be useful to fine tune the gene definitions for a given problem to optimise specific elements of a structure or to optimise within a specific area of the state space.

Examples

The following are examples I posted to the soda race artificial intelligence forum, they are linked here for convenience. Clicking on a link will start the soda race application and demonstrate some of my soda creations prepared using this genetic algorithm tool set.

Downloads

The tool bat files were separated from the required libraries for download size reasons. Simply unzip the library in the appropriate tool directory and run the relevant bat file. Bat files are not needed to run the tools of course, they are only provided for convenience.

 

Home