Skip to content

Commit 11fed47

Browse files
committed
add test for sim events interesting case
1 parent faa853d commit 11fed47

6 files changed

Lines changed: 21 additions & 17 deletions

File tree

32 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.

ciw/import_params.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import yaml
3+
import copy
34
from network import *
45

56

@@ -32,17 +33,17 @@ def create_network_from_yml(directory_name):
3233
"""
3334
Creates a Network object form a yaml file
3435
"""
35-
params = load_parameters(directory_name)
36-
fill_out_dictionary(params)
36+
params_input = load_parameters(directory_name)
37+
params = fill_out_dictionary(params_input)
3738
validify_dictionary(params)
3839
return create_network_from_dictionary(params)
3940

4041

41-
def create_network_from_dictionary(params):
42+
def create_network_from_dictionary(params_input):
4243
"""
4344
Creates a Network object from a parameters dictionary
4445
"""
45-
fill_out_dictionary(params)
46+
params = fill_out_dictionary(params_input)
4647
validify_dictionary(params)
4748
# Then make the Network object
4849
arrivals = [params['Arrival_distributions']['Class ' + str(cls)]
@@ -78,11 +79,12 @@ def create_network_from_dictionary(params):
7879
return Network(nodes, classes)
7980

8081

81-
def fill_out_dictionary(params):
82+
def fill_out_dictionary(params_input):
8283
"""
8384
Fills out the parameters dictionary with the
8485
optional arguments
8586
"""
87+
params = copy.deepcopy(params_input)
8688
if isinstance(params['Arrival_distributions'], list):
8789
arr_dists = params['Arrival_distributions']
8890
params['Arrival_distributions'] = {'Class 0': arr_dists}

ciw/tests/test_simulation.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,53 +205,55 @@ def test_simultaneous_events_example(self):
205205
# Due to randomly choosing the order of events, the seed has
206206
# a big affect on this.
207207

208-
set_seed(73)
209208
params = {'Arrival_distributions': [['Deterministic', 10.0], 'NoArrivals'],
210209
'Service_distributions': [['Deterministic', 5.0], ['Deterministic', 5.0]],
211210
'Transition_matrices': [[1.0, 0.0], [0.0, 0.0]],
212211
'Number_of_servers': [2, 1]}
212+
213+
214+
set_seed(73)
213215
Q = ciw.Simulation(ciw.create_network(params))
214216
Q.simulate_until_max_time(36)
215217
inds = Q.get_all_individuals()
216218
recs = Q.get_all_records()
217219
self.assertEqual(len(inds), 2)
218220
self.assertTrue(all([x[6] == 5.0 for x in recs[1:]]))
219221

220-
221222
set_seed(74)
222-
params = {'Arrival_distributions': [['Deterministic', 10.0], 'NoArrivals'],
223-
'Service_distributions': [['Deterministic', 5.0], ['Deterministic', 5.0]],
224-
'Transition_matrices': [[1.0, 0.0], [0.0, 0.0]],
225-
'Number_of_servers': [2, 1]}
226223
Q = ciw.Simulation(ciw.create_network(params))
227224
Q.simulate_until_max_time(36)
228225
inds = Q.get_all_individuals()
229226
recs = Q.get_all_records()
230227
self.assertEqual(len(inds), 3)
231228
self.assertTrue(all([x[6] == 5.0 for x in recs[1:]]))
232229

230+
completed_inds = []
231+
for _ in xrange(1000):
232+
Q = ciw.Simulation(ciw.create_network(params))
233+
Q.simulate_until_max_time(36)
234+
inds = Q.get_all_individuals()
235+
completed_inds.append(len(inds))
236+
self.assertAlmostEqual(completed_inds.count(2) / float(1000), 1 / 4.0, places=1)
237+
233238
def test_exactness(self):
234-
set_seed(777)
235239
params = {'Arrival_distributions': [['Exponential', 20]],
236240
'Service_distributions': [['Deterministic', 0.01]],
237241
'Transition_matrices': [[0.0]],
238242
'Number_of_servers': ['server_schedule'],
239243
'server_schedule': [[0.5, 0], [0.55, 1], [3.0, 0]]}
244+
245+
set_seed(777)
240246
Q = ciw.Simulation(ciw.create_network(params))
241247
Q.simulate_until_max_time(10)
242248
recs = Q.get_all_records(headers=False)
243249
mod_service_starts = [obs%3 for obs in [r[5] for r in recs]]
244250
self.assertNotEqual(set(mod_service_starts), set([0.50, 0.51, 0.52, 0.53, 0.54]))
245251

246252
set_seed(777)
247-
params = {'Arrival_distributions': [['Exponential', 20]],
248-
'Service_distributions': [['Deterministic', 0.01]],
249-
'Transition_matrices': [[0.0]],
250-
'Number_of_servers': ['server_schedule'],
251-
'server_schedule': [[0.5, 0], [0.55, 1], [3.0, 0]]}
252253
Q = ciw.Simulation(ciw.create_network(params), exact=14)
253254
Q.simulate_until_max_time(10)
254255
recs = Q.get_all_records(headers=False)
255256
mod_service_starts = [obs%3 for obs in [r[5] for r in recs]]
256257
expected_set = set([Decimal(k) for k in ['0.50', '0.51', '0.52', '0.53', '0.54']])
257258
self.assertEqual(set(mod_service_starts), expected_set)
259+

0 commit comments

Comments
 (0)