-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_optimize_simple1.py
63 lines (42 loc) · 1.6 KB
/
example_optimize_simple1.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
# Simple optimization example (finding the solution by iteration)
# The waiting times and the number of operators are each assigned a cost.
# The search is for the number of operators for which the costs become minimal.
# Importing modules
# Processing results arrays
import numpy as np
# Simulator
from queuesim import Simulator
from queuesim.tools import SimProcess, run_parallel
# Station types
from queuesim.stations import Source, Process, Dispose
from queuesim.models import mmc_model
# Plot model
import matplotlib.pyplot as plt
import seaborn as sns
# Defining general plot style
sns.set()
# Model parameters
# Arrivals to be simulated
count = 100_000
# Arrival process
mean_I = 50
# Service process
mean_S = 600
# Costs
cost_waiting = 10 # Costs per waiting second
cost_c = 120 # Costs per operator
# Definition of the $x$ range (=number of operators)
c_range = range(14, 25)
if __name__ == '__main__':
# Parallel simulation of the models
models, simulators = run_parallel([SimProcess(mmc_model(mean_I, mean_S, c, count)) for c in c_range])
# Processing results
waiting_times = np.array([model['Dispose'].statistic_client_waiting.mean for model in models])
costs = waiting_times * cost_waiting + np.array(c_range) * cost_c
# Output of results
print("Cost-optimal number of operators:", c_range[np.argmin(costs)])
print("Analyzed range:", c_range[0], "...", c_range[-1])
fig, ax = plt.subplots(figsize=(16, 9))
ax.plot(c_range, costs)
ax.set(title="Costs as a function of the number of operators", xlabel="Number of operators $c$", ylabel="Costs")
plt.show()