benedictpepper commited on
Commit
1a72a61
·
1 Parent(s): 5ca99dc
Files changed (3) hide show
  1. README.md +20 -7
  2. docs/guidebook.pdf +2 -2
  3. simulator.py +70 -29
README.md CHANGED
@@ -11,34 +11,47 @@ Testing operational changes in the real world (like hiring more staff or alterin
11
  * **Language:** Python
12
  * **GUI Framework:** Tkinter
13
  * **Data Visualization:** Matplotlib (Real-time graphing)
14
- * **Data Processing:** NumPy, Collections, CSV
15
 
16
  ## 🚀 Key Features
17
  * **Multi-Server & Priority Queues:** Simulate any number of parallel servers and toggle VIP customer priorities, separating standard FIFO logic into distinct VIP vs. Regular queues.
18
  * **Cost Analysis:** Input abstract "Waiting Costs" and "Server Costs" to mathematically calculate the optimal trade-off between customer satisfaction and business overhead.
19
- * **Flexible Data Input:** Supports manual entry, CSV imports, or automated randomized distributions (Exponential for arrivals, Normal for service times).
20
  * **Real-Time Visualization:** Watch the system dynamically update with visual representations of idle/busy servers, queue lengths, and live line charts for Q(t) and B(t).
21
  * **Statistical Replications:** Run the simulation hundreds of times automatically to generate a "Replication Report" featuring 95% Confidence Intervals (C.I. Half-Width) for rock-solid, data-driven decision making.
22
  * **Comprehensive Exporting:** Export event logs, customer statistics, and final system reports to `.csv`, or save the real-time plots as `.png` images.
23
 
24
  ## 💻 How to Run Locally
25
 
 
 
26
  **1. Clone the repository:**
27
  ```bash
28
  git clone https://github.com/bennypepper/Queueing-System-Simulator.git
29
- cd queueing-system-simulator
30
  ```
31
 
32
  **2. Install dependencies:**
33
  ```bash
34
- pip install numpy matplotlib
35
  ```
36
 
37
- **3. Launch the Simulator:**
38
  ```bash
39
  python simulator.py
40
  ```
41
- *(Ensure your Python installation includes Tkinter, which is typically bundled by default on Windows/macOS).*
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  ## 📊 Using the Simulator (Example Scenario)
44
  To analyze whether adding a second barista to a cafe is cost-effective:
@@ -51,4 +64,4 @@ To analyze whether adding a second barista to a cafe is cost-effective:
51
  ## 👥 Authors
52
  * Benedict Michael Pepper
53
  * Yudhistira Nalendra Aryadhewa Az-zhafir
54
- * *Informatics Engineering, Ma Chung University (2023)*
 
11
  * **Language:** Python
12
  * **GUI Framework:** Tkinter
13
  * **Data Visualization:** Matplotlib (Real-time graphing)
14
+ * **Data Processing:** NumPy, SciPy, Collections, CSV
15
 
16
  ## 🚀 Key Features
17
  * **Multi-Server & Priority Queues:** Simulate any number of parallel servers and toggle VIP customer priorities, separating standard FIFO logic into distinct VIP vs. Regular queues.
18
  * **Cost Analysis:** Input abstract "Waiting Costs" and "Server Costs" to mathematically calculate the optimal trade-off between customer satisfaction and business overhead.
19
+ * **Flexible Data Input:** Supports manual entry, CSV imports, or automated randomized distributions (Exponential for arrivals, Lognormal for service times).
20
  * **Real-Time Visualization:** Watch the system dynamically update with visual representations of idle/busy servers, queue lengths, and live line charts for Q(t) and B(t).
21
  * **Statistical Replications:** Run the simulation hundreds of times automatically to generate a "Replication Report" featuring 95% Confidence Intervals (C.I. Half-Width) for rock-solid, data-driven decision making.
22
  * **Comprehensive Exporting:** Export event logs, customer statistics, and final system reports to `.csv`, or save the real-time plots as `.png` images.
23
 
24
  ## 💻 How to Run Locally
25
 
26
+ You can run this project either as a local Desktop App or a Web Dashboard. Both share the exact same underlying mathematical engine.
27
+
28
  **1. Clone the repository:**
29
  ```bash
30
  git clone https://github.com/bennypepper/Queueing-System-Simulator.git
31
+ cd Queueing-System-Simulator
32
  ```
33
 
34
  **2. Install dependencies:**
35
  ```bash
36
+ pip install numpy scipy matplotlib streamlit
37
  ```
38
 
39
+ **3a. Launch the Desktop Simulator (Tkinter):**
40
  ```bash
41
  python simulator.py
42
  ```
43
+ *(Ensure your Python installation includes Tkinter, which is typically bundled by default on Windows).*
44
+
45
+ **3b. Launch the Web Dashboard (Streamlit):**
46
+ ```bash
47
+ streamlit run app.py
48
+ ```
49
+
50
+ ## 📖 Technical Guidebook
51
+
52
+ A comprehensive, mathematically detailed manual explaining the Discrete Event Simulation mechanisms, formulas, and real-world business applications of this software is provided.
53
+
54
+ 👉 **[Read the Full Guidebook (`guidebook.pdf`)](guidebook.pdf)**
55
 
56
  ## 📊 Using the Simulator (Example Scenario)
57
  To analyze whether adding a second barista to a cafe is cost-effective:
 
64
  ## 👥 Authors
65
  * Benedict Michael Pepper
66
  * Yudhistira Nalendra Aryadhewa Az-zhafir
67
+ * *Informatics Engineering, Ma Chung University*
docs/guidebook.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6b61d39cdc65b55ee7d0f39e55b26c512952b5c50f3d90326685dfe36371ad98
3
- size 4013382
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c0d84d675cac37dd7229d430fdbfd7933089f1859d617d1d38bb226658d9179
3
+ size 67657
simulator.py CHANGED
@@ -6,6 +6,7 @@ import numpy as np
6
  import csv
7
  import math
8
  from matplotlib.figure import Figure
 
9
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
10
 
11
  class QueueingSystemSimulator:
@@ -29,6 +30,7 @@ class QueueingSystemSimulator:
29
  self.num_servers = p['num_servers']
30
  self.queue_capacity = p['capacity']
31
  self.priority_enabled = p.get('priority_enabled', False)
 
32
  self.interarrival_times = collections.deque(p['interarrivals'])
33
  self.service_times = collections.deque(p['services'])
34
  self.priorities = collections.deque(p['priorities'])
@@ -52,6 +54,7 @@ class QueueingSystemSimulator:
52
  self.num_delayed = 0
53
  self.area_under_Q_t = 0.0
54
  self.customers_served = 0
 
55
  self.customers_rejected = 0
56
 
57
  # --- Data Logging ---
@@ -79,10 +82,12 @@ class QueueingSystemSimulator:
79
  def _update_stats(self):
80
  """Updates area-based statistical counters before an event occurs."""
81
  if self.sim_clock > self.time_of_last_event:
82
- time_since_last_event = self.sim_clock - self.time_of_last_event
83
- num_busy_servers = sum(1 for s in self.servers if s['status'] == 'busy')
84
- self.area_under_Q_t += (len(self.vip_queue) + len(self.regular_queue)) * time_since_last_event
85
- self.total_server_busy_time += num_busy_servers * time_since_last_event
 
 
86
 
87
  def _arrival(self):
88
  """Handles a customer arrival, with priority and server logic."""
@@ -143,8 +148,11 @@ class QueueingSystemSimulator:
143
  self.servers[server_idx]['departure_time'] = self.sim_clock + service_time
144
 
145
  delay = self.sim_clock - arrival_time
146
- self.total_delay += delay
147
- if delay > 0: self.num_delayed += 1
 
 
 
148
 
149
  self.completed_customers_details.append({
150
  "id": cust_id, "arrival_time": arrival_time, "wait_delay": delay,
@@ -196,10 +204,10 @@ class QueueingSystemSimulator:
196
 
197
  def calculate_report(self):
198
  """Calculates and returns the final performance measures and costs."""
199
- final_time = self.time_of_last_event
200
- avg_delay = self.total_delay / self.num_delayed if self.num_delayed > 0 else 0.0
201
- avg_num_in_queue = self.area_under_Q_t / final_time if final_time > 0 else 0.0
202
- avg_server_utilization = self.total_server_busy_time / (self.num_servers * final_time) if final_time > 0 else 0.0
203
 
204
  total_wait_cost = self.total_delay * self.cost_wait_per_unit_time
205
  total_server_cost = self.total_server_busy_time * self.cost_server_per_unit_time
@@ -209,7 +217,8 @@ class QueueingSystemSimulator:
209
  "q(n)": avg_num_in_queue,
210
  "u(n)": avg_server_utilization,
211
  "Number of customers rejected": self.customers_rejected,
212
- "Total simulation time T(n)": final_time,
 
213
  }
214
 
215
  if self.cost_wait_per_unit_time > 0 or self.cost_server_per_unit_time > 0:
@@ -240,8 +249,8 @@ class App(tk.Tk):
240
  'services': [2.0, 0.7, 0.2, 1.1, 3.7, 0.6],
241
  'priorities': ['regular'] * 6,
242
  'num_servers': 1, 'capacity': float('inf'),
243
- 'cost_wait': 0, 'cost_server': 0,
244
- 'priority_enabled': False
245
  }
246
  self.simulator = QueueingSystemSimulator(self.initial_params)
247
 
@@ -262,6 +271,7 @@ class App(tk.Tk):
262
  "u(n)": "u(n) - Utilization",
263
  "Number of customers rejected": "Rejected Customers",
264
  "Total simulation time T(n)": "T(n) - Total Time",
 
265
  }
