Example #1
0
def Start():
    Obs.setOutputDir(
        '___Results'
    )  # curves, average values and screenshots will be stored there
    Obs.recordInfo('Background',
                   'grey')  # windows will have this background by default
    # Background could be 'yellow' or 'toto.jpg' or '11' or '#F0B554'
    #Obs.recordInfo('CurvesWallpaper', '../QtGraphics/EvolifeBG.png')
    #Obs.recordInfo('TrajectoriesWallpaper', '../QtGraphics/EvolifeBG.png')
    Obs.recordInfo(
        'DefaultViews',
        [('Field', 500, 500)])  # Evolife should start with these windows open
    Obs.record(('obsta', (500, 500, 2, 1, 'shape=rectangle')), Window='Field')

    #--------------------------------------------------------------------------#
    # Start: launching Evolife window system                                   #
    #--------------------------------------------------------------------------#
    # Start(Callback function, Observer, Capabilities, Options)
    # Callback function:    this locally defined function is called by Evolife at each time step
    # Observer:    locally defined
    # Capabilities: string containing any of the following letters
    #    C = Curves
    #    F = Field (2D seasonal display) (excludes R)
    #    G = Genome display
    #    L = Log Terminal (not implemented)
    #    N = social network display
    #    P = Photo (screenshot)
    #    R = Region (2D ongoing display) (excludes F)
    #    T = Trajectory display (requires additional implementation in each case)

    EW.Start(one_year, Obs, Capabilities='FG')
Example #2
0
def Start(Gbl=None, PopClass=Population, ObsClass=None, Capabilities='PCGFN'):
    " Launch function "
    if Gbl == None: Gbl = Scenario()
    if ObsClass == None:
        Observer = EO.EvolifeObserver(Gbl)  # Observer contains statistics
    Pop = PopClass(Gbl, Observer)
    BatchMode = Gbl.Parameter('BatchMode')

    if BatchMode:  # Non-graphic mode (for large-scale experiments)
        EB.Start(Pop.one_year, Observer)
    else:
        EW.Start(Pop.one_year, Observer, Capabilities=Capabilities)
    if not BatchMode: print("Bye.......")
    sleep(2.1)
    return
Example #3
0
def Start():
    generation = 0
    pos_in_solution = 0
    Obs.setOutputDir(
        '___Results'
    )  # curves, average values and screenshots will be stored there
    Obs.recordInfo('Background',
                   'white')  # windows will have this background by default

    Obs.recordInfo('DefaultViews', [
        ('Field', window_width, window_height)
    ])  # Evolife should start with these windows open
    Obs.record(
        ('point', (window_width, window_height, 2, 1, 'shape=rectangle')),
        Window='Field')

    EW.Start(one_generation, Obs, Capabilities='FG')
Example #4
0
def Start(Gbl=None,
          PopClass=Patriotic_Population,
          ObsClass=None,
          Capabilities='FGCNP'):
    " Launch function "
    if Gbl == None: Gbl = Scenario()
    if ObsClass == None:
        Observer = EO.EvolifeObserver(Gbl)  # Observer contains statistics
    Pop = PopClass(Gbl, Observer)
    BatchMode = Gbl.Parameter('BatchMode')

    if BatchMode:
        EB.Start(Pop.one_year, Observer)
    else:
        EW.Start(Pop.one_year, Observer, Capabilities=Capabilities)
    if not BatchMode: print("Bye.......")
    sleep(2.1)
    return
Example #5
0
def Start(Gbl = None, PopClass = Population, ObsClass = None, Capabilities = 'FGCNP'):
    " Launch function "
    if Gbl == None: Gbl = Scenario()
    if ObsClass == None: Observer = EO.EvolifeObserver(Gbl)	# Observer contains statistics
    Pop = PopClass(Gbl, Observer)
    BatchMode = Gbl.Parameter('BatchMode')
    if BatchMode:
        EB.Start(Pop.one_year, Observer)
    else:
        Views = []
        if 'F' in Capabilities:	Views.append(('Field', 500, 350))	# start with 'Field' window on screen
        if 'T' in Capabilities:	Views.append(('Trajectories', 500, 350))	# 'Trajectories' on screen
        if 'N' in Capabilities:	Views.append(('Network', 500, 150))	# 'Network' on screen
        Observer.recordInfo('DefaultViews',	Views)	# Evolife should start with these window open
        EW.Start(Pop.one_year, Observer, Capabilities=Capabilities, Options=[('Background','green11')])
    if not BatchMode:	print("Bye.......")
    time.sleep(2.1)	
    return
