simulation wrapper, response time depending on arrival rate plot
This commit is contained in:
41
src/main.py
41
src/main.py
@@ -1,6 +1,7 @@
|
||||
#!/bin/python3
|
||||
import random
|
||||
from heapq import heappush, heappop
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
class Event:
|
||||
def __init__(self, event_type, request):
|
||||
@@ -56,7 +57,7 @@ class Simulation:
|
||||
self.total_requests += 1
|
||||
if len(self.router_queue) == 0 and self.router_state == "idle":
|
||||
self.router_process(request)
|
||||
elif ((len(self.router_queue) + + (self.router_state == "processing")) < 100):
|
||||
elif ((len(self.router_queue) + (self.router_state == "processing")) < 100):
|
||||
self.router_queue.append(request)
|
||||
else:
|
||||
self.lost_requests += 1
|
||||
@@ -128,6 +129,44 @@ class Simulation:
|
||||
|
||||
|
||||
|
||||
def simulation_wrapper():
|
||||
C_values = [1, 2, 3, 6]
|
||||
simulation_time = 10000
|
||||
|
||||
lambda_vals = [l / 100 for l in range(1, 301)]
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
|
||||
for c in C_values:
|
||||
lambda_values = []
|
||||
mean_response_times = []
|
||||
print(f"Processing C={c}...")
|
||||
for lambda_val in lambda_vals:
|
||||
try:
|
||||
sim = Simulation(c, lambda_val)
|
||||
sim.run(simulation_time)
|
||||
|
||||
if not sim.response_times:
|
||||
print(f"No completed requests for C={c}, λ={lambda_val:.2f}")
|
||||
continue
|
||||
|
||||
mean_rt = sum(sim.response_times) / len(sim.response_times)
|
||||
lambda_values.append(lambda_val)
|
||||
mean_response_times.append(mean_rt)
|
||||
print(f"C={c}, λ={lambda_val:.2f}, Mean RT={mean_rt:.2f}, Loss Rate={sim.loss_rate:.2%}")
|
||||
except ValueError as e:
|
||||
print(f"Stopped at λ={lambda_val:.2f} for C={c}: {str(e)}")
|
||||
break
|
||||
|
||||
plt.plot(lambda_values, mean_response_times, marker='.', linestyle='-', label=f'C={c}')
|
||||
|
||||
plt.xlabel('Arrival Rate (λ)')
|
||||
plt.ylabel('Mean Response Time')
|
||||
plt.title('Mean Response Time depending on Arrival Rate for different configurations of C (number of clusters)')
|
||||
plt.legend()
|
||||
plt.grid(True)
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user