コード例 #1
0
        yield hold, self, tib
        yield release, self, counter

        # print "%8.4f %s: Finished    "%(now(),self.name)


## Experiment data -------------------------

maxTime = 400.0  # minutes
counter = Resource(1, name="Clerk", monitored=True)

## Model -----------------------------------


def model(SEED=393939):
    seed(SEED)

    initialize()
    source = Source()
    activate(source, source.generate(number=20, rate=0.1), at=0.0)
    simulate(until=maxTime)


## Experiment -----------------------------------

model()

plt = SimPlot()
plt.plotStep(counter.waitMon, color="red", width=2)
plt.mainloop()
コード例 #2
0

# Model -----------------------------------


class BankModel(Simulation):
    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)


# Experiment data -------------------------

maxTime = 400.0  # minutes
seedVal = 393939

# Experiment -----------------------------------

mymodel = BankModel()
mymodel.run(aseed=seedVal)

# Output ---------------------------------------

plt = SimPlot()
plt.plotStep(mymodel.counter.waitMon, color="red", width=2)
plt.mainloop()
コード例 #3
0
tShopOpen = 8
tBeforeOpen = 1
tEndBake = tBeforeOpen + tShopOpen  # hours
nrDays = 100
r = random.Random(12371)
PLOTTING = True
# Experiment
waits = {}
waits["retail"] = []
waits["restaurant"] = []
for day in range(nrDays):
    bakery = model()
# Analysis/output
print("bakery")
for cType in ["retail", "restaurant"]:
    print("Average wait for {0} customers: {1:4.2f} hours".format(
        cType, (1.0 * sum(waits[cType])) / len(waits[cType])))
    print("Longest wait for {0} customers: {1:4.1f} hours".format(
        cType, max(waits[cType])))
    nrLong = len([1 for x in waits[cType] if x > 0.25])
    nrCust = len(waits[cType])
    print("Percentage of {0} customers having to wait for more than"
          " 0.25 hours: {1}".format(cType, 100 * nrLong / nrCust))

if PLOTTING:
    plt = SimPlot()
    plt.plotStep(bakery.stock.bufferMon,
                 title="Number of baguettes in stock during arbitrary day",
                 color="blue")
    plt.mainloop()
コード例 #4
0
# Prog3.py
from SimPy.SimPlot import *
plt = SimPlot()
plt.plotStep([[0, 0], [1, 1], [2, 4], [3, 9]], color="red", width=2)
plt.mainloop()
コード例 #5
0
# Monitorplot.py
from random import uniform
from SimPy.Simulation import *
from SimPy.Recording import *
from SimPy.SimPlot import *


class Source(Process):
    def __init__(self, monitor):
        Process.__init__(self)
        self.moni = monitor
        self.arrived = 0

    def arrivalGenerator(self):
        while True:
            yield hold, self, uniform(0, 20)
            self.arrived += 1
            self.moni.observe(self.arrived)


initialize()
moni = Monitor(name="Arrivals", ylab="nr arrived")
s = Source(moni)
activate(s, s.arrivalGenerator())
simulate(until=100)

plt = SimPlot()
plt.plotStep(moni, color='blue')
plt.mainloop()
コード例 #6
0
tBakeMin = 25/60.; tBakeMax=30/60.                                #hours
tArrivals = {"retail":1.0/40,"restaurant":1.0/4}                  #hours
buy = {"retail":[1,2,3],"restaurant":[20,40,60]}                 #nr baguettes
tShopOpen = 8; tBeforeOpen = 1; tEndBake = tBeforeOpen+tShopOpen  #hours
nrDays=100
r=random.Random(12371)
PLOTTING=True
## Experiment ------------------------------
waits={}
waits["retail"]=[]; waits["restaurant"]=[]
bakMod = BakeryModel()
for day in range(nrDays):
    bakery = bakMod.run()
## Analysis/output -------------------------
print 'bakery_OO'
for cType in ["retail","restaurant"]:
    print "Average wait for %s customers: %4.2f hours"\
    %(cType,(1.0*sum(waits[cType]))/len(waits[cType]))
    print "Longest wait for %s customers: %4.1f hours"%(cType,max(waits[cType]))
    nrLong = len([1 for x in waits[cType] if x>0.25])
    nrCust = len(waits[cType])
    print "Percentage of %s customers having to wait for more than 0.25 hours: %s"\
           %(cType,100*nrLong/nrCust)    


if PLOTTING:
    plt = SimPlot()
    plt.plotStep(bakery.stock.bufferMon,
             title="Number of baguettes in stock during arbitrary day",color="blue")
    plt.mainloop()
コード例 #7
0
ファイル: bank16.py プロジェクト: weimingtom/simpy
        yield hold, self, tib
        yield release, self, counter

        #print("%8.4f %s: Finished    " % (now(), self.name))

## Experiment data -------------------------

maxTime = 400.0   # minutes
counter = Resource(1, name="Clerk", monitored=True)

## Model -----------------------------------


def model(SEED=393939):
    seed(SEED)

    initialize()
    source = Source()
    activate(source,
             source.generate(number=20, rate=0.1), at=0.0)
    simulate(until=maxTime)

## Experiment -----------------------------------

model()

plt = SimPlot()
plt.plotStep(counter.waitMon,
        color="red", width=2)
plt.mainloop()
コード例 #8
0
ファイル: bank16.py プロジェクト: SimPyClassic/SimPyClassic
# Experiment data -------------------------

maxTime = 400.0  # minutes
counter = Resource(1, name="Clerk", monitored=True)

# Model -----------------------------------


def model(SEED=393939):  # 3
    seed(SEED)
    initialize()
    source = Source()
    activate(
        source,  # 4
        source.generate(number=20, rate=0.1),
        at=0.0)
    simulate(until=maxTime)  # 5


# Experiment -----------------------------------

model()

plt = SimPlot()  # 6
plt.plotStep(
    counter.waitMon,  # 7
    color="red",
    width=2)  # 8
plt.mainloop()  # 9