Exemple #1
0
while True:

    # Next event is an arrival.
    while nextArrival < nextService:
        # Simulate an arrival
        queue.enqueue(nextArrival)
        nextArrival += stdrandom.exp(lamb)

    # Next event is a service completion.
    arrival = queue.dequeue()
    wait = nextService - arrival

    # Update the histogram.
    stddraw.clear(stddraw.LIGHT_GRAY)
    histogram.addDataPoint(min(60, int(round(wait))))
    histogram.draw()
    stddraw.show(20.0)

    # Update the queue.
    if queue.isEmpty():
        nextService = nextArrival + stdrandom.exp(mu)
    else:
        nextService = nextService + stdrandom.exp(mu)


#-----------------------------------------------------------------------

# python mm1queue.py .167 .25

# python mm1queue.py .167 .20
# Simulate the M/M/1 queue.
while True:

    # Next event is an arrival.
    while nextArrival < nextService:
        # Simulate an arrival
        queue.enqueue(nextArrival)
        nextArrival += stdrandom.exp(lamb)

    # Next event is a service completion.
    arrival = queue.dequeue()
    wait = nextService - arrival

    # Update the histogram.
    stddraw.clear(stddraw.LIGHT_GRAY)
    histogram.addDataPoint(min(60, int(round(wait))))
    histogram.draw()
    stddraw.show(20.0)

    # Update the queue.
    if queue.isEmpty():
        nextService = nextArrival + stdrandom.exp(mu)
    else:
        nextService = nextService + stdrandom.exp(mu)

#-----------------------------------------------------------------------

# python mm1queue.py .167 .25

# python mm1queue.py .167 .20