Evolife
Evolife has been developed to study Genetic algorithms, Natural evolution and behavioural ecology.
CustomScenario.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2""" @brief Customized scenario.
3
4 Use this if you REALLY need to re-implement the
5 - Individual
6 - Group
7 - Observer
8 classes. Otherwise, create a scenation named S_xxx.py
9 as shown in the many examples contained in this directory.
10"""
11
12
13
14#============================================================================#
15# EVOLIFE http://evolife.telecom-paris.fr Jean-Louis Dessalles #
16# Telecom Paris 2022-04-11 www.dessalles.fr #
17# -------------------------------------------------------------------------- #
18# License: Creative Commons BY-NC-SA #
19#============================================================================#
20# Documentation: https://evolife.telecom-paris.fr/Classes #
21#============================================================================#
22
23
24
25import sys
26sys.path.append('../..')
27
32from Evolife.Ecology import Individual
33from Evolife.Graphics import Evolife_Window
34
36 """ Implement a scenario here, by instantiating Default_Scenario.
37 See documentation in Default_Scenario.py to see how.
38 """
39
40 def __init__(self):
41 Evolife.Scenarii.Default_Scenario.Default_Scenario.__init__(self, Name='MyCustomScenario') # loads 'MyCustomScenario.evo'
42
43 def genemap(self):
44 return [('gene1',16),('gene2',4)]
45
46 def display_(self):
47 return [('blue', 'gene1', 'First gene'), ('green4', 'gene2', 'Second gene')]
48
49
51 """ Observer stores display instructions and makes statistics
52 See Evolife/Apps/GraphicExample.py for examples
53 """
54 def Field_grid(self):
55 """ initial draw: here a blue line
56 """
57 return [(0, 0, 'blue', 1, 100, 100, 'blue', 1), (100, 100, 1, 0)]
58
59class Individual_(Individual.EvolifeIndividual):
60 """ class Individual_: defines what an individual consists of
61 """
62 def __init__(self, Scenario=None, ID=None, Newborn=False, maxQuality=100):
63 Individual.EvolifeIndividual.__init__(self, Scenario=Scenario, ID=ID, Newborn=Newborn)
64 self.Quality = (100.0 * int(ID)) / maxQuality # quality may be displayed
65 self.Points = 0 # stores current performance
66 self.Risk = 0 # Risk taking
67
68
70 """ Calls local class when creating individuals
71 """
72 def createIndividual(self, ID=None, Newborn=True):
73 return Individual_(self.Scenario, ID=self.free_ID(Prefix=''), Newborn=Newborn)
74
75
77 """ Calls local class when creating group
78 """
79 def createGroup(self, ID=0, Size=0):
80 return Group(self.Scenario, ID=ID, Size=Size)
81
83 for gr in self.groups:
84 for agent in gr:
85 # agent.lessening_friendship() # eroding past gurus performances
86 if self.Scenario['EraseNetwork']: agent.forgetAll()
87 agent.Points = 0
88 agent.Risk = 100 # maximum risk
89
90
91if __name__ == "__main__":
92 Gbl = Scenario() # includes parameters
93 Obs = Observer(Gbl)
94 Pop = Population(Scenario=Gbl, Evolife_Obs=Obs)
95 if Gbl['BatchMode'] == 0: print(__doc__)
96
97 # launching windows
98 # See Evolife_Window.py for details
99 Capabilities='FGCP' # F = 'Field'; G = 'Genomes'; C = 'Curves';
100 Views = []
101 if 'F' in Capabilities: Views.append(('Field', 500, 350)) # start with 'Field' window on screen
102 if 'T' in Capabilities: Views.append(('Trajectories', 500, 350)) # 'Trajectories' on screen
103 Obs.recordInfo('DefaultViews', Views) # Evolife should start with these window open
104 Evolife_Window.Start(SimulationStep=Pop.one_year, Obs=Obs, Capabilities=Capabilities,
105 Options=[('Background','green11')])
106
107
108
109__author__ = 'Dessalles'
class Group: list of individuals that interact and reproduce.
Definition: Group.py:162
def free_ID(self, Prefix=None)
returns an available ID
Definition: Group.py:56
Evolife-aware observer based on the use of a scenario.
Definition: Observer.py:598
Population + reproduction + call to Scenario life_game.
Definition: Population.py:221
Calls local class when creating individuals.
def createIndividual(self, ID=None, Newborn=True)
calls the 'EvolifeIndividual' class calls 'Scenario.new_agent'
class Individual_: defines what an individual consists of
def __init__(self, Scenario=None, ID=None, Newborn=False, maxQuality=100)
Observer stores display instructions and makes statistics See Evolife/Apps/GraphicExample....
Calls local class when creating group.
def createGroup(self, ID=0, Size=0)
This version of 'createGroup' calls the 'EvolifeGroup' class instead of the 'Group' class.
Implement a scenario here, by instantiating Default_Scenario.
def genemap(self)
Defines the name of genes and their position on the DNA.
def display_(self)
Defines what is to be displayed.
All functions defined here can be overloaded in specific scenarii (see module doc)
def __init__(self, Name='Default scenario', CfgFile='')
Loads parameters, sets gene map and calls local initialization.
Groups are lists of Individuals.
Definition: Group.py:1
Gets data from various modules and stores them for display and statistics.
Definition: Observer.py:1
A population is a set of semi-permeable groups.
Definition: Population.py:1
Determines how individuals acquire their score, either by themselves or through interactions.