Example #6
0
def Start(Params=None, PopClass=Social_Population, ObsClass=Social_Observer, Windows='FNC'):
	if Params is None:	Params = Global()
	Observer = ObsClass(Params)   # Observer contains statistics
	Observer.setOutputDir('___Results')
	Views = [('Field', 500, 350), ('Network', 530, 200)]
	if 'T' in Windows:	Views.append(('Trajectories', 500, 350))
	Observer.recordInfo('DefaultViews',	Views)	# Evolife should start with that window open
	# Observer.record((100, 100, 0, 0), Window='Field')	# to resize the field
	Pop = PopClass(Params, Params.Param('NbAgents'), Observer)   # population of agents
	BatchMode = Params.Param('BatchMode')
	
	if BatchMode :
		####################
		# Batch mode
		####################
		# # # # for Step in range(Gbl.Param('TimeLimit')):
			# # # # #print '.',
			# # # # Pop.One_Run()
			# # # # if os.path.exists('stop'):	break
		EB.Start(Pop.One_Run, Observer)
		# writing header to result file
		open(Observer.get_info('ResultFile')+'_res.csv', 'w').write(Observer.get_info('ResultHeader'))
	else:
		####################
		# Interactive mode
		####################
		print(__doc__)
		" launching window "
		try:
			EW.Start(Pop.One_Run, Observer, Capabilities=Windows+'P', Options=[('Background','lightblue')])
		except Exception as Msg:
			from sys import excepthook, exc_info
			excepthook(exc_info()[0],exc_info()[1],exc_info()[2])
			input('[Entree]')
		print("Bye.......")
		
	Params.Dump_(Pop.Dump, Observer.get_info('ResultFile'), Observer.get_info('DumpFeatures'), 
					Observer.get_info('ExperienceID'), Verbose = not BatchMode)
	sleep(2.1)	
	return
Example #7
0
                NewState = self.EvolveCell(C)
            self.VPosition += 1
            return True
        return False


if __name__ == "__main__":
    print(__doc__)

    #############################
    # Global objects			#
    #############################
    Scenario = CA_Scenario('_Params.evo')

    CAutomaton = Automaton(Scenario)  # logical settlement grid

    Observer = EO.Generic_Observer()  # Observer records display orders
    Observer.recordInfo('FieldWallpaper', 'white')
    margin = 4  # horizontal margins in the window
    zoom = 4
    Observer.recordInfo('DefaultViews',
                        [('Field', CAutomaton.Size * zoom + 2 * margin)])

    EW.Start(
        CAutomaton.OneStep, Observer, Capabilities='RP'
    )  # R means that only changed positions have to be displayed; P enables photos

    print("Bye.......")

__author__ = 'Dessalles'
Example #8
0
    Observer = Antnet_Observer(Gbl)  # Observer contains statistics
    Ntwrk = Network(Size=Gbl.Parameter('DisplaySize'),
                    NbNodes=Gbl.Parameter('NumberOfNodes'))
    Pop = AntPopulation(Gbl, Observer, Ntwrk.nodes())  # Ant colony

    # Initial draw
    Observer.recordInfo('FieldWallpaper', 'yellow')
    Observer.recordInfo('TrajectoriesWallpaper', 'lightblue')
    Observer.recordInfo('DefaultViews', ['Field', 'Trajectories'])
    Observer.recordChanges(
        ('Dummy', (Gbl.Parameter('DisplaySize'), Gbl.Parameter('DisplaySize'),
                   0, 1)))  # to resize the field
    Observer.recordChanges(
        ('Dummy',
         (Gbl.Parameter('DisplaySize'), Gbl.Parameter('DisplaySize'), 0, 1)),
        Slot='Trajectories')  # to resize the field
    # Initial display of network on Field window
    for link in Ntwrk.draw():
        Observer.recordChanges(link, Slot='Positions')
    # Initial display of network on trajectory window
    for link in Ntwrk.draw():
        Observer.recordChanges(link, Slot='Trajectories')

    EW.Start(Pop.one_decision, Observer, Capabilities='RPCT')

    print("Bye.......")
    sleep(1.0)
