예제 #1
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.kk = [Resource(name="Clerk0", sim=self),
                Resource(name="Clerk1", sim=self)]
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=maxNumber, interval=ARRint), at=0.0)
     self.simulate(until=maxTime)
예제 #2
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.counter = Resource(1, name="Clerk", monitored=True, sim=self)
     source = Source(sim=self)
     self.activate(source, source.generate(number=20, rate=0.1), at=0.0)
     self.simulate(until=maxTime)
예제 #3
0
파일: bank07_OO.py 프로젝트: yeungsl/simpy
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.k = Resource(name="Counter", unitName="Clerk", sim=self)
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=maxNumber, meanTBA=ARRint), at=0.0)
     self.simulate(until=maxTime)
예제 #4
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.counter = Resource(name="Karen", sim=self)
     source = Source('Source', sim=self)
     self.activate(source, source.generate(number=5, interval=10.0), at=0.0)
     self.simulate(until=maxTime)
예제 #5
0
파일: bank11_OO.py 프로젝트: yeungsl/simpy
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.k = Resource(capacity=Nc, name="Clerk", sim=self)
     self.wM = Monitor(sim=self)
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=maxNumber, interval=ARRint), at=0.0)
     self.simulate(until=maxTime)
예제 #6
0
 def run(self, aseed):
     self.initialize()
     seed(aseed)
     self.k = Resource(capacity=Nc, name="Clerk", sim=self)
     self.wM = Monitor(sim=self)
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=maxNumber, interval=ARRint), at=0.0)
     self.simulate(until=maxTime)
     return (self.wM.count(), self.wM.mean())
예제 #7
0
파일: bank13_OO.py 프로젝트: yeungsl/simpy
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.dooropen = SimEvent("Door Open", sim=self)
     self.counter = Resource(1, name="Clerk", sim=self)
     doorman = Doorman(sim=self)
     self.activate(doorman, doorman.openthedoor())
     source = Source(sim=self)
     self.activate(source, source.generate(number=5, rate=0.1), at=0.0)
     self.simulate(until=maxTime)
예제 #8
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     Customer.numBalking = 0
     self.k = Resource(capacity=numServers,
                       name="Counter",
                       unitName="Clerk",
                       sim=self)
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=maxNumber, meanTBA=ARRint), at=0.0)
     self.simulate(until=maxTime)
예제 #9
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.counter = Resource(capacity=1, name="Clerk", sim=self)
     self.door = 'Shut'
     doorman = Doorman(sim=self)
     self.activate(doorman, doorman.openthedoor())
     source = Source(sim=self)
     self.activate(source,
          source.generate(number=5, rate=0.1), at=0.0)
     self.simulate(until=400.0)
예제 #10
0
 def run(self, aseed):
     """ PEM """
     seed(aseed)
     self.k = Resource(name="Counter",
                       unitName="Karen",
                       qType=PriorityQ,
                       sim=self)
     s = Source('Source', sim=self)
     self.activate(s, s.generate(number=5, interval=10.0), at=0.0)
     guido = Customer(name="Guido     ", sim=self)
     self.activate(guido, guido.visit(timeInBank=12.0, P=100), at=23.0)
     self.simulate(until=maxTime)
예제 #11
0
 def __init__(self, cnode, ID, configs):
     IDable.__init__(self, '%s/sn%s' % (cnode.ID.split('/')[0], ID))
     Thread.__init__(self)
     RTI.__init__(self, self.ID)
     self.logger = logging.getLogger(self.__class__.__name__)
     self.system = cnode.system
     self.configs = configs
     self.cnode = cnode
     self.maxNumTxns = configs.get('max.num.txns.per.storage.node', 1024)
     self.pool = Resource(self.maxNumTxns, name='pool', unitName='thread')
     self.groups = {}  #{gid : group}
     self.newTxns = []
     self.txnsRunning = set([])
     self.shouldClose = False
     self.monitor = Profiler.getMonitor(self.ID)
     self.M_POOL_WAIT_PREFIX = '%s.pool.wait' % self.ID
     self.M_TXN_RUN_PREFIX = '%s.txn.run' % self.ID
     self.M_NUM_TXNS_RUN_KEY = '%s.num.txns' % self.ID
     self.runningThreads = set([])
     self.closeEvent = SimEvent()
     self.newTxnEvent = SimEvent()
예제 #12
0
    def initialize(self):
        CoreObject.initialize(self)
        # queue to hold the entities all through the stay of an entity in the composite object
        self.Res = Resource(self.capacity)
        # the inner Giver that will feed the compound object receiver
        self.innerGiver = None
        # the inner object that will receive the object most recently added to the self.Res.activeQ
        self.innerReceiver = None
        # entity that will passed on to the innerReceiver
        self.entityForInternalProc = None

        #         # inner queues that buffer the entities before they are handed in to the inner objects
        #         # and receive them again after the internal processing
        #         self.entryRes = Resource(self.capacity)
        #         self.exitRes = Resource(self.capacity)
        # initialize all resources
        # will have to reconsider as some of the resources may have been already initialized
        for resource in self.resources:
            if not resource.isInitialized():
                resource.initialize()
        # initialize all objects - and the entrance object
        #         self.firstObject.initialize()
        for object in self.coreObjects:
            object.initialize()
