@@ -86,6 +86,93 @@ def test_base_accept_method_within_simulation(self):
8686 self .assertEqual (Q .statetracker .state , None )
8787
8888
89+ class TestSystemPopulation (unittest .TestCase ):
90+ def test_systempop_init_method (self ):
91+ Q = ciw .Simulation (ciw .create_network_from_yml (
92+ 'ciw/tests/testing_parameters/params.yml' ))
93+ B = ciw .trackers .SystemPopulation ()
94+ B .initialise (Q )
95+ self .assertEqual (B .simulation , Q )
96+ self .assertEqual (B .state , 0 )
97+
98+ def test_systempop_change_state_accept_method (self ):
99+ Q = ciw .Simulation (ciw .create_network_from_yml (
100+ 'ciw/tests/testing_parameters/params.yml' ))
101+ B = ciw .trackers .SystemPopulation ()
102+ B .initialise (Q )
103+ self .assertEqual (B .state , 0 )
104+ B .change_state_accept (1 , 1 )
105+ self .assertEqual (B .state , 1 )
106+
107+ def test_systempop_change_state_block_method (self ):
108+ Q = ciw .Simulation (ciw .create_network_from_yml (
109+ 'ciw/tests/testing_parameters/params.yml' ))
110+ B = ciw .trackers .SystemPopulation ()
111+ B .initialise (Q )
112+ B .state = 1
113+ B .change_state_block (1 , 1 , 2 )
114+ self .assertEqual (B .state , 1 )
115+
116+ def test_systempop_change_state_release_method (self ):
117+ Q = ciw .Simulation (ciw .create_network_from_yml (
118+ 'ciw/tests/testing_parameters/params.yml' ))
119+ B = ciw .trackers .SystemPopulation ()
120+ B .initialise (Q )
121+ B .state = 15
122+ B .change_state_release (1 , 1 , 2 , False )
123+ self .assertEqual (B .state , 14 )
124+ B .change_state_release (1 , 1 , 2 , True )
125+ self .assertEqual (B .state , 13 )
126+
127+ def test_systempop_hash_state_method (self ):
128+ Q = ciw .Simulation (ciw .create_network_from_yml (
129+ 'ciw/tests/testing_parameters/params.yml' ))
130+ B = ciw .trackers .SystemPopulation ()
131+ B .initialise (Q )
132+ B .state = 13
133+ self .assertEqual (B .hash_state (), 13 )
134+
135+ def test_systempop_release_method_within_simulation (self ):
136+ params = ciw .create_network_from_yml (
137+ 'ciw/tests/testing_parameters/params.yml' )
138+ Q = ciw .Simulation (params , tracker = ciw .trackers .SystemPopulation ())
139+ N = Q .transitive_nodes [2 ]
140+ inds = [ciw .Individual (i ) for i in range (5 )]
141+ N .individuals = [inds ]
142+ for ind in N .individuals [0 ]:
143+ srvr = N .find_free_server ()
144+ N .attach_server (srvr , ind )
145+ Q .statetracker .state = 14
146+ self .assertEqual (Q .statetracker .state , 14 )
147+ Q .current_time = 43.11
148+ N .release (0 , Q .nodes [1 ])
149+ self .assertEqual (Q .statetracker .state , 14 )
150+ N .all_individuals [1 ].is_blocked = True
151+ Q .current_time = 46.72
152+ N .release (1 , Q .nodes [1 ])
153+ self .assertEqual (Q .statetracker .state , 14 )
154+ N .release (1 , Q .nodes [- 1 ])
155+ self .assertEqual (Q .statetracker .state , 13 )
156+
157+ def test_systempop_block_method_within_simulation (self ):
158+ params = ciw .create_network_from_yml (
159+ 'ciw/tests/testing_parameters/params.yml' )
160+ Q = ciw .Simulation (params , tracker = ciw .trackers .SystemPopulation ())
161+ N = Q .transitive_nodes [2 ]
162+ Q .statetracker .state = 14
163+ self .assertEqual (Q .statetracker .state , 14 )
164+ N .block_individual (ciw .Individual (1 ), Q .nodes [1 ])
165+ self .assertEqual (Q .statetracker .state , 14 )
166+
167+ def test_systempop_accept_method_within_simulation (self ):
168+ params = ciw .create_network_from_yml (
169+ 'ciw/tests/testing_parameters/params.yml' )
170+ Q = ciw .Simulation (params , tracker = ciw .trackers .SystemPopulation ())
171+ N = Q .transitive_nodes [2 ]
172+ self .assertEqual (Q .statetracker .state , 0 )
173+ Q .current_time = 45.6
174+ N .accept (ciw .Individual (3 , 2 ))
175+ self .assertEqual (Q .statetracker .state , 1 )
89176
90177
91178class TestNaiveBlocking (unittest .TestCase ):
@@ -363,7 +450,7 @@ def test_matrix_accept_method_within_simulation(self):
363450
364451
365452class TestTrackHistory (unittest .TestCase ):
366- def test_one_node_deterministic_ (self ):
453+ def test_one_node_deterministic_naiveblocking (self ):
367454 N = ciw .create_network (
368455 arrival_distributions = [ciw .dists .Sequential ([1.5 , 0.3 , 2.4 , 1.1 ])],
369456 service_distributions = [ciw .dists .Sequential ([1.8 , 2.2 , 0.2 , 0.2 , 0.2 , 0.2 ])],
@@ -398,3 +485,39 @@ def test_one_node_deterministic_(self):
398485 [Decimal ('15.0' ), ((0 , 0 ),)]
399486 ]
400487 self .assertEqual (Q .statetracker .history , expected_history )
488+
489+ def test_one_node_deterministic_systempopulation (self ):
490+ N = ciw .create_network (
491+ arrival_distributions = [ciw .dists .Sequential ([1.5 , 0.3 , 2.4 , 1.1 ])],
492+ service_distributions = [ciw .dists .Sequential ([1.8 , 2.2 , 0.2 , 0.2 , 0.2 , 0.2 ])],
493+ number_of_servers = [1 ]
494+ )
495+ B = ciw .trackers .SystemPopulation ()
496+ Q = ciw .Simulation (N , tracker = B , exact = 26 )
497+ Q .simulate_until_max_time (15.5 )
498+ expected_history = [
499+ [Decimal ('0.0' ), 0 ],
500+ [Decimal ('1.5' ), 1 ],
501+ [Decimal ('1.8' ), 2 ],
502+ [Decimal ('3.3' ), 1 ],
503+ [Decimal ('4.2' ), 2 ],
504+ [Decimal ('5.3' ), 3 ],
505+ [Decimal ('5.5' ), 2 ],
506+ [Decimal ('5.7' ), 1 ],
507+ [Decimal ('5.9' ), 0 ],
508+ [Decimal ('6.8' ), 1 ],
509+ [Decimal ('7.0' ), 0 ],
510+ [Decimal ('7.1' ), 1 ],
511+ [Decimal ('7.3' ), 0 ],
512+ [Decimal ('9.5' ), 1 ],
513+ [Decimal ('10.6' ), 2 ],
514+ [Decimal ('11.3' ), 1 ],
515+ [Decimal ('12.1' ), 2 ],
516+ [Decimal ('12.4' ), 3 ],
517+ [Decimal ('13.5' ), 2 ],
518+ [Decimal ('13.7' ), 1 ],
519+ [Decimal ('13.9' ), 0 ],
520+ [Decimal ('14.8' ), 1 ],
521+ [Decimal ('15.0' ), 0 ]
522+ ]
523+ self .assertEqual (Q .statetracker .history , expected_history )
0 commit comments