Jean-Louis Dessalles

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

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

Some examples illustrating how to use some of Evolife’s components are available in the directory Other. They include:
To see how to use Evolife’s graphic, look at GraphicExample.py in Other. This program implements many of Sans MS(Evolife)’s graphic capabilities (including drawing, moving objects, curves, mouse clicks) together with comments.

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.

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.

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

Your programme may define a class MyObserver that inherits

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))]