Debian Codegraph @

docs/source/Manuals/SimulationRTprograms/variableTimeRatio.py

raw symbols SCIP
1 """variableTimeRatio.py
2 Shows the SimulationRT capability to change the ratio simulation
3 time to wallclock time during the run of a simulation.
4 """
5 from SimPy.SimulationRT import *
6
7 class Changer(Process):
8 def change(self,when,rat):
9 global ratio
10 yield hold,self,when
11 rtset(rat)
12 ratio=rat
13 class Series(Process):
14 def tick(self,nrTicks):
15 oldratio=ratio
16 for i in range(nrTicks):
17 tLastSim=now()
18 tLastWallclock=wallclock()
19 yield hold,self,1
20 diffSim=now()-tLastSim
21 diffWall=wallclock()-tLastWallclock
22 print "now(): %s, sim. time elapsed: %s, wall clock elapsed: "\
23 "%6.3f, sim/wall time ratio: %6.3f"\
24 %(now(),diffSim,diffWall,diffSim/diffWall)
25 if not ratio==oldratio:
26 print "At simulation time %s: ratio simulation/wallclock "\
27 "time now changed to %s"%(now(),ratio)
28 oldratio=ratio
29 initialize()
30 ticks=15
31 s=Series()
32 activate(s,s.tick(nrTicks=ticks))
33 c=Changer()
34 activate(c,c.change(5,5))
35 c=Changer()
36 activate(c,c.change(10,10))
37 ratio=1
38 print "At simulation time %s: set ratio simulation/wallclock time to %s"\
39 %(now(),ratio)
40 simulate(until=100,real_time=True,rel_speed=ratio)