266
 
267
  self.create_widgets()
@@ -335,8 +345,8 @@ class App(tk.Tk):
335
 
336
  ui_mode_frame = ttk.LabelFrame(self.left_panel_container, text="UI Mode", style='Medium.TLabelframe')
337
  ui_mode_frame.pack(fill=tk.X, padx=5, pady=5)
338
- ttk.Radiobutton(ui_mode_frame, text="Default", variable=self.ui_mode, value="Default", command=self.rebuild_ui, style='Medium.TRadiobutton').pack(side=tk.LEFT, padx=5)
339
- ttk.Radiobutton(ui_mode_frame, text="Scientific", variable=self.ui_mode, value="Scientific", command=self.rebuild_ui, style='Medium.TRadiobutton').pack(side=tk.LEFT, padx=5)
340
 
341
  canvas = tk.Canvas(self.left_panel_container, bg=self.COLOR_BG_DARK, highlightthickness=0)
342
  scrollbar = ttk.Scrollbar(self.left_panel_container, orient="vertical", command=canvas.yview)
@@ -390,7 +400,7 @@ class App(tk.Tk):
390
  about_frame = ttk.Frame(about_window, padding="20", style='Medium.TFrame')
391
  about_frame.pack(fill=tk.BOTH, expand=True)
392
 
393
- ttk.Label(about_frame, text="Indomaret Queing System Simulator", font=('Segoe UI', 14, 'bold'), style='Medium.TLabel').pack(pady=(0, 20))
394
 
395
  info_frame = ttk.Frame(about_frame, style='Medium.TFrame')
396
  info_frame.pack(fill=tk.BOTH, expand=True)
@@ -402,7 +412,7 @@ class App(tk.Tk):
402
  ttk.Label(dev_frame, text="- Yudhistira Nalendra Aryadhewa Az-zhafir", style='Medium.TLabel').pack(anchor='w')
403
 
404
  ttk.Label(info_frame, text="Institution:", font=('Segoe UI', 10, 'bold'), style='Medium.TLabel').grid(row=1, column=0, sticky='nw', pady=(10,0), padx=5)
405
- institution_label = ttk.Label(info_frame, text="Informatics Engineering Study Program 2023, Ma Chung University", style='Medium.TLabel', wraplength=320, justify=tk.LEFT)
406
  institution_label.grid(row=1, column=1, sticky='w', pady=(10,0), padx=5)
407
 
408
  ttk.Label(info_frame, text="Description:", font=('Segoe UI', 10, 'bold'), style='Medium.TLabel').grid(row=2, column=0, sticky='nw', pady=(10,0), padx=5)
@@ -462,18 +472,22 @@ class App(tk.Tk):
462
 
463
  self.gen_frame = ttk.LabelFrame(self.input_frame, text="General Settings", style='Medium.TLabelframe')
464
  self.gen_frame.pack(fill=tk.X, padx=5, pady=5)