예제 #13
0
    outClients = []

    def __init__(self, name):
        Process.__init__(self, name)

    def getserved(self, servtime, myServer):
        print('%s requests 1 unit at t = %s' % (self.name, now()))
        yield request, self, myServer
        yield hold, self, servtime
        yield release, self, myServer
        print('%s done at t = %s' % (self.name, now()))


initialize()

server = Resource(capacity=1, monitored=True, monitorType=Monitor)

c1, c2 = Client(name='c1'), Client(name='c2')
c3, c4 = Client(name='c3'), Client(name='c4')

activate(c1, c1.getserved(servtime=100, myServer=server))
activate(c2, c2.getserved(servtime=100, myServer=server))
activate(c3, c3.getserved(servtime=100, myServer=server))
activate(c4, c4.getserved(servtime=100, myServer=server))

simulate(until=500)

print('')
print('(TimeAverage no. waiting: %s' % server.waitMon.timeAverage())
print('(Number) Average no. waiting: %.4f' % server.waitMon.mean())
print('(Number) Var of no. waiting: %.4f' % server.waitMon.var())
예제 #14
0
from SimPy.Simulation import (Simulation, Process, Resource, request, hold,
                              release)
"""Object Oriented SimPy API"""

# Model components -------------------------------


class Car(Process):
    def run(self, res):
        yield request, self, res
        yield hold, self, 10
        yield release, self, res
        print("Time: %s" % self.sim.now())


# Model and Experiment ---------------------------

s = Simulation()
s.initialize()
r = Resource(capacity=5, sim=s)
auto = Car(sim=s)
s.activate(auto, auto.run(res=r))
s.simulate(until=100)
예제 #15
0
    def getserved(self, servtime, priority, myServer):
        Client.inClients.append(self.name)
        print('%s requests 1 unit at t = %s' % (self.name, now()))
        # request use of a resource unit
        yield request, self, myServer, priority
        yield hold, self, servtime
        # release the resource
        yield release, self, myServer
        print('%s done at t = %s' % (self.name, now()))
        Client.outClients.append(self.name)


initialize()

# the next line creates the ``server`` Resource object
server = Resource(capacity=2)  # server defaults to qType==FIFO

# the next lines create some Client process objects
c1, c2 = Client(name='c1'), Client(name='c2')
c3, c4 = Client(name='c3'), Client(name='c4')
c5, c6 = Client(name='c5'), Client(name='c6')

# in the next lines each client requests
# one of the ``server``'s Resource units
activate(c1, c1.getserved(servtime=100, priority=1, myServer=server))
activate(c2, c2.getserved(servtime=100, priority=2, myServer=server))
activate(c3, c3.getserved(servtime=100, priority=3, myServer=server))
activate(c4, c4.getserved(servtime=100, priority=4, myServer=server))
activate(c5, c5.getserved(servtime=100, priority=5, myServer=server))
activate(c6, c6.getserved(servtime=100, priority=6, myServer=server))
예제 #16
0
from SimPy.Simulation import (Process, Resource, activate, initialize, hold,
                              now, release, request, simulate)


class Car(Process):
    def __init__(self, name, cc):
        Process.__init__(self, name=name)
        self.cc = cc

    def go(self):
        print('%s %s %s' % (now(), self.name, 'Starting'))
        yield request, self, gasstation
        print('%s %s %s' % (now(), self.name, 'Got a pump'))
        yield hold, self, 100.0
        yield release, self, gasstation
        print('%s %s %s' % (now(), self.name, 'Leaving'))


gasstation = Resource(capacity=2, name='gasStation', unitName='pump')
initialize()
c1 = Car('Car1', 2000)
c2 = Car('Car2', 1600)
c3 = Car('Car3', 3000)
c4 = Car('Car4', 1600)
activate(c1, c1.go(), at=4.0)  # activate at time 4.0
activate(c2, c2.go())  # activate at time 0.0
activate(c3, c3.go(), at=3.0)  # activate at time 3.0
activate(c4, c4.go(), at=3.0)  # activate at time 2.0
simulate(until=300)
print('Current time is %s' % now())
예제 #17
0
from SimPy.Simulation import (PriorityQ, Process, Resource, activate,
        initialize, hold, now, release, request, simulate)


class Client(Process):
    def __init__(self, name):
        Process.__init__(self, name)

    def getserved(self, servtime, priority, myServer):
        print('%s requests 1 unit at t=%s' % (self.name, now()))
        yield request, self, myServer, priority
        yield hold, self, servtime
        yield release, self, myServer
        print('%s done at t=%s' % (self.name, now()))


initialize()
# create the *server* Resource object
server = Resource(capacity=1, qType=PriorityQ, preemptable=1)
# create some Client process objects
c1 = Client(name='c1')
c2 = Client(name='c2')
activate(c1, c1.getserved(servtime=100, priority=1, myServer=server), at=0)
activate(c2, c2.getserved(servtime=100, priority=9, myServer=server), at=50)
simulate(until=500)
예제 #18
0
from SimPy.Simulation import (activate, hold, initialize, now, request,
                              release, simulate, Process, Resource)
"""Traditional SimPy API"""

# Model components -------------------------------


class Car(Process):
    def run(self, res):
        yield request, self, res
        yield hold, self, 10
        yield release, self, res
        print("Time: %s" % now())


# Model and Experiment ---------------------------

initialize()
r = Resource(capacity=5)
auto = Car()
activate(auto, auto.run(res=r))
simulate(until=100)