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