Telling time in Python
From GeoMod
I need to give my pedestrian agents a flow rate into the simulation. In order to do this I need to tell how much time has elapsed so I can trigger their appearance. It calls the time module using the system clock
#---master_crono determines the length of the simulation
# it will be added to to give more functions such as controling the events of
# the entire simulation
import time
class master_chrono:
def _init_ (self):
print time.time()
def tock(self,simsec,timemx):
self.start=time.time()
print 'the start time is'
print self.start
self.simsec=simsec
self.switch=1
hand=self.start
total_simtime= self.simsec*timemx
while self.switch ==1:
if time.time()== hand + 1.0:
print time.time()
print 'update'
hand=hand+1.0
if time.time()== self.start+ total_simtime:
print 'stop event'
self.switch=0
print 'total simulation time'
print total_simtime
print 'seconds'
return self.switch
Calling the class inside the simulation Right now I pass the number of seconds I want the simulation to run and a multiplier in case I want to speed up or slow down
##---simulation time setup
run=1
stop=0
tick=master_chrono()
sim_master_clock=run
#---test setup
testcounter=10
while testcounter <> 0:
# add a ped every #sec
while sim_master_clock <> stop:
sim_master_clock=tick.tock(5,1.0)
people.append(walker(uniform(putfolkxmin,putfolkxmax),1,uniform(putfolkzmin,putfolkzmax)))
if tick.tock(1,1.0) == 0:
testcounter=testcounter-1