##	raw_input("\n[Return]")

__author__ = 'Dessalles'
Example #9
0
    " Calls local class when creating group "

    def createGroup(self, ID=0, Size=0):
        return Group(self.Scenario, ID=ID, Size=Size)  # local class


if __name__ == "__main__":
    Gbl = Scenario()
    Obs = EO.EvolifeObserver(Gbl)
    Pop = Population(Scenario=Gbl, Evolife_Obs=Obs)
    if Gbl['BatchMode'] == 0: print(__doc__)

    # launching windows
    # See Evolife_Window.py for details
    Capabilities = 'FGCP'  # F = 'Field'; G = 'Genomes'; C = 'Curves';
    Views = []
    if 'F' in Capabilities:
        Views.append(
            ('Field', 500, 350))  # start with 'Field' window on screen
    if 'T' in Capabilities:
        Views.append(('Trajectories', 500, 350))  # 'Trajectories' on screen
    Obs.recordInfo('DefaultViews',
                   Views)  # Evolife should start with these window open
    EW.Start(SimulationStep=Pop.one_year,
             Obs=Obs,
             Capabilities=Capabilities,
             Options=[('Background', 'green11')])
    time.sleep(1.1)

__author__ = 'Dessalles'
Example #10
0
                self.Index = (self.Index + 1) % 3
        return Color.Colors[self.Index] + str(self.Shade)


if __name__ == "__main__":

    print(__doc__)
    print(ET.boost())  # significantly accelerates python on some platforms

    # Global objects
    Gbl = EPar.Parameters('_Params.evo')  # Loading global parameter values
    Observer = Worm_Observer(Gbl)  # Observer prints the worm

    StartPosition = [
        4 * (Gbl.Parameter('Size') / 4), 4 * ((Gbl.Parameter('Size') - 1) / 4)
    ]

    # Initial draw
    Observer.recordInfo('FieldWallpaper', 'white')
    Observer.recordInfo('DefaultViews', ['Field'])
    Observer.record(('Worm', (StartPosition[0], StartPosition[1], 'black', 2)))

    # Initialization of the worm
    TheWorm = Worm(Observer,
                   RuleString=Gbl.Parameter('Rule'),
                   speed=Gbl.Parameter('Speed'),
                   startPosition=StartPosition)
    EW.Start(TheWorm.doStep, Observer, Capabilities='PCR')

    print("Bye.......")
Example #11
0
if __name__ == "__main__":
    print(__doc__)

    #############################
    # Global objects            #
    #############################
    Gbl = Scenario()
    Observer = EO.Observer(Gbl)  # Observer contains statistics
    Land = Landscapes.Landscape(
        Gbl.Parameter('LandSize'))  # logical settlement grid
    Land.setAdmissible(Gbl.Colours)
    Pop = Population(Gbl, Observer)

    # Observer.recordInfo('Background', 'white')
    Observer.recordInfo('FieldWallpaper', 'white')

    # declaration of curves
    for Col in Gbl.Colours:
        Observer.curve(Name='%s Satisfaction' % str(Col),
                       Color=Col,
                       Legend='average satisfaction of %s individuals' %
                       str(Col))
    # Observer.curve(Name='Global Satisfaction', Color='black', Legend='average global satisfaction')

    EW.Start(Pop.One_Decision, Observer, Capabilities='RPC')

    print("Bye.......")

__author__ = 'Dessalles'
Example #12
0
        # find last file
        CsvFiles = glob.glob('___Results/*.csv')
        if CsvFiles:
            CsvFiles.sort(key=lambda x: os.stat(x).st_mtime)
            Files = [CsvFiles[-1]]
    elif len(Args) > 3:
        print('''Usage:	%s <curve file name> [<constant config file name>]''' %
              os.path.basename(Args[0]))
    else:
        Files = glob.glob(Args[1])
        ConstantConfigFileName = Args[2] if (len(Args) == 3) else None
    for Argfile in Files:
        yield (Argfile, ConstantConfigFileName)


