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
Esempio 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
Esempio n. 3
0
    # 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

Esempio n. 4
0
        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

        prev_service_time = next_service
        next_service = next_client + stdrandom.exp(srv_time)
        # jak kolejka jest pusta to czas trawnia obsługi = czas wyjścia - czas przyjścia
        service_duration = next_service - next_client

    else:
        prev_service_time = 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)
        next_client += stdrandom.exp(arrv_rate)
        server_empty = next_client > next_service
        clients_in_system += 1
        if len(queue) > 1:
            clients_in_queue += 1

    # sprawdzamy czy w systemie jest jakiś klient, czy będzie obsługiwany klient wyimaginowany
    if not queue.isEmpty():
        current_client = queue.dequeue()
        if len(queue) > 0:
            clients_in_queue -= 1
        clients_in_system -= 1
        # czas przebywania w systemie = czas kiedy klient zostanie obsłużony - czas przybycia klienta
        system_time = next_service - current_client
        real_client = True

    if queue.isEmpty():

        prev_service_time = next_service

        # jeżeli kolejka jest pusta i system obsłuży klienta szybciej niż nowy napłynie to wtedy system ma obsłużyć
        # wyimaginowanego klienta
        if next_service < next_client: