|
1 | 1 | from __future__ import division |
2 | 2 | import os |
3 | | -from random import (random, expovariate, uniform, triangular, |
4 | | - gammavariate, gauss, lognormvariate, weibullvariate) |
| 3 | +import tqdm |
| 4 | +from random import (expovariate, uniform, triangular, gammavariate, |
| 5 | + lognormvariate, weibullvariate) |
5 | 6 | from csv import writer, reader |
6 | | -import copy |
7 | | -from decimal import Decimal, getcontext |
| 7 | +from decimal import getcontext |
8 | 8 | from collections import namedtuple |
9 | 9 |
|
10 | | -import yaml |
11 | 10 | import numpy.random as nprandom |
12 | 11 |
|
13 | 12 | from .node import Node |
14 | 13 | from .exactnode import ExactNode, ExactArrivalNode |
15 | 14 | from .arrival_node import ArrivalNode |
16 | 15 | from .exit_node import ExitNode |
17 | | -from .server import Server |
18 | | -from .individual import Individual |
19 | | -from .data_record import DataRecord |
20 | 16 | from .state_tracker import * |
21 | 17 | from .deadlock_detector import * |
22 | 18 |
|
23 | | - |
24 | 19 | Record = namedtuple('Record', 'id_number customer_class node arrival_date waiting_time service_start_date service_time service_end_date time_blocked exit_date destination queue_size_at_arrival queue_size_at_departure') |
25 | 20 |
|
26 | 21 | class Simulation(object): |
@@ -236,20 +231,35 @@ def simulate_until_deadlock(self): |
236 | 231 | time_of_deadlock - self.times_dictionary[state] |
237 | 232 | for state in self.times_dictionary.keys()} |
238 | 233 |
|
239 | | - def simulate_until_max_time(self, max_simulation_time): |
| 234 | + def simulate_until_max_time(self, max_simulation_time, progress_bar=False): |
240 | 235 | """ |
241 | 236 | Runs the simulation until max_simulation_time is reached. |
242 | 237 | """ |
243 | 238 | self.nodes[0].update_next_event_date() |
244 | 239 | next_active_node = self.find_next_active_node() |
245 | 240 | current_time = next_active_node.next_event_date |
| 241 | + |
| 242 | + if progress_bar is not False: |
| 243 | + self.progress_bar = tqdm.tqdm(total=max_simulation_time) |
| 244 | + |
246 | 245 | while current_time < max_simulation_time: |
247 | 246 | next_active_node.have_event() |
248 | 247 | for node in self.transitive_nodes: |
249 | 248 | node.update_next_event_date(current_time) |
250 | 249 | next_active_node = self.find_next_active_node() |
| 250 | + |
| 251 | + if progress_bar: |
| 252 | + remaining_time = max_simulation_time - self.progress_bar.n |
| 253 | + time_increment = next_active_node.next_event_date - current_time |
| 254 | + self.progress_bar.update(min(time_increment, remaining_time)) |
| 255 | + |
251 | 256 | current_time = next_active_node.next_event_date |
252 | 257 |
|
| 258 | + if progress_bar: |
| 259 | + remaining_time = max(max_simulation_time - self.progress_bar.n, 0) |
| 260 | + self.progress_bar.update(remaining_time) |
| 261 | + self.progress_bar.close() |
| 262 | + |
253 | 263 | def source(self, c, n, kind): |
254 | 264 | """ |
255 | 265 | Returns the location of class c node n's arrival or |
|
0 commit comments