465
- ttk.Label(self.gen_frame, text="Number of Servers (c):", style='Medium.TLabel').grid(row=0, column=0, sticky='w', padx=5, pady=2)
466
- self.num_servers_entry = ttk.Entry(self.gen_frame, width=10); self.num_servers_entry.grid(row=0, column=1, padx=5, pady=2); self.num_servers_entry.insert(0, "1")
467
- ttk.Label(self.gen_frame, text="Queue Capacity (K):", style='Medium.TLabel').grid(row=1, column=0, sticky='w', padx=5, pady=2)
468
- self.capacity_entry = ttk.Entry(self.gen_frame, width=10); self.capacity_entry.grid(row=1, column=1, padx=5, pady=2); self.capacity_entry.insert(0, "inf")
 
 
 
 
469
 
470
  self.priority_enabled_var = tk.BooleanVar(value=False)
471
  self.priority_check = ttk.Checkbutton(self.gen_frame, text="Enable Customer Priority", variable=self.priority_enabled_var, command=self.toggle_priority_visibility, style='Medium.TCheckbutton')
472
- self.priority_check.grid(row=2, column=0, columnspan=2, sticky='w', padx=5, pady=5)
473
 
474
  self.cost_enabled_var = tk.BooleanVar(value=False)
475
  self.cost_check = ttk.Checkbutton(self.gen_frame, text="Enable Cost Analysis", variable=self.cost_enabled_var, command=self.toggle_cost_visibility, style='Medium.TCheckbutton')
476
- self.cost_check.grid(row=3, column=0, columnspan=2, sticky='w', padx=5, pady=5)
477
 
478
  self.cost_frame = ttk.LabelFrame(self.input_frame, text="Cost Analysis (per time unit)", style='Medium.TLabelframe')
479
  ttk.Label(self.cost_frame, text="Waiting Cost:", style='Medium.TLabel').grid(row=0, column=0, sticky='w', padx=5, pady=2)
@@ -839,9 +853,11 @@ class App(tk.Tk):
839
 
840
  self.after_id = self.after(int(self.speed_scale.get()), self.run_all_loop)
841
 
842
- def get_params_from_ui(self):
843
  params = {}
844
  try:
 
 
845
  params['num_servers'] = int(self.num_servers_entry.get())
846
  capacity_str = self.capacity_entry.get().strip()
847
  params['capacity'] = float(capacity_str) if capacity_str.lower() != 'inf' else float('inf')
@@ -880,10 +896,22 @@ class App(tk.Tk):
880
  else: # Distribution mode
881
  num_cust = int(self.num_customers_var.get())
882
  if num_cust <= 0: raise ValueError("Number of customers for distribution must be positive.")
883
- params['interarrivals'] = [random.expovariate(1.0/float(self.arrival_mean.get())) for _ in range(num_cust)]
884
- params['services'] = [max(0, random.normalvariate(float(self.service_mean.get()), float(self.service_stdev.get()))) for _ in range(num_cust)]
 
 
 
 
 
 
 
 
 
 
 
 
885
  if params['priority_enabled']:
886
- params['priorities'] = ['vip' if random.random() < float(self.vip_percentage.get())/100 else 'regular' for _ in range(num_cust)]
887
  else:
888
  params['priorities'] = ['regular'] * num_cust
889
 
@@ -899,6 +927,11 @@ class App(tk.Tk):
899
  self.stop_all_tasks()
900
  params = self.get_params_from_ui()
901
  if params is None: return
 
 
 
 
 
902
  self.simulator.reset(params)
903
  self.log_text.configure(state='normal'); self.log_text.delete(1.0, tk.END); self.log_text.configure(state='disabled')
904
  self.report_text.configure(state='normal'); self.report_text.delete(1.0, tk.END); self.report_text.configure(state='disabled')
@@ -934,7 +967,11 @@ class App(tk.Tk):
934
  if not self.is_running_replications: return
935
 
936
  if self.replication_count < self.num_replications_total:
937
- current_params = self.get_params_from_ui() if self.input_mode.get() == "Distribution" else self.base_params
 
 
 
 
938
  if current_params is None:
939
  self.stop_all_tasks()
940
  return
@@ -963,7 +1000,11 @@ class App(tk.Tk):
963
  for key, values in self.replication_results.items():
964
  display_key = self.scientific_labels.get(key, key)
965
  mean = np.mean(values); stdev = np.std(values, ddof=1) if len(values) > 1 else 0
966
- half_width = 1.96 * (stdev / math.sqrt(len(values))) if len(values) > 1 else 0
 
 
 
 
967
  final_report += f"{display_key:<40} {mean:>15.4f} {stdev:>15.4f} {half_width:>20.4f}\n"
968
 
