def generate(self, number, interval): rv = Random(self.SEED) for i in range(number): c = Customer(name="Customer%02d" % (i,)) Simulation.activate(c, c.visit(timeInBank=12.0)) t = rv.expovariate(1.0 / interval) yield Simulation.hold, self, t
def model(): Simulation.initialize() c1 = Customer(name="Klaus") Simulation.activate(c1, c1.visit(timeInBank=10.0), delay=5.0) c2 = Customer(name="Tony") Simulation.activate(c2, c2.visit(timeInBank=8.0), delay=2.0) c3 = Customer(name="Evelyn") Simulation.activate(c3, c3.visit(timeInBank=20.0), delay=12.0) Simulation.simulate(until=400.0)
def visit(self, timeInBank=0): arrive = Simulation.now() print("%7.4f %s: Here I am " % (Simulation.now(), self.name)) yield Simulation.request, self, counter wait = Simulation.now() - arrive print("%7.4f %s: Waited %6.3f" % (Simulation.now(), self.name, wait)) tib = counterRV.expovariate(1.0 / timeInBank) yield Simulation.hold, self, tib yield Simulation.release, self, counter print("%7.4f %s: Finished" % (Simulation.now(), self.name))
def pytest_funcarg__sim(request): if request.param == 'default': return Simulation.Simulation() elif request.param == 'step': return SimulationStep.SimulationStep() elif request.param == 'trace': return SimulationTrace.SimulationTrace() elif request.param == 'rt': return SimulationRT.SimulationRT() elif request.param.startswith('global'): if request.param.endswith('default'): Globals.sim = Simulation.Simulation() elif request.param.endswith('step'): Globals.sim = SimulationStep.SimulationStep() elif request.param.endswith('trace'): Globals.sim = SimulationTrace.SimulationTrace() elif request.param.endswith('rt'): Globals.sim = SimulationRT.SimulationRT() return Globals.sim
def model(counterseed=3939393): global counter, counterRV counter = Simulation.Resource(name="Clerk", capacity=2) # Lcapacity counterRV = Random(counterseed) Simulation.initialize() sourceseed = 1133 source = Source(seed=sourceseed) Simulation.activate(source, source.generate(5, 10.0), 0.0) Simulation.simulate(until=400.0)
neuron_producing = Neuron('inhibitory', i, in_settings, 'off') if inhi == 'on': inhibitory.append(neuron_producing) for inhibitee in random.sample(excitatory_a+excitatory_b, 20): inhibitee.connect(neuron_producing) neuron_producing.connect(inhibitee) all_neuron = excitatory_a + excitatory_b + inhibitory + downstream + noise duration = 2400 for i in range(duration): for neuron in all_neuron: event = Event(name = 'update') simpy.activate(event, event.update(neuron), delay = i) print("simulation scheduled.") simpy.simulate(until = duration+0.0) print("simulation done.") #ex_spikes_number = 0.0 #for i in excitatory_a+excitatory_b: #ex_spikes_number += i.spikes_number #ds_spikes_number = 0.0 #for i in downstream: #ds_spikes_number += i.spikes_number #print ds_spikes_number/ex_spikes_number
def visit(self, timeInBank=0): print("%7.4f %s: Here I am" % (Simulation.now(), self.name)) yield Simulation.hold, self, timeInBank print("%7.4f %s: I must leave" % (Simulation.now(), self.name))
def go(self): print("{0} {1} Starting".format(sim.now(), self.name)) yield sim.hold, self, 100.0 print("{0} {1} Arrived".format(sim.now(), self.name))
sim1.py Created by Jakub Konka on 2011-04-20. Copyright (c) 2011 University of Strathclyde. All rights reserved. """ import sys import os import SimPy.SimulationTrace as sim class Car(sim.Process): def __init__(self, name, cc): sim.Process.__init__(self, name=name) self.cc = cc def go(self): print("{0} {1} Starting".format(sim.now(), self.name)) yield sim.hold, self, 100.0 print("{0} {1} Arrived".format(sim.now(), self.name)) if __name__ == '__main__': sim.initialize() car1 = Car("Car1", 2000) sim.activate(car1, car1.go(), at=6.0) car2 = Car("Car2", 1600) sim.activate(car2, car2.go()) sim.simulate(until=200) print("Current time is {0}".format(sim.now()))
class Client(Simulation.Process): def __init__(self, name): Simulation.Process.__init__(self, name) def getServed(self, tank): yield (Simulation.get, self, tank, 10), (Simulation.hold, self, 1.5) if self.acquired(tank): print("%s got 10 %s" % (self.name, tank.unitName)) else: print("%s reneged" % self.name) class Filler(Simulation.Process): def __init__(self, name): Simulation.Process.__init__(self, name) def fill(self, tank): for i in range(3): yield Simulation.hold, self, 1 yield Simulation.put, self, tank, 10 Simulation.initialize() tank = Simulation.Level(name="Tank", unitName="gallons") for i in range(2): c = Client("Client %s" % i) Simulation.activate(c, c.getServed(tank)) f = Filler("Tanker") Simulation.activate(f, f.fill(tank)) Simulation.simulate(until=10)
if __name__ == "__main__": import random as r r.seed(1234567) class Test(Process): def run(self): while self.sim.now() < until: yield hold, self, r.uniform(1, 10) class Waiter(Process): def run(self, evt): def gt30(): return self.sim.now() > 30 yield waituntil, self, gt30 print("now() is past 30") self.sim.stopSimulation() until = 100 s = SimulationTrace() s.initialize() evt = SimEvent(sim=s) t = Test("Test1", sim=s) s.activate(t, t.run()) t2 = Test("Test2", sim=s) s.activate(t2, t2.run()) w = Waiter("Waiter", sim=s) s.activate(w, w.run(evt=evt)) stepper(whichsim=s)
Simulation.trace.ttext("<%s> has arrived" % self.name) class Breakdown(Simulation.Process): def __init__(self, myBus): Simulation.Process.__init__(self, name="Breakdown " + myBus.name) self.bus = myBus def breakBus(self, interval): while True: Simulation.trace.ttext("Breakdown process waiting for %s" % interval) yield Simulation.hold, self, interval if self.bus.terminated(): break Simulation.trace.ttext("Breakdown of %s" % self.bus.name) self.interrupt(self.bus) print("\n\n+++test_interrupt") Simulation.initialize() b = Bus("Bus 1") Simulation.trace.ttext("Start %s" % b.name) Simulation.activate(b, b.operate(repairduration=20)) br = Breakdown(b) Simulation.trace.ttext("Start the Breakdown process for %s" % b.name) Simulation.activate(br, br.breakBus(200)) Simulation.trace.start = 100 print(Simulation.simulate(until=4000))
if __name__ == "__main__": import random as r r.seed(1234567) class Test(Process): def run(self): while self.sim.now() < until: yield hold,self,r.uniform(1,10) class Waiter(Process): def run(self,evt): def gt30(): return self.sim.now() > 30 yield waituntil,self,gt30 print("now() is past 30") self.sim.stopSimulation() until = 100 s = SimulationTrace() s.initialize() evt = SimEvent(sim=s) t=Test("Test1", sim=s) s.activate(t,t.run()) t2=Test("Test2", sim=s) s.activate(t2,t2.run()) w=Waiter("Waiter", sim=s) s.activate(w,w.run(evt=evt)) stepper(whichsim=s)
import unittest if __debug__: import SimPy.SimulationTrace as Sim else: import SimPy.Simulation as Sim import pyprt.sim.layout as layout import pyprt.sim.vehicle as vehicle Sim.initialize() class StationTest(unittest.TestCase): def setUp(self): self.s = layout.Station(ID=1, length=68, max_speed=100, x=0, y=0, label='', v_adv_time=0.5, unload_size=3, queue_size=3, load_size=3, storage_size=5, policy='QUEUE') def test_advance_queue_no_vehicles(self): # No vehicles, no change q = self.s.queue