if __name__ == "__main__":
    for (Argfile, ConstantConfigFileName) in Parse(sys.argv):
        if Argfile:
            Observer = EO.Generic_Observer('')
            plot = Plot(Argfile, Observer, ConstantConfigFileName)
            print(plot.RelevantParam if plot.RelevantParam else plot.Cfg)
            Cap = 'CFP' if plot.FieldDisplay else 'CP'
            EW.Start(plot.one_plot,
                     plot.Obs,
                     Capabilities=Cap,
                     Options=[('Run', 'Yes'),
                              ('ExitOnEnd', 'No')])  # start Evolife display
            if plot.FieldDisplay: plot.save()

__author__ = 'Dessalles'
Example #13
0
    # Observer.recordInfo('FieldWallpaper', 'white')
    Observer.recordInfo('Background', 'white')
    PhysicalSize = Gbl.P('DotSize') * Gbl.P('LandSize')
    Observer.recordInfo('DefaultViews',
                        [('Field', PhysicalSize, PhysicalSize),
                         ('Trajectories', PhysicalSize, PhysicalSize)])
    Observer.record([(0, Gbl.P('LandSize'), 2, 0),
                     (Gbl.P('LandSize'), 0, 2, 0)])  # to resize
    Observer.record([(0, Gbl.P('LandSize'), 2, 0),
                     (Gbl.P('LandSize'), 0, 2, 0)],
                    Window='Trajectories')  # to resize

    Land = Landscape(Gbl.P('LandSize'), (Gbl.P('Da'), Gbl.P('Db')),
                     (Gbl.P('MaxA'), Gbl.P('MaxB')),
                     Gbl.P('NeighbourhoodRadius'),
                     Gbl.P('Precision'))  # 2D square grid
    Land.Seed((Gbl.P('LandSize') // 3, Gbl.P('LandSize') // 3), (0.4, 0.9),
              Radius=4)
    Land.Seed((2 * Gbl.P('LandSize') // 3, 2 * Gbl.P('LandSize') // 3),
              (0.4, 0.9),
              Radius=4)
    # print len(Land.ActiveCells)

    # Land.setAdmissible(range(101))	# max concentration

    EW.Start(One_Step, Observer, Capabilities='RPT')

    print("Bye.......")

__author__ = 'Dessalles'
    def OneStep(self):
        Observer.season()  # One step = one agent has moved
        if self.Time < Scenario.Parameter('TimeLimit'):
            for x in range(self.Size):
                for y in range(self.Size):
                    NewState = self.EvolveCell(self.Ground[x][y])
            self.display()
            self.Time += 1
            return True
        return False


if __name__ == "__main__":
    print __doc__

    #############################
    # Global objects			#
    #############################
    Scenario = CA_Scenario('_Params.evo')
    Observer = CA_Observer(Scenario)  # Observer contains statistics
    CAutomaton = Automaton(Scenario)  # logical settlement grid

    EW.Start(CAutomaton.OneStep, Observer, Capabilities='FP'
             )  # F means that all cells must be displayed each time
    #EW.Start(CAutomaton.OneStep, Observer, Capabilities='RP')		# R means that only changed positions have to be displayed

    print "Bye......."

__author__ = 'Dessalles'
Example #15
0
		Observer.Perched = self.Perched
		Observer.record((agent.Name,(agent.IdNb,agent.Position, 'black', 30, 'shape=swallow.gif')))
		# Observer.Positions[agent.IdNb] = (agent.Name,(agent.IdNb,agent.Position, 'black', 6))	# last coord = size
		# % of individuals perched
		Observer.curve('#indiv', 100.0 * self.Perched/self.PopSize)
		# perching probability
		Observer.curve('timeslope', 1000 * PerchingProb(Observer.StepId, Observer.Parameter('TimeSlope'), Observer.TimeLimit))
		return agent.IdNb	 

	def Many_decisions(self):
		" every swallow on average has been given a chance to perch down "
		for Sw in range(self.PopSize):
			self.One_Decision()
		return True
	
if __name__ == '__main__':

	print(__doc__)

	Observer = Swallow_Observer()   # Observer contains statistics
	#Observer.recordInfo('Background', 'blue11')	# windows will have this background by default
	Observer.recordInfo('DefaultViews', [('Field', 1100, 700)])	# windows will have this background by default
	Observer.recordInfo('CurvesWallpaper', 'swallow_.gif')
	Pop = Population(Observer.Parameter('NbAgents'))   # set of flying swallows
	
	EW.Start(Pop.Many_decisions, Observer, Capabilities='RCP')

	

__author__ = 'Dessalles'