-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_sim_mmc_priorities2.py
86 lines (61 loc) · 2.25 KB
/
example_sim_mmc_priorities2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Different priorities for different client types
# Importing modules
# Simulation
from queuesim.random_dist import exp as dist_exp
from queuesim.descore import Simulator
from queuesim.stations import Source, Process, DecideClientType, Dispose
# Plot model
from queuesim import build_graph
import networkx as nx
import matplotlib.pyplot as plt
# Model parameters
# Mean inter-arrival time
mean_i = 100
# Mean service time
mean_s = 80
# Number of operators
c = 1
# Number of arrivals to be simulated
count = 100_000
# Priority formula
# For type A clients, each waiting second has 5 times more value in terms of service priority than for type B clients.
def priority(client, waiting_time):
if client.type_name == "ClientsA":
return 5 * waiting_time
else:
return waiting_time
# Building model
# Define parameters
get_i = dist_exp(mean_i * 2) # average inter-arrival time mean_i is for both client types together. mean_i*2 is for a single client type.
get_s = dist_exp(mean_s)
# Create and configure stations
simulator = Simulator()
source1 = Source(simulator, count / 2, get_i, client_type_name="ClientsA")
source2 = Source(simulator, count / 2, get_i, client_type_name="ClientsB")
process = Process(simulator, get_s, c, getPriority=priority)
decide = DecideClientType(simulator)
dispose1 = Dispose(simulator)
dispose2 = Dispose(simulator)
# Link stations
source1.set_next(process)
source2.set_next(process)
process.set_next(decide)
decide.set_next("ClientsA", dispose1)
decide.set_next("ClientsB", dispose2)
# Simulation
# Run simulation
simulator.run()
# Show results
print("ClientsA")
print(" Service times (S): " + dispose1.statistic_client_service.info)
print(" Residence times (V): " + dispose1.statistic_client_residence.info)
print(" Waiting times (W): " + dispose1.statistic_client_waiting.info)
print("ClientsB")
print(" Service times (S): " + dispose2.statistic_client_service.info)
print(" Residence times (V): " + dispose2.statistic_client_residence.info)
print(" Waiting times (W): " + dispose2.statistic_client_waiting.info)
# Queueing network model
dg = build_graph([source1, source2])
fig, ax = plt.subplots(figsize=(19, 9))
nx.draw(dg, ax=ax, with_labels=True, node_color='#CCCCFF', node_size=2000, arrowsize=30, width=2)
plt.show()