def lives(self, members): """ Lions and gazelles should be evaluated separately """ gazelles = [G for G in members if self.gazelle(G)] lions = [L for L in members if not self.gazelle(L)] Default_Scenario.lives(self, gazelles) Default_Scenario.lives(self, lions)
def couples(self, RankedMembers): """ Lions and gazelles should not attempt to mate (because the selection of both subspecies operates on different scales) """ if len(RankedMembers) == 0: return [] livingGazelles = [ G for G in RankedMembers if self.gazelle(G) and G.score() >= 0 ] lions = [L for L in RankedMembers if self.lion(L)] # print([G.score() for G in gazelles]) # print([L.score() for L in lions]) Desired_ratio = self.Parameter('GazelleToLionRatio') # global number of children nb_children = chances( self.Parameter('ReproductionRate') / 100.0, len(livingGazelles) + len(lions)) # Distribution: nb_gazelle_target = int(round(Desired_ratio * nb_children / 100.0)) nb_lion_target = 1 + int( round((100 - Desired_ratio) * nb_children / 100.0)) # Correction nb_gazelle_target += len(lions) * Desired_ratio / ( 100.0 - Desired_ratio) - len(livingGazelles) # print(len(RankedMembers), len(livingGazelles), Desired_ratio, nb_gazelle_target, nb_lion_target) Couples = Default_Scenario.couples( self, livingGazelles, int(nb_gazelle_target)) + Default_Scenario.couples( self, lions, int(nb_lion_target)) # print(len(livingGazelles), len(lions)) # print(["%d%d (%.01f/%0.1f)" % (1*self.gazelle(C[0]),1*self.gazelle(C[1]), C[0].score(), C[1].score(), ) for C in Couples], end="\n") # print() return Couples
def start_game(self, members): """ defines what to be done at the group level before interactions occur """ for m in members: m.score(0, FlagSet=True) # resetting scores each year Default_Scenario.start_game(self, members)
def couples(self, members): """ Lions and gazelles should not attempt to make babies together (because the selection of both subspecies operates on different scales) """ gazelles = [G for G in members if self.gazelle(G)] lions = [L for L in members if not self.gazelle(L)] Couples = Default_Scenario.couples(self, gazelles) + Default_Scenario.couples(self, lions) #print sorted(["%d%d" % (1*self.gazelle(C[0]),1*self.gazelle(C[1])) for C in Couples]) return Couples
def start_game(self,members): """ defines what to be done at the group level before interactions occur - Used in 'life_game' """ for indiv in members: #Don't forget that scores MUST REMAIN POSITIVE # So include a line such as: indiv.score(len(members)*10, FlagSet=True) # or whatever appropriate value to set scores to some initial value each year Default_Scenario.start_game(self, members)
def start_game(self, members): """ defines what to be done at the group level before interactions occur - Used in 'life_game' """ for indiv in members: #Don't forget that scores MUST REMAIN POSITIVE # So include a line such as: indiv.score( len(members) * 10, FlagSet=True ) # or whatever appropriate value to set scores to some initial value each year Default_Scenario.start_game(self, members)
def start_game(self, members): """ defines what is to be done at the group level before interactions occur - Used in 'life_game' """ for indiv in members: # set offset values indiv.score(self.Parameter('EmittedPoison') * len(members), FlagSet=True) if self.Species(indiv) == 'B': # this individual polutes the enviroment with poison self.Pollution += self.Parameter('EmittedPoison') indiv.score(-self.Parameter('PoisonCost'),FlagSet=False) self.InitPollution = self.Pollution Default_Scenario.start_game(self, members)
def start_game(self, members): """ defines what is to be done at the group level before interactions occur - Used in 'life_game' """ for indiv in members: # set offset values indiv.score(self.Parameter('EmittedPoison') * len(members), FlagSet=True) if self.Species(indiv) == 'B': # this individual polutes the enviroment with poison self.Pollution += self.Parameter('EmittedPoison') indiv.score(-self.Parameter('PoisonCost'), FlagSet=False) self.InitPollution = self.Pollution Default_Scenario.start_game(self, members)
def couples(self, RankedMembers): """ Lions and gazelles should not attempt to mate (because the selection of both subspecies operates on different scales) """ if len(RankedMembers) == 0: return [] livingGazelles = [G for G in RankedMembers if self.gazelle(G) and G.score() >= 0] lions = [L for L in RankedMembers if self.lion(L)] # print([G.score() for G in gazelles]) # print([L.score() for L in lions]) Desired_ratio = self.Parameter('GazelleToLionRatio') # global number of children nb_children = chances(self.Parameter('ReproductionRate') / 100.0, len(livingGazelles) + len(lions)) # Distribution: nb_gazelle_target = int(round(Desired_ratio * nb_children / 100.0)) nb_lion_target = 1 + int(round((100 - Desired_ratio) * nb_children / 100.0)) # Correction nb_gazelle_target += len(lions) * Desired_ratio / (100.0-Desired_ratio) - len(livingGazelles) # print(len(RankedMembers), len(livingGazelles), Desired_ratio, nb_gazelle_target, nb_lion_target) Couples = Default_Scenario.couples(self, livingGazelles, int(nb_gazelle_target)) + Default_Scenario.couples(self, lions, int(nb_lion_target)) # print(len(livingGazelles), len(lions)) # print(["%d%d (%.01f/%0.1f)" % (1*self.gazelle(C[0]),1*self.gazelle(C[1]), C[0].score(), C[1].score(), ) for C in Couples], end="\n") # print() return Couples
def wallpaper(self, Window): " displays background image or colour when the window is created " # Possible windows are: 'Field', 'Curves', 'Genome', 'Log', 'Help', 'Trajectories', 'Network' if Window == 'Curves': return 'Scenarii/male-and-female-symbols-vector-246764_.jpg' return Default_Scenario.wallpaper(self, Window)
def wallpaper(self, Window): " displays background image or colour when the window is created " # Possible windows are: 'Field', 'Curves', 'Genome', 'Log', 'Help', 'Trajectories', 'Network' if Window == 'Trajectories': return 'Scenarii/Labyr.png' return Default_Scenario.wallpaper(self, Window)
def start_game(self, members): self.Peace = 0 # done every year self.GroupSize = len(members) self.Encounters = 0 Default_Scenario.start_game(self, members)
def legends(self): return "<u>Field window</u><p>Blue dots: gazelles ranked by strength - lightblue dots: dead gazelles - y-axis: jump<br>Red dots: lions - y-axis: lion threshold<P>" \ + Default_Scenario.legends(self)
def wallpaper(self, Window): " displays background image or colour when the window is created " # Possible windows are: 'Field', 'Curves', 'Genome', 'Log', 'Help', 'Trajectories', 'Network' if Window == 'Curves': return 'Scenarii/Landscape_.png' return Default_Scenario.wallpaper(self, Window)
def legends(self): return "\nBlue dots:\tgazelles ranked by strength - lightblue dots: dead gazelles - y-axis: jump\nRed dots:\tlions - y-axis: lion threshold\n\n" \ + Default_Scenario.legends(self)