Esempio n. 1
0
def main(argv):

    lamb = float(argv[1])  # Arrival rate
    mu = float(argv[2])  # Service rate

    hist = histogram.Histogram(60 + 1)
    q = linkedlistqueue.Queue()
    stddraw.createWindow(700, 500)

    nextArrival = stdrandom.exp(lamb)  # Time of next arrival
    nextService = nextArrival + 1.0 / mu  # Time of next completed service

    # Simulate the M/D/1 queue
    while True:

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

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

        # Update the histogram.
        stddraw.clear()
        hist.addDataPoint(min([60, int(wait + 0.5)]))
        hist.draw()
        #stddraw.sleep(20)
        stddraw.sleep(20)
        stddraw.show()
        # Update the queue.
        if q.isEmpty():
            nextService = nextArrival + 1.0 / mu
        else:
            nextService = nextService + 1.0 / mu
Esempio n. 2
0
def main(argv):

    lamb = float(argv[1])  # Arrival rate
    mu = float(argv[2])    # Service rate

    hist = histogram.Histogram(60 + 1)
    q = linkedlistqueue.Queue()
    stddraw.createWindow(700, 500)

    nextArrival = stdrandom.exp(lamb)  # Time of next arrival
    nextService = nextArrival + 1.0/mu # Time of next completed service

    # Simulate the M/D/1 queue
    while True:

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

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

        # Update the histogram.
        stddraw.clear()
        hist.addDataPoint(min([60, int(wait+0.5)]))
        hist.draw()
        #stddraw.sleep(20)
        stddraw.sleep(20)
        stddraw.show()
        # Update the queue.
        if q.isEmpty():
            nextService = nextArrival + 1.0/mu
        else:
            nextService = nextService + 1.0/mu
Esempio n. 3
0
import stdrandom
from linkedqueue import Queue
from histogram import Histogram

# Accept float command-line arguments lamb and mu. Simulate an
# M/M/1 queue with arrival rate lamb and service rate mu.

lamb = float(sys.argv[1])  # Arrival rate
mu = float(sys.argv[2])    # Service rate

histogram = Histogram(60 + 1)
queue = Queue()
stddraw.setCanvasSize(700, 500)

# Compute time of next arrival.
nextArrival = stdrandom.exp(lamb)

# Compute time of next completed service.
nextService = nextArrival + stdrandom.exp(mu) 

# 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()
Esempio n. 4
0
queue = Queue()

empty_system_time = 0
empty_system_prob_dict = {}
system_time = 0
system_time_list = []
service_list = []
clients_in_system_list = []
clients_in_queue_list = []

clients_in_system = 0
clients_in_queue = 0
system_usage = arrv_rate / srv_time

# generowanie czasu pierwszego zgłoszenia i czasu obsługi
next_client = stdrandom.exp(arrv_rate)
next_service = next_client + stdrandom.exp(srv_time)
# obliczenie czasu obługi dla pierwszego kilenta
service_duration = next_service - next_client
service_list.append(service_duration)

server_empty = next_client > next_service

while next_client < limit:

    print(
        f"Simulation completion: {int(round((next_client / limit) * 100))} %",
        end='\r')

    while not server_empty:
        queue.enqueue(next_client)
import stdrandom
from linkedqueue import Queue
from histogram import Histogram

# Accept float command-line arguments lamb and mu. Simulate an
# M/M/1 queue with arrival rate lamb and service rate mu.

lamb = float(sys.argv[1])  # Arrival rate
mu = float(sys.argv[2])  # Service rate

histogram = Histogram(60 + 1)
queue = Queue()
stddraw.setCanvasSize(700, 500)

# Compute time of next arrival.
nextArrival = stdrandom.exp(lamb)

# Compute time of next completed service.
nextService = nextArrival + stdrandom.exp(mu)

# 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()