def __init__(self, graph, s):
     self._distTo = dict()
     self._edgeTo = dict()
     queue = Queue()
     queue.enqueue(s)
     self._distTo[s] = 0
     self._edgeTo[s] = None
     while not queue.isEmpty():
         v = queue.dequeue()
         for w in graph.adjacentTo(v):
             if w not in self._distTo:
                 queue.enqueue(w)
                 self._distTo[w] = 1 + self._distTo[v]
                 self._edgeTo[w] = v
Ejemplo n.º 2
0
 def __init__(self, graph, s):
     self._distTo = dict()
     self._edgeTo = dict()
     queue = Queue()
     queue.enqueue(s)
     self._distTo[s] = 0
     self._edgeTo[s] = None
     while not queue.isEmpty():
         v = queue.dequeue()
         for w in graph.adjacentTo(v):
             if w not in self._distTo:
                 queue.enqueue(w)
                 self._distTo[w] = 1 + self._distTo[v]
                 self._edgeTo[w] = v
Ejemplo n.º 3
0
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()
    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)

Ejemplo n.º 4
0
while next_client < limit:

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

    while not server_empty:
        queue.enqueue(next_client)
        next_client += stdrandom.exp(arrv_rate)
        server_empty = next_client > next_service
        clients_in_system += 1
        if len(queue) > 1:
            clients_in_queue += 1

    # obsługa pierwszego w kolejce klienta
    current_client = queue.dequeue()
    clients_in_system -= 1
    if len(queue) > 0:
        clients_in_queue -= 1

    # czas przebywania w systemie = czas kiedy klient zostanie obsłużony - czas przybycia klienta
    system_time = next_service - current_client

    if queue.isEmpty():

        # jeżeli kolejka jest pusta, to system obsłuży obecnego klienta szybciej niż nowy napłynie
        # wtedy system będzie pusty do czasu napływu nowego klienta
        empty_system_time += next_client - next_service

        # lista p-stwa pustego systemu w czasie P(t) = czas kiedy system jest pusty/całkowity czas symulacji
        empty_system_prob_dict[next_service] = empty_system_time / next_service
Ejemplo n.º 5
0
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()
    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)

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