Package SimPy :: Module testRT_Behavior_OO
[hide private]
[frames] | no frames]

Source Code for Module SimPy.testRT_Behavior_OO

 1  #!/usr / bin / env python 
 2  from SimPy.SimulationRT import * 
 3  """testRT_Behavior_OO.py 
 4  Tests SimulationRT for degree to which simulation time 
 5  and wallclock time can be synchronized. 
 6   
 7  OO API. 
 8  """ 
 9  # $Revision: 295 $ $Date: 2009-03-30 14:26:20 +0200 (Mo, 30 Mrz 2009) $ 
10   
11  print "Under test: SimulationRT.py %s"% version 
12  __version__ = '2.0 $Revision: 295 $ $Date: 2009-03-30 14:26:20 +0200 (Mo, 30 Mrz 2009) $ ' 
13  print 'testRT_Behavior.py %s'%__version__ 
14   
15 -class Ticker(Process):
16 - def tick(self):
17 self.timing = [] 18 while True: 19 yield hold,self,1 20 tSim = self.sim.now() 21 tRT = self.sim.rtnow() 22 self.timing.append((tSim,tRT))
23 24 s=SimulationRT() 25 s.initialize() 26 t=Ticker(sim=s) 27 s.activate(t,t.tick()) 28 s.simulate(until=10,real_time=True,rel_speed=1) 29 30 print "Speed ratio set: 1" 31 print "------------------" 32 for tSim,tRT in t.timing: 33 print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT) 34 35 s1=SimulationRT() 36 s1.initialize() 37 t=Ticker(sim=s1) 38 s1.activate(t,t.tick()) 39 s1.simulate(until=10,real_time=True,rel_speed=5) 40 41 print 42 print "Speed ratio set: 5" 43 print "------------------" 44 for tSim,tRT in t.timing: 45 print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT) 46