@@ -251,7 +251,7 @@ def test_begin_service_if_possible_release_method(self):
251251 self .assertEqual (ind .service_start_date , False )
252252 self .assertEqual (ind .service_end_date , False )
253253 Q .current_time = 200.0
254- Q .transitive_nodes [0 ].begin_service_if_possible_release ()
254+ Q .transitive_nodes [0 ].begin_service_if_possible_release (ind )
255255 self .assertEqual (ind .arrival_date , 100.0 )
256256 self .assertEqual (round (ind .service_time , 5 ), 0.03382 )
257257 self .assertEqual (ind .service_start_date , 200.0 )
@@ -266,9 +266,9 @@ def test_release_blocked_individual_method(self):
266266 N1 .individuals = [[ciw .Individual (i ) for i in range (N1 .c + 3 )]]
267267 N2 .individuals = [[ciw .Individual (i + 100 ) for i in range (N2 .c + 4 )]]
268268 for ind in N1 .all_individuals [:2 ]:
269- N1 .attach_server (N1 .find_free_server (), ind )
269+ N1 .attach_server (N1 .find_free_server (ind ), ind )
270270 for ind in N2 .all_individuals [:1 ]:
271- N2 .attach_server (N2 .find_free_server (), ind )
271+ N2 .attach_server (N2 .find_free_server (ind ), ind )
272272
273273 self .assertEqual ([str (obs ) for obs in N1 .all_individuals ],
274274 ['Individual 0' ,
@@ -722,3 +722,76 @@ def event_and_return_nextnode(simself, next_active_node):
722722 'ciw/tests/testing_parameters/params.yml' )
723723 Q = AssertSim (N )
724724 Q .simulate_until_max_time (100 )
725+
726+ def test_server_priority_function_allocate_to_less_busy (self ):
727+ """
728+ Test the server priority function when we prioritise the server that was
729+ less busy throughout the simulation.
730+ """
731+ def get_server_busy_time (server , ind ):
732+ return server .busy_time
733+
734+ ciw .seed (0 )
735+ Q = ciw .Simulation (ciw .create_network (
736+ arrival_distributions = [ciw .dists .Exponential (1 )],
737+ service_distributions = [ciw .dists .Exponential (2 )],
738+ number_of_servers = [2 ],
739+ server_priority_functions = [get_server_busy_time ]
740+ )
741+ )
742+ Q .simulate_until_max_time (1000 )
743+
744+ expected_times = [245.07547532640024 , 244.68396417751663 ]
745+ for i , srv in enumerate (Q .nodes [1 ].servers ):
746+ self .assertEqual (srv .busy_time , expected_times [i ])
747+
748+
749+ def test_server_priority_function_allocate_to_last_server_first (self ):
750+ """
751+ Test the server priority function when we prioritise the server with the
752+ highest id number.
753+ """
754+ def get_server_busy_time (server , ind ):
755+ return - server .id_number
756+
757+ ciw .seed (0 )
758+ Q = ciw .Simulation (ciw .create_network (
759+ arrival_distributions = [ciw .dists .Exponential (1 )],
760+ service_distributions = [ciw .dists .Exponential (2 )],
761+ number_of_servers = [2 ],
762+ server_priority_functions = [get_server_busy_time ]
763+ )
764+ )
765+ Q .simulate_until_max_time (1000 )
766+
767+ expected_times = [158.68745586286119 , 331.0719836410557 ]
768+ for i , srv in enumerate (Q .nodes [1 ].servers ):
769+ self .assertEqual (srv .busy_time , expected_times [i ])
770+
771+ def test_server_priority_function_two_nodes (self ):
772+ """
773+ Test the server priority function with two nodes that each has a
774+ different priority rule.
775+ """
776+ def prioritise_less_busy (srv , ind ):
777+ return srv .busy_time
778+
779+ def prioritise_highest_id (srv , ind ):
780+ return - srv .id_number
781+
782+ ciw .seed (0 )
783+ Q = ciw .Simulation (ciw .create_network (
784+ arrival_distributions = [ciw .dists .Exponential (1 ), ciw .dists .Exponential (1 )],
785+ service_distributions = [ciw .dists .Exponential (2 ), ciw .dists .Exponential (2 )],
786+ number_of_servers = [2 , 2 ],
787+ routing = [[0 , 0 ], [0 , 0 ]],
788+ server_priority_functions = [prioritise_less_busy , prioritise_highest_id ]
789+ )
790+ )
791+ Q .simulate_until_max_time (1000 )
792+ expected_times_node_1 = [256.2457715650031 , 257.59339967047254 ]
793+ expected_times_node_2 = [157.35577182806387 , 356.41473247082365 ]
794+
795+ for i , (srv_1 , srv_2 ) in enumerate (zip (Q .nodes [1 ].servers , Q .nodes [2 ].servers )):
796+ self .assertEqual (srv_1 .busy_time , expected_times_node_1 [i ])
797+ self .assertEqual (srv_2 .busy_time , expected_times_node_2 [i ])
0 commit comments