def model(): SimulationRT.initialize() for i in range(nrLaunchers): lau = Launcher() SimulationRT.activate(lau, lau.launch()) SimulationRT.simulate(real_time=True, rel_speed=1, until=20) # unit sim time = 1 sec clock
def test_ticker(): """Tests SimulationRT for degree to which simulation time and wallclock time can be synchronized.""" rel_speed = 10 sim_slow = SimulationRT() t = Ticker(sim=sim_slow) sim_slow.activate(t, t.tick()) sim_slow.simulate(until=10, real_time=True, rel_speed=rel_speed) for tSim, tRT in t.timing: assert tSim / tRT > rel_speed - 1 rel_speed = 20 sim_fast = SimulationRT() sim_fast.initialize() t = Ticker(sim=sim_fast) sim_fast.activate(t, t.tick()) sim_fast.simulate(until=10, real_time=True, rel_speed=rel_speed) for tSim, tRT in t.timing: assert tSim / tRT > rel_speed - 1
def test_ticker(): """Tests SimulationRT for degree to which simulation time and wallclock time can be synchronized.""" rel_speed = 10 sim_slow=SimulationRT() t=Ticker(sim=sim_slow) sim_slow.activate(t,t.tick()) sim_slow.simulate(until=10,real_time=True,rel_speed=rel_speed) for tSim, tRT in t.timing: assert tSim/tRT > rel_speed - 1 rel_speed = 20 sim_fast=SimulationRT() sim_fast.initialize() t=Ticker(sim=sim_fast) sim_fast.activate(t,t.tick()) sim_fast.simulate(until=10,real_time=True,rel_speed=rel_speed) for tSim, tRT in t.timing: assert tSim/tRT > rel_speed - 1
class Series(SimulationRT.Process): def tick(self, nrTicks): oldratio = ratio for i in range(nrTicks): tLastSim = SimulationRT.now() tLastWallclock = SimulationRT.wallclock() yield SimulationRT.hold, self, 1 diffSim = SimulationRT.now() - tLastSim diffWall = SimulationRT.wallclock() - tLastWallclock print("now(): %s, sim. time elapsed: %s, wall clock elapsed: " "%6.3f, sim/wall time ratio: %6.3f" % (SimulationRT.now(), diffSim, diffWall, diffSim / diffWall)) if not ratio == oldratio: print("At simulation time %s: ratio simulation/wallclock " "time now changed to %s" % (SimulationRT.now(), ratio)) oldratio = ratio SimulationRT.initialize() ticks = 15 s = Series() SimulationRT.activate(s, s.tick(nrTicks=ticks)) c = Changer() SimulationRT.activate(c, c.change(5, 5)) c = Changer() SimulationRT.activate(c, c.change(10, 10)) ratio = 1 print("At simulation time %s: set ratio simulation/wallclock time to %s" % (SimulationRT.now(), ratio)) SimulationRT.simulate(until=100, real_time=True, rel_speed=ratio)
stateData = [] for i in range(0,numOfSamples): stateData.append([time[i], data[i]]) # Algorithm parameter #------------------------------------------------------------------------------ # Simulation maxTime = 2000.0 # Algorithm txRate = 50 # Simulation #------------------------------------------------------------------------------ simpy.initialize() # Create hosts hostA = Host(name='HostA') hostB = Host(name='HostB') # Create network network = Network() Host.network = network Transmitter.network = network a_b_link = Link(hostFrom=hostA, hostTo=hostB, delay=100, jitter=10, packetLoss=0) b_a_link = Link(hostFrom=hostB, hostTo=hostA, delay=100, jitter=10, packetLoss=0) network.links.append(a_b_link) network.links.append(b_a_link) # Create algorithms