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)
Beispiel #5
0
# Create algorithms
transmitter = Transmitter(name='SynchA')
simpy.activate(transmitter, transmitter.run(stateData, txRate))
if realTimeMode:
	receiver = ReceiverRT(name='SnapB')
	plotter = Plotter(name='ReceivedData')
	simpy.activate(receiver, receiver.run(samplingInterval=samplingInterval, plotter=plotter))
	simpy.activate(plotter, plotter.run(timeStep=1000))
else:
	receiver = Receiver('SnapB')

# Connect hosts
hostA.addSimplexPath(name='SimplePath', remoteHost=hostB, transmitter=transmitter, receiver=receiver)

if realTimeMode:
	simpy.simulate(real_time=True,rel_speed=12, until=maxTime)
else:
	simpy.simulate(until=maxTime)


# Analysis
#------------------------------------------------------------------------------
source = hostA.sources[0]
session = source.sinks[0].session
packets = session.transmittedPackets

print "\n"
for packet in packets:
	print str(packet)