def __init__(self, time, payload, *args, **kwargs): super(AlarmClock, self).__init__(name="AlarmClock") self.time = time self.payload = payload self.args = args self.kwargs = kwargs Sim.activate(self, self.ring())
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 _request_vehicle(self, pos, loc): """Request that a vehicle be moved to pos on loc. The effect takes place immediately. To simulate a delay, see reserve_vehicle. """ v = None if len(self._storage_track.vehicles): v = self._storage_track.vehicles[0] v._move_to(pos, loc) v._operational_times.append((Sim.now(), True)) else: # create a new vehicle v_id = max(vehicle.ID for vehicle in common.vehicles.itervalues()) + 1 v = common.vehicle_models[self.model_name](ID=v_id, loc=loc, position=pos, vel=0) common.vehicles[v_id] = v common.vehicle_list.append(v) Sim.activate(v, v.ctrl_loop()) self._num_pending_exit -= 1 self._num_vehicles -= 1 assert 0 <= self._num_vehicles - self._num_pending_exit <= self.max_capacity return v
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)
def startup(self): # upon station activation, activate berths for platform in self.platforms: for berth in platform.berths: Sim.activate(berth, berth.run())
def simTransmission(self, receiver, packet): if not self.simPacketLoss(): packet.rxTime = packet.txTime + self.simDelay() receivePacket = ReceivePacket(receiver=receiver, packet=packet) simpy.activate(receivePacket, receivePacket.run())
# 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 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)
def startup(self): """Activates all the berths""" for platform in self.platforms: for berth in platform.berths: Sim.activate(berth, berth.run())