-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathexactnode.py
69 lines (59 loc) · 1.85 KB
/
exactnode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from .node import Node
from .arrival_node import ArrivalNode
from decimal import Decimal, getcontext
from .server import Server
class ExactNode(Node):
"""
Inherits from the Node class, implements a more
precise version of addition to fix discrepencies
with floating point numbers.
"""
@property
def now(self):
"""
Gets the current time
"""
return Decimal(self.simulation.current_time)
def create_starting_servers(self):
"""
Initialise the servers
"""
return [Server(self, i + 1, Decimal("0.0")) for i in range(self.c)]
def increment_time(self, original, increment):
"""
Increments the original time by the increment
"""
return Decimal(str(original)) + Decimal(str(increment))
def get_service_time(self, ind):
"""
Returns a service time for the given customer class
"""
return Decimal(
str(
self.simulation.service_times[self.id_number][
ind.customer_class
]._sample(self.simulation.current_time, ind=ind)
)
)
class ExactArrivalNode(ArrivalNode):
"""
Inherits from the ArrivalNode class, implements a
more precise version of addition to fix discrepencies
with floating point numbers.
"""
def increment_time(self, original, increment):
"""
Increments the original time by the increment
"""
return Decimal(str(original)) + Decimal(str(increment))
def inter_arrival(self, nd, clss):
"""
Samples the inter-arrival time for next class and node.
"""
return Decimal(
str(
self.simulation.inter_arrival_times[nd][clss]._sample(
self.simulation.current_time
)
)
)