969
  self.replication_text.configure(state='normal'); self.replication_text.delete(1.0, tk.END)
 
6
  import csv
7
  import math
8
  from matplotlib.figure import Figure
9
+ import scipy.stats as stt
10
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
11
 
12
  class QueueingSystemSimulator:
 
30
  self.num_servers = p['num_servers']
31
  self.queue_capacity = p['capacity']
32
  self.priority_enabled = p.get('priority_enabled', False)
33
+ self.warmup_time = p.get('warmup_time', 0.0)
34
  self.interarrival_times = collections.deque(p['interarrivals'])
35
  self.service_times = collections.deque(p['services'])
36
  self.priorities = collections.deque(p['priorities'])
 
54
  self.num_delayed = 0
55
  self.area_under_Q_t = 0.0
56
  self.customers_served = 0
57
+ self.customers_served_after_warmup = 0
58
  self.customers_rejected = 0
59
 
60
  # --- Data Logging ---
 
82
  def _update_stats(self):
83
  """Updates area-based statistical counters before an event occurs."""
84
  if self.sim_clock > self.time_of_last_event:
85
+ if self.sim_clock > self.warmup_time:
86
+ effective_last_event = max(self.time_of_last_event, self.warmup_time)
87
+ time_since_last_event = self.sim_clock - effective_last_event
88
+ num_busy_servers = sum(1 for s in self.servers if s['status'] == 'busy')
89
+ self.area_under_Q_t += (len(self.vip_queue) + len(self.regular_queue)) * time_since_last_event
90
+ self.total_server_busy_time += num_busy_servers * time_since_last_event
91
 
92
  def _arrival(self):
93
  """Handles a customer arrival, with priority and server logic."""
 
148
  self.servers[server_idx]['departure_time'] = self.sim_clock + service_time
149
 
150
  delay = self.sim_clock - arrival_time
151
+
152
+ if arrival_time >= self.warmup_time:
153
+ self.total_delay += delay
154
+ self.customers_served_after_warmup += 1
155
+ if delay > 0: self.num_delayed += 1
156
 
157
  self.completed_customers_details.append({
158
  "id": cust_id, "arrival_time": arrival_time, "wait_delay": delay,
 
204
 
205
  def calculate_report(self):
206
  """Calculates and returns the final performance measures and costs."""
207
+ effective_time = max(0.0, self.time_of_last_event - self.warmup_time)
208
+ avg_delay = self.total_delay / self.customers_served_after_warmup if self.customers_served_after_warmup > 0 else 0.0
209
+ avg_num_in_queue = self.area_under_Q_t / effective_time if effective_time > 0 else 0.0
210
+ avg_server_utilization = self.total_server_busy_time / (self.num_servers * effective_time) if effective_time > 0 else 0.0
211
 
212
  total_wait_cost = self.total_delay * self.cost_wait_per_unit_time
213
  total_server_cost = self.total_server_busy_time * self.cost_server_per_unit_time
 
217
  "q(n)": avg_num_in_queue,
218
  "u(n)": avg_server_utilization,
219
  "Number of customers rejected": self.customers_rejected,
220
+ "Total simulation time T(n)": self.time_of_last_event,
221
+ "Effective Time (Post-Warmup)": effective_time
222
  }
223
 
224
  if self.cost_wait_per_unit_time > 0 or self.cost_server_per_unit_time > 0:
 
249
  'services': [2.0, 0.7, 0.2, 1.1, 3.7, 0.6],
250
  'priorities': ['regular'] * 6,
251
  'num_servers': 1, 'capacity': float('inf'),
252
+ 'cost_wait': 0.0, 'cost_server': 0.0,
253
+ 'priority_enabled': False, 'warmup_time': 0.0, 'random_seed': 42
254
  }
255
  self.simulator = QueueingSystemSimulator(self.initial_params)
256
 
 
271
  "u(n)": "u(n) - Utilization",
272
  "Number of customers rejected": "Rejected Customers",
273
  "Total simulation time T(n)": "T(n) - Total Time",
274
+ "Effective Time (Post-Warmup)": "Effective Time (Post-Warmup)"
275
  }
276
 
277
  self.create_widgets()
 
345
 
346
  ui_mode_frame = ttk.LabelFrame(self.left_panel_container, text="UI Mode", style='Medium.TLabelframe')
347
  ui_mode_frame.pack(fill=tk.X, padx=5, pady=5)
