@@ -19,32 +19,32 @@ def __init__(self, id_, simulation):
1919 Initialise a node.
2020 """
2121 self .simulation = simulation
22- self .mu = [self .simulation .mu [cls ][id_ - 1 ]
22+ self .mu = [self .simulation .mu [cls ][id_ - 1 ]
2323 for cls in xrange (len (self .simulation .mu ))]
24- self .scheduled_servers = self .simulation .schedules [id_ - 1 ]
24+ self .scheduled_servers = self .simulation .schedules [id_ - 1 ]
2525 if self .scheduled_servers :
2626 self .schedule = self .simulation .parameters [
27- self .simulation .c [id_ - 1 ]]
27+ self .simulation .c [id_ - 1 ]]
2828 self .cyclelength = self .simulation .parameters [
2929 'Cycle_length' ]
3030 self .c = self .schedule [0 ][1 ]
31- self .masterschedule = [i * self .cyclelength + obs
32- for i in xrange (int (
31+ self .masterschedule = [self . increment_time ( i * self .cyclelength ,
32+ obs ) for i in xrange (int (
3333 self .simulation .max_simulation_time // self .cyclelength
3434 ) + 2 ) for obs in [t [0 ] for t in self .schedule ]][1 :]
3535 else :
36- self .c = self .simulation .c [id_ - 1 ]
37- if self .simulation .queue_capacities [id_ - 1 ] == "Inf" :
36+ self .c = self .simulation .c [id_ - 1 ]
37+ if self .simulation .queue_capacities [id_ - 1 ] == "Inf" :
3838 self .node_capacity = "Inf"
3939 else :
4040 self .node_capacity = self .simulation .queue_capacities [
41- id_ - 1 ] + self .c
41+ id_ - 1 ] + self .c
4242 self .transition_row = [self .simulation .transition_matrix [j ][
43- id_ - 1 ] for j in xrange (len (
43+ id_ - 1 ] for j in xrange (len (
4444 self .simulation .transition_matrix ))]
4545 if self .simulation .class_change_matrix != 'NA' :
4646 self .class_change = self .simulation .class_change_matrix [
47- id_ - 1 ]
47+ id_ - 1 ]
4848 self .individuals = []
4949 self .id_number = id_
5050 if self .scheduled_servers :
@@ -53,7 +53,7 @@ def __init__(self, id_, simulation):
5353 self .next_event_date = "Inf"
5454 self .blocked_queue = []
5555 if self .c < 'Inf' :
56- self .servers = [Server (self , i + 1 ) for i in xrange (self .c )]
56+ self .servers = [Server (self , i + 1 ) for i in xrange (self .c )]
5757 if simulation .detecting_deadlock :
5858 self .simulation .digraph .add_nodes_from ([str (s )
5959 for s in self .servers ])
@@ -110,16 +110,16 @@ def begin_service_if_possible_accept(self,
110110 Begins the service of the next individual, giving
111111 that customer a service time, end date and node.
112112 """
113- next_individual .arrival_date = current_time
114- next_individual .service_time = self .simulation . service_times [
115- self . id_number ][ next_individual .customer_class ]( )
113+ next_individual .arrival_date = self . get_now ( current_time )
114+ next_individual .service_time = self .get_service_time (
115+ next_individual .customer_class )
116116 if self .free_server ():
117117 if self .c < 'Inf' :
118118 self .attach_server (self .find_free_server (),
119119 next_individual )
120- next_individual .service_start_date = current_time
121- next_individual .service_end_date = ( current_time +
122- next_individual .service_time )
120+ next_individual .service_start_date = self . get_now ( current_time )
121+ next_individual .service_end_date = self . increment_time (
122+ current_time , next_individual .service_time )
123123
124124 def begin_service_if_possible_change_shift (self , current_time ):
125125 """
@@ -131,9 +131,9 @@ def begin_service_if_possible_change_shift(self, current_time):
131131 if len ([i for i in self .individuals if not i .server ]) > 0 :
132132 ind = [i for i in self .individuals if not i .server ][0 ]
133133 self .attach_server (srvr , ind )
134- ind .service_start_date = current_time
135- ind .service_end_date = ( ind . service_start_date +
136- ind .service_time )
134+ ind .service_start_date = self . get_now ( current_time )
135+ ind .service_end_date = self . increment_time (
136+ ind .service_start_date , ind . service_time )
137137
138138 def begin_service_if_possible_release (self , current_time ):
139139 """
@@ -145,9 +145,9 @@ def begin_service_if_possible_release(self, current_time):
145145 if len ([i for i in self .individuals if not i .server ]) > 0 :
146146 ind = [i for i in self .individuals if not i .server ][0 ]
147147 self .attach_server (srvr , ind )
148- ind .service_start_date = current_time
149- ind .service_end_date = ( ind . service_start_date +
150- ind .service_time )
148+ ind .service_start_date = self . get_now ( current_time )
149+ ind .service_end_date = self . increment_time (
150+ ind .service_start_date , ind . service_time )
151151
152152 def block_individual (self , individual , next_node ):
153153 """
@@ -170,10 +170,10 @@ def change_customer_class(self,individual):
170170 according to a probability distribution.
171171 """
172172 if self .simulation .class_change_matrix != 'NA' :
173- individual .previous_class = individual .customer_class
174- individual .customer_class = nprandom .choice (
173+ individual .previous_class = individual .customer_class
174+ individual .customer_class = nprandom .choice (
175175 xrange (len (self .class_change )),
176- p = self .class_change [individual .previous_class ])
176+ p = self .class_change [individual .previous_class ])
177177
178178 def change_shift (self ):
179179 """
@@ -188,7 +188,7 @@ def change_shift(self):
188188 try : inx = self .schedule .index (shift )
189189 except :
190190 tms = [obs [0 ] for obs in self .schedule ]
191- diffs = [abs (x - shift ) for x in tms ]
191+ diffs = [abs (x - float ( shift ) ) for x in tms ]
192192 indx = diffs .index (min (diffs ))
193193
194194 self .take_servers_off_duty ()
@@ -261,6 +261,12 @@ def finish_service(self):
261261 else :
262262 self .block_individual (next_individual , next_node )
263263
264+ def get_now (self , current_time ):
265+ """
266+ Gets the current time
267+ """
268+ return current_time
269+
264270 def have_event (self ):
265271 """
266272 Has an event
@@ -270,6 +276,12 @@ def have_event(self):
270276 else :
271277 self .finish_service ()
272278
279+ def increment_time (self , original , increment ):
280+ """
281+ Increments the original time by the increment
282+ """
283+ return original + increment
284+
273285 def kill_server (self ,srvr ):
274286 """
275287 Kills server.
@@ -282,7 +294,7 @@ def next_node(self, customer_class):
282294 Finds the next node according the random distribution.
283295 """
284296 return nprandom .choice (self .simulation .nodes [1 :],
285- p = self .transition_row [customer_class ]+ [1.0 - sum (
297+ p = self .transition_row [customer_class ] + [1.0 - sum (
286298 self .transition_row [customer_class ])])
287299
288300 def release (self , next_individual_index , next_node , current_time ):
@@ -319,6 +331,12 @@ def release_blocked_individual(self, current_time):
319331 node_to_receive_from .release (individual_to_receive_index ,
320332 self , current_time )
321333
334+ def get_service_time (self , cls ):
335+ """
336+ Returns a service time for the given customer class
337+ """
338+ return self .simulation .service_times [self .id_number ][cls ]()
339+
322340 def take_servers_off_duty (self ):
323341 """
324342 Gathers servers that should be deleted.
@@ -339,7 +357,7 @@ def update_next_event_date(self, current_time):
339357 next_end_service = min ([ind .service_end_date
340358 for ind in self .individuals
341359 if not ind .is_blocked
342- if ind .service_end_date >= current_time ] + ["Inf" ])
360+ if ind .service_end_date >= current_time ] + ["Inf" ])
343361 if self .scheduled_servers :
344362 next_shift_change = self .masterschedule [0 ]
345363 self .next_event_date = min (
0 commit comments