Skip to content

Commit e8ebfe9

Browse files
Merge pull request #145 from CiwPython/fix-utilisation-bug
Fix utilisation bug Fixes bug in which utilisation is not calculated correctly, resulting in utilisation > 100%.
2 parents c3793b3 + c688036 commit e8ebfe9

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

ciw/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def wrap_up_servers(self, current_time):
444444
for srvr in self.servers:
445445
srvr.total_time = self.increment_time(current_time, -srvr.start_date)
446446
if srvr.busy:
447-
srvr.busy_time += self.increment_time(current_time, -srvr.cust.arrival_date)
447+
srvr.busy_time += self.increment_time(current_time, -srvr.cust.service_start_date)
448448

449449

450450
def write_individual_record(self, individual):

ciw/tests/test_node.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import unittest
22
import ciw
3+
from hypothesis import given
4+
from hypothesis.strategies import floats, integers, random_module
35

46
class TestNode(unittest.TestCase):
57

@@ -637,6 +639,36 @@ def test_server_utilisation_with_schedules(self):
637639
recs = Q.get_all_records()
638640
self.assertEqual(Q.transitive_nodes[0].server_utilisation, 21.0/37.0)
639641

642+
def test_server_utilisation_with_wrapup(self):
643+
N = ciw.create_network(
644+
Arrival_distributions=[['Exponential',7.14]],
645+
Service_distributions=[['Exponential',0.04]],
646+
Number_of_servers=[70]
647+
)
648+
ciw.seed(1)
649+
Q = ciw.Simulation(N)
650+
Q.simulate_until_max_time(168)
651+
for srvr in Q.transitive_nodes[0].servers:
652+
self.assertGreaterEqual(srvr.total_time, srvr.busy_time)
653+
654+
@given(lmbda=floats(min_value=0.01, max_value=10),
655+
mu=floats(min_value=0.01, max_value=10),
656+
c=integers(min_value=1, max_value=10),
657+
rm=random_module())
658+
def test_utilisation_always_1_or_less(self, lmbda, mu, c, rm):
659+
N = ciw.create_network(
660+
Arrival_distributions=[['Exponential', lmbda]],
661+
Service_distributions=[['Exponential', mu]],
662+
Number_of_servers=[c]
663+
)
664+
ciw.seed(1)
665+
Q = ciw.Simulation(N)
666+
Q.simulate_until_max_time(200)
667+
for srvr in Q.transitive_nodes[0].servers:
668+
self.assertGreaterEqual(srvr.total_time, srvr.busy_time)
669+
self.assertLessEqual(Q.transitive_nodes[0].server_utilisation, 1.0)
670+
self.assertGreaterEqual(Q.transitive_nodes[0].server_utilisation, 0.0)
671+
640672
def test_num_inds_equal_len_all_inds(self):
641673
# Create a Simulatin class that inherits form ciw.Simulation so that
642674
# an assertion than number_of_individuals == len(all_individuals)

0 commit comments

Comments
 (0)