348
+ ttk.Radiobutton(ui_mode_frame, text="Default", variable=self.ui_mode, value="Default", command=self.update_ui, style='Medium.TRadiobutton').pack(side=tk.LEFT, padx=5)
349
+ ttk.Radiobutton(ui_mode_frame, text="Scientific", variable=self.ui_mode, value="Scientific", command=self.update_ui, style='Medium.TRadiobutton').pack(side=tk.LEFT, padx=5)
350
 
351
  canvas = tk.Canvas(self.left_panel_container, bg=self.COLOR_BG_DARK, highlightthickness=0)
352
  scrollbar = ttk.Scrollbar(self.left_panel_container, orient="vertical", command=canvas.yview)
 
400
  about_frame = ttk.Frame(about_window, padding="20", style='Medium.TFrame')
401
  about_frame.pack(fill=tk.BOTH, expand=True)
402
 
403
+ ttk.Label(about_frame, text="Queing System Simulator", font=('Segoe UI', 14, 'bold'), style='Medium.TLabel').pack(pady=(0, 20))
404
 
405
  info_frame = ttk.Frame(about_frame, style='Medium.TFrame')
406
  info_frame.pack(fill=tk.BOTH, expand=True)
 
412
  ttk.Label(dev_frame, text="- Yudhistira Nalendra Aryadhewa Az-zhafir", style='Medium.TLabel').pack(anchor='w')
413
 
414
  ttk.Label(info_frame, text="Institution:", font=('Segoe UI', 10, 'bold'), style='Medium.TLabel').grid(row=1, column=0, sticky='nw', pady=(10,0), padx=5)
415
+ institution_label = ttk.Label(info_frame, text="Informatics Engineering Study Program, Ma Chung University", style='Medium.TLabel', wraplength=320, justify=tk.LEFT)
416
  institution_label.grid(row=1, column=1, sticky='w', pady=(10,0), padx=5)
417
 
418
  ttk.Label(info_frame, text="Description:", font=('Segoe UI', 10, 'bold'), style='Medium.TLabel').grid(row=2, column=0, sticky='nw', pady=(10,0), padx=5)
 
472
 
473
  self.gen_frame = ttk.LabelFrame(self.input_frame, text="General Settings", style='Medium.TLabelframe')
474
  self.gen_frame.pack(fill=tk.X, padx=5, pady=5)
475
+ ttk.Label(self.gen_frame, text="Random Seed (Reproducibility):", style='Medium.TLabel').grid(row=0, column=0, sticky='w', padx=5, pady=2)
476
+ self.random_seed_entry = ttk.Entry(self.gen_frame, width=10); self.random_seed_entry.grid(row=0, column=1, padx=5, pady=2); self.random_seed_entry.insert(0, "42")
477
+ ttk.Label(self.gen_frame, text="Warm-up Time (T_w):", style='Medium.TLabel').grid(row=1, column=0, sticky='w', padx=5, pady=2)
478
+ self.warmup_time_entry = ttk.Entry(self.gen_frame, width=10); self.warmup_time_entry.grid(row=1, column=1, padx=5, pady=2); self.warmup_time_entry.insert(0, "0")
479
+ ttk.Label(self.gen_frame, text="Number of Servers (c):", style='Medium.TLabel').grid(row=2, column=0, sticky='w', padx=5, pady=2)
480
+ self.num_servers_entry = ttk.Entry(self.gen_frame, width=10); self.num_servers_entry.grid(row=2, column=1, padx=5, pady=2); self.num_servers_entry.insert(0, "1")
481
+ ttk.Label(self.gen_frame, text="Queue Capacity (K):", style='Medium.TLabel').grid(row=3, column=0, sticky='w', padx=5, pady=2)
482
+ self.capacity_entry = ttk.Entry(self.gen_frame, width=10); self.capacity_entry.grid(row=3, column=1, padx=5, pady=2); self.capacity_entry.insert(0, "inf")
483
 
484
  self.priority_enabled_var = tk.BooleanVar(value=False)
485
  self.priority_check = ttk.Checkbutton(self.gen_frame, text="Enable Customer Priority", variable=self.priority_enabled_var, command=self.toggle_priority_visibility, style='Medium.TCheckbutton')
486
+ self.priority_check.grid(row=4, column=0, columnspan=2, sticky='w', padx=5, pady=5)
487
 
488
  self.cost_enabled_var = tk.BooleanVar(value=False)
489
  self.cost_check = ttk.Checkbutton(self.gen_frame, text="Enable Cost Analysis", variable=self.cost_enabled_var, command=self.toggle_cost_visibility, style='Medium.TCheckbutton')
490
+ self.cost_check.grid(row=5, column=0, columnspan=2, sticky='w', padx=5, pady=5)
491
 
492
  self.cost_frame = ttk.LabelFrame(self.input_frame, text="Cost Analysis (per time unit)", style='Medium.TLabelframe')
493
  ttk.Label(self.cost_frame, text="Waiting Cost:", style='Medium.TLabel').grid(row=0, column=0, sticky='w', padx=5, pady=2)
 
853
 
854
  self.after_id = self.after(int(self.speed_scale.get()), self.run_all_loop)
855
 
856
+ def get_params_from_ui(self, override_seed=None):
857
  params = {}
858
  try:
859
+ params['random_seed'] = int(self.random_seed_entry.get())
860
+ params['warmup_time'] = float(self.warmup_time_entry.get())
861
  params['num_servers'] = int(self.num_servers_entry.get())
862
  capacity_str = self.capacity_entry.get().strip()
863
  params['capacity'] = float(capacity_str) if capacity_str.lower() != 'inf' else float('inf')
 
896
  else: # Distribution mode
897
  num_cust = int(self.num_customers_var.get())
898
  if num_cust <= 0: raise ValueError("Number of customers for distribution must be positive.")
899
+
900
+ seed_val = override_seed if override_seed is not None else params['random_seed']
901
+ random.seed(seed_val)
902
+
903
+ arr_mean = float(self.arrival_mean.get())
904
+ srv_mean = float(self.service_mean.get())
905
+ srv_std = float(self.service_stdev.get())
906
+ vip_pct = float(self.vip_percentage.get()) / 100.0
907
+
908
+ mu_lognorm = math.log(srv_mean**2 / math.sqrt(srv_mean**2 + srv_std**2))
909
+ sigma_lognorm = math.sqrt(math.log(1 + (srv_std**2 / srv_mean**2)))
910
+
911
+ params['interarrivals'] = [random.expovariate(1.0/arr_mean) for _ in range(num_cust)]
912
+ params['services'] = [random.lognormvariate(mu_lognorm, sigma_lognorm) for _ in range(num_cust)]
913
  if params['priority_enabled']:
914
+ params['priorities'] = ['vip' if random.random() < vip_pct else 'regular' for _ in range(num_cust)]
915
  else:
916
  params['priorities'] = ['regular'] * num_cust
917
 
 
927
  self.stop_all_tasks()
928
  params = self.get_params_from_ui()
929
  if params is None: return
930
+
931
+ # Apply random seed
932
+ random.seed(params['random_seed'])
933
+ np.random.seed(params['random_seed'])
934
+
935
  self.simulator.reset(params)
936
  self.log_text.configure(state='normal'); self.log_text.delete(1.0, tk.END); self.log_text.configure(state='disabled')
937
  self.report_text.configure(state='normal'); self.report_text.delete(1.0, tk.END); self.report_text.configure(state='disabled')
 
967
  if not self.is_running_replications: return
968
 
969
  if self.replication_count < self.num_replications_total:
970
+ seed_val = self.base_params['random_seed'] + self.replication_count
971
+ random.seed(seed_val)
972
+ np.random.seed(seed_val)
973
+
974
+ current_params = self.get_params_from_ui(override_seed=seed_val) if self.input_mode.get() == "Distribution" else self.base_params
975
  if current_params is None:
976
  self.stop_all_tasks()
977
  return
 
1000
  for key, values in self.replication_results.items():
1001
  display_key = self.scientific_labels.get(key, key)
1002
  mean = np.mean(values); stdev = np.std(values, ddof=1) if len(values) > 1 else 0
1003
+ if len(values) > 1:
1004
+ t_crit = stt.t.ppf(0.975, df=len(values)-1)
1005
+ half_width = t_crit * (stdev / math.sqrt(len(values)))
1006
+ else:
1007
+ half_width = 0.0
1008
  final_report += f"{display_key:<40} {mean:>15.4f} {stdev:>15.4f} {half_width:>20.4f}\n"
1009
 
1010
  self.replication_text.configure(state='normal'); self.replication_text.delete(1.0, tk.END)