Evolife

Jean-Louis Dessalles


Courbes.jpg
  1. Overall description
  2. How to execute Evolife (+ download)
  3. Evolife source files
  4. Evolife classes and functions
  5. How Evolife works
  6. Create your own Evolife scenario
  7. Use Evolife’s components separately (graphics, ecology, genetic algorithm)

    ↪    Program documentation


8. Use Evolife’s components separately (graphics, ecology, genetic algorithm)

Some examples illustrating how to use some of Evolife’s components are available.
To see how to use Evolife’s graphic, look at Trajectories.py or GraphicExample.py in Graphics. The latter implements many of Evolife’s graphic capabilities (including drawing, moving objects, curves, mouse clicks) together with comments.
    
Some basic graphic examples (in the directory Examples)
Trajectories.py Simple example to show how Evolife’s graphics can be used to display movement. animated graphics
GraphicExample.py More elaborate example to show how to use Evolife’s graphics. animated graphics

To see how to introduce a genetic algorithm in a non-GA application, look at the difference between Segregationism.py and SegregationismGA.py. The main difference is in the name of inherited classes. Note that reproduction significantly slows down execution.

    
Other examples (in the directory Other)
Ants moving ants foraging for food animated graphics    
CellularAutomaton a basic implementation of 1-D C.A. just drawing
Cocktail the cocktail party effect animated graphics
Segregationism Thomas Schelling’s famous experiment animated graphics
SegregationismGA Thomas Schelling’s famous experiment same + GA
Swallows Collective decision animated graphics
EcologyExample.py Just a living population ecology, no GA
GAExample.py Evolife void scenario, waiting for being customized GA

The six first examples in the above list can be executed in their respective directories by executing starter.
This is a snapshot of the Swallows.py program.

SwallowScr.png

In all these example, you can see that the interface with Evolife’s graphics is achieved using the function Start:
Evolife.Graphics.Start(OneStep, MyObserver, Capabilities)

Your programme may define a class MyObserver that inherits
Evolife.Ecology.Observer.Observer

Your MyObserver class may redefine the following functions :

1. get_data(Slot). This function is called from Evolife_window.py. The main slots are: 2. get_info(Slot). Possible slots (see Evolife_window.py) are: 3. GetPlotOrders. This function should return a list containing couples: [(Curve_id, (x,y)),...] where Curve_id is an Evolife Colour name or a number indicating the colour (between 1 and something like 45), and (x,y) are the coordinates of the next point to plot on the curve.
x is typically equal to MyObserver.StepId, which represent the current year.
StepId can be incremented by calling MyObserver.season().

The preceding functions need only be implemented when the corresponding capabilities are indicated when calling Start.

As an alternative to CurveNames, you may use the curve function:


    self.curve()    # resets curve definitions
    self.curve(Name, Colour, Description)    # defines a new curve
    self.curve(Name)    # returns the colour of an already defined function

Colour is an Evolife Colour or a number. For instance, the slot GetPlotOrders may return something like:


def get_info(self, Slot):
    if Slot == 'PlotOrders':
        return [(self.curve('my curve'), (self.StepId, some_value))]
    ...