API Reference¶
This reference is generated from the source code with mkdocstrings, so it stays in step with the implementation. Every public module, class, function, and method is documented with Google-style docstrings.
Core¶
import_params ¶
Build Network objects from user-supplied parameters.
ServiceCentre ¶
ServiceCentre(
number_of_servers,
queueing_capacity,
class_change_matrix=None,
priority_preempt=False,
ps_threshold=1,
server_priority_function=None,
service_discipline=None,
)
Store the class-independent information for a service centre.
Attributes:
| Name | Type | Description |
|---|---|---|
number_of_servers |
int or Schedule
|
The number of servers, or a schedule describing how it varies over time. |
queueing_capacity |
int or float
|
The maximum queue length. |
class_change_matrix |
dict
|
Matrix describing class changes, if any. |
priority_preempt |
bool
|
Whether priority classes preempt service. |
ps_threshold |
int
|
Threshold used by the processor-sharing discipline. |
server_priority_function |
callable
|
Function assigning server priority. |
service_discipline |
callable
|
The service discipline used at the node. |
class_change_time |
bool
|
Whether class change times are modelled. |
Initialise a ServiceCentre object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_of_servers
|
int or Schedule
|
The number of servers, or a schedule describing how it varies over time. |
required |
queueing_capacity
|
int or float
|
The maximum queue length. |
required |
class_change_matrix
|
dict
|
Matrix describing class changes, if any. |
None
|
priority_preempt
|
bool
|
Whether priority classes
preempt service. Defaults to |
False
|
ps_threshold
|
int
|
Threshold used by the
processor-sharing discipline. Defaults to |
1
|
server_priority_function
|
callable
|
Function assigning server priority. |
None
|
service_discipline
|
callable
|
The service discipline used at the node. |
None
|
Source code in hciw/network.py
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 | |
CustomerClass ¶
CustomerClass(
arrival_distributions,
service_distributions,
routing,
priority_class,
baulking_functions,
batching_distributions,
reneging_time_distributions,
class_change_time_distributions,
benchmark=None,
)
Store the class-dependent information for a customer class.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_distributions |
dict
|
Arrival distributions for each node. |
service_distributions |
dict
|
Service distributions for each node. |
batching_distributions |
dict
|
Batching distributions for each node. |
routing |
Routing
|
The routing object for the class. |
priority_class |
int
|
The priority class of the customer class. |
baulking_functions |
dict
|
Baulking functions for each node. |
reneging_time_distributions |
dict
|
Reneging time distributions for each node. |
class_change_time_distributions |
dict
|
Class change time distributions for each pair of customer classes. |
benchmark |
float or None
|
The target maximum waiting time for this customer class, used by the benchmark-aware service disciplines. |
Initialise a CustomerClass object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arrival_distributions
|
dict
|
Arrival distributions for each node. |
required |
service_distributions
|
dict
|
Service distributions for each node. |
required |
routing
|
Routing
|
The routing object for the class. |
required |
priority_class
|
int
|
The priority class of the customer class. |
required |
baulking_functions
|
dict
|
Baulking functions for each node. |
required |
batching_distributions
|
dict
|
Batching distributions for each node. |
required |
reneging_time_distributions
|
dict
|
Reneging time distributions for each node. |
required |
class_change_time_distributions
|
dict
|
Class change time distributions for each pair of customer classes. |
required |
benchmark
|
float or None
|
The target maximum waiting
time for this class. Defaults to |
None
|
Source code in hciw/network.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Network ¶
Network(service_centres, customer_classes)
Store the queueing network.
Holds a list of ServiceCentre objects for each service centre and
a dictionary of CustomerClass objects keyed by class name.
Attributes:
| Name | Type | Description |
|---|---|---|
service_centres |
list
|
The service centres of the network. |
customer_classes |
dict
|
The customer classes, keyed by class name. |
number_of_nodes |
int
|
The number of service centres. |
number_of_classes |
int
|
The number of customer classes. |
customer_class_names |
list
|
The sorted names of the customer classes. |
number_of_priority_classes |
int
|
The number of distinct priority classes. |
priority_class_mapping |
dict
|
Maps class names to priority classes. |
system_capacity |
float
|
The total capacity of the system. |
Initialise a Network object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_centres
|
list
|
The service centres of the network. |
required |
customer_classes
|
dict
|
The customer classes, keyed by class name. |
required |
Source code in hciw/network.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
NetworkRouting ¶
NetworkRouting(routers)
Hold a number of routing objects, one for each node.
Set up the router objects for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
routers
|
list
|
The routing objects, one for each node. |
required |
Source code in hciw/routing/routing.py
11 12 13 14 15 16 17 | |
initialise ¶
initialise(simulation)
Give the simulation and node attributes to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Source code in hciw/routing/routing.py
19 20 21 22 23 24 25 26 27 28 29 30 | |
initialise_individual ¶
initialise_individual(ind)
Run at the arrival node when the individual is spawned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being spawned. |
required |
Source code in hciw/routing/routing.py
32 33 34 35 36 37 | |
next_node ¶
next_node(ind, node_id)
Choose the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
39 40 41 42 43 44 45 46 47 48 49 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind, node_id)
Choose the next node when rerouting a preempted customer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
51 52 53 54 55 56 57 58 59 60 61 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind, node_id)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
63 64 65 66 67 68 69 70 71 72 73 | |
TransitionMatrix ¶
TransitionMatrix(transition_matrix)
Bases: NetworkRouting
Hold a number of probabilistic routing objects.
Set up the relevant probabilistic router objects for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transition_matrix
|
list
|
A square matrix where the entry in row
|
required |
Source code in hciw/routing/routing.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |
initialise ¶
initialise(simulation)
Give the simulation to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of rows in the transition matrix does not equal the number of nodes in the network. |
Source code in hciw/routing/routing.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
ProcessBased ¶
ProcessBased(route_function)
Bases: NetworkRouting
Route an individual based on a pre-defined process.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_function
|
callable
|
A function that returns a pre-defined route for an individual. |
required |
Source code in hciw/routing/routing.py
115 116 117 118 119 120 121 122 | |
initialise ¶
initialise(simulation)
Give the simulation and node attributes to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Source code in hciw/routing/routing.py
124 125 126 127 128 129 130 131 | |
initialise_individual ¶
initialise_individual(ind)
Set the route of the individual when they are spawned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being spawned. |
required |
Source code in hciw/routing/routing.py
133 134 135 136 137 138 139 | |
next_node ¶
next_node(ind, node_id)
Choose the next node from the process-based pre-defined route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind, node_id)
Choose the next node when rerouting a preempted customer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
154 155 156 157 158 159 160 161 162 163 164 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind, node_id)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
166 167 168 169 170 171 172 173 174 175 176 | |
FlexibleProcessBased ¶
FlexibleProcessBased(route_function, rule, choice)
Bases: ProcessBased
Route an individual based on a pre-defined process.
The route is flexible: each step may be a subset of nodes from which the next node is chosen according to a rule and a choice method.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_function
|
callable
|
A function that returns a pre-defined route for an individual. |
required |
rule
|
str
|
Either |
required |
choice
|
str
|
Either |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Source code in hciw/routing/routing.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
find_next_node_from_subset ¶
find_next_node_from_subset(subset, ind)
Find the next node within a subset according to choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
list
|
The subset of node indices to choose from. |
required |
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The id number of the chosen node. |
Source code in hciw/routing/routing.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
update_individual_route ¶
update_individual_route(ind, next_node_id)
Remove chosen nodes from the individual's route according to rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
next_node_id
|
int
|
The id number of the chosen next node. |
required |
Source code in hciw/routing/routing.py
236 237 238 239 240 241 242 243 244 245 246 247 248 | |
next_node ¶
next_node(ind, node_id)
Choose the next node from the process-based pre-defined route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
NodeRouting ¶
A generic routing class to determine next sampled node.
initialise ¶
initialise(simulation, node)
Give the simulation and node attributes to the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the router belongs to. |
required |
node
|
Node
|
The node the router belongs to. |
required |
Source code in hciw/routing/routing.py
271 272 273 274 275 276 277 278 279 280 281 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the routing object is valid when it is initialised.
Source code in hciw/routing/routing.py
283 284 | |
next_node ¶
next_node(ind)
Choose the next node for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
286 287 288 289 290 291 292 293 294 295 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Choose the next node when rerouting a preempted customer.
By default, the next node for rerouting uses the same method as
:meth:next_node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
297 298 299 300 301 302 303 304 305 306 307 308 309 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
311 312 313 314 315 316 317 318 319 320 | |
Probabilistic ¶
Probabilistic(destinations, probs)
Bases: NodeRouting
A router that probabilistically chooses the next node.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destinations
|
list
|
A list of node indices. |
required |
probs
|
list
|
A list of probabilities associated with each destination. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any probability is not a float. |
ValueError
|
If any probability is less than 0 or greater than 1. |
ValueError
|
If the probabilities sum to more than 1. |
Source code in hciw/routing/routing.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the probabilities and destinations are valid.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the probabilities and destinations differ in length. |
ValueError
|
If the destinations are not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
next_node ¶
next_node(ind)
Probabilistically choose the next node from the destinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
372 373 374 375 376 377 378 379 380 381 382 | |
Direct ¶
Direct(to)
Bases: NodeRouting
A router that sends the individual directly to another node.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
int
|
The node index to send to. |
required |
Source code in hciw/routing/routing.py
388 389 390 391 392 393 394 | |
next_node ¶
next_node(ind)
Choose the node to with probability 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The destination node. |
Source code in hciw/routing/routing.py
396 397 398 399 400 401 402 403 404 405 | |
Leave ¶
Bases: NodeRouting
A router that sends the individual directly to the exit node.
next_node ¶
next_node(ind)
Choose the exit node with probability 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
411 412 413 414 415 416 417 418 419 420 | |
JoinShortestQueue ¶
JoinShortestQueue(destinations, tie_break='random')
Bases: NodeRouting
A router that sends the individual to the node with the shortest queue.
The node is chosen from a list of destinations.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destinations
|
list
|
A list of node indices. |
required |
tie_break
|
str
|
The method to deal with ties. One of
|
'random'
|
Source code in hciw/routing/routing.py
429 430 431 432 433 434 435 436 437 438 439 440 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the destinations are a subset of the network's nodes.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the destinations are not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
442 443 444 445 446 447 448 449 450 451 452 453 454 | |
get_queue_size ¶
get_queue_size(node_index)
Get the size of the queue at node_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_index
|
int
|
The index of the node. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of waiting individuals. |
Source code in hciw/routing/routing.py
456 457 458 459 460 461 462 463 464 465 466 467 468 | |
next_node ¶
next_node(ind)
Choose the destination node with the shortest queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
LoadBalancing ¶
LoadBalancing(destinations, tie_break='random')
Bases: JoinShortestQueue
A version of JoinShortestQueue that also counts customers in service.
Source code in hciw/routing/routing.py
429 430 431 432 433 434 435 436 437 438 439 440 | |
get_queue_size ¶
get_queue_size(node_index)
Get the size of the queue at node_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_index
|
int
|
The index of the node. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of individuals at the node. |
Source code in hciw/routing/routing.py
500 501 502 503 504 505 506 507 508 509 | |
Cycle ¶
Cycle(cycle)
Bases: NodeRouting
A router that cycles through destinations, repeating the cycle once ended.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
list
|
An ordered sequence of node indices. |
required |
Source code in hciw/routing/routing.py
515 516 517 518 519 520 521 522 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the cycle is a subset of the network's nodes.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the cycle is not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
524 525 526 527 528 529 530 531 532 533 534 535 536 | |
next_node ¶
next_node(ind)
Choose the next node in the cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
538 539 540 541 542 543 544 545 546 547 548 | |
Schedule ¶
Schedule(
numbers_of_servers: list[int],
shift_end_dates: list[float],
preemption: bool | str = False,
offset: float = 0.0,
)
Store server schedule information and generate the next shifts.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
shift_end_dates |
List[float]
|
The end dates of each shift. |
numbers_of_servers |
List[int]
|
The number of servers for each shift. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
offset |
float
|
The offset applied to the schedule. |
Initialise a Schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers_of_servers
|
List[int]
|
The number of servers working at each shift. |
required |
shift_end_dates
|
List[float]
|
The end dates of each shift. |
required |
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
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 | |
initialise ¶
initialise() -> None
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
58 59 60 61 62 63 64 65 | |
get_schedule_generator ¶
get_schedule_generator(
boundaries: list[float],
values: list[int],
offset: float,
) -> Generator[tuple[float, int], None, None]
Yield the next shift date and server count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
List[float]
|
The shift boundaries. |
required |
values
|
List[int]
|
The number of servers corresponding to each boundary. |
required |
offset
|
float
|
The offset applied to the schedule. |
required |
Yields:
| Type | Description |
|---|---|
Tuple[float, int]
|
The next shift date and the number of servers. |
Source code in hciw/schedules.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
get_next_shift ¶
get_next_shift() -> None
Update the next shift from the generator.
Source code in hciw/schedules.py
93 94 95 96 97 98 | |
Slotted ¶
Slotted(
slots,
slot_sizes,
capacitated=False,
preemption=False,
offset=0.0,
)
Bases: Schedule
A schedule divided into slots with a number of servers per slot.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
offset |
float
|
The offset applied to the schedule. |
slots |
list
|
The slot boundaries. |
slot_sizes |
list
|
The number of servers in each slot. |
next_slot_sizes |
list
|
The slot sizes of the next cycle. |
capacitated |
bool
|
Whether the slots are capacitated. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
c |
int
|
The current number of servers. |
Initialise a Slotted schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slots
|
list
|
The slot boundaries. |
required |
slot_sizes
|
list
|
The number of servers in each slot. |
required |
capacitated
|
bool
|
Whether the slots are capacitated.
Defaults to |
False
|
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
initialise ¶
initialise()
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
160 161 162 163 164 165 | |
get_next_slot ¶
get_next_slot()
Update the next slot date and size from the generator.
Source code in hciw/schedules.py
167 168 169 170 171 | |
create_network ¶
create_network(
arrival_distributions=None,
baulking_functions=None,
class_change_matrices=None,
class_change_time_distributions=None,
number_of_servers=None,
priority_classes=None,
queue_capacities=None,
service_distributions=None,
routing=None,
batching_distributions=None,
ps_thresholds=None,
server_priority_functions=None,
reneging_time_distributions=None,
service_disciplines=None,
customer_class_benchmarks=None,
system_capacity=float("inf"),
)
Create a Network object from keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arrival_distributions
|
dict
|
Arrival distributions for each customer class and node. Required. |
None
|
baulking_functions
|
dict
|
Baulking functions for each customer class and node. |
None
|
class_change_matrices
|
list
|
Class change matrices, one per node. |
None
|
class_change_time_distributions
|
dict
|
Class change time distributions for each pair of customer classes. |
None
|
number_of_servers
|
list
|
The number of servers at each node, or schedules. Required. |
None
|
priority_classes
|
dict or tuple
|
The priority class of each customer class. |
None
|
queue_capacities
|
list
|
The queue capacity of each node. |
None
|
service_distributions
|
dict
|
Service distributions for each customer class and node. Required. |
None
|
routing
|
list, dict, or Routing
|
The routing for each customer class. |
None
|
batching_distributions
|
dict
|
Batching distributions for each customer class and node. |
None
|
ps_thresholds
|
list
|
Processor-sharing thresholds, one per node. |
None
|
server_priority_functions
|
list
|
Server priority functions, one per node. |
None
|
reneging_time_distributions
|
dict
|
Reneging time distributions for each customer class and node. |
None
|
service_disciplines
|
list
|
Service disciplines, one per node. |
None
|
customer_class_benchmarks
|
dict
|
The target maximum
waiting time for each customer class, keyed by class name. Read
by the benchmark-aware service disciplines such as
|
None
|
system_capacity
|
int or float
|
The maximum number of customers allowed in the system. Defaults to infinity. |
float('inf')
|
Returns:
| Type | Description |
|---|---|
Network
|
The constructed network object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/import_params.py
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
create_network_from_dictionary ¶
create_network_from_dictionary(params_input)
Create a Network object from a parameters dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params_input
|
dict
|
The dictionary of network parameters. |
required |
Returns:
| Type | Description |
|---|---|
Network
|
The constructed network object. |
Source code in hciw/import_params.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
fill_out_dictionary ¶
fill_out_dictionary(params)
Fill out a parameters dictionary with default optional values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The parameters dictionary to complete. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The completed parameters dictionary. |
Source code in hciw/import_params.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
validify_dictionary ¶
validify_dictionary(params)
Raise errors if a parameters dictionary is invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The parameters dictionary to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the parameters are inconsistent or invalid. |
Source code in hciw/import_params.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
simulation ¶
The Simulation engine that drives customers through a network.
ArrivalNode ¶
ArrivalNode(simulation)
Represent the arrival node of the network.
This class handles arrivals, baulking, and rejections of individuals.
See hciw.Simulation for the main simulation class.
Initialise the arrival node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
object
|
The simulation to which this arrival node belongs. |
required |
Source code in hciw/arrival_node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
initialise ¶
initialise()
Initialise the event dates dictionary and next event date.
Source code in hciw/arrival_node.py
36 37 38 39 | |
decide_baulk ¶
decide_baulk(next_node, next_individual)
Either make an individual baulk or send them to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being considered. |
required |
Source code in hciw/arrival_node.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
find_next_event_date ¶
find_next_event_date()
Find the time of the next arrival.
Source code in hciw/arrival_node.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
have_event ¶
have_event()
Create and send a batch of arriving individuals.
Finds a batch size, creates that many individuals, sends them to the relevant node, then updates the event dates dictionary.
Source code in hciw/arrival_node.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/arrival_node.py
120 121 122 123 124 125 126 127 128 129 130 | |
initialise_event_dates_dict ¶
initialise_event_dates_dict()
Initialise the event dates dictionary.
Random times are sampled for each node and class.
Source code in hciw/arrival_node.py
132 133 134 135 136 137 138 139 140 141 142 | |
inter_arrival ¶
inter_arrival(nd, clss)
Sample the inter-arrival time for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
|
The sampled inter-arrival time. |
Source code in hciw/arrival_node.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
batch_size ¶
batch_size(nd, clss)
Sample the batch size for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The sampled batch size. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sampled batch size is not a non-negative integer. |
Source code in hciw/arrival_node.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
record_baulk ¶
record_baulk(next_node, individual)
Write a baulking record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual would have joined. |
required |
individual
|
Individual
|
The baulking individual. |
required |
Source code in hciw/arrival_node.py
179 180 181 182 183 184 185 186 | |
record_rejection ¶
record_rejection(next_node, individual)
Write a rejection record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual was rejected from. |
required |
individual
|
Individual
|
The rejected individual. |
required |
Source code in hciw/arrival_node.py
188 189 190 191 192 193 194 195 196 197 | |
release_individual ¶
release_individual(next_node, next_individual)
Release an individual to the next node.
Either rejects the individual due to lack of capacity, or sends that individual to baulk or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being released. |
required |
Source code in hciw/arrival_node.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
send_individual ¶
send_individual(next_node, next_individual)
Send the next individual to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being sent. |
required |
Source code in hciw/arrival_node.py
217 218 219 220 221 222 223 224 225 226 | |
update_next_event_date ¶
update_next_event_date()
Do nothing, as the next event update happens at the event time.
Source code in hciw/arrival_node.py
228 229 | |
ExactArrivalNode ¶
ExactArrivalNode(simulation)
Bases: ArrivalNode
Represent an arrival node with exact numerical precision.
Inherits from ArrivalNode and implements a more precise version of
addition to fix discrepancies with floating point numbers.
Source code in hciw/arrival_node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
increment_time ¶
increment_time(original, increment) -> Decimal
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The incremented time. |
Source code in hciw/exactnode.py
71 72 73 74 75 76 77 78 79 80 81 | |
inter_arrival ¶
inter_arrival(nd, clss) -> Decimal
Sample the inter-arrival time for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
Node
|
The next node. |
required |
clss
|
Individual
|
The individual class to select next. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The sampled inter-arrival time. |
Source code in hciw/exactnode.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
ExactNode ¶
ExactNode(id_, simulation)
Bases: Node
Represent a node with exact numerical precision.
This class inherits from Node and implements a more precise version of
addition to fix discrepancies with floating point numbers.
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now: Decimal
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
Decimal
|
The current simulation time. |
create_starting_servers ¶
create_starting_servers() -> list[Server]
Initialise the servers at this node.
Returns:
| Type | Description |
|---|---|
List[Server]
|
The newly created starting servers. |
Source code in hciw/exactnode.py
26 27 28 29 30 31 32 | |
increment_time ¶
increment_time(original, increment) -> Decimal
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The incremented time. |
Source code in hciw/exactnode.py
34 35 36 37 38 39 40 41 42 43 44 | |
get_service_time ¶
get_service_time(ind) -> Decimal
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The sampled service time. |
Source code in hciw/exactnode.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ExitNode ¶
ExitNode()
Represent the exit node of the network.
Initialise the exit node.
Source code in hciw/exit_node.py
7 8 9 10 11 12 13 14 | |
accept ¶
accept(next_individual, completed=True)
Add an individual to the list of completed individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual completed service. |
True
|
Source code in hciw/exit_node.py
24 25 26 27 28 29 30 31 32 33 34 35 | |
update_next_event_date ¶
update_next_event_date()
Do nothing, as the next event date is always the max time.
Source code in hciw/exit_node.py
37 38 | |
Individual ¶
Individual(
id_number,
customer_class="Customer",
priority_class=0,
simulation=False,
)
Represent an individual agent in a queueing network simulation.
An Individual models the flow of an agent through a queueing
network, tracking its arrival time, service time, priority and other
relevant data.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_date |
bool or float
|
Timestamp of the individual's arrival. |
service_start_date |
bool or float
|
Timestamp the current service started. |
service_time |
bool or float
|
Duration of the current service. |
service_end_date |
bool or float
|
Timestamp the current service ends. |
exit_date |
bool or float
|
Timestamp the individual exits the system. |
id_number |
int
|
Unique identifier for the individual. |
data_records |
list
|
The data records attached to the individual. |
customer_class |
str
|
The customer class of the individual. |
previous_class |
str
|
The previous customer class of the individual. |
priority_class |
int
|
The priority class of the individual. |
prev_priority_class |
int
|
The previous priority class of the individual. |
original_class |
str
|
The original customer class of the individual. |
is_blocked |
bool
|
Whether the individual is blocked. |
server |
bool or Server
|
The server assigned to the individual, if any. |
queue_size_at_arrival |
bool or int
|
Queue size when the individual arrived. |
queue_size_at_departure |
bool or int
|
Queue size when the individual departed. |
destination |
bool or int
|
The destination node in the network. |
interrupted |
bool
|
Whether the individual's service was interrupted. |
node |
bool or int
|
The node where the individual is located. |
simulation |
bool or Simulation
|
The simulation the individual belongs to. |
Example
.. code-block:: python
individual = Individual(
id_number=1, customer_class='Gold', priority_class=1,
simulation=True,
)
Initialise an Individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_number
|
int
|
A unique identifier for the individual. |
required |
customer_class
|
str
|
The customer class the individual
belongs to. Defaults to |
'Customer'
|
priority_class
|
int
|
The priority class of the
individual. Defaults to |
0
|
simulation
|
bool or Simulation
|
The simulation the
individual is part of. Defaults to |
False
|
Source code in hciw/individual.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
Node ¶
Node(id_, simulation)
Represent a node in the queueing network.
The node holds a queue of individuals and, where applicable, the servers that process them.
Initialise a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
int
|
Identifier for the node. |
required |
simulation
|
object
|
The simulation to which this node belongs. |
required |
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
float
|
The current simulation time. |
all_individuals
property
¶
all_individuals
Get all individuals currently at the node.
Returns:
| Type | Description |
|---|---|
list
|
Every individual at the node, across all priority classes. |
accept ¶
accept(next_individual, completed=False)
Accept a new individual into the queue.
Removes any previous exit date and blockage status, begins service if possible, records arrival information, and updates the state tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual has completed service. |
False
|
Source code in hciw/node.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
add_new_servers ¶
add_new_servers(num_servers)
Add the appropriate number of servers for the given shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_servers
|
int
|
The number of servers to add. |
required |
Source code in hciw/node.py
129 130 131 132 133 134 135 136 137 138 139 | |
attach_server ¶
attach_server(server, individual)
Attach a server to an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to attach. |
required |
individual
|
Individual
|
The individual to attach. |
required |
Source code in hciw/node.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
begin_service_if_possible_accept ¶
begin_service_if_possible_accept(next_individual)
Begin service for an individual at the acceptance point.
Sets the arrival date to the current time, and if a server is free or there are infinitely many servers, attaches the server, gets the service start time, service time and service end time, and updates the server's end date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
begin_interrupted_individuals_service ¶
begin_interrupted_individuals_service(srvr)
Restart an interrupted individual's service.
The individual's service time is resampled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to give to the individual. |
required |
Source code in hciw/node.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
begin_service_if_possible_change_shift ¶
begin_service_if_possible_change_shift()
Begin service for customers after a shift change.
If there are free servers, restarts interrupted customers' services and begins service for any waiting customers by giving a start date and end date and attaching servers to individuals.
Source code in hciw/node.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
begin_service_if_possible_release ¶
begin_service_if_possible_release(
next_individual, newly_free_server
)
Begin service for an individual after a release.
Checks for interrupted individuals left to restart service, then gives an arrival date and service time, gives a start date and end date, and attaches the server to the individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual being released. |
required |
newly_free_server
|
Server
|
The server freed by the release. |
required |
Source code in hciw/node.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
block_individual ¶
block_individual(individual, next_node)
Block an individual from entering the next node.
Changes the blocked status, updates the state tracker, adds information to the next node's blocked queue, and updates the deadlock detector, informing the simulation that there are unchecked blockages for deadlock detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/node.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
change_customer_class ¶
change_customer_class(individual)
Change an individual's customer class.
The new class is chosen according to a probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual whose class changes. |
required |
Source code in hciw/node.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
change_customer_class_while_waiting ¶
change_customer_class_while_waiting()
Change the next queued individual's class while waiting.
The individual is moved between priority queues and preemption is decided if the priority class changes.
Source code in hciw/node.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
change_priority_queue ¶
change_priority_queue(individual)
Move an individual to their new priority queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to move. |
required |
Source code in hciw/node.py
332 333 334 335 336 337 338 339 | |
change_shift ¶
change_shift()
Implement a server shift change.
Adds or deletes servers, or indicates which servers should go off duty, and begins any new services if there are free servers.
Source code in hciw/node.py
341 342 343 344 345 346 347 348 349 350 351 352 353 | |
find_number_of_slotted_services ¶
find_number_of_slotted_services()
Find the number of slotted services to start in this slot.
Returns:
| Type | Description |
|---|---|
int
|
The number of services to start. |
Source code in hciw/node.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
interrupt_slotted_services ¶
interrupt_slotted_services()
Interrupt services when there is not enough slot capacity.
Finds the customers whose slotted services need to be interrupted because of insufficient capacity at the current slot, and interrupts their services.
Source code in hciw/node.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
slotted_service ¶
slotted_service()
Serve a set number of customers at the current time.
Only the number of customers allowed by the current slot may have service at the exact time the method is called.
Source code in hciw/node.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
choose_next_customer ¶
choose_next_customer()
Choose which customer will be next to be served.
Returns:
| Type | Description |
|---|---|
Individual
|
The customer chosen by the service discipline, or None if no customer is waiting. |
Source code in hciw/node.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
create_starting_servers ¶
create_starting_servers()
Initialise the servers.
Returns:
| Type | Description |
|---|---|
list
|
The newly created starting servers. |
Source code in hciw/node.py
432 433 434 435 436 437 438 439 440 | |
decide_class_change ¶
decide_class_change(next_individual)
Decide the next class and class change date for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to update. |
required |
Source code in hciw/node.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
decide_preempt ¶
decide_preempt(individual)
Decide whether priority preemption is needed.
If needed, finds the individual to preempt and preempts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual seeking service. |
required |
Source code in hciw/node.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
detatch_server ¶
detatch_server(server, individual)
Detach a server from an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to detach. |
required |
individual
|
Individual
|
The individual to detach. |
required |
Source code in hciw/node.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
find_free_server ¶
find_free_server(ind)
Find a free server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual needing a server. |
required |
Returns:
| Type | Description |
|---|---|
Server
|
A free server, or None if none is available. |
Source code in hciw/node.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
decide_between_simultaneous_individuals ¶
decide_between_simultaneous_individuals()
Find the next individual that should now finish service.
Returns:
| Type | Description |
|---|---|
Individual
|
A randomly chosen individual when several finish at the same time. |
Source code in hciw/node.py
527 528 529 530 531 532 533 534 535 536 537 538 539 | |
find_next_class_change ¶
find_next_class_change()
Update the next class change date and individual.
Source code in hciw/node.py
541 542 543 544 545 546 547 548 | |
find_server_utilisation ¶
find_server_utilisation()
Find the overall server utilisation for the node.
Source code in hciw/node.py
550 551 552 553 554 555 556 557 558 559 560 | |
finish_service ¶
finish_service()
Finish the service of the next individual.
Finds the individual to finish service, checks whether they need to change class, finds their next node, and releases the individual if there is capacity at the destination, otherwise causes blockage.
Source code in hciw/node.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
give_individual_a_service_time ¶
give_individual_a_service_time(individual)
Give a service time to an individual.
Either a new service time, or a service time after pre-emption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
581 582 583 584 585 586 587 588 589 590 591 592 | |
give_service_time_after_preemption ¶
give_service_time_after_preemption(individual)
Give a service time after preemption.
Either resamples, restarts, or resumes service time from where it was left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
have_event ¶
have_event()
Trigger the node's next event.
Source code in hciw/node.py
610 611 612 613 614 615 616 617 618 619 620 621 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/node.py
623 624 625 626 627 628 629 630 631 632 633 | |
kill_server ¶
kill_server(srvr)
Kill a server when it goes off duty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to remove. |
required |
Source code in hciw/node.py
635 636 637 638 639 640 641 642 643 644 645 646 | |
next_node ¶
next_node(ind)
Find the next node according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/node.py
648 649 650 651 652 653 654 655 656 657 658 659 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Find the next node for rerouting according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being rerouted. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for rerouting. |
Source code in hciw/node.py
661 662 663 664 665 666 667 668 669 670 671 672 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Find the next node for jockeying according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The jockeying individual. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for jockeying. |
Source code in hciw/node.py
674 675 676 677 678 679 680 681 682 683 684 685 | |
preempt ¶
preempt(individual_to_preempt, next_individual)
Preempt an individual and replace them in service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual_to_preempt
|
Individual
|
The individual removed from service. |
required |
next_individual
|
Individual
|
The individual taking their place. |
required |
Source code in hciw/node.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
release ¶
release(next_individual, next_node, reroute=False)
Release an individual from the node.
Removes the individual from the queue, records relevant information, detaches the server, updates the state tracker, begins service of any waiting customers, sends the individual to their next destination, and releases any individuals blocked by this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to release. |
required |
next_node
|
Node
|
The node receiving the individual. |
required |
reroute
|
bool
|
Whether the release is due to rerouting. |
False
|
Source code in hciw/node.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
release_blocked_individual ¶
release_blocked_individual()
Release an individual blocked by this node.
Finds the individual who has been blocked the longest, removes them from the blocked queue, restores their service if it was interrupted, and releases them from their node.
Source code in hciw/node.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
reset_class_change ¶
reset_class_change(individual)
Reset an individual's class change date when service begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual beginning service. |
required |
Source code in hciw/node.py
786 787 788 789 790 791 792 793 794 795 | |
renege ¶
renege()
Remove an individual from the queue due to reneging.
Resets the individual's reneging date and sends the individual to their reneging destination.
Source code in hciw/node.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
get_reneging_date ¶
get_reneging_date(ind)
Return the reneging date for a given individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The reneging date. |
Source code in hciw/node.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
get_service_time ¶
get_service_time(ind)
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sampled service time. |
Source code in hciw/node.py
836 837 838 839 840 841 842 843 844 845 846 847 | |
take_servers_off_duty ¶
take_servers_off_duty(preemption: bool | str = False)
Gather the servers that should be deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preemption
|
bool
|
Whether preemption is active for this shift change. |
False
|
Source code in hciw/node.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
interrupt_service ¶
interrupt_service(individual)
Interrupt an individual's service.
Places the individual in the interrupted queue and writes an interruption record for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being interrupted. |
required |
Source code in hciw/node.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
sort_interrupted_individuals ¶
sort_interrupted_individuals()
Sort interrupted individuals by priority class and arrival date.
Source code in hciw/node.py
899 900 901 902 903 | |
reroute ¶
reroute(individual)
Reroute a preempted individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being rerouted. |
required |
Source code in hciw/node.py
905 906 907 908 909 910 911 912 913 | |
update_next_end_service_without_server ¶
update_next_end_service_without_server()
Update the next end of a slotted service in possible_next_events.
Source code in hciw/node.py
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
update_next_end_service_with_server ¶
update_next_end_service_with_server()
Update the next end service with a server in possible_next_events.
Source code in hciw/node.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
update_next_renege_time ¶
update_next_renege_time()
Update the next renege time in possible_next_events.
Source code in hciw/node.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
update_next_class_change_while_waiting ¶
update_next_class_change_while_waiting()
Update the next class change while waiting in possible_next_events.
Source code in hciw/node.py
963 964 965 966 967 968 969 | |
update_next_shift_change_or_slot_time ¶
update_next_shift_change_or_slot_time()
Update possible_next_events with the next shift or slot time.
Source code in hciw/node.py
971 972 973 974 975 976 977 978 979 980 981 982 983 | |
update_next_event_date ¶
update_next_event_date()
Find the time of the next event at this node.
With infinite servers this is the time of the next individual to end service, or infinity. Otherwise it is the minimum of the next shift change and the time for the next individual (who is not blocked) to end service, or infinity.
Source code in hciw/node.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
decide_next_event ¶
decide_next_event()
Decide the next event.
Chooses the next service end, renege, shift change, or class change. In the case of a tie, events are prioritised in the following order:
- slotted service
- shift change
- end service
- class change
- renege
Returns:
| Type | Description |
|---|---|
tuple
|
The next event and its event type. |
Source code in hciw/node.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server total and busy times at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The simulation end time. |
required |
Source code in hciw/node.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
write_individual_record ¶
write_individual_record(individual)
Write a data record for an individual leaving a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual leaving the node. |
required |
Source code in hciw/node.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
write_incomplete_record ¶
write_incomplete_record(individual)
Write an incomplete data record at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual still at the node. |
required |
Returns:
| Type | Description |
|---|---|
DataRecord
|
The incomplete data record. |
Source code in hciw/node.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 | |
write_interruption_record ¶
write_interruption_record(individual, destination=nan)
Write a data record for an individual being interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The interrupted individual. |
required |
destination
|
int
|
The destination node number. |
nan
|
Source code in hciw/node.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
write_reneging_record ¶
write_reneging_record(individual)
Write a data record for an individual when reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The reneging individual. |
required |
Source code in hciw/node.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
write_baulking_or_rejection_record ¶
write_baulking_or_rejection_record(individual, record_type)
Write a data record for an individual who baulks or is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual. |
required |
record_type
|
str
|
The type of record to write. |
required |
Source code in hciw/node.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
reset_individual_attributes ¶
reset_individual_attributes(individual)
Reset the attributes of an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to reset. |
required |
Source code in hciw/node.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
Server ¶
Server(node, id_number, start_date: float | Decimal = 0.0)
Contain information about a server.
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server belongs to. |
required |
id_number
|
int
|
Identifier for the server. |
required |
start_date
|
float | Decimal
|
The time at which the server started, and whose type sets the precision of the server's accumulated times. |
0.0
|
Source code in hciw/server.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
utilisation
property
¶
utilisation
Get the server utilisation.
Returns:
| Type | Description |
|---|---|
float | Decimal
|
The proportion of total time the server was busy. |
Simulation ¶
Simulation(
network,
exact=False,
name="Simulation",
tracker=None,
deadlock_detector=None,
node_class=None,
arrival_node_class=None,
exit_node_class=None,
individual_class=None,
server_class=None,
initial_individuals=None,
)
The engine that runs a queueing network simulation.
A Simulation drives customers through the network's nodes over
simulated time, collecting data records and tracking state.
Attributes:
| Name | Type | Description |
|---|---|---|
current_time |
float
|
The current simulated time. |
network |
Network
|
The network being simulated. |
name |
str
|
The name of the simulation. |
NodeTypes |
list
|
The node classes used at each service centre. |
ArrivalNodeType |
type
|
The class used for the arrival node. |
ExitNodeType |
type
|
The class used for the exit node. |
IndividualType |
type
|
The class used for individuals. |
ServerType |
type
|
The class used for servers. |
deadlock_detector |
object
|
The detector used to identify deadlocks. |
inter_arrival_times |
dict
|
Inter-arrival distributions by node and class. |
service_times |
dict
|
Service distributions by node and class. |
batch_sizes |
dict
|
Batch size distributions by node and class. |
number_of_priority_classes |
int
|
The number of priority classes. |
transitive_nodes |
list
|
The service centre nodes. |
nodes |
list
|
The arrival, transitive and exit nodes. |
active_nodes |
list
|
The nodes that are not the exit node. |
routers |
dict
|
The routing objects by customer class. |
statetracker |
StateTracker
|
The state tracker in use. |
times_dictionary |
dict
|
Maps hashed states to the time first seen. |
times_to_deadlock |
dict
|
The time from each state to deadlock. |
unchecked_blockage |
bool
|
Whether a blockage needs checking. |
Initialise a simulation instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network to simulate. |
required |
exact
|
int
|
If truthy, use exact |
False
|
name
|
str
|
The name of the simulation. Defaults to
|
'Simulation'
|
tracker
|
StateTracker
|
The state tracker to use.
Defaults to a plain |
None
|
deadlock_detector
|
object
|
The deadlock detector to
use. Defaults to |
None
|
node_class
|
type or list
|
The node class or classes to
use. Defaults to |
None
|
arrival_node_class
|
type
|
The arrival node class to use.
Defaults to |
None
|
exit_node_class
|
type
|
The exit node class to use.
Defaults to |
None
|
individual_class
|
type
|
The individual class to use.
Defaults to |
None
|
server_class
|
type
|
The server class to use. Defaults
to |
None
|
initial_individuals
|
list[list]
|
A list of backlogged
individuals to seed the simulation with, in the form
|
None
|
Source code in hciw/simulation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
number_of_individuals
property
¶
number_of_individuals
Return the number of individuals currently in the system.
Returns:
| Type | Description |
|---|---|
int
|
The number of individuals currently in the system. |
find_arrival_dists ¶
find_arrival_dists()
Create the arrival time distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Arrival time distributions keyed by node and customer class. |
Source code in hciw/simulation.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
find_service_dists ¶
find_service_dists()
Create the service time distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Service time distributions keyed by node and customer class. |
Source code in hciw/simulation.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
find_batching_dists ¶
find_batching_dists()
Create the batch size distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Batch size distributions keyed by node and customer class. |
Source code in hciw/simulation.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
show_simulation_to_distributions ¶
show_simulation_to_distributions()
Add the simulation as an attribute of the distribution objects.
Source code in hciw/simulation.py
208 209 210 211 212 213 214 215 | |
find_and_initialise_routers ¶
find_and_initialise_routers()
Initialise and return the routing objects.
Returns:
| Type | Description |
|---|---|
dict
|
Routing objects keyed by customer class. |
Source code in hciw/simulation.py
217 218 219 220 221 222 223 224 225 226 227 | |
find_next_active_node ¶
find_next_active_node()
Return the active node with the earliest next event date.
If several nodes share the earliest date, one is chosen at random.
Returns:
| Type | Description |
|---|---|
Node
|
The next active node. |
Source code in hciw/simulation.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
get_all_individuals ¶
get_all_individuals()
Return all individuals with at least one data record.
Returns:
| Type | Description |
|---|---|
list
|
The individuals with at least one data record. |
Source code in hciw/simulation.py
249 250 251 252 253 254 255 256 257 258 259 | |
get_all_records ¶
get_all_records(only=None, include_incomplete=False)
Get data records from all individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only
|
list
|
The record types to include. Defaults to service, baulk, rejection, renege and interrupted service records. |
None
|
include_incomplete
|
bool
|
Whether to include records
for individuals still in the system. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
list
|
The collected data records. |
Source code in hciw/simulation.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
set_classes ¶
set_classes(
node_class,
arrival_node_class,
exit_node_class,
individual_class,
server_class,
)
Set the node, individual and server classes used by the simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_class
|
type or list
|
The node class or classes to use. If a list, it must have one entry per node. |
required |
arrival_node_class
|
type
|
The arrival node class to use, or
|
required |
exit_node_class
|
type
|
The exit node class to use, or |
required |
individual_class
|
type
|
The individual class to use, or |
required |
server_class
|
type
|
The server class to use, or |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/simulation.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
event_and_return_nextnode ¶
event_and_return_nextnode(next_active_node)
Carry out an event and return the next active node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_active_node
|
Node
|
The node whose event to carry out. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next active node. |
Source code in hciw/simulation.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
simulate_until_deadlock ¶
simulate_until_deadlock()
Run the simulation until deadlock is reached.
Source code in hciw/simulation.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
simulate_until_max_time ¶
simulate_until_max_time(
max_simulation_time, progress_bar=False
)
Run the simulation until a maximum simulated time is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_simulation_time
|
float
|
The time to stop the simulation at. |
required |
progress_bar
|
bool
|
Whether to display a progress bar.
Defaults to |
False
|
Source code in hciw/simulation.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
simulate_until_max_customers ¶
simulate_until_max_customers(
max_customers, progress_bar=False, method="Complete"
)
Run the simulation until a number of customers is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_customers
|
int
|
The number of customers to stop at. |
required |
progress_bar
|
bool
|
Whether to display a progress bar.
Defaults to |
False
|
method
|
str
|
The measure used to count customers. One of:
Defaults to |
'Complete'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/simulation.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server times and find the overall server utilisation.
Updates each server's total time and busy time at the end of the simulation run, and finds the overall server utilisation for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The time at which the run finished. |
required |
Source code in hciw/simulation.py
498 499 500 501 502 503 504 505 506 507 508 509 | |
seed ¶
seed(z)
Set all seeds used to generate random number streams.
Seeds both the standard library random module and the NumPy
random generator used by hciw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
int
|
The seed value to use. |
required |
Source code in hciw/auxiliary.py
14 15 16 17 18 19 20 21 22 23 24 | |
random_choice ¶
random_choice(array, probs=None)
Select a random element from an array using optional weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list
|
The values to choose from. |
required |
probs
|
list
|
Probability weights corresponding to each value. If omitted, a uniform choice is made. |
None
|
Returns:
| Type | Description |
|---|---|
|
The randomly selected element of |
Source code in hciw/auxiliary.py
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 | |
truncated_normal ¶
truncated_normal(mean, sd)
Sample from a Normal distribution truncated at zero.
Values less than or equal to zero are resampled until a positive value is obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
The mean of the Normal distribution. |
required |
sd
|
float
|
The standard deviation of the Normal distribution. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A positive sample from the truncated Normal distribution. |
Source code in hciw/auxiliary.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
flatten_list ¶
flatten_list(list_of_lists)
Flatten a list of lists into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_lists
|
list
|
A list whose elements are themselves lists. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A single list containing all elements of the inner lists. |
Source code in hciw/auxiliary.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
no_routing ¶
no_routing(ind)
Send a customer straight to the exit node.
This process-based routing function is a placeholder used when
NoArrivals is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
list
|
An empty list of destinations. |
Source code in hciw/auxiliary.py
91 92 93 94 95 96 97 98 99 100 101 102 103 | |
network ¶
Information stores describing the nodes and classes of a network.
ServiceCentre ¶
ServiceCentre(
number_of_servers,
queueing_capacity,
class_change_matrix=None,
priority_preempt=False,
ps_threshold=1,
server_priority_function=None,
service_discipline=None,
)
Store the class-independent information for a service centre.
Attributes:
| Name | Type | Description |
|---|---|---|
number_of_servers |
int or Schedule
|
The number of servers, or a schedule describing how it varies over time. |
queueing_capacity |
int or float
|
The maximum queue length. |
class_change_matrix |
dict
|
Matrix describing class changes, if any. |
priority_preempt |
bool
|
Whether priority classes preempt service. |
ps_threshold |
int
|
Threshold used by the processor-sharing discipline. |
server_priority_function |
callable
|
Function assigning server priority. |
service_discipline |
callable
|
The service discipline used at the node. |
class_change_time |
bool
|
Whether class change times are modelled. |
Initialise a ServiceCentre object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number_of_servers
|
int or Schedule
|
The number of servers, or a schedule describing how it varies over time. |
required |
queueing_capacity
|
int or float
|
The maximum queue length. |
required |
class_change_matrix
|
dict
|
Matrix describing class changes, if any. |
None
|
priority_preempt
|
bool
|
Whether priority classes
preempt service. Defaults to |
False
|
ps_threshold
|
int
|
Threshold used by the
processor-sharing discipline. Defaults to |
1
|
server_priority_function
|
callable
|
Function assigning server priority. |
None
|
service_discipline
|
callable
|
The service discipline used at the node. |
None
|
Source code in hciw/network.py
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 | |
CustomerClass ¶
CustomerClass(
arrival_distributions,
service_distributions,
routing,
priority_class,
baulking_functions,
batching_distributions,
reneging_time_distributions,
class_change_time_distributions,
benchmark=None,
)
Store the class-dependent information for a customer class.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_distributions |
dict
|
Arrival distributions for each node. |
service_distributions |
dict
|
Service distributions for each node. |
batching_distributions |
dict
|
Batching distributions for each node. |
routing |
Routing
|
The routing object for the class. |
priority_class |
int
|
The priority class of the customer class. |
baulking_functions |
dict
|
Baulking functions for each node. |
reneging_time_distributions |
dict
|
Reneging time distributions for each node. |
class_change_time_distributions |
dict
|
Class change time distributions for each pair of customer classes. |
benchmark |
float or None
|
The target maximum waiting time for this customer class, used by the benchmark-aware service disciplines. |
Initialise a CustomerClass object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arrival_distributions
|
dict
|
Arrival distributions for each node. |
required |
service_distributions
|
dict
|
Service distributions for each node. |
required |
routing
|
Routing
|
The routing object for the class. |
required |
priority_class
|
int
|
The priority class of the customer class. |
required |
baulking_functions
|
dict
|
Baulking functions for each node. |
required |
batching_distributions
|
dict
|
Batching distributions for each node. |
required |
reneging_time_distributions
|
dict
|
Reneging time distributions for each node. |
required |
class_change_time_distributions
|
dict
|
Class change time distributions for each pair of customer classes. |
required |
benchmark
|
float or None
|
The target maximum waiting
time for this class. Defaults to |
None
|
Source code in hciw/network.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Network ¶
Network(service_centres, customer_classes)
Store the queueing network.
Holds a list of ServiceCentre objects for each service centre and
a dictionary of CustomerClass objects keyed by class name.
Attributes:
| Name | Type | Description |
|---|---|---|
service_centres |
list
|
The service centres of the network. |
customer_classes |
dict
|
The customer classes, keyed by class name. |
number_of_nodes |
int
|
The number of service centres. |
number_of_classes |
int
|
The number of customer classes. |
customer_class_names |
list
|
The sorted names of the customer classes. |
number_of_priority_classes |
int
|
The number of distinct priority classes. |
priority_class_mapping |
dict
|
Maps class names to priority classes. |
system_capacity |
float
|
The total capacity of the system. |
Initialise a Network object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_centres
|
list
|
The service centres of the network. |
required |
customer_classes
|
dict
|
The customer classes, keyed by class name. |
required |
Source code in hciw/network.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
auxiliary ¶
Auxiliary helper functions used throughout the simulation.
This module provides seeding utilities, weighted random sampling, and small list helpers used by the simulation engine.
seed ¶
seed(z)
Set all seeds used to generate random number streams.
Seeds both the standard library random module and the NumPy
random generator used by hciw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
int
|
The seed value to use. |
required |
Source code in hciw/auxiliary.py
14 15 16 17 18 19 20 21 22 23 24 | |
random_choice ¶
random_choice(array, probs=None)
Select a random element from an array using optional weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list
|
The values to choose from. |
required |
probs
|
list
|
Probability weights corresponding to each value. If omitted, a uniform choice is made. |
None
|
Returns:
| Type | Description |
|---|---|
|
The randomly selected element of |
Source code in hciw/auxiliary.py
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 | |
truncated_normal ¶
truncated_normal(mean, sd)
Sample from a Normal distribution truncated at zero.
Values less than or equal to zero are resampled until a positive value is obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
The mean of the Normal distribution. |
required |
sd
|
float
|
The standard deviation of the Normal distribution. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A positive sample from the truncated Normal distribution. |
Source code in hciw/auxiliary.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
flatten_list ¶
flatten_list(list_of_lists)
Flatten a list of lists into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_lists
|
list
|
A list whose elements are themselves lists. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A single list containing all elements of the inner lists. |
Source code in hciw/auxiliary.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
no_routing ¶
no_routing(ind)
Send a customer straight to the exit node.
This process-based routing function is a placeholder used when
NoArrivals is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
list
|
An empty list of destinations. |
Source code in hciw/auxiliary.py
91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Warm starts¶
waitlist ¶
Warm-start a simulation with an initial backlog of individuals.
A warm start seeds a simulation with individuals who are already present at time zero, rather than waiting for them to arrive via the arrival process. This is useful when simulating a system that is already busy, for example a hospital whose current patients are known from historical data.
Each backlog entry supplies the individual's identifier, customer class, historical arrival date, and the node they are waiting at. Arrival dates are expected to be at or before the simulation start time, so that the time an individual spent waiting before the simulation began is captured in their waiting-time statistics.
accept ¶
accept(
individual_id: int,
individual_class: str,
arrival_date: float,
node: Node,
simulation: Simulation,
) -> None
Place an individual already present at time zero into a node.
The individual is accepted by the node using the usual acceptance logic,
so that service begins immediately if a server is free. Their recorded
arrival_date is then overwritten with the supplied historical date so
that waiting-time statistics include the time spent in the system before
the simulation started.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual_id
|
int
|
A unique identifier for the individual. |
required |
individual_class
|
str
|
The customer class the individual belongs to. |
required |
arrival_date
|
float
|
The historical date at which the individual arrived. This should be at or before the simulation start time. |
required |
node
|
Node
|
The node the individual is waiting at. |
required |
simulation
|
Simulation
|
The simulation the individual belongs to. |
required |
Source code in hciw/waitlist.py
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 | |
_update_arrival_node ¶
_update_arrival_node(
simulation: Simulation,
individual_id: int,
individual_class: str,
) -> None
Advance the arrival node's counters to account for a seeded individual.
The arrival node's number_of_individuals is also the source of new
individual identifiers, so it is advanced past the seeded identifier to
prevent later arrivals from reusing it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being seeded. |
required |
individual_id
|
int
|
The identifier of the seeded individual. |
required |
individual_class
|
str
|
The customer class of the seeded individual. |
required |
Source code in hciw/waitlist.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
create_existing_customers_from_list ¶
create_existing_customers_from_list(
backlog: list[list], simulation: Simulation
) -> None
Seed a simulation with an initial backlog of individuals.
Each row of the backlog describes one individual already present at time zero. Rows are supplied in the order the individuals should be placed into their queues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backlog
|
list[list]
|
A list of rows, each of the form
|
required |
simulation
|
Simulation
|
The simulation to seed. |
required |
Source code in hciw/waitlist.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
_record_initial_state ¶
_record_initial_state(simulation: Simulation) -> None
Record the state tracker's initial state after seeding.
The state tracker records its state when Simulation initialises it,
before any individual has been seeded. Seeding changes that state at time
zero, so the tracker's first history entry is refreshed to match, ensuring
state probabilities cover the whole simulation correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation that was seeded. |
required |
Source code in hciw/waitlist.py
114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Distribution classes¶
distributions ¶
Distributions available in HCiw.
Individual ¶
Individual(
id_number,
customer_class="Customer",
priority_class=0,
simulation=False,
)
Represent an individual agent in a queueing network simulation.
An Individual models the flow of an agent through a queueing
network, tracking its arrival time, service time, priority and other
relevant data.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_date |
bool or float
|
Timestamp of the individual's arrival. |
service_start_date |
bool or float
|
Timestamp the current service started. |
service_time |
bool or float
|
Duration of the current service. |
service_end_date |
bool or float
|
Timestamp the current service ends. |
exit_date |
bool or float
|
Timestamp the individual exits the system. |
id_number |
int
|
Unique identifier for the individual. |
data_records |
list
|
The data records attached to the individual. |
customer_class |
str
|
The customer class of the individual. |
previous_class |
str
|
The previous customer class of the individual. |
priority_class |
int
|
The priority class of the individual. |
prev_priority_class |
int
|
The previous priority class of the individual. |
original_class |
str
|
The original customer class of the individual. |
is_blocked |
bool
|
Whether the individual is blocked. |
server |
bool or Server
|
The server assigned to the individual, if any. |
queue_size_at_arrival |
bool or int
|
Queue size when the individual arrived. |
queue_size_at_departure |
bool or int
|
Queue size when the individual departed. |
destination |
bool or int
|
The destination node in the network. |
interrupted |
bool
|
Whether the individual's service was interrupted. |
node |
bool or int
|
The node where the individual is located. |
simulation |
bool or Simulation
|
The simulation the individual belongs to. |
Example
.. code-block:: python
individual = Individual(
id_number=1, customer_class='Gold', priority_class=1,
simulation=True,
)
Initialise an Individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_number
|
int
|
A unique identifier for the individual. |
required |
customer_class
|
str
|
The customer class the individual
belongs to. Defaults to |
'Customer'
|
priority_class
|
int
|
The priority class of the
individual. Defaults to |
0
|
simulation
|
bool or Simulation
|
The simulation the
individual is part of. Defaults to |
False
|
Source code in hciw/individual.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
__repr__ ¶
__repr__() -> str
Return a string representation of the individual.
Returns:
| Type | Description |
|---|---|
str
|
The individual represented as |
Source code in hciw/individual.py
98 99 100 101 102 103 104 | |
Distribution ¶
A general distribution from which all other distributions inherit.
mean
property
¶
mean
Return the default mean of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean, NaN by default. |
variance
property
¶
variance
Return the default variance of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance, NaN by default. |
sd
property
¶
sd
Return the default standard deviation of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The square root of the variance. |
median
property
¶
median
Return the default median of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median, NaN by default. |
upper_limit
property
¶
upper_limit
Return the default upper limit of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The upper limit, NaN by default. |
lower_limit
property
¶
lower_limit
Return the default lower limit of a distribution.
Returns:
| Type | Description |
|---|---|
float
|
The lower limit, NaN by default. |
__repr__ ¶
__repr__() -> str
Return a string representation of the distribution.
Source code in hciw/dists/distributions.py
28 29 30 | |
sample ¶
sample(
t: float | None = None, ind: Individual | None = None
) -> float
Sample a value from the distribution.
The base class implements no sampling; subclasses must override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sampled value. The base class returns |
float
|
meth: |
Source code in hciw/dists/distributions.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
_sample ¶
_sample(t=None, ind=None)
Perform validity checks before sampling.
Source code in hciw/dists/distributions.py
48 49 50 51 52 53 | |
__add__ ¶
__add__(dist)
Add two distributions such that sampling is the sum of the samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
Distribution
|
The distribution to add. |
required |
Returns:
| Type | Description |
|---|---|
CombinedDistribution
|
A distribution sampling the sum. |
Source code in hciw/dists/distributions.py
55 56 57 58 59 60 61 62 63 64 | |
__sub__ ¶
__sub__(dist)
Subtract two distributions such that sampling is the difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
Distribution
|
The distribution to subtract. |
required |
Returns:
| Type | Description |
|---|---|
CombinedDistribution
|
A distribution sampling the difference. |
Source code in hciw/dists/distributions.py
66 67 68 69 70 71 72 73 74 75 | |
__mul__ ¶
__mul__(dist)
Multiply two distributions such that sampling is the product.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
Distribution
|
The distribution to multiply by. |
required |
Returns:
| Type | Description |
|---|---|
CombinedDistribution
|
A distribution sampling the product. |
Source code in hciw/dists/distributions.py
77 78 79 80 81 82 83 84 85 86 | |
__truediv__ ¶
__truediv__(dist)
Divide two distributions such that sampling is the ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist
|
Distribution
|
The distribution to divide by. |
required |
Returns:
| Type | Description |
|---|---|
CombinedDistribution
|
A distribution sampling the ratio. |
Source code in hciw/dists/distributions.py
88 89 90 91 92 93 94 95 96 97 | |
CombinedDistribution ¶
CombinedDistribution(dist1, dist2, operator)
Bases: Distribution
A distribution combining the samples of two other distributions.
The samples of dist1 and dist2 are combined using operator.
Attributes:
| Name | Type | Description |
|---|---|---|
d1 |
Distribution
|
A deep copy of the first distribution. |
d2 |
Distribution
|
A deep copy of the second distribution. |
operator |
callable
|
The binary operator used to combine samples. |
Initialize the combined distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist1
|
Distribution
|
The first distribution. |
required |
dist2
|
Distribution
|
The second distribution. |
required |
operator
|
callable
|
The binary operator used to combine samples. |
required |
Source code in hciw/dists/distributions.py
165 166 167 168 169 170 171 172 173 174 175 | |
mean
property
¶
mean: float
Return the combined mean of the two distributions.
Returns:
| Type | Description |
|---|---|
float
|
The mean implied by the operator. |
variance
property
¶
variance: float
Return the combined variance of the two distributions.
Returns:
| Type | Description |
|---|---|
float
|
The variance implied by the operator. |
upper_limit
property
¶
upper_limit
Return the combined upper limit.
Returns:
| Type | Description |
|---|---|
float
|
The sum of the upper limits for addition, NaN otherwise. |
lower_limit
property
¶
lower_limit
Return the combined lower limit.
Returns:
| Type | Description |
|---|---|
float
|
The sum of the lower limits for addition, NaN otherwise. |
__repr__ ¶
__repr__()
Return a string representation of the combined distribution.
Source code in hciw/dists/distributions.py
177 178 179 | |
sample ¶
sample(t=None, ind=None)
Sample from each distribution and combine the samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The combined sample. |
Source code in hciw/dists/distributions.py
181 182 183 184 185 186 187 188 189 190 191 192 193 | |
Uniform ¶
Uniform(lower, upper)
Bases: Distribution
The Uniform distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
lower |
float
|
The lower bound. |
upper |
float
|
The upper bound. |
Initialize the Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
float
|
The lower bound. |
required |
upper
|
float
|
The upper bound. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bound is negative or |
Source code in hciw/dists/distributions.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
mean
property
¶
mean
Return the mean of the Uniform distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Uniform distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Uniform distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Uniform distribution.
Returns:
| Type | Description |
|---|---|
float
|
The upper bound. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Uniform distribution.
Returns:
| Type | Description |
|---|---|
float
|
The lower bound. |
__repr__ ¶
__repr__()
Return a string representation of the Uniform distribution.
Source code in hciw/dists/distributions.py
292 293 294 | |
sample ¶
sample(t=None, ind=None)
Sample from the Uniform distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample between |
Source code in hciw/dists/distributions.py
296 297 298 299 300 301 302 303 304 305 306 | |
Deterministic ¶
Deterministic(value)
Bases: Distribution
The Deterministic distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
float
|
The value always returned by the distribution. |
Initialize the Deterministic distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to return. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/dists/distributions.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
mean
property
¶
mean
Return the mean of the Deterministic distribution.
Returns:
| Type | Description |
|---|---|
float
|
The deterministic value. |
variance
property
¶
variance
Return the variance of the Deterministic distribution.
Returns:
| Type | Description |
|---|---|
float
|
Always 0.0. |
median
property
¶
median
Return the median of the Deterministic distribution.
Returns:
| Type | Description |
|---|---|
float
|
The deterministic value. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Deterministic distribution.
Returns:
| Type | Description |
|---|---|
float
|
The deterministic value. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Deterministic distribution.
Returns:
| Type | Description |
|---|---|
float
|
The deterministic value. |
__repr__ ¶
__repr__()
Return a string representation of the Deterministic distribution.
Source code in hciw/dists/distributions.py
376 377 378 | |
sample ¶
sample(t=None, ind=None)
Sample from the Deterministic distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The deterministic value. |
Source code in hciw/dists/distributions.py
380 381 382 383 384 385 386 387 388 389 390 | |
Triangular ¶
Triangular(lower, mode, upper)
Bases: Distribution
The Triangular distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
lower |
float
|
The lower bound. |
mode |
float
|
The modal value. |
upper |
float
|
The upper bound. |
Initialize the Triangular distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
float
|
The lower bound. |
required |
mode
|
float
|
The modal value. |
required |
upper
|
float
|
The upper bound. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any parameter is negative. |
ValueError
|
If the bounds do not satisfy |
Source code in hciw/dists/distributions.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
mean
property
¶
mean
Return the mean of the Triangular distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Triangular distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Triangular distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Triangular distribution.
Returns:
| Type | Description |
|---|---|
float
|
The upper bound. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Triangular distribution.
Returns:
| Type | Description |
|---|---|
float
|
The lower bound. |
__repr__ ¶
__repr__()
Return a string representation of the Triangular distribution.
Source code in hciw/dists/distributions.py
472 473 474 | |
sample ¶
sample(t=None, ind=None)
Sample from the Triangular distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample between |
Source code in hciw/dists/distributions.py
476 477 478 479 480 481 482 483 484 485 486 | |
Exponential ¶
Exponential(rate)
Bases: Distribution
The Exponential distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
rate |
float
|
The rate parameter, lambda. |
Initialize the Exponential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The rate parameter, lambda. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/dists/distributions.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
mean
property
¶
mean
Return the mean of the Exponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Exponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Exponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Exponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Exponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the Exponential distribution.
Source code in hciw/dists/distributions.py
562 563 564 | |
sample ¶
sample(t=None, ind=None)
Sample from the Exponential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
566 567 568 569 570 571 572 573 574 575 576 | |
Gamma ¶
Gamma(shape, scale)
Bases: Distribution
The Gamma distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
float
|
The shape parameter, alpha. |
scale |
float
|
The scale parameter, beta. |
Initialize the Gamma distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
The shape parameter, alpha. |
required |
scale
|
float
|
The scale parameter, beta. |
required |
Source code in hciw/dists/distributions.py
632 633 634 635 636 637 638 639 640 | |
mean
property
¶
mean
Return the mean of the Gamma distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Gamma distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Gamma distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Gamma distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the Gamma distribution.
Source code in hciw/dists/distributions.py
642 643 644 | |
sample ¶
sample(t=None, ind=None)
Sample from the Gamma distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
646 647 648 649 650 651 652 653 654 655 656 | |
Normal ¶
Normal(mean, sd)
Bases: Distribution
Truncated Normal distribution, truncated below at 0.
Initialize the truncated Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
Mean of the underlying normal distribution. |
required |
sd
|
float
|
Standard deviation of the underlying normal distribution. |
required |
Source code in hciw/dists/distributions.py
698 699 700 701 702 703 704 705 706 | |
mean
property
¶
mean
Return the mean of the truncated Normal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean of the truncated distribution. |
variance
property
¶
variance
Return the variance of the truncated Normal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance of the truncated distribution. |
median
property
¶
median
Return the median of the truncated Normal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median of the truncated distribution. |
upper_limit
property
¶
upper_limit
Return the upper limit of the truncated Normal distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the truncated Normal distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the Normal distribution.
Source code in hciw/dists/distributions.py
708 709 710 | |
sample ¶
sample(t=None, ind=None)
Sample from the truncated Normal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample truncated below at 0. |
Source code in hciw/dists/distributions.py
712 713 714 715 716 717 718 719 720 721 722 | |
Lognormal ¶
Lognormal(mean, sd)
Bases: Distribution
The Lognormal distribution.
Initialize the Lognormal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
The mean of the underlying normal, mu. |
required |
sd
|
float
|
The standard deviation of the underlying normal, sigma. |
required |
Source code in hciw/dists/distributions.py
784 785 786 787 788 789 790 791 792 | |
mean
property
¶
mean
Return the mean of the Lognormal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Lognormal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Lognormal distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Lognormal distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Lognormal distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the Lognormal distribution.
Source code in hciw/dists/distributions.py
794 795 796 | |
sample ¶
sample(t=None, ind=None)
Sample from the Lognormal distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
798 799 800 801 802 803 804 805 806 807 808 | |
Weibull ¶
Weibull(scale, shape)
Bases: Distribution
The Weibull distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
scale |
float
|
The scale parameter, alpha. |
shape |
float
|
The shape parameter, beta. |
Initialize the Weibull distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
The scale parameter, alpha. |
required |
shape
|
float
|
The shape parameter, beta. |
required |
Source code in hciw/dists/distributions.py
864 865 866 867 868 869 870 871 872 | |
mean
property
¶
mean
Return the mean of the Weibull distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Weibull distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Weibull distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Weibull distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Weibull distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the Weibull distribution.
Source code in hciw/dists/distributions.py
874 875 876 | |
sample ¶
sample(t=None, ind=None)
Sample from the Weibull distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
878 879 880 881 882 883 884 885 886 887 888 | |
Empirical ¶
Empirical(observations)
Bases: Distribution
The Empirical distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
observations |
list
|
The observations from which to sample. |
Initialize the Empirical distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observations
|
list
|
The observations from which to sample. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any observation is negative. |
Source code in hciw/dists/distributions.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 | |
mean
property
¶
mean
Return the mean of the Empirical distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean of the observations. |
variance
property
¶
variance
Return the variance of the Empirical distribution.
Returns:
| Type | Description |
|---|---|
float
|
The population variance of the observations. |
median
property
¶
median
Return the median of the Empirical distribution.
Returns:
| Type | Description |
|---|---|
float
|
The sample median of the observations. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Empirical distribution.
Returns:
| Type | Description |
|---|---|
float
|
The largest observation. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Empirical distribution.
Returns:
| Type | Description |
|---|---|
float
|
The smallest observation. |
__repr__ ¶
__repr__()
Return a string representation of the Empirical distribution.
Source code in hciw/dists/distributions.py
960 961 962 | |
sample ¶
sample(t=None, ind=None)
Sample from the Empirical distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A value chosen uniformly from |
Source code in hciw/dists/distributions.py
964 965 966 967 968 969 970 971 972 973 974 | |
Sequential ¶
Sequential(sequence)
Bases: Distribution
The Sequential distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
sequence |
list
|
The sequence of values to cycle through. |
generator |
cycle
|
The cycle iterator over |
Initialize the Sequential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
list
|
The sequence of values to cycle through. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value in |
Source code in hciw/dists/distributions.py
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | |
mean
property
¶
mean
Return the mean of the Sequential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean of the sequence. |
variance
property
¶
variance
Return the variance of the Sequential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The population variance of the sequence. |
median
property
¶
median
Return the median of the Sequential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The sample median of the sequence. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Sequential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The largest value in the sequence. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Sequential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The smallest value in the sequence. |
__repr__ ¶
__repr__()
Return a string representation of the Sequential distribution.
Source code in hciw/dists/distributions.py
1055 1056 1057 1058 1059 | |
sample ¶
sample(t=None, ind=None)
Sample the next value from the sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The next value in the sequence. |
Source code in hciw/dists/distributions.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |
Pmf ¶
Pmf(values, probs)
Bases: Distribution
A distribution defined by a probability mass function (pmf).
Attributes:
| Name | Type | Description |
|---|---|---|
values |
list
|
The values that can be sampled. |
probs |
list
|
The probability associated with each value. |
Initialize the Pmf distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
The values to sample. |
required |
probs
|
list
|
The associated probabilities, which must sum to 1. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any value is negative. |
ValueError
|
If any probability is outside [0, 1]. |
ValueError
|
If the probabilities do not sum to 1.0. |
Source code in hciw/dists/distributions.py
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
mean
property
¶
mean
Return the mean of the Pmf distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Pmf distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Pmf distribution.
Returns:
| Type | Description |
|---|---|
float
|
The value at which the cumulative probability reaches 0.5. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Pmf distribution.
Returns:
| Type | Description |
|---|---|
float
|
The largest value. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Pmf distribution.
Returns:
| Type | Description |
|---|---|
float
|
The smallest value. |
__repr__ ¶
__repr__()
Return a string representation of the Pmf distribution.
Source code in hciw/dists/distributions.py
1157 1158 1159 | |
sample ¶
sample(t=None, ind=None)
Sample from the Pmf distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A value chosen according to |
Source code in hciw/dists/distributions.py
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 | |
PhaseType ¶
PhaseType(initial_state, absorbing_matrix)
Bases: Distribution
A distribution defined by an initial vector and an absorbing Markov chain.
The final state of the chain is the absorbing state.
Attributes:
| Name | Type | Description |
|---|---|---|
initial_state |
list
|
The initial probability of being in each state. |
states |
tuple
|
The indices of the states. |
absorbing_matrix |
list
|
The rates of the absorbing Markov chain. |
Initialize the PhaseType distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_state
|
list
|
The initial probabilities of being in each state. |
required |
absorbing_matrix
|
list
|
The matrix representation of the absorbing Markov chain, with the final state the absorbing state. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the initial state contains negative probabilities. |
ValueError
|
If the initial state contains probabilities above 1.0. |
ValueError
|
If the initial state probabilities do not sum to 1.0. |
ValueError
|
If the absorbing matrix is not square. |
ValueError
|
If the initial state and matrix sizes differ. |
ValueError
|
If any transition rate is negative. |
ValueError
|
If the matrix rows do not sum to 0. |
ValueError
|
If the final state is not the absorbing state. |
ValueError
|
If the absorbing state cannot be reached. |
Source code in hciw/dists/distributions.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | |
mean
property
¶
mean
Return the mean of the PhaseType distribution.
Returns:
| Type | Description |
|---|---|
float
|
The expected time to absorption. |
variance
property
¶
variance
Return the variance of the PhaseType distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance of the time to absorption. |
upper_limit
property
¶
upper_limit
Return the upper limit of the PhaseType distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the PhaseType distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__() -> str
Return a string representation of the PhaseType distribution.
Source code in hciw/dists/distributions.py
1295 1296 1297 | |
sample_transition ¶
sample_transition(rate)
Sample the time to a single transition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The rate of the transition. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sampled transition time, or infinity if |
Source code in hciw/dists/distributions.py
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 | |
sample ¶
sample(t=None, ind=None)
Sample from the PhaseType distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The total time until absorption. |
Source code in hciw/dists/distributions.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 | |
Erlang ¶
Erlang(rate, num_phases)
Bases: PhaseType
A shortcut for the Erlang distribution, using the PhaseType distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
rate |
float
|
The rate spent in each phase. |
num_phases |
int
|
The number of phases in series. |
Initialize the Erlang distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The rate spent in each phase. |
required |
num_phases
|
int
|
The number of phases in series. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Source code in hciw/dists/distributions.py
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
mean
property
¶
mean
Return the mean of the Erlang distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Erlang distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
__repr__ ¶
__repr__()
Return a string representation of the Erlang distribution.
Source code in hciw/dists/distributions.py
1417 1418 1419 | |
HyperExponential ¶
HyperExponential(rates, probs)
Bases: PhaseType
A shortcut for the HyperExponential distribution using PhaseType.
Attributes:
| Name | Type | Description |
|---|---|---|
rates |
list
|
The rate of each phase. |
probs |
list
|
The probability of starting in each phase. |
Initialize the HyperExponential distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
list
|
A vector of rates for each phase. |
required |
probs
|
list
|
A probability vector for starting in each phase. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any rate is not positive. |
Source code in hciw/dists/distributions.py
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 | |
mean
property
¶
mean
Return the mean of the HyperExponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the HyperExponential distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
__repr__ ¶
__repr__()
Return a string representation of the HyperExponential distribution.
Source code in hciw/dists/distributions.py
1470 1471 1472 | |
HyperErlang ¶
HyperErlang(rates, probs, phase_lengths)
Bases: PhaseType
A shortcut for the HyperErlang distribution, using the PhaseType distribution.
Attributes:
| Name | Type | Description |
|---|---|---|
rates |
list
|
The rate of each phase. |
probs |
list
|
The probability of starting in each phase. |
phase_lengths |
list
|
The number of sub-phases in each phase. |
Initialize the HyperErlang distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
list
|
A vector of rates for each phase. |
required |
probs
|
list
|
A probability vector for starting in each phase. |
required |
phase_lengths
|
list
|
The number of sub-phases in each phase. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any rate is not positive. |
ValueError
|
If any phase length is less than 1. |
Source code in hciw/dists/distributions.py
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 | |
mean
property
¶
mean
Return the mean of the HyperErlang distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the HyperErlang distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
__repr__ ¶
__repr__()
Return a string representation of the HyperErlang distribution.
Source code in hciw/dists/distributions.py
1543 1544 1545 | |
Coxian ¶
Coxian(rates, probs)
Bases: PhaseType
A shortcut for the Coxian distribution, using the PhaseType distribution.
Initialize the Coxian distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
list
|
A vector of rates for each phase. |
required |
probs
|
list
|
A vector of the probability of absorption at each phase. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any rate is not positive. |
ValueError
|
If any probability is outside [0, 1]. |
ValueError
|
If the final probability is not exactly 1.0. |
Source code in hciw/dists/distributions.py
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 | |
__repr__ ¶
__repr__()
Return a string representation of the Coxian distribution.
Source code in hciw/dists/distributions.py
1608 1609 1610 | |
PoissonIntervals ¶
PoissonIntervals(rates, endpoints, max_sample_date)
Bases: Sequential
A time-dependent Poisson distribution for arrivals.
The number of arrivals in each time interval is sampled from a Poisson distribution, the arrival dates are distributed uniformly within each interval, and the consecutive differences of these dates are used as the inter-arrival times.
Attributes:
| Name | Type | Description |
|---|---|---|
rates |
list
|
The Poisson rate for each time interval. |
endpoints |
list
|
The endpoints of each time interval. |
max_sample_date |
float
|
The point after which no arrivals occur. |
Initialize the PoissonIntervals distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
list
|
A list of Poisson rates for each time interval. |
required |
endpoints
|
list
|
The endpoints of each time interval. |
required |
max_sample_date
|
float
|
The point where no more arrivals can occur. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any rate is negative. |
ValueError
|
If any endpoint is not positive. |
ValueError
|
If |
ValueError
|
If the endpoints are not strictly increasing. |
ValueError
|
If the numbers of rates and endpoints differ. |
Source code in hciw/dists/distributions.py
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | |
overall_rate
property
¶
overall_rate
Return the overall rate across all intervals.
Returns:
| Type | Description |
|---|---|
float
|
The time-averaged Poisson rate. |
mean
property
¶
mean
Return the mean inter-arrival time.
Returns:
| Type | Description |
|---|---|
float
|
The reciprocal of the overall rate, or infinity. |
variance
property
¶
variance
Return the variance of the inter-arrival times.
Returns:
| Type | Description |
|---|---|
float
|
The variance, which is NaN. |
median
property
¶
median
Return the median inter-arrival time.
Returns:
| Type | Description |
|---|---|
float
|
The median, which is NaN. |
upper_limit
property
¶
upper_limit
Return the upper limit of the inter-arrival times.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the inter-arrival times.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
__repr__ ¶
__repr__()
Return a string representation of the PoissonIntervals distribution.
Source code in hciw/dists/distributions.py
1666 1667 1668 | |
get_intervals ¶
get_intervals()
Build the list of time intervals up to max_sample_date.
Source code in hciw/dists/distributions.py
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 | |
get_dates ¶
get_dates()
Sample the arrival dates within each time interval.
Source code in hciw/dists/distributions.py
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 | |
Poisson ¶
Poisson(rate)
Bases: Distribution
The Poisson distribution.
Note that this is a discrete integer distribution, for use with batching.
Attributes:
| Name | Type | Description |
|---|---|---|
rate |
float
|
The rate parameter, lambda. |
Initialize the Poisson distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
The rate parameter, lambda. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/dists/distributions.py
1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 | |
mean
property
¶
mean
Return the mean of the Poisson distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Poisson distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Poisson distribution.
Returns:
| Type | Description |
|---|---|
float
|
An approximation of the median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Poisson distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Poisson distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
sample ¶
sample(t=None, ind=None)
Sample from the Poisson distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 | |
__repr__ ¶
__repr__()
Return a string representation of the Poisson distribution.
Source code in hciw/dists/distributions.py
1799 1800 1801 | |
Geometric ¶
Geometric(prob)
Bases: Distribution
The Geometric distribution.
Note that this is a discrete integer distribution, for use with batching.
Attributes:
| Name | Type | Description |
|---|---|---|
prob |
float
|
The probability parameter. |
Initialize the Geometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prob
|
float
|
The probability parameter. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/dists/distributions.py
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 | |
mean
property
¶
mean
Return the mean of the Geometric distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Geometric distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Geometric distribution.
Returns:
| Type | Description |
|---|---|
float
|
The median. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Geometric distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Geometric distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
sample ¶
sample(t=None, ind=None)
Sample from the Geometric distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 | |
__repr__ ¶
__repr__()
Return a string representation of the Geometric distribution.
Source code in hciw/dists/distributions.py
1885 1886 1887 | |
Binomial ¶
Binomial(n, prob)
Bases: Distribution
The Binomial distribution.
Note that this is a discrete integer distribution, for use with batching.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
The total number of experiments. |
prob |
float
|
The probability parameter. |
Initialize the Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The total number of experiments. |
required |
prob
|
float
|
The probability parameter. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Source code in hciw/dists/distributions.py
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 | |
mean
property
¶
mean
Return the mean of the Binomial distribution.
Returns:
| Type | Description |
|---|---|
float
|
The mean. |
variance
property
¶
variance
Return the variance of the Binomial distribution.
Returns:
| Type | Description |
|---|---|
float
|
The variance. |
median
property
¶
median
Return the median of the Binomial distribution.
Returns:
| Type | Description |
|---|---|
float
|
The rounded mean. |
upper_limit
property
¶
upper_limit
Return the upper limit of the Binomial distribution.
Returns:
| Type | Description |
|---|---|
float
|
Infinity. |
lower_limit
property
¶
lower_limit
Return the lower limit of the Binomial distribution.
Returns:
| Type | Description |
|---|---|
float
|
Zero. |
sample ¶
sample(t=None, ind=None)
Sample from the Binomial distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
A sample from the distribution. |
Source code in hciw/dists/distributions.py
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 | |
__repr__ ¶
__repr__()
Return a string representation of the Binomial distribution.
Source code in hciw/dists/distributions.py
1980 1981 1982 | |
MixtureDistribution ¶
MixtureDistribution(
dists: list[Distribution], probs: list[float]
)
Bases: Distribution
A mixture distribution combining multiple probability distributions.
Attributes:
| Name | Type | Description |
|---|---|---|
probs |
List[float]
|
The weights of each distribution, summing to 1. |
dists |
List[Distribution]
|
The distributions in the mixture. |
Initialize the MixtureDistribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dists
|
List[Distribution]
|
The distributions to combine in the mixture. |
required |
probs
|
List[float]
|
The weights of each distribution, summing to 1. |
required |
Source code in hciw/dists/distributions.py
2038 2039 2040 2041 2042 2043 2044 2045 2046 | |
mean
property
¶
mean
Return the mean of the mixture distribution.
Returns:
| Type | Description |
|---|---|
float
|
The weighted mean of the component distributions. |
variance
property
¶
variance
Return the variance of the mixture distribution.
Returns:
| Type | Description |
|---|---|
float
|
The weighted variance of the component distributions. |
upper_limit
property
¶
upper_limit
Return the upper limit of the mixture distribution.
Returns:
| Type | Description |
|---|---|
float
|
The largest component upper limit, or NaN if any is NaN. |
lower_limit
property
¶
lower_limit
Return the lower limit of the mixture distribution.
Returns:
| Type | Description |
|---|---|
float
|
The smallest component lower limit, or NaN if any is NaN. |
sample ¶
sample(
t: float | None = None, ind: Individual | None = None
) -> float
Generate a random sample from the mixture distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
The current time. Defaults to None. |
None
|
ind
|
Individual
|
The individual being sampled. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
A sample from one of the distributions, chosen by weight. |
Source code in hciw/dists/distributions.py
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 | |
__repr__ ¶
__repr__()
Return a string representation of the mixture distribution.
Source code in hciw/dists/distributions.py
2062 2063 2064 | |
seed ¶
seed(z)
Set all seeds used to generate random number streams.
Seeds both the standard library random module and the NumPy
random generator used by hciw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
int
|
The seed value to use. |
required |
Source code in hciw/auxiliary.py
14 15 16 17 18 19 20 21 22 23 24 | |
random_choice ¶
random_choice(array, probs=None)
Select a random element from an array using optional weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list
|
The values to choose from. |
required |
probs
|
list
|
Probability weights corresponding to each value. If omitted, a uniform choice is made. |
None
|
Returns:
| Type | Description |
|---|---|
|
The randomly selected element of |
Source code in hciw/auxiliary.py
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 | |
truncated_normal ¶
truncated_normal(mean, sd)
Sample from a Normal distribution truncated at zero.
Values less than or equal to zero are resampled until a positive value is obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
The mean of the Normal distribution. |
required |
sd
|
float
|
The standard deviation of the Normal distribution. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A positive sample from the truncated Normal distribution. |
Source code in hciw/auxiliary.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
flatten_list ¶
flatten_list(list_of_lists)
Flatten a list of lists into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_lists
|
list
|
A list whose elements are themselves lists. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A single list containing all elements of the inner lists. |
Source code in hciw/auxiliary.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
no_routing ¶
no_routing(ind)
Send a customer straight to the exit node.
This process-based routing function is a placeholder used when
NoArrivals is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
list
|
An empty list of destinations. |
Source code in hciw/auxiliary.py
91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Disciplines¶
disciplines ¶
Service disciplines for selecting the next individual from a queue.
Individual ¶
Individual(
id_number,
customer_class="Customer",
priority_class=0,
simulation=False,
)
Represent an individual agent in a queueing network simulation.
An Individual models the flow of an agent through a queueing
network, tracking its arrival time, service time, priority and other
relevant data.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_date |
bool or float
|
Timestamp of the individual's arrival. |
service_start_date |
bool or float
|
Timestamp the current service started. |
service_time |
bool or float
|
Duration of the current service. |
service_end_date |
bool or float
|
Timestamp the current service ends. |
exit_date |
bool or float
|
Timestamp the individual exits the system. |
id_number |
int
|
Unique identifier for the individual. |
data_records |
list
|
The data records attached to the individual. |
customer_class |
str
|
The customer class of the individual. |
previous_class |
str
|
The previous customer class of the individual. |
priority_class |
int
|
The priority class of the individual. |
prev_priority_class |
int
|
The previous priority class of the individual. |
original_class |
str
|
The original customer class of the individual. |
is_blocked |
bool
|
Whether the individual is blocked. |
server |
bool or Server
|
The server assigned to the individual, if any. |
queue_size_at_arrival |
bool or int
|
Queue size when the individual arrived. |
queue_size_at_departure |
bool or int
|
Queue size when the individual departed. |
destination |
bool or int
|
The destination node in the network. |
interrupted |
bool
|
Whether the individual's service was interrupted. |
node |
bool or int
|
The node where the individual is located. |
simulation |
bool or Simulation
|
The simulation the individual belongs to. |
Example
.. code-block:: python
individual = Individual(
id_number=1, customer_class='Gold', priority_class=1,
simulation=True,
)
Initialise an Individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_number
|
int
|
A unique identifier for the individual. |
required |
customer_class
|
str
|
The customer class the individual
belongs to. Defaults to |
'Customer'
|
priority_class
|
int
|
The priority class of the
individual. Defaults to |
0
|
simulation
|
bool or Simulation
|
The simulation the
individual is part of. Defaults to |
False
|
Source code in hciw/individual.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
Simulation ¶
Simulation(
network,
exact=False,
name="Simulation",
tracker=None,
deadlock_detector=None,
node_class=None,
arrival_node_class=None,
exit_node_class=None,
individual_class=None,
server_class=None,
initial_individuals=None,
)
The engine that runs a queueing network simulation.
A Simulation drives customers through the network's nodes over
simulated time, collecting data records and tracking state.
Attributes:
| Name | Type | Description |
|---|---|---|
current_time |
float
|
The current simulated time. |
network |
Network
|
The network being simulated. |
name |
str
|
The name of the simulation. |
NodeTypes |
list
|
The node classes used at each service centre. |
ArrivalNodeType |
type
|
The class used for the arrival node. |
ExitNodeType |
type
|
The class used for the exit node. |
IndividualType |
type
|
The class used for individuals. |
ServerType |
type
|
The class used for servers. |
deadlock_detector |
object
|
The detector used to identify deadlocks. |
inter_arrival_times |
dict
|
Inter-arrival distributions by node and class. |
service_times |
dict
|
Service distributions by node and class. |
batch_sizes |
dict
|
Batch size distributions by node and class. |
number_of_priority_classes |
int
|
The number of priority classes. |
transitive_nodes |
list
|
The service centre nodes. |
nodes |
list
|
The arrival, transitive and exit nodes. |
active_nodes |
list
|
The nodes that are not the exit node. |
routers |
dict
|
The routing objects by customer class. |
statetracker |
StateTracker
|
The state tracker in use. |
times_dictionary |
dict
|
Maps hashed states to the time first seen. |
times_to_deadlock |
dict
|
The time from each state to deadlock. |
unchecked_blockage |
bool
|
Whether a blockage needs checking. |
Initialise a simulation instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
Network
|
The network to simulate. |
required |
exact
|
int
|
If truthy, use exact |
False
|
name
|
str
|
The name of the simulation. Defaults to
|
'Simulation'
|
tracker
|
StateTracker
|
The state tracker to use.
Defaults to a plain |
None
|
deadlock_detector
|
object
|
The deadlock detector to
use. Defaults to |
None
|
node_class
|
type or list
|
The node class or classes to
use. Defaults to |
None
|
arrival_node_class
|
type
|
The arrival node class to use.
Defaults to |
None
|
exit_node_class
|
type
|
The exit node class to use.
Defaults to |
None
|
individual_class
|
type
|
The individual class to use.
Defaults to |
None
|
server_class
|
type
|
The server class to use. Defaults
to |
None
|
initial_individuals
|
list[list]
|
A list of backlogged
individuals to seed the simulation with, in the form
|
None
|
Source code in hciw/simulation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
number_of_individuals
property
¶
number_of_individuals
Return the number of individuals currently in the system.
Returns:
| Type | Description |
|---|---|
int
|
The number of individuals currently in the system. |
find_arrival_dists ¶
find_arrival_dists()
Create the arrival time distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Arrival time distributions keyed by node and customer class. |
Source code in hciw/simulation.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
find_service_dists ¶
find_service_dists()
Create the service time distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Service time distributions keyed by node and customer class. |
Source code in hciw/simulation.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
find_batching_dists ¶
find_batching_dists()
Create the batch size distribution objects for each node and class.
Returns:
| Type | Description |
|---|---|
dict
|
Batch size distributions keyed by node and customer class. |
Source code in hciw/simulation.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
show_simulation_to_distributions ¶
show_simulation_to_distributions()
Add the simulation as an attribute of the distribution objects.
Source code in hciw/simulation.py
208 209 210 211 212 213 214 215 | |
find_and_initialise_routers ¶
find_and_initialise_routers()
Initialise and return the routing objects.
Returns:
| Type | Description |
|---|---|
dict
|
Routing objects keyed by customer class. |
Source code in hciw/simulation.py
217 218 219 220 221 222 223 224 225 226 227 | |
find_next_active_node ¶
find_next_active_node()
Return the active node with the earliest next event date.
If several nodes share the earliest date, one is chosen at random.
Returns:
| Type | Description |
|---|---|
Node
|
The next active node. |
Source code in hciw/simulation.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
get_all_individuals ¶
get_all_individuals()
Return all individuals with at least one data record.
Returns:
| Type | Description |
|---|---|
list
|
The individuals with at least one data record. |
Source code in hciw/simulation.py
249 250 251 252 253 254 255 256 257 258 259 | |
get_all_records ¶
get_all_records(only=None, include_incomplete=False)
Get data records from all individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only
|
list
|
The record types to include. Defaults to service, baulk, rejection, renege and interrupted service records. |
None
|
include_incomplete
|
bool
|
Whether to include records
for individuals still in the system. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
list
|
The collected data records. |
Source code in hciw/simulation.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
set_classes ¶
set_classes(
node_class,
arrival_node_class,
exit_node_class,
individual_class,
server_class,
)
Set the node, individual and server classes used by the simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_class
|
type or list
|
The node class or classes to use. If a list, it must have one entry per node. |
required |
arrival_node_class
|
type
|
The arrival node class to use, or
|
required |
exit_node_class
|
type
|
The exit node class to use, or |
required |
individual_class
|
type
|
The individual class to use, or |
required |
server_class
|
type
|
The server class to use, or |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/simulation.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
event_and_return_nextnode ¶
event_and_return_nextnode(next_active_node)
Carry out an event and return the next active node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_active_node
|
Node
|
The node whose event to carry out. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next active node. |
Source code in hciw/simulation.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
simulate_until_deadlock ¶
simulate_until_deadlock()
Run the simulation until deadlock is reached.
Source code in hciw/simulation.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
simulate_until_max_time ¶
simulate_until_max_time(
max_simulation_time, progress_bar=False
)
Run the simulation until a maximum simulated time is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_simulation_time
|
float
|
The time to stop the simulation at. |
required |
progress_bar
|
bool
|
Whether to display a progress bar.
Defaults to |
False
|
Source code in hciw/simulation.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
simulate_until_max_customers ¶
simulate_until_max_customers(
max_customers, progress_bar=False, method="Complete"
)
Run the simulation until a number of customers is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_customers
|
int
|
The number of customers to stop at. |
required |
progress_bar
|
bool
|
Whether to display a progress bar.
Defaults to |
False
|
method
|
str
|
The measure used to count customers. One of:
Defaults to |
'Complete'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/simulation.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server times and find the overall server utilisation.
Updates each server's total time and busy time at the end of the simulation run, and finds the overall server utilisation for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The time at which the run finished. |
required |
Source code in hciw/simulation.py
498 499 500 501 502 503 504 505 506 507 508 509 | |
random_choice ¶
random_choice(array, probs=None)
Select a random element from an array using optional weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list
|
The values to choose from. |
required |
probs
|
list
|
Probability weights corresponding to each value. If omitted, a uniform choice is made. |
None
|
Returns:
| Type | Description |
|---|---|
|
The randomly selected element of |
Source code in hciw/auxiliary.py
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 | |
FIFO ¶
FIFO(individuals: list[Individual], t: float) -> Individual
Select individuals first in, first out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
List[Individual]
|
The individuals in the queue. |
required |
t
|
float
|
The current simulation time. |
required |
Returns:
| Type | Description |
|---|---|
Individual
|
The individual at the head of the queue. |
Source code in hciw/disciplines.py
13 14 15 16 17 18 19 20 21 22 23 | |
SIRO ¶
SIRO(individuals: list[Individual], t: float) -> Individual
Select individuals in random order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
List[Individual]
|
The individuals in the queue. |
required |
t
|
float
|
The current simulation time. |
required |
Returns:
| Type | Description |
|---|---|
Individual
|
A randomly selected individual from the queue. |
Source code in hciw/disciplines.py
26 27 28 29 30 31 32 33 34 35 36 | |
LIFO ¶
LIFO(individuals: list[Individual], t: float) -> Individual
Select individuals last in, first out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
List[Individual]
|
The individuals in the queue. |
required |
t
|
float
|
The current simulation time. |
required |
Returns:
| Type | Description |
|---|---|
Individual
|
The individual who joined the queue most recently. |
Source code in hciw/disciplines.py
39 40 41 42 43 44 45 46 47 48 49 | |
wait_time_over_benchmark ¶
wait_time_over_benchmark(
individuals: list[Individual], t: float | Decimal
) -> Individual
Select the individual furthest past their customer class's benchmark.
Each customer class may declare a target waiting time, set with
create_network(customer_class_benchmarks={...}). The individual chosen
is the one for whom t - arrival_date - benchmark is greatest: that is,
the individual who has waited furthest beyond their target. This is the
discipline HCiw uses to express a service target such as "no one should
wait more than X time units", by treating any wait beyond X as a first
claim on the next free server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individuals
|
list[Individual]
|
The individuals in the queue. |
required |
t
|
float or Decimal
|
The current simulation time. |
required |
Returns:
| Type | Description |
|---|---|
Individual
|
The individual furthest past their benchmark. Ties are broken by queue order, so the earliest of the tied individuals is served next. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any individual's customer class has no benchmark set. |
Source code in hciw/disciplines.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
Schedules¶
schedules ¶
Server schedules for varying the number of servers over time.
Schedule ¶
Schedule(
numbers_of_servers: list[int],
shift_end_dates: list[float],
preemption: bool | str = False,
offset: float = 0.0,
)
Store server schedule information and generate the next shifts.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
shift_end_dates |
List[float]
|
The end dates of each shift. |
numbers_of_servers |
List[int]
|
The number of servers for each shift. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
offset |
float
|
The offset applied to the schedule. |
Initialise a Schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers_of_servers
|
List[int]
|
The number of servers working at each shift. |
required |
shift_end_dates
|
List[float]
|
The end dates of each shift. |
required |
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
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 | |
initialise ¶
initialise() -> None
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
58 59 60 61 62 63 64 65 | |
get_schedule_generator ¶
get_schedule_generator(
boundaries: list[float],
values: list[int],
offset: float,
) -> Generator[tuple[float, int], None, None]
Yield the next shift date and server count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
List[float]
|
The shift boundaries. |
required |
values
|
List[int]
|
The number of servers corresponding to each boundary. |
required |
offset
|
float
|
The offset applied to the schedule. |
required |
Yields:
| Type | Description |
|---|---|
Tuple[float, int]
|
The next shift date and the number of servers. |
Source code in hciw/schedules.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
get_next_shift ¶
get_next_shift() -> None
Update the next shift from the generator.
Source code in hciw/schedules.py
93 94 95 96 97 98 | |
Slotted ¶
Slotted(
slots,
slot_sizes,
capacitated=False,
preemption=False,
offset=0.0,
)
Bases: Schedule
A schedule divided into slots with a number of servers per slot.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
offset |
float
|
The offset applied to the schedule. |
slots |
list
|
The slot boundaries. |
slot_sizes |
list
|
The number of servers in each slot. |
next_slot_sizes |
list
|
The slot sizes of the next cycle. |
capacitated |
bool
|
Whether the slots are capacitated. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
c |
int
|
The current number of servers. |
Initialise a Slotted schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slots
|
list
|
The slot boundaries. |
required |
slot_sizes
|
list
|
The number of servers in each slot. |
required |
capacitated
|
bool
|
Whether the slots are capacitated.
Defaults to |
False
|
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
initialise ¶
initialise()
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
160 161 162 163 164 165 | |
get_next_slot ¶
get_next_slot()
Update the next slot date and size from the generator.
Source code in hciw/schedules.py
167 168 169 170 171 | |
Routing¶
routing ¶
Routing classes that determine the next node an individual visits.
NetworkRouting ¶
NetworkRouting(routers)
Hold a number of routing objects, one for each node.
Set up the router objects for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
routers
|
list
|
The routing objects, one for each node. |
required |
Source code in hciw/routing/routing.py
11 12 13 14 15 16 17 | |
initialise ¶
initialise(simulation)
Give the simulation and node attributes to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Source code in hciw/routing/routing.py
19 20 21 22 23 24 25 26 27 28 29 30 | |
initialise_individual ¶
initialise_individual(ind)
Run at the arrival node when the individual is spawned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being spawned. |
required |
Source code in hciw/routing/routing.py
32 33 34 35 36 37 | |
next_node ¶
next_node(ind, node_id)
Choose the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
39 40 41 42 43 44 45 46 47 48 49 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind, node_id)
Choose the next node when rerouting a preempted customer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
51 52 53 54 55 56 57 58 59 60 61 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind, node_id)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
63 64 65 66 67 68 69 70 71 72 73 | |
TransitionMatrix ¶
TransitionMatrix(transition_matrix)
Bases: NetworkRouting
Hold a number of probabilistic routing objects.
Set up the relevant probabilistic router objects for each node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transition_matrix
|
list
|
A square matrix where the entry in row
|
required |
Source code in hciw/routing/routing.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |
initialise ¶
initialise(simulation)
Give the simulation to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of rows in the transition matrix does not equal the number of nodes in the network. |
Source code in hciw/routing/routing.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
ProcessBased ¶
ProcessBased(route_function)
Bases: NetworkRouting
Route an individual based on a pre-defined process.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_function
|
callable
|
A function that returns a pre-defined route for an individual. |
required |
Source code in hciw/routing/routing.py
115 116 117 118 119 120 121 122 | |
initialise ¶
initialise(simulation)
Give the simulation and node attributes to the routing objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the routers belong to. |
required |
Source code in hciw/routing/routing.py
124 125 126 127 128 129 130 131 | |
initialise_individual ¶
initialise_individual(ind)
Set the route of the individual when they are spawned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being spawned. |
required |
Source code in hciw/routing/routing.py
133 134 135 136 137 138 139 | |
next_node ¶
next_node(ind, node_id)
Choose the next node from the process-based pre-defined route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
141 142 143 144 145 146 147 148 149 150 151 152 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind, node_id)
Choose the next node when rerouting a preempted customer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
154 155 156 157 158 159 160 161 162 163 164 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind, node_id)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
166 167 168 169 170 171 172 173 174 175 176 | |
FlexibleProcessBased ¶
FlexibleProcessBased(route_function, rule, choice)
Bases: ProcessBased
Route an individual based on a pre-defined process.
The route is flexible: each step may be a subset of nodes from which the next node is chosen according to a rule and a choice method.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_function
|
callable
|
A function that returns a pre-defined route for an individual. |
required |
rule
|
str
|
Either |
required |
choice
|
str
|
Either |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Source code in hciw/routing/routing.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
find_next_node_from_subset ¶
find_next_node_from_subset(subset, ind)
Find the next node within a subset according to choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subset
|
list
|
The subset of node indices to choose from. |
required |
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The id number of the chosen node. |
Source code in hciw/routing/routing.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
update_individual_route ¶
update_individual_route(ind, next_node_id)
Remove chosen nodes from the individual's route according to rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
next_node_id
|
int
|
The id number of the chosen next node. |
required |
Source code in hciw/routing/routing.py
236 237 238 239 240 241 242 243 244 245 246 247 248 | |
next_node ¶
next_node(ind, node_id)
Choose the next node from the process-based pre-defined route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
node_id
|
int
|
The id number of the node the individual is at. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
NodeRouting ¶
A generic routing class to determine next sampled node.
initialise ¶
initialise(simulation, node)
Give the simulation and node attributes to the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation the router belongs to. |
required |
node
|
Node
|
The node the router belongs to. |
required |
Source code in hciw/routing/routing.py
271 272 273 274 275 276 277 278 279 280 281 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the routing object is valid when it is initialised.
Source code in hciw/routing/routing.py
283 284 | |
next_node ¶
next_node(ind)
Choose the next node for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
286 287 288 289 290 291 292 293 294 295 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Choose the next node when rerouting a preempted customer.
By default, the next node for rerouting uses the same method as
:meth:next_node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
297 298 299 300 301 302 303 304 305 306 307 308 309 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Choose the next node when jockeying to another node after reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
311 312 313 314 315 316 317 318 319 320 | |
Probabilistic ¶
Probabilistic(destinations, probs)
Bases: NodeRouting
A router that probabilistically chooses the next node.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destinations
|
list
|
A list of node indices. |
required |
probs
|
list
|
A list of probabilities associated with each destination. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any probability is not a float. |
ValueError
|
If any probability is less than 0 or greater than 1. |
ValueError
|
If the probabilities sum to more than 1. |
Source code in hciw/routing/routing.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the probabilities and destinations are valid.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the probabilities and destinations differ in length. |
ValueError
|
If the destinations are not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
next_node ¶
next_node(ind)
Probabilistically choose the next node from the destinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
372 373 374 375 376 377 378 379 380 381 382 | |
Direct ¶
Direct(to)
Bases: NodeRouting
A router that sends the individual directly to another node.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
int
|
The node index to send to. |
required |
Source code in hciw/routing/routing.py
388 389 390 391 392 393 394 | |
next_node ¶
next_node(ind)
Choose the node to with probability 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The destination node. |
Source code in hciw/routing/routing.py
396 397 398 399 400 401 402 403 404 405 | |
Leave ¶
Bases: NodeRouting
A router that sends the individual directly to the exit node.
next_node ¶
next_node(ind)
Choose the exit node with probability 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The exit node. |
Source code in hciw/routing/routing.py
411 412 413 414 415 416 417 418 419 420 | |
JoinShortestQueue ¶
JoinShortestQueue(destinations, tie_break='random')
Bases: NodeRouting
A router that sends the individual to the node with the shortest queue.
The node is chosen from a list of destinations.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destinations
|
list
|
A list of node indices. |
required |
tie_break
|
str
|
The method to deal with ties. One of
|
'random'
|
Source code in hciw/routing/routing.py
429 430 431 432 433 434 435 436 437 438 439 440 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the destinations are a subset of the network's nodes.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the destinations are not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
442 443 444 445 446 447 448 449 450 451 452 453 454 | |
get_queue_size ¶
get_queue_size(node_index)
Get the size of the queue at node_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_index
|
int
|
The index of the node. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of waiting individuals. |
Source code in hciw/routing/routing.py
456 457 458 459 460 461 462 463 464 465 466 467 468 | |
next_node ¶
next_node(ind)
Choose the destination node with the shortest queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
LoadBalancing ¶
LoadBalancing(destinations, tie_break='random')
Bases: JoinShortestQueue
A version of JoinShortestQueue that also counts customers in service.
Source code in hciw/routing/routing.py
429 430 431 432 433 434 435 436 437 438 439 440 | |
get_queue_size ¶
get_queue_size(node_index)
Get the size of the queue at node_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_index
|
int
|
The index of the node. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of individuals at the node. |
Source code in hciw/routing/routing.py
500 501 502 503 504 505 506 507 508 509 | |
Cycle ¶
Cycle(cycle)
Bases: NodeRouting
A router that cycles through destinations, repeating the cycle once ended.
Initialise the routing object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cycle
|
list
|
An ordered sequence of node indices. |
required |
Source code in hciw/routing/routing.py
515 516 517 518 519 520 521 522 | |
error_check_at_initialise ¶
error_check_at_initialise()
Check the cycle is a subset of the network's nodes.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the cycle is not a subset of the nodes in the network. |
Source code in hciw/routing/routing.py
524 525 526 527 528 529 530 531 532 533 534 535 536 | |
next_node ¶
next_node(ind)
Choose the next node in the cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/routing/routing.py
538 539 540 541 542 543 544 545 546 547 548 | |
State trackers¶
state_tracker ¶
State tracker classes that record the state of a simulation over time.
StateTracker ¶
A generic class to record a system's state.
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
7 8 9 10 11 12 13 14 15 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
17 18 19 20 21 22 23 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
25 26 27 28 29 30 31 32 33 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
35 36 37 38 39 40 41 42 43 44 | |
change_state_renege ¶
change_state_renege(node, destination, ind, blocked)
Change the state of the system when a customer reneges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual reneges. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual reneging. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
46 47 48 49 50 51 52 53 54 55 56 | |
change_state_classchange ¶
change_state_classchange(node, ind)
Change the state of the system when a customer changes class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual changes class. |
required |
ind
|
Individual
|
The individual changing class. |
required |
Source code in hciw/trackers/state_tracker.py
58 59 60 61 62 63 64 | |
hash_state ¶
hash_state() -> object
Return a hashable state.
Returns:
| Type | Description |
|---|---|
Hashable
|
A hashable representation of the state. |
Source code in hciw/trackers/state_tracker.py
66 67 68 69 70 71 72 | |
timestamp ¶
timestamp()
Record the current state in the history if it has changed.
Source code in hciw/trackers/state_tracker.py
74 75 76 77 78 | |
state_probabilities ¶
state_probabilities(observation_period=(0, float('Inf')))
Get the state probabilities from the history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation_period
|
tuple
|
A |
(0, float('Inf'))
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary of states as keys and probabilities as values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the observation period is not a positive interval above zero. |
Source code in hciw/trackers/state_tracker.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
SystemPopulation ¶
Bases: StateTracker
Record the number of customers in the system, regardless of node.
Example
3 This denotes 3 customers in the whole system.
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
145 146 147 148 149 150 151 152 153 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
155 156 157 158 159 160 161 162 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
164 165 166 167 168 169 170 171 172 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
174 175 176 177 178 179 180 181 182 183 184 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
int
|
The number of customers in the system. |
Source code in hciw/trackers/state_tracker.py
186 187 188 189 190 191 192 | |
NodePopulation ¶
Bases: StateTracker
Record the number of customers at each node.
Example
(3, 1) This denotes 3 customers at the first node, and 1 customer at the second node.
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
204 205 206 207 208 209 210 211 212 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
214 215 216 217 218 219 220 221 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
223 224 225 226 227 228 229 230 231 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
233 234 235 236 237 238 239 240 241 242 243 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The number of customers at each node. |
Source code in hciw/trackers/state_tracker.py
245 246 247 248 249 250 251 | |
NodePopulationSubset ¶
NodePopulationSubset(observed_nodes)
Bases: StateTracker
Record the number of customers at each node in a given set.
Example
(3, 1) This denotes 3 customers at the first node, and 1 customer at the second node.
Pre-initialise the object with the observed nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed_nodes
|
list
|
The indices of the nodes to observe. |
required |
Source code in hciw/trackers/state_tracker.py
263 264 265 266 267 268 269 | |
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
271 272 273 274 275 276 277 278 279 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
281 282 283 284 285 286 287 288 289 290 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
292 293 294 295 296 297 298 299 300 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
302 303 304 305 306 307 308 309 310 311 312 313 314 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The number of customers at each observed node. |
Source code in hciw/trackers/state_tracker.py
316 317 318 319 320 321 322 | |
GroupedNodePopulation ¶
GroupedNodePopulation(groups)
Bases: StateTracker
Record the number of customers at each group of nodes.
Node groups are defined by the user.
Example
(3, 1) This denotes 3 customers at the first node group, and 1 customer at the second node group.
Pre-initialise the object with the observed node groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
list
|
A list of node groups, each a list of node indices. |
required |
Source code in hciw/trackers/state_tracker.py
336 337 338 339 340 341 342 343 | |
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
345 346 347 348 349 350 351 352 353 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
355 356 357 358 359 360 361 362 363 364 365 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
367 368 369 370 371 372 373 374 375 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The number of customers at each node group. |
Source code in hciw/trackers/state_tracker.py
392 393 394 395 396 397 398 | |
NodeClassMatrix ¶
NodeClassMatrix(class_ordering=None)
Bases: StateTracker
Record the number of customers of each class at each node.
Example
::
((3, 1),
(0, 1))
This denotes 4 customers at the first node (3 of Class 0, 1 of
Class 0), and 1 customer at the second node (0 of Class 0, 1 of
Class 1).
Pre-initialise the object with the class ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_ordering
|
list
|
The order of the customer
classes. Defaults to |
None
|
Source code in hciw/trackers/state_tracker.py
414 415 416 417 418 419 420 421 422 | |
initialise ¶
initialise(simulation)
Initialise the state tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
448 449 450 451 452 453 454 455 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
457 458 459 460 461 462 463 464 465 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
467 468 469 470 471 472 473 474 475 476 477 | |
change_state_classchange ¶
change_state_classchange(node, ind)
Change the state of the system when a customer changes class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual changes class. |
required |
ind
|
Individual
|
The individual changing class. |
required |
Source code in hciw/trackers/state_tracker.py
479 480 481 482 483 484 485 486 487 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The number of customers of each class at each node. |
Source code in hciw/trackers/state_tracker.py
489 490 491 492 493 494 495 | |
NaiveBlocking ¶
Bases: StateTracker
Record the number of customers and blocked customers at each node.
Example
((3, 0), (1, 4)) This denotes 3 customers at the first node, 0 of which are blocked, 5 customers at the second node, 4 of which are blocked.
initialise ¶
initialise(simulation)
Initialise the naive blocking tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
508 509 510 511 512 513 514 515 516 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
518 519 520 521 522 523 524 525 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
527 528 529 530 531 532 533 534 535 536 537 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The number of customers and blocked customers at each node. |
Source code in hciw/trackers/state_tracker.py
554 555 556 557 558 559 560 | |
MatrixBlocking ¶
Bases: StateTracker
Record the order and destination of blockages, and node populations.
The blockages are recorded in the form of a matrix, alongside the number of customers at each node.
Example
::
((((1, 4), (2)),
(3), ())),
(5, 8))
This denotes 5 customers at the first node, 8 customers at the
second; 2 customers blocked from the first node to the first,
one from the first node to the second, and one from the second
node to the first. The numbers denote the order at which they
became blocked.
initialise ¶
initialise(simulation)
Initialise the matrix blocking tracker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation being tracked. |
required |
Source code in hciw/trackers/state_tracker.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
change_state_accept ¶
change_state_accept(node, ind)
Change the state of the system when a customer is accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is accepted. |
required |
ind
|
Individual
|
The individual being accepted. |
required |
Source code in hciw/trackers/state_tracker.py
599 600 601 602 603 604 605 606 | |
change_state_block ¶
change_state_block(node, destination, ind)
Change the state of the system when a customer gets blocked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is blocked. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
ind
|
Individual
|
The individual being blocked. |
required |
Source code in hciw/trackers/state_tracker.py
608 609 610 611 612 613 614 615 616 617 618 619 620 | |
change_state_release ¶
change_state_release(node, destination, ind, blocked)
Change the state of the system when a customer is released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node at which the individual is released. |
required |
destination
|
Node
|
The node the individual was blocked from entering. |
required |
ind
|
Individual
|
The individual being released. |
required |
blocked
|
bool
|
Whether the individual was blocked. |
required |
Source code in hciw/trackers/state_tracker.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
find_blocked_position_and_pop ¶
find_blocked_position_and_pop(node, destination)
Find the position of the next customer to unblock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the individual is blocked at. |
required |
destination
|
Node
|
The node the individual is blocked from entering. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The order position of the blocked customer. |
Source code in hciw/trackers/state_tracker.py
640 641 642 643 644 645 646 647 648 649 650 651 | |
adjust_positions ¶
adjust_positions(position)
Reduce any positions greater than position by one.
Loops through the whole matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
int
|
The order position that was removed. |
required |
Source code in hciw/trackers/state_tracker.py
653 654 655 656 657 658 659 660 661 662 663 664 665 | |
hash_state ¶
hash_state()
Return a hashable state.
Returns:
| Type | Description |
|---|---|
tuple
|
The blockage matrix and the number of customers at each node. |
Source code in hciw/trackers/state_tracker.py
667 668 669 670 671 672 673 674 675 676 677 678 | |
Deadlock detection¶
deadlock_detector ¶
Deadlock detection mechanisms for queueing networks.
NoDetection ¶
NoDetection()
A generic class for all deadlock detector classes to inherit from.
Using this class is equivalent to having no deadlock detection capabilities.
Initialise the detection mechanism class.
Source code in hciw/deadlock/deadlock_detector.py
13 14 | |
initialise_at_node ¶
initialise_at_node(node)
Initialise the detection mechanism when the node is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node being created. |
required |
Source code in hciw/deadlock/deadlock_detector.py
16 17 18 19 20 21 | |
detect_deadlock ¶
detect_deadlock() -> bool
Return whether deadlock has been reached.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in hciw/deadlock/deadlock_detector.py
23 24 25 26 27 28 29 | |
action_at_attach_server ¶
action_at_attach_server(node, server, individual)
Take action when the node's attach_server method is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server is attached to. |
required |
server
|
Server
|
The server being attached. |
required |
individual
|
Individual
|
The individual being served. |
required |
Source code in hciw/deadlock/deadlock_detector.py
31 32 33 34 35 36 37 38 | |
action_at_blockage ¶
action_at_blockage(individual, next_node)
Take action when the node's block_individual method is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/deadlock/deadlock_detector.py
40 41 42 43 44 45 46 47 | |
action_at_detatch_server ¶
action_at_detatch_server(server)
Take action when the node's detatch_server method is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server being detached. |
required |
Source code in hciw/deadlock/deadlock_detector.py
49 50 51 52 53 54 | |
StateDigraph ¶
StateDigraph()
Bases: NoDetection
Keep track of a directed graph of the simulation state.
Vertices represent servers. Edges represent blockage relationships,
such that there is a directed edge from vertex j to vertex k if
and only if the customer at server j is blocked from entering the
node that contains k. Deadlock is equivalent to a knot in the
directed graph.
Initialise the state digraph detection mechanism class.
Source code in hciw/deadlock/deadlock_detector.py
67 68 69 | |
initialise_at_node ¶
initialise_at_node(node)
Initialise the state digraph when the node is created.
Adds the servers of that node if c < Inf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node being created. |
required |
Source code in hciw/deadlock/deadlock_detector.py
71 72 73 74 75 76 77 78 79 80 | |
detect_deadlock ¶
detect_deadlock()
Detect whether the system is in a deadlocked state.
That is, whether there is a knot. Note that this code is taken and adapted from the NetworkX Developer Zone Ticket #663 knot.py (09/06/2015).
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in hciw/deadlock/deadlock_detector.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
action_at_attach_server ¶
action_at_attach_server(node, server, individual)
Take action when the node's attach_server method is called.
If a new customer joins a server, and their server is still blocking
a customer, then that edge needs to remain. However it was removed
in :meth:action_at_detatch_server, so it needs to be added back in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server is attached to. |
required |
server
|
Server
|
The server being attached. |
required |
individual
|
Individual
|
The individual being served. |
required |
Source code in hciw/deadlock/deadlock_detector.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
action_at_blockage ¶
action_at_blockage(individual, next_node)
Take action when the node's block_individual method is called.
Adds edges between the blocked server and the servers of the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/deadlock/deadlock_detector.py
131 132 133 134 135 136 137 138 139 140 141 142 143 | |
action_at_detatch_server ¶
action_at_detatch_server(server)
Take action when the node's detatch_server method is called.
Removes any edges of servers that have been detached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server being detached. |
required |
Source code in hciw/deadlock/deadlock_detector.py
145 146 147 148 149 150 151 152 153 154 155 156 | |
Simulation internals¶
The classes below model the internal workings of a simulation. They are
documented for reference and for advanced use, but most users will interact
with HCiw only through hciw.create_network and hciw.Simulation.
node ¶
Transient node of the queueing network.
DataRecord
module-attribute
¶
DataRecord = namedtuple(
"Record",
[
"id_number",
"customer_class",
"original_customer_class",
"node",
"arrival_date",
"waiting_time",
"service_start_date",
"service_time",
"service_end_date",
"time_blocked",
"exit_date",
"destination",
"queue_size_at_arrival",
"queue_size_at_departure",
"server_id",
"record_type",
],
)
Individual ¶
Individual(
id_number,
customer_class="Customer",
priority_class=0,
simulation=False,
)
Represent an individual agent in a queueing network simulation.
An Individual models the flow of an agent through a queueing
network, tracking its arrival time, service time, priority and other
relevant data.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_date |
bool or float
|
Timestamp of the individual's arrival. |
service_start_date |
bool or float
|
Timestamp the current service started. |
service_time |
bool or float
|
Duration of the current service. |
service_end_date |
bool or float
|
Timestamp the current service ends. |
exit_date |
bool or float
|
Timestamp the individual exits the system. |
id_number |
int
|
Unique identifier for the individual. |
data_records |
list
|
The data records attached to the individual. |
customer_class |
str
|
The customer class of the individual. |
previous_class |
str
|
The previous customer class of the individual. |
priority_class |
int
|
The priority class of the individual. |
prev_priority_class |
int
|
The previous priority class of the individual. |
original_class |
str
|
The original customer class of the individual. |
is_blocked |
bool
|
Whether the individual is blocked. |
server |
bool or Server
|
The server assigned to the individual, if any. |
queue_size_at_arrival |
bool or int
|
Queue size when the individual arrived. |
queue_size_at_departure |
bool or int
|
Queue size when the individual departed. |
destination |
bool or int
|
The destination node in the network. |
interrupted |
bool
|
Whether the individual's service was interrupted. |
node |
bool or int
|
The node where the individual is located. |
simulation |
bool or Simulation
|
The simulation the individual belongs to. |
Example
.. code-block:: python
individual = Individual(
id_number=1, customer_class='Gold', priority_class=1,
simulation=True,
)
Initialise an Individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_number
|
int
|
A unique identifier for the individual. |
required |
customer_class
|
str
|
The customer class the individual
belongs to. Defaults to |
'Customer'
|
priority_class
|
int
|
The priority class of the
individual. Defaults to |
0
|
simulation
|
bool or Simulation
|
The simulation the
individual is part of. Defaults to |
False
|
Source code in hciw/individual.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
Schedule ¶
Schedule(
numbers_of_servers: list[int],
shift_end_dates: list[float],
preemption: bool | str = False,
offset: float = 0.0,
)
Store server schedule information and generate the next shifts.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
shift_end_dates |
List[float]
|
The end dates of each shift. |
numbers_of_servers |
List[int]
|
The number of servers for each shift. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
offset |
float
|
The offset applied to the schedule. |
Initialise a Schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers_of_servers
|
List[int]
|
The number of servers working at each shift. |
required |
shift_end_dates
|
List[float]
|
The end dates of each shift. |
required |
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
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 | |
initialise ¶
initialise() -> None
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
58 59 60 61 62 63 64 65 | |
get_schedule_generator ¶
get_schedule_generator(
boundaries: list[float],
values: list[int],
offset: float,
) -> Generator[tuple[float, int], None, None]
Yield the next shift date and server count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
List[float]
|
The shift boundaries. |
required |
values
|
List[int]
|
The number of servers corresponding to each boundary. |
required |
offset
|
float
|
The offset applied to the schedule. |
required |
Yields:
| Type | Description |
|---|---|
Tuple[float, int]
|
The next shift date and the number of servers. |
Source code in hciw/schedules.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
get_next_shift ¶
get_next_shift() -> None
Update the next shift from the generator.
Source code in hciw/schedules.py
93 94 95 96 97 98 | |
Slotted ¶
Slotted(
slots,
slot_sizes,
capacitated=False,
preemption=False,
offset=0.0,
)
Bases: Schedule
A schedule divided into slots with a number of servers per slot.
Attributes:
| Name | Type | Description |
|---|---|---|
schedule_type |
str
|
The type of the schedule. |
offset |
float
|
The offset applied to the schedule. |
slots |
list
|
The slot boundaries. |
slot_sizes |
list
|
The number of servers in each slot. |
next_slot_sizes |
list
|
The slot sizes of the next cycle. |
capacitated |
bool
|
Whether the slots are capacitated. |
preemption |
Union[bool, str]
|
The pre-emption option. |
cyclelength |
float
|
The length of the schedule cycle. |
c |
int
|
The current number of servers. |
Initialise a Slotted schedule instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slots
|
list
|
The slot boundaries. |
required |
slot_sizes
|
list
|
The number of servers in each slot. |
required |
capacitated
|
bool
|
Whether the slots are capacitated.
Defaults to |
False
|
preemption
|
Union[bool, str]
|
The pre-emption option,
one of |
False
|
offset
|
float
|
A non-negative offset applied to the
schedule. Defaults to |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hciw/schedules.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
initialise ¶
initialise()
Initialise the generator at the beginning of a simulation.
Source code in hciw/schedules.py
160 161 162 163 164 165 | |
get_next_slot ¶
get_next_slot()
Update the next slot date and size from the generator.
Source code in hciw/schedules.py
167 168 169 170 171 | |
Server ¶
Server(node, id_number, start_date: float | Decimal = 0.0)
Contain information about a server.
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server belongs to. |
required |
id_number
|
int
|
Identifier for the server. |
required |
start_date
|
float | Decimal
|
The time at which the server started, and whose type sets the precision of the server's accumulated times. |
0.0
|
Source code in hciw/server.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
utilisation
property
¶
utilisation
Get the server utilisation.
Returns:
| Type | Description |
|---|---|
float | Decimal
|
The proportion of total time the server was busy. |
Node ¶
Node(id_, simulation)
Represent a node in the queueing network.
The node holds a queue of individuals and, where applicable, the servers that process them.
Initialise a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
int
|
Identifier for the node. |
required |
simulation
|
object
|
The simulation to which this node belongs. |
required |
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
float
|
The current simulation time. |
all_individuals
property
¶
all_individuals
Get all individuals currently at the node.
Returns:
| Type | Description |
|---|---|
list
|
Every individual at the node, across all priority classes. |
accept ¶
accept(next_individual, completed=False)
Accept a new individual into the queue.
Removes any previous exit date and blockage status, begins service if possible, records arrival information, and updates the state tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual has completed service. |
False
|
Source code in hciw/node.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
add_new_servers ¶
add_new_servers(num_servers)
Add the appropriate number of servers for the given shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_servers
|
int
|
The number of servers to add. |
required |
Source code in hciw/node.py
129 130 131 132 133 134 135 136 137 138 139 | |
attach_server ¶
attach_server(server, individual)
Attach a server to an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to attach. |
required |
individual
|
Individual
|
The individual to attach. |
required |
Source code in hciw/node.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
begin_service_if_possible_accept ¶
begin_service_if_possible_accept(next_individual)
Begin service for an individual at the acceptance point.
Sets the arrival date to the current time, and if a server is free or there are infinitely many servers, attaches the server, gets the service start time, service time and service end time, and updates the server's end date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
begin_interrupted_individuals_service ¶
begin_interrupted_individuals_service(srvr)
Restart an interrupted individual's service.
The individual's service time is resampled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to give to the individual. |
required |
Source code in hciw/node.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
begin_service_if_possible_change_shift ¶
begin_service_if_possible_change_shift()
Begin service for customers after a shift change.
If there are free servers, restarts interrupted customers' services and begins service for any waiting customers by giving a start date and end date and attaching servers to individuals.
Source code in hciw/node.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
begin_service_if_possible_release ¶
begin_service_if_possible_release(
next_individual, newly_free_server
)
Begin service for an individual after a release.
Checks for interrupted individuals left to restart service, then gives an arrival date and service time, gives a start date and end date, and attaches the server to the individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual being released. |
required |
newly_free_server
|
Server
|
The server freed by the release. |
required |
Source code in hciw/node.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
block_individual ¶
block_individual(individual, next_node)
Block an individual from entering the next node.
Changes the blocked status, updates the state tracker, adds information to the next node's blocked queue, and updates the deadlock detector, informing the simulation that there are unchecked blockages for deadlock detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/node.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
change_customer_class ¶
change_customer_class(individual)
Change an individual's customer class.
The new class is chosen according to a probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual whose class changes. |
required |
Source code in hciw/node.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
change_customer_class_while_waiting ¶
change_customer_class_while_waiting()
Change the next queued individual's class while waiting.
The individual is moved between priority queues and preemption is decided if the priority class changes.
Source code in hciw/node.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
change_priority_queue ¶
change_priority_queue(individual)
Move an individual to their new priority queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to move. |
required |
Source code in hciw/node.py
332 333 334 335 336 337 338 339 | |
change_shift ¶
change_shift()
Implement a server shift change.
Adds or deletes servers, or indicates which servers should go off duty, and begins any new services if there are free servers.
Source code in hciw/node.py
341 342 343 344 345 346 347 348 349 350 351 352 353 | |
find_number_of_slotted_services ¶
find_number_of_slotted_services()
Find the number of slotted services to start in this slot.
Returns:
| Type | Description |
|---|---|
int
|
The number of services to start. |
Source code in hciw/node.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
interrupt_slotted_services ¶
interrupt_slotted_services()
Interrupt services when there is not enough slot capacity.
Finds the customers whose slotted services need to be interrupted because of insufficient capacity at the current slot, and interrupts their services.
Source code in hciw/node.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
slotted_service ¶
slotted_service()
Serve a set number of customers at the current time.
Only the number of customers allowed by the current slot may have service at the exact time the method is called.
Source code in hciw/node.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
choose_next_customer ¶
choose_next_customer()
Choose which customer will be next to be served.
Returns:
| Type | Description |
|---|---|
Individual
|
The customer chosen by the service discipline, or None if no customer is waiting. |
Source code in hciw/node.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
create_starting_servers ¶
create_starting_servers()
Initialise the servers.
Returns:
| Type | Description |
|---|---|
list
|
The newly created starting servers. |
Source code in hciw/node.py
432 433 434 435 436 437 438 439 440 | |
decide_class_change ¶
decide_class_change(next_individual)
Decide the next class and class change date for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to update. |
required |
Source code in hciw/node.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
decide_preempt ¶
decide_preempt(individual)
Decide whether priority preemption is needed.
If needed, finds the individual to preempt and preempts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual seeking service. |
required |
Source code in hciw/node.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
detatch_server ¶
detatch_server(server, individual)
Detach a server from an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to detach. |
required |
individual
|
Individual
|
The individual to detach. |
required |
Source code in hciw/node.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
find_free_server ¶
find_free_server(ind)
Find a free server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual needing a server. |
required |
Returns:
| Type | Description |
|---|---|
Server
|
A free server, or None if none is available. |
Source code in hciw/node.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
decide_between_simultaneous_individuals ¶
decide_between_simultaneous_individuals()
Find the next individual that should now finish service.
Returns:
| Type | Description |
|---|---|
Individual
|
A randomly chosen individual when several finish at the same time. |
Source code in hciw/node.py
527 528 529 530 531 532 533 534 535 536 537 538 539 | |
find_next_class_change ¶
find_next_class_change()
Update the next class change date and individual.
Source code in hciw/node.py
541 542 543 544 545 546 547 548 | |
find_server_utilisation ¶
find_server_utilisation()
Find the overall server utilisation for the node.
Source code in hciw/node.py
550 551 552 553 554 555 556 557 558 559 560 | |
finish_service ¶
finish_service()
Finish the service of the next individual.
Finds the individual to finish service, checks whether they need to change class, finds their next node, and releases the individual if there is capacity at the destination, otherwise causes blockage.
Source code in hciw/node.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
give_individual_a_service_time ¶
give_individual_a_service_time(individual)
Give a service time to an individual.
Either a new service time, or a service time after pre-emption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
581 582 583 584 585 586 587 588 589 590 591 592 | |
give_service_time_after_preemption ¶
give_service_time_after_preemption(individual)
Give a service time after preemption.
Either resamples, restarts, or resumes service time from where it was left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
have_event ¶
have_event()
Trigger the node's next event.
Source code in hciw/node.py
610 611 612 613 614 615 616 617 618 619 620 621 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/node.py
623 624 625 626 627 628 629 630 631 632 633 | |
kill_server ¶
kill_server(srvr)
Kill a server when it goes off duty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to remove. |
required |
Source code in hciw/node.py
635 636 637 638 639 640 641 642 643 644 645 646 | |
next_node ¶
next_node(ind)
Find the next node according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/node.py
648 649 650 651 652 653 654 655 656 657 658 659 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Find the next node for rerouting according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being rerouted. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for rerouting. |
Source code in hciw/node.py
661 662 663 664 665 666 667 668 669 670 671 672 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Find the next node for jockeying according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The jockeying individual. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for jockeying. |
Source code in hciw/node.py
674 675 676 677 678 679 680 681 682 683 684 685 | |
preempt ¶
preempt(individual_to_preempt, next_individual)
Preempt an individual and replace them in service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual_to_preempt
|
Individual
|
The individual removed from service. |
required |
next_individual
|
Individual
|
The individual taking their place. |
required |
Source code in hciw/node.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
release ¶
release(next_individual, next_node, reroute=False)
Release an individual from the node.
Removes the individual from the queue, records relevant information, detaches the server, updates the state tracker, begins service of any waiting customers, sends the individual to their next destination, and releases any individuals blocked by this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to release. |
required |
next_node
|
Node
|
The node receiving the individual. |
required |
reroute
|
bool
|
Whether the release is due to rerouting. |
False
|
Source code in hciw/node.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
release_blocked_individual ¶
release_blocked_individual()
Release an individual blocked by this node.
Finds the individual who has been blocked the longest, removes them from the blocked queue, restores their service if it was interrupted, and releases them from their node.
Source code in hciw/node.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
reset_class_change ¶
reset_class_change(individual)
Reset an individual's class change date when service begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual beginning service. |
required |
Source code in hciw/node.py
786 787 788 789 790 791 792 793 794 795 | |
renege ¶
renege()
Remove an individual from the queue due to reneging.
Resets the individual's reneging date and sends the individual to their reneging destination.
Source code in hciw/node.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
get_reneging_date ¶
get_reneging_date(ind)
Return the reneging date for a given individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The reneging date. |
Source code in hciw/node.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
get_service_time ¶
get_service_time(ind)
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sampled service time. |
Source code in hciw/node.py
836 837 838 839 840 841 842 843 844 845 846 847 | |
take_servers_off_duty ¶
take_servers_off_duty(preemption: bool | str = False)
Gather the servers that should be deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preemption
|
bool
|
Whether preemption is active for this shift change. |
False
|
Source code in hciw/node.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
interrupt_service ¶
interrupt_service(individual)
Interrupt an individual's service.
Places the individual in the interrupted queue and writes an interruption record for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being interrupted. |
required |
Source code in hciw/node.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
sort_interrupted_individuals ¶
sort_interrupted_individuals()
Sort interrupted individuals by priority class and arrival date.
Source code in hciw/node.py
899 900 901 902 903 | |
reroute ¶
reroute(individual)
Reroute a preempted individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being rerouted. |
required |
Source code in hciw/node.py
905 906 907 908 909 910 911 912 913 | |
update_next_end_service_without_server ¶
update_next_end_service_without_server()
Update the next end of a slotted service in possible_next_events.
Source code in hciw/node.py
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
update_next_end_service_with_server ¶
update_next_end_service_with_server()
Update the next end service with a server in possible_next_events.
Source code in hciw/node.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
update_next_renege_time ¶
update_next_renege_time()
Update the next renege time in possible_next_events.
Source code in hciw/node.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
update_next_class_change_while_waiting ¶
update_next_class_change_while_waiting()
Update the next class change while waiting in possible_next_events.
Source code in hciw/node.py
963 964 965 966 967 968 969 | |
update_next_shift_change_or_slot_time ¶
update_next_shift_change_or_slot_time()
Update possible_next_events with the next shift or slot time.
Source code in hciw/node.py
971 972 973 974 975 976 977 978 979 980 981 982 983 | |
update_next_event_date ¶
update_next_event_date()
Find the time of the next event at this node.
With infinite servers this is the time of the next individual to end service, or infinity. Otherwise it is the minimum of the next shift change and the time for the next individual (who is not blocked) to end service, or infinity.
Source code in hciw/node.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
decide_next_event ¶
decide_next_event()
Decide the next event.
Chooses the next service end, renege, shift change, or class change. In the case of a tie, events are prioritised in the following order:
- slotted service
- shift change
- end service
- class change
- renege
Returns:
| Type | Description |
|---|---|
tuple
|
The next event and its event type. |
Source code in hciw/node.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server total and busy times at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The simulation end time. |
required |
Source code in hciw/node.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
write_individual_record ¶
write_individual_record(individual)
Write a data record for an individual leaving a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual leaving the node. |
required |
Source code in hciw/node.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
write_incomplete_record ¶
write_incomplete_record(individual)
Write an incomplete data record at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual still at the node. |
required |
Returns:
| Type | Description |
|---|---|
DataRecord
|
The incomplete data record. |
Source code in hciw/node.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 | |
write_interruption_record ¶
write_interruption_record(individual, destination=nan)
Write a data record for an individual being interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The interrupted individual. |
required |
destination
|
int
|
The destination node number. |
nan
|
Source code in hciw/node.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
write_reneging_record ¶
write_reneging_record(individual)
Write a data record for an individual when reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The reneging individual. |
required |
Source code in hciw/node.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
write_baulking_or_rejection_record ¶
write_baulking_or_rejection_record(individual, record_type)
Write a data record for an individual who baulks or is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual. |
required |
record_type
|
str
|
The type of record to write. |
required |
Source code in hciw/node.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
reset_individual_attributes ¶
reset_individual_attributes(individual)
Reset the attributes of an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to reset. |
required |
Source code in hciw/node.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
flatten_list ¶
flatten_list(list_of_lists)
Flatten a list of lists into a single list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_of_lists
|
list
|
A list whose elements are themselves lists. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A single list containing all elements of the inner lists. |
Source code in hciw/auxiliary.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
random_choice ¶
random_choice(array, probs=None)
Select a random element from an array using optional weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list
|
The values to choose from. |
required |
probs
|
list
|
Probability weights corresponding to each value. If omitted, a uniform choice is made. |
None
|
Returns:
| Type | Description |
|---|---|
|
The randomly selected element of |
Source code in hciw/auxiliary.py
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 | |
arrival_node ¶
Arrival node of the queueing network.
ArrivalNode ¶
ArrivalNode(simulation)
Represent the arrival node of the network.
This class handles arrivals, baulking, and rejections of individuals.
See hciw.Simulation for the main simulation class.
Initialise the arrival node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
object
|
The simulation to which this arrival node belongs. |
required |
Source code in hciw/arrival_node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
initialise ¶
initialise()
Initialise the event dates dictionary and next event date.
Source code in hciw/arrival_node.py
36 37 38 39 | |
decide_baulk ¶
decide_baulk(next_node, next_individual)
Either make an individual baulk or send them to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being considered. |
required |
Source code in hciw/arrival_node.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
find_next_event_date ¶
find_next_event_date()
Find the time of the next arrival.
Source code in hciw/arrival_node.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
have_event ¶
have_event()
Create and send a batch of arriving individuals.
Finds a batch size, creates that many individuals, sends them to the relevant node, then updates the event dates dictionary.
Source code in hciw/arrival_node.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/arrival_node.py
120 121 122 123 124 125 126 127 128 129 130 | |
initialise_event_dates_dict ¶
initialise_event_dates_dict()
Initialise the event dates dictionary.
Random times are sampled for each node and class.
Source code in hciw/arrival_node.py
132 133 134 135 136 137 138 139 140 141 142 | |
inter_arrival ¶
inter_arrival(nd, clss)
Sample the inter-arrival time for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
|
The sampled inter-arrival time. |
Source code in hciw/arrival_node.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
batch_size ¶
batch_size(nd, clss)
Sample the batch size for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The sampled batch size. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sampled batch size is not a non-negative integer. |
Source code in hciw/arrival_node.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
record_baulk ¶
record_baulk(next_node, individual)
Write a baulking record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual would have joined. |
required |
individual
|
Individual
|
The baulking individual. |
required |
Source code in hciw/arrival_node.py
179 180 181 182 183 184 185 186 | |
record_rejection ¶
record_rejection(next_node, individual)
Write a rejection record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual was rejected from. |
required |
individual
|
Individual
|
The rejected individual. |
required |
Source code in hciw/arrival_node.py
188 189 190 191 192 193 194 195 196 197 | |
release_individual ¶
release_individual(next_node, next_individual)
Release an individual to the next node.
Either rejects the individual due to lack of capacity, or sends that individual to baulk or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being released. |
required |
Source code in hciw/arrival_node.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
send_individual ¶
send_individual(next_node, next_individual)
Send the next individual to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being sent. |
required |
Source code in hciw/arrival_node.py
217 218 219 220 221 222 223 224 225 226 | |
update_next_event_date ¶
update_next_event_date()
Do nothing, as the next event update happens at the event time.
Source code in hciw/arrival_node.py
228 229 | |
exit_node ¶
Exit node of the queueing network.
ExitNode ¶
ExitNode()
Represent the exit node of the network.
Initialise the exit node.
Source code in hciw/exit_node.py
7 8 9 10 11 12 13 14 | |
accept ¶
accept(next_individual, completed=True)
Add an individual to the list of completed individuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual completed service. |
True
|
Source code in hciw/exit_node.py
24 25 26 27 28 29 30 31 32 33 34 35 | |
update_next_event_date ¶
update_next_event_date()
Do nothing, as the next event date is always the max time.
Source code in hciw/exit_node.py
37 38 | |
server ¶
Server that processes individuals at a node.
Server ¶
Server(node, id_number, start_date: float | Decimal = 0.0)
Contain information about a server.
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server belongs to. |
required |
id_number
|
int
|
Identifier for the server. |
required |
start_date
|
float | Decimal
|
The time at which the server started, and whose type sets the precision of the server's accumulated times. |
0.0
|
Source code in hciw/server.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
utilisation
property
¶
utilisation
Get the server utilisation.
Returns:
| Type | Description |
|---|---|
float | Decimal
|
The proportion of total time the server was busy. |
individual ¶
The individual agent that flows through a queueing network.
Server ¶
Server(node, id_number, start_date: float | Decimal = 0.0)
Contain information about a server.
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server belongs to. |
required |
id_number
|
int
|
Identifier for the server. |
required |
start_date
|
float | Decimal
|
The time at which the server started, and whose type sets the precision of the server's accumulated times. |
0.0
|
Source code in hciw/server.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
utilisation
property
¶
utilisation
Get the server utilisation.
Returns:
| Type | Description |
|---|---|
float | Decimal
|
The proportion of total time the server was busy. |
Individual ¶
Individual(
id_number,
customer_class="Customer",
priority_class=0,
simulation=False,
)
Represent an individual agent in a queueing network simulation.
An Individual models the flow of an agent through a queueing
network, tracking its arrival time, service time, priority and other
relevant data.
Attributes:
| Name | Type | Description |
|---|---|---|
arrival_date |
bool or float
|
Timestamp of the individual's arrival. |
service_start_date |
bool or float
|
Timestamp the current service started. |
service_time |
bool or float
|
Duration of the current service. |
service_end_date |
bool or float
|
Timestamp the current service ends. |
exit_date |
bool or float
|
Timestamp the individual exits the system. |
id_number |
int
|
Unique identifier for the individual. |
data_records |
list
|
The data records attached to the individual. |
customer_class |
str
|
The customer class of the individual. |
previous_class |
str
|
The previous customer class of the individual. |
priority_class |
int
|
The priority class of the individual. |
prev_priority_class |
int
|
The previous priority class of the individual. |
original_class |
str
|
The original customer class of the individual. |
is_blocked |
bool
|
Whether the individual is blocked. |
server |
bool or Server
|
The server assigned to the individual, if any. |
queue_size_at_arrival |
bool or int
|
Queue size when the individual arrived. |
queue_size_at_departure |
bool or int
|
Queue size when the individual departed. |
destination |
bool or int
|
The destination node in the network. |
interrupted |
bool
|
Whether the individual's service was interrupted. |
node |
bool or int
|
The node where the individual is located. |
simulation |
bool or Simulation
|
The simulation the individual belongs to. |
Example
.. code-block:: python
individual = Individual(
id_number=1, customer_class='Gold', priority_class=1,
simulation=True,
)
Initialise an Individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_number
|
int
|
A unique identifier for the individual. |
required |
customer_class
|
str
|
The customer class the individual
belongs to. Defaults to |
'Customer'
|
priority_class
|
int
|
The priority class of the
individual. Defaults to |
0
|
simulation
|
bool or Simulation
|
The simulation the
individual is part of. Defaults to |
False
|
Source code in hciw/individual.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
data_record ¶
The data record stored for each visit of an individual to a node.
Attributes:
| Name | Type | Description |
|---|---|---|
id_number |
int
|
Unique identifier of the individual. |
customer_class |
str
|
The customer class of the individual. |
original_customer_class |
str
|
The original customer class of the individual. |
node |
int
|
The node the record refers to. |
arrival_date |
float
|
The date the individual arrived at the node. |
waiting_time |
float
|
The time the individual waited before service. |
service_start_date |
float
|
The date service started. |
service_time |
float
|
The duration of service. |
service_end_date |
float
|
The date service ended. |
time_blocked |
float
|
The time the individual spent blocked. |
exit_date |
float
|
The date the individual left the node. |
destination |
int
|
The destination node. |
queue_size_at_arrival |
int
|
The queue size when the individual arrived. |
queue_size_at_departure |
int
|
The queue size when the individual departed. |
server_id |
int
|
The identifier of the server that served the individual. |
record_type |
str
|
The type of record. |
DataRecord
module-attribute
¶
DataRecord = namedtuple(
"Record",
[
"id_number",
"customer_class",
"original_customer_class",
"node",
"arrival_date",
"waiting_time",
"service_start_date",
"service_time",
"service_end_date",
"time_blocked",
"exit_date",
"destination",
"queue_size_at_arrival",
"queue_size_at_departure",
"server_id",
"record_type",
],
)
processor_sharing ¶
Limited processor-sharing node.
Node ¶
Node(id_, simulation)
Represent a node in the queueing network.
The node holds a queue of individuals and, where applicable, the servers that process them.
Initialise a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
int
|
Identifier for the node. |
required |
simulation
|
object
|
The simulation to which this node belongs. |
required |
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
float
|
The current simulation time. |
all_individuals
property
¶
all_individuals
Get all individuals currently at the node.
Returns:
| Type | Description |
|---|---|
list
|
Every individual at the node, across all priority classes. |
accept ¶
accept(next_individual, completed=False)
Accept a new individual into the queue.
Removes any previous exit date and blockage status, begins service if possible, records arrival information, and updates the state tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual has completed service. |
False
|
Source code in hciw/node.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
add_new_servers ¶
add_new_servers(num_servers)
Add the appropriate number of servers for the given shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_servers
|
int
|
The number of servers to add. |
required |
Source code in hciw/node.py
129 130 131 132 133 134 135 136 137 138 139 | |
attach_server ¶
attach_server(server, individual)
Attach a server to an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to attach. |
required |
individual
|
Individual
|
The individual to attach. |
required |
Source code in hciw/node.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
begin_service_if_possible_accept ¶
begin_service_if_possible_accept(next_individual)
Begin service for an individual at the acceptance point.
Sets the arrival date to the current time, and if a server is free or there are infinitely many servers, attaches the server, gets the service start time, service time and service end time, and updates the server's end date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
begin_interrupted_individuals_service ¶
begin_interrupted_individuals_service(srvr)
Restart an interrupted individual's service.
The individual's service time is resampled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to give to the individual. |
required |
Source code in hciw/node.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
begin_service_if_possible_change_shift ¶
begin_service_if_possible_change_shift()
Begin service for customers after a shift change.
If there are free servers, restarts interrupted customers' services and begins service for any waiting customers by giving a start date and end date and attaching servers to individuals.
Source code in hciw/node.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
begin_service_if_possible_release ¶
begin_service_if_possible_release(
next_individual, newly_free_server
)
Begin service for an individual after a release.
Checks for interrupted individuals left to restart service, then gives an arrival date and service time, gives a start date and end date, and attaches the server to the individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual being released. |
required |
newly_free_server
|
Server
|
The server freed by the release. |
required |
Source code in hciw/node.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
block_individual ¶
block_individual(individual, next_node)
Block an individual from entering the next node.
Changes the blocked status, updates the state tracker, adds information to the next node's blocked queue, and updates the deadlock detector, informing the simulation that there are unchecked blockages for deadlock detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/node.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
change_customer_class ¶
change_customer_class(individual)
Change an individual's customer class.
The new class is chosen according to a probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual whose class changes. |
required |
Source code in hciw/node.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
change_customer_class_while_waiting ¶
change_customer_class_while_waiting()
Change the next queued individual's class while waiting.
The individual is moved between priority queues and preemption is decided if the priority class changes.
Source code in hciw/node.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
change_priority_queue ¶
change_priority_queue(individual)
Move an individual to their new priority queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to move. |
required |
Source code in hciw/node.py
332 333 334 335 336 337 338 339 | |
change_shift ¶
change_shift()
Implement a server shift change.
Adds or deletes servers, or indicates which servers should go off duty, and begins any new services if there are free servers.
Source code in hciw/node.py
341 342 343 344 345 346 347 348 349 350 351 352 353 | |
find_number_of_slotted_services ¶
find_number_of_slotted_services()
Find the number of slotted services to start in this slot.
Returns:
| Type | Description |
|---|---|
int
|
The number of services to start. |
Source code in hciw/node.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
interrupt_slotted_services ¶
interrupt_slotted_services()
Interrupt services when there is not enough slot capacity.
Finds the customers whose slotted services need to be interrupted because of insufficient capacity at the current slot, and interrupts their services.
Source code in hciw/node.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
slotted_service ¶
slotted_service()
Serve a set number of customers at the current time.
Only the number of customers allowed by the current slot may have service at the exact time the method is called.
Source code in hciw/node.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
choose_next_customer ¶
choose_next_customer()
Choose which customer will be next to be served.
Returns:
| Type | Description |
|---|---|
Individual
|
The customer chosen by the service discipline, or None if no customer is waiting. |
Source code in hciw/node.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
create_starting_servers ¶
create_starting_servers()
Initialise the servers.
Returns:
| Type | Description |
|---|---|
list
|
The newly created starting servers. |
Source code in hciw/node.py
432 433 434 435 436 437 438 439 440 | |
decide_class_change ¶
decide_class_change(next_individual)
Decide the next class and class change date for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to update. |
required |
Source code in hciw/node.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
decide_preempt ¶
decide_preempt(individual)
Decide whether priority preemption is needed.
If needed, finds the individual to preempt and preempts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual seeking service. |
required |
Source code in hciw/node.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
detatch_server ¶
detatch_server(server, individual)
Detach a server from an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to detach. |
required |
individual
|
Individual
|
The individual to detach. |
required |
Source code in hciw/node.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
find_free_server ¶
find_free_server(ind)
Find a free server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual needing a server. |
required |
Returns:
| Type | Description |
|---|---|
Server
|
A free server, or None if none is available. |
Source code in hciw/node.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
decide_between_simultaneous_individuals ¶
decide_between_simultaneous_individuals()
Find the next individual that should now finish service.
Returns:
| Type | Description |
|---|---|
Individual
|
A randomly chosen individual when several finish at the same time. |
Source code in hciw/node.py
527 528 529 530 531 532 533 534 535 536 537 538 539 | |
find_next_class_change ¶
find_next_class_change()
Update the next class change date and individual.
Source code in hciw/node.py
541 542 543 544 545 546 547 548 | |
find_server_utilisation ¶
find_server_utilisation()
Find the overall server utilisation for the node.
Source code in hciw/node.py
550 551 552 553 554 555 556 557 558 559 560 | |
finish_service ¶
finish_service()
Finish the service of the next individual.
Finds the individual to finish service, checks whether they need to change class, finds their next node, and releases the individual if there is capacity at the destination, otherwise causes blockage.
Source code in hciw/node.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
give_individual_a_service_time ¶
give_individual_a_service_time(individual)
Give a service time to an individual.
Either a new service time, or a service time after pre-emption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
581 582 583 584 585 586 587 588 589 590 591 592 | |
give_service_time_after_preemption ¶
give_service_time_after_preemption(individual)
Give a service time after preemption.
Either resamples, restarts, or resumes service time from where it was left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
have_event ¶
have_event()
Trigger the node's next event.
Source code in hciw/node.py
610 611 612 613 614 615 616 617 618 619 620 621 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/node.py
623 624 625 626 627 628 629 630 631 632 633 | |
kill_server ¶
kill_server(srvr)
Kill a server when it goes off duty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to remove. |
required |
Source code in hciw/node.py
635 636 637 638 639 640 641 642 643 644 645 646 | |
next_node ¶
next_node(ind)
Find the next node according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/node.py
648 649 650 651 652 653 654 655 656 657 658 659 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Find the next node for rerouting according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being rerouted. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for rerouting. |
Source code in hciw/node.py
661 662 663 664 665 666 667 668 669 670 671 672 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Find the next node for jockeying according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The jockeying individual. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for jockeying. |
Source code in hciw/node.py
674 675 676 677 678 679 680 681 682 683 684 685 | |
preempt ¶
preempt(individual_to_preempt, next_individual)
Preempt an individual and replace them in service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual_to_preempt
|
Individual
|
The individual removed from service. |
required |
next_individual
|
Individual
|
The individual taking their place. |
required |
Source code in hciw/node.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
release ¶
release(next_individual, next_node, reroute=False)
Release an individual from the node.
Removes the individual from the queue, records relevant information, detaches the server, updates the state tracker, begins service of any waiting customers, sends the individual to their next destination, and releases any individuals blocked by this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to release. |
required |
next_node
|
Node
|
The node receiving the individual. |
required |
reroute
|
bool
|
Whether the release is due to rerouting. |
False
|
Source code in hciw/node.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
release_blocked_individual ¶
release_blocked_individual()
Release an individual blocked by this node.
Finds the individual who has been blocked the longest, removes them from the blocked queue, restores their service if it was interrupted, and releases them from their node.
Source code in hciw/node.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
reset_class_change ¶
reset_class_change(individual)
Reset an individual's class change date when service begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual beginning service. |
required |
Source code in hciw/node.py
786 787 788 789 790 791 792 793 794 795 | |
renege ¶
renege()
Remove an individual from the queue due to reneging.
Resets the individual's reneging date and sends the individual to their reneging destination.
Source code in hciw/node.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
get_reneging_date ¶
get_reneging_date(ind)
Return the reneging date for a given individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The reneging date. |
Source code in hciw/node.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
get_service_time ¶
get_service_time(ind)
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sampled service time. |
Source code in hciw/node.py
836 837 838 839 840 841 842 843 844 845 846 847 | |
take_servers_off_duty ¶
take_servers_off_duty(preemption: bool | str = False)
Gather the servers that should be deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preemption
|
bool
|
Whether preemption is active for this shift change. |
False
|
Source code in hciw/node.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
interrupt_service ¶
interrupt_service(individual)
Interrupt an individual's service.
Places the individual in the interrupted queue and writes an interruption record for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being interrupted. |
required |
Source code in hciw/node.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
sort_interrupted_individuals ¶
sort_interrupted_individuals()
Sort interrupted individuals by priority class and arrival date.
Source code in hciw/node.py
899 900 901 902 903 | |
reroute ¶
reroute(individual)
Reroute a preempted individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being rerouted. |
required |
Source code in hciw/node.py
905 906 907 908 909 910 911 912 913 | |
update_next_end_service_without_server ¶
update_next_end_service_without_server()
Update the next end of a slotted service in possible_next_events.
Source code in hciw/node.py
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
update_next_end_service_with_server ¶
update_next_end_service_with_server()
Update the next end service with a server in possible_next_events.
Source code in hciw/node.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
update_next_renege_time ¶
update_next_renege_time()
Update the next renege time in possible_next_events.
Source code in hciw/node.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
update_next_class_change_while_waiting ¶
update_next_class_change_while_waiting()
Update the next class change while waiting in possible_next_events.
Source code in hciw/node.py
963 964 965 966 967 968 969 | |
update_next_shift_change_or_slot_time ¶
update_next_shift_change_or_slot_time()
Update possible_next_events with the next shift or slot time.
Source code in hciw/node.py
971 972 973 974 975 976 977 978 979 980 981 982 983 | |
update_next_event_date ¶
update_next_event_date()
Find the time of the next event at this node.
With infinite servers this is the time of the next individual to end service, or infinity. Otherwise it is the minimum of the next shift change and the time for the next individual (who is not blocked) to end service, or infinity.
Source code in hciw/node.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
decide_next_event ¶
decide_next_event()
Decide the next event.
Chooses the next service end, renege, shift change, or class change. In the case of a tie, events are prioritised in the following order:
- slotted service
- shift change
- end service
- class change
- renege
Returns:
| Type | Description |
|---|---|
tuple
|
The next event and its event type. |
Source code in hciw/node.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server total and busy times at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The simulation end time. |
required |
Source code in hciw/node.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
write_individual_record ¶
write_individual_record(individual)
Write a data record for an individual leaving a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual leaving the node. |
required |
Source code in hciw/node.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
write_incomplete_record ¶
write_incomplete_record(individual)
Write an incomplete data record at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual still at the node. |
required |
Returns:
| Type | Description |
|---|---|
DataRecord
|
The incomplete data record. |
Source code in hciw/node.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 | |
write_interruption_record ¶
write_interruption_record(individual, destination=nan)
Write a data record for an individual being interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The interrupted individual. |
required |
destination
|
int
|
The destination node number. |
nan
|
Source code in hciw/node.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
write_reneging_record ¶
write_reneging_record(individual)
Write a data record for an individual when reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The reneging individual. |
required |
Source code in hciw/node.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
write_baulking_or_rejection_record ¶
write_baulking_or_rejection_record(individual, record_type)
Write a data record for an individual who baulks or is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual. |
required |
record_type
|
str
|
The type of record to write. |
required |
Source code in hciw/node.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
reset_individual_attributes ¶
reset_individual_attributes(individual)
Reset the attributes of an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to reset. |
required |
Source code in hciw/node.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
PSNode ¶
PSNode(id_, simulation)
Bases: Node
Represent a limited processor-sharing node.
In processor-sharing systems the service load is shared equally between
all customers at the node. While there are x customers present, the
service slows down x-fold, so the service time increases x-fold.
number_of_servers represents the node capacity, the maximum number of
customers allowed to share the service load at a time. Customers arriving
when the node is overcapacity wait in line.
Initialise the node.
Differs from Node by setting last_occupancy to 0, required to
calculate service times for the current period, setting
ps_capacity to the node capacity, and setting c to infinity,
as within capacity the code logic behaves more like an infinite
server queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
int
|
Identifier for the node. |
required |
simulation
|
object
|
The simulation to which this node belongs. |
required |
Source code in hciw/processor_sharing.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
update_all_service_end_dates ¶
update_all_service_end_dates()
Update projected service end dates for customers in service.
For each individual receiving service, calculates the projected end service dates if the system state remains constant.
Source code in hciw/processor_sharing.py
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 | |
begin_service_if_possible_accept ¶
begin_service_if_possible_accept(next_individual)
Begin service for an individual at the acceptance point.
Gives an arrival date and service time, gives a start date and a service time to complete if there is free capacity, marks the individual as 'with server', and updates all customers' service times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/processor_sharing.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
begin_service_if_possible_release ¶
begin_service_if_possible_release(
next_individual=None, newly_free_server=None
)
Begin service for an individual at a release point.
Checks for individuals waiting for capacity, gives a start date and 'last update' date, samples a service time and uses it as the time left, and updates all customers' service times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual being released. |
None
|
newly_free_server
|
Server
|
The server freed by the release. |
None
|
Source code in hciw/processor_sharing.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
exactnode ¶
Node classes with exact numerical precision.
ArrivalNode ¶
ArrivalNode(simulation)
Represent the arrival node of the network.
This class handles arrivals, baulking, and rejections of individuals.
See hciw.Simulation for the main simulation class.
Initialise the arrival node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
object
|
The simulation to which this arrival node belongs. |
required |
Source code in hciw/arrival_node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
initialise ¶
initialise()
Initialise the event dates dictionary and next event date.
Source code in hciw/arrival_node.py
36 37 38 39 | |
decide_baulk ¶
decide_baulk(next_node, next_individual)
Either make an individual baulk or send them to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being considered. |
required |
Source code in hciw/arrival_node.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
find_next_event_date ¶
find_next_event_date()
Find the time of the next arrival.
Source code in hciw/arrival_node.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
have_event ¶
have_event()
Create and send a batch of arriving individuals.
Finds a batch size, creates that many individuals, sends them to the relevant node, then updates the event dates dictionary.
Source code in hciw/arrival_node.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/arrival_node.py
120 121 122 123 124 125 126 127 128 129 130 | |
initialise_event_dates_dict ¶
initialise_event_dates_dict()
Initialise the event dates dictionary.
Random times are sampled for each node and class.
Source code in hciw/arrival_node.py
132 133 134 135 136 137 138 139 140 141 142 | |
inter_arrival ¶
inter_arrival(nd, clss)
Sample the inter-arrival time for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
|
The sampled inter-arrival time. |
Source code in hciw/arrival_node.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
batch_size ¶
batch_size(nd, clss)
Sample the batch size for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
int
|
The destination node. |
required |
clss
|
str
|
The customer class. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The sampled batch size. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sampled batch size is not a non-negative integer. |
Source code in hciw/arrival_node.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
record_baulk ¶
record_baulk(next_node, individual)
Write a baulking record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual would have joined. |
required |
individual
|
Individual
|
The baulking individual. |
required |
Source code in hciw/arrival_node.py
179 180 181 182 183 184 185 186 | |
record_rejection ¶
record_rejection(next_node, individual)
Write a rejection record for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The node the individual was rejected from. |
required |
individual
|
Individual
|
The rejected individual. |
required |
Source code in hciw/arrival_node.py
188 189 190 191 192 193 194 195 196 197 | |
release_individual ¶
release_individual(next_node, next_individual)
Release an individual to the next node.
Either rejects the individual due to lack of capacity, or sends that individual to baulk or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being released. |
required |
Source code in hciw/arrival_node.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
send_individual ¶
send_individual(next_node, next_individual)
Send the next individual to the next node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_node
|
Node
|
The next node. |
required |
next_individual
|
Individual
|
The individual being sent. |
required |
Source code in hciw/arrival_node.py
217 218 219 220 221 222 223 224 225 226 | |
update_next_event_date ¶
update_next_event_date()
Do nothing, as the next event update happens at the event time.
Source code in hciw/arrival_node.py
228 229 | |
Node ¶
Node(id_, simulation)
Represent a node in the queueing network.
The node holds a queue of individuals and, where applicable, the servers that process them.
Initialise a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
int
|
Identifier for the node. |
required |
simulation
|
object
|
The simulation to which this node belongs. |
required |
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
float
|
The current simulation time. |
all_individuals
property
¶
all_individuals
Get all individuals currently at the node.
Returns:
| Type | Description |
|---|---|
list
|
Every individual at the node, across all priority classes. |
accept ¶
accept(next_individual, completed=False)
Accept a new individual into the queue.
Removes any previous exit date and blockage status, begins service if possible, records arrival information, and updates the state tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to accept. |
required |
completed
|
bool
|
Whether the individual has completed service. |
False
|
Source code in hciw/node.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
add_new_servers ¶
add_new_servers(num_servers)
Add the appropriate number of servers for the given shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_servers
|
int
|
The number of servers to add. |
required |
Source code in hciw/node.py
129 130 131 132 133 134 135 136 137 138 139 | |
attach_server ¶
attach_server(server, individual)
Attach a server to an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to attach. |
required |
individual
|
Individual
|
The individual to attach. |
required |
Source code in hciw/node.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
begin_service_if_possible_accept ¶
begin_service_if_possible_accept(next_individual)
Begin service for an individual at the acceptance point.
Sets the arrival date to the current time, and if a server is free or there are infinitely many servers, attaches the server, gets the service start time, service time and service end time, and updates the server's end date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
begin_interrupted_individuals_service ¶
begin_interrupted_individuals_service(srvr)
Restart an interrupted individual's service.
The individual's service time is resampled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to give to the individual. |
required |
Source code in hciw/node.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
begin_service_if_possible_change_shift ¶
begin_service_if_possible_change_shift()
Begin service for customers after a shift change.
If there are free servers, restarts interrupted customers' services and begins service for any waiting customers by giving a start date and end date and attaching servers to individuals.
Source code in hciw/node.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
begin_service_if_possible_release ¶
begin_service_if_possible_release(
next_individual, newly_free_server
)
Begin service for an individual after a release.
Checks for interrupted individuals left to restart service, then gives an arrival date and service time, gives a start date and end date, and attaches the server to the individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual being released. |
required |
newly_free_server
|
Server
|
The server freed by the release. |
required |
Source code in hciw/node.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
block_individual ¶
block_individual(individual, next_node)
Block an individual from entering the next node.
Changes the blocked status, updates the state tracker, adds information to the next node's blocked queue, and updates the deadlock detector, informing the simulation that there are unchecked blockages for deadlock detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being blocked. |
required |
next_node
|
Node
|
The node the individual is blocked from entering. |
required |
Source code in hciw/node.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
change_customer_class ¶
change_customer_class(individual)
Change an individual's customer class.
The new class is chosen according to a probability distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual whose class changes. |
required |
Source code in hciw/node.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
change_customer_class_while_waiting ¶
change_customer_class_while_waiting()
Change the next queued individual's class while waiting.
The individual is moved between priority queues and preemption is decided if the priority class changes.
Source code in hciw/node.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
change_priority_queue ¶
change_priority_queue(individual)
Move an individual to their new priority queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to move. |
required |
Source code in hciw/node.py
332 333 334 335 336 337 338 339 | |
change_shift ¶
change_shift()
Implement a server shift change.
Adds or deletes servers, or indicates which servers should go off duty, and begins any new services if there are free servers.
Source code in hciw/node.py
341 342 343 344 345 346 347 348 349 350 351 352 353 | |
find_number_of_slotted_services ¶
find_number_of_slotted_services()
Find the number of slotted services to start in this slot.
Returns:
| Type | Description |
|---|---|
int
|
The number of services to start. |
Source code in hciw/node.py
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
interrupt_slotted_services ¶
interrupt_slotted_services()
Interrupt services when there is not enough slot capacity.
Finds the customers whose slotted services need to be interrupted because of insufficient capacity at the current slot, and interrupts their services.
Source code in hciw/node.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
slotted_service ¶
slotted_service()
Serve a set number of customers at the current time.
Only the number of customers allowed by the current slot may have service at the exact time the method is called.
Source code in hciw/node.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
choose_next_customer ¶
choose_next_customer()
Choose which customer will be next to be served.
Returns:
| Type | Description |
|---|---|
Individual
|
The customer chosen by the service discipline, or None if no customer is waiting. |
Source code in hciw/node.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
create_starting_servers ¶
create_starting_servers()
Initialise the servers.
Returns:
| Type | Description |
|---|---|
list
|
The newly created starting servers. |
Source code in hciw/node.py
432 433 434 435 436 437 438 439 440 | |
decide_class_change ¶
decide_class_change(next_individual)
Decide the next class and class change date for an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to update. |
required |
Source code in hciw/node.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
decide_preempt ¶
decide_preempt(individual)
Decide whether priority preemption is needed.
If needed, finds the individual to preempt and preempts them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual seeking service. |
required |
Source code in hciw/node.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
detatch_server ¶
detatch_server(server, individual)
Detach a server from an individual, and vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
Server
|
The server to detach. |
required |
individual
|
Individual
|
The individual to detach. |
required |
Source code in hciw/node.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
find_free_server ¶
find_free_server(ind)
Find a free server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual needing a server. |
required |
Returns:
| Type | Description |
|---|---|
Server
|
A free server, or None if none is available. |
Source code in hciw/node.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
decide_between_simultaneous_individuals ¶
decide_between_simultaneous_individuals()
Find the next individual that should now finish service.
Returns:
| Type | Description |
|---|---|
Individual
|
A randomly chosen individual when several finish at the same time. |
Source code in hciw/node.py
527 528 529 530 531 532 533 534 535 536 537 538 539 | |
find_next_class_change ¶
find_next_class_change()
Update the next class change date and individual.
Source code in hciw/node.py
541 542 543 544 545 546 547 548 | |
find_server_utilisation ¶
find_server_utilisation()
Find the overall server utilisation for the node.
Source code in hciw/node.py
550 551 552 553 554 555 556 557 558 559 560 | |
finish_service ¶
finish_service()
Finish the service of the next individual.
Finds the individual to finish service, checks whether they need to change class, finds their next node, and releases the individual if there is capacity at the destination, otherwise causes blockage.
Source code in hciw/node.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
give_individual_a_service_time ¶
give_individual_a_service_time(individual)
Give a service time to an individual.
Either a new service time, or a service time after pre-emption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
581 582 583 584 585 586 587 588 589 590 591 592 | |
give_service_time_after_preemption ¶
give_service_time_after_preemption(individual)
Give a service time after preemption.
Either resamples, restarts, or resumes service time from where it was left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to serve. |
required |
Source code in hciw/node.py
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
have_event ¶
have_event()
Trigger the node's next event.
Source code in hciw/node.py
610 611 612 613 614 615 616 617 618 619 620 621 | |
increment_time ¶
increment_time(original, increment)
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
|
The incremented time. |
Source code in hciw/node.py
623 624 625 626 627 628 629 630 631 632 633 | |
kill_server ¶
kill_server(srvr)
Kill a server when it goes off duty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srvr
|
Server
|
The server to remove. |
required |
Source code in hciw/node.py
635 636 637 638 639 640 641 642 643 644 645 646 | |
next_node ¶
next_node(ind)
Find the next node according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being routed. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node. |
Source code in hciw/node.py
648 649 650 651 652 653 654 655 656 657 658 659 | |
next_node_for_rerouting ¶
next_node_for_rerouting(ind)
Find the next node for rerouting according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being rerouted. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for rerouting. |
Source code in hciw/node.py
661 662 663 664 665 666 667 668 669 670 671 672 | |
next_node_for_jockeying ¶
next_node_for_jockeying(ind)
Find the next node for jockeying according to the routing method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The jockeying individual. |
required |
Returns:
| Type | Description |
|---|---|
Node
|
The next node for jockeying. |
Source code in hciw/node.py
674 675 676 677 678 679 680 681 682 683 684 685 | |
preempt ¶
preempt(individual_to_preempt, next_individual)
Preempt an individual and replace them in service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual_to_preempt
|
Individual
|
The individual removed from service. |
required |
next_individual
|
Individual
|
The individual taking their place. |
required |
Source code in hciw/node.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
release ¶
release(next_individual, next_node, reroute=False)
Release an individual from the node.
Removes the individual from the queue, records relevant information, detaches the server, updates the state tracker, begins service of any waiting customers, sends the individual to their next destination, and releases any individuals blocked by this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_individual
|
Individual
|
The individual to release. |
required |
next_node
|
Node
|
The node receiving the individual. |
required |
reroute
|
bool
|
Whether the release is due to rerouting. |
False
|
Source code in hciw/node.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
release_blocked_individual ¶
release_blocked_individual()
Release an individual blocked by this node.
Finds the individual who has been blocked the longest, removes them from the blocked queue, restores their service if it was interrupted, and releases them from their node.
Source code in hciw/node.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
reset_class_change ¶
reset_class_change(individual)
Reset an individual's class change date when service begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual beginning service. |
required |
Source code in hciw/node.py
786 787 788 789 790 791 792 793 794 795 | |
renege ¶
renege()
Remove an individual from the queue due to reneging.
Resets the individual's reneging date and sends the individual to their reneging destination.
Source code in hciw/node.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | |
get_reneging_date ¶
get_reneging_date(ind)
Return the reneging date for a given individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The reneging date. |
Source code in hciw/node.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
get_service_time ¶
get_service_time(ind)
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The sampled service time. |
Source code in hciw/node.py
836 837 838 839 840 841 842 843 844 845 846 847 | |
take_servers_off_duty ¶
take_servers_off_duty(preemption: bool | str = False)
Gather the servers that should be deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preemption
|
bool
|
Whether preemption is active for this shift change. |
False
|
Source code in hciw/node.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
interrupt_service ¶
interrupt_service(individual)
Interrupt an individual's service.
Places the individual in the interrupted queue and writes an interruption record for them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being interrupted. |
required |
Source code in hciw/node.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
sort_interrupted_individuals ¶
sort_interrupted_individuals()
Sort interrupted individuals by priority class and arrival date.
Source code in hciw/node.py
899 900 901 902 903 | |
reroute ¶
reroute(individual)
Reroute a preempted individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual being rerouted. |
required |
Source code in hciw/node.py
905 906 907 908 909 910 911 912 913 | |
update_next_end_service_without_server ¶
update_next_end_service_without_server()
Update the next end of a slotted service in possible_next_events.
Source code in hciw/node.py
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
update_next_end_service_with_server ¶
update_next_end_service_with_server()
Update the next end service with a server in possible_next_events.
Source code in hciw/node.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
update_next_renege_time ¶
update_next_renege_time()
Update the next renege time in possible_next_events.
Source code in hciw/node.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 | |
update_next_class_change_while_waiting ¶
update_next_class_change_while_waiting()
Update the next class change while waiting in possible_next_events.
Source code in hciw/node.py
963 964 965 966 967 968 969 | |
update_next_shift_change_or_slot_time ¶
update_next_shift_change_or_slot_time()
Update possible_next_events with the next shift or slot time.
Source code in hciw/node.py
971 972 973 974 975 976 977 978 979 980 981 982 983 | |
update_next_event_date ¶
update_next_event_date()
Find the time of the next event at this node.
With infinite servers this is the time of the next individual to end service, or infinity. Otherwise it is the minimum of the next shift change and the time for the next individual (who is not blocked) to end service, or infinity.
Source code in hciw/node.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
decide_next_event ¶
decide_next_event()
Decide the next event.
Chooses the next service end, renege, shift change, or class change. In the case of a tie, events are prioritised in the following order:
- slotted service
- shift change
- end service
- class change
- renege
Returns:
| Type | Description |
|---|---|
tuple
|
The next event and its event type. |
Source code in hciw/node.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | |
wrap_up_servers ¶
wrap_up_servers(current_time)
Update server total and busy times at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
float
|
The simulation end time. |
required |
Source code in hciw/node.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
write_individual_record ¶
write_individual_record(individual)
Write a data record for an individual leaving a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual leaving the node. |
required |
Source code in hciw/node.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |
write_incomplete_record ¶
write_incomplete_record(individual)
Write an incomplete data record at the end of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual still at the node. |
required |
Returns:
| Type | Description |
|---|---|
DataRecord
|
The incomplete data record. |
Source code in hciw/node.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 | |
write_interruption_record ¶
write_interruption_record(individual, destination=nan)
Write a data record for an individual being interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The interrupted individual. |
required |
destination
|
int
|
The destination node number. |
nan
|
Source code in hciw/node.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
write_reneging_record ¶
write_reneging_record(individual)
Write a data record for an individual when reneging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The reneging individual. |
required |
Source code in hciw/node.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
write_baulking_or_rejection_record ¶
write_baulking_or_rejection_record(individual, record_type)
Write a data record for an individual who baulks or is rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual. |
required |
record_type
|
str
|
The type of record to write. |
required |
Source code in hciw/node.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 | |
reset_individual_attributes ¶
reset_individual_attributes(individual)
Reset the attributes of an individual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
individual
|
Individual
|
The individual to reset. |
required |
Source code in hciw/node.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | |
Server ¶
Server(node, id_number, start_date: float | Decimal = 0.0)
Contain information about a server.
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Node
|
The node the server belongs to. |
required |
id_number
|
int
|
Identifier for the server. |
required |
start_date
|
float | Decimal
|
The time at which the server started, and whose type sets the precision of the server's accumulated times. |
0.0
|
Source code in hciw/server.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
utilisation
property
¶
utilisation
Get the server utilisation.
Returns:
| Type | Description |
|---|---|
float | Decimal
|
The proportion of total time the server was busy. |
ExactNode ¶
ExactNode(id_, simulation)
Bases: Node
Represent a node with exact numerical precision.
This class inherits from Node and implements a more precise version of
addition to fix discrepancies with floating point numbers.
Source code in hciw/node.py
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 70 71 72 73 74 75 76 77 78 | |
now
property
¶
now: Decimal
Get the current simulation time.
Returns:
| Type | Description |
|---|---|
Decimal
|
The current simulation time. |
create_starting_servers ¶
create_starting_servers() -> list[Server]
Initialise the servers at this node.
Returns:
| Type | Description |
|---|---|
List[Server]
|
The newly created starting servers. |
Source code in hciw/exactnode.py
26 27 28 29 30 31 32 | |
increment_time ¶
increment_time(original, increment) -> Decimal
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The incremented time. |
Source code in hciw/exactnode.py
34 35 36 37 38 39 40 41 42 43 44 | |
get_service_time ¶
get_service_time(ind) -> Decimal
Return a service time for the given customer class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind
|
Individual
|
The individual being served. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The sampled service time. |
Source code in hciw/exactnode.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ExactArrivalNode ¶
ExactArrivalNode(simulation)
Bases: ArrivalNode
Represent an arrival node with exact numerical precision.
Inherits from ArrivalNode and implements a more precise version of
addition to fix discrepancies with floating point numbers.
Source code in hciw/arrival_node.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
increment_time ¶
increment_time(original, increment) -> Decimal
Increment the original time by the increment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
float
|
The original time. |
required |
increment
|
float
|
The amount to add. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The incremented time. |
Source code in hciw/exactnode.py
71 72 73 74 75 76 77 78 79 80 81 | |
inter_arrival ¶
inter_arrival(nd, clss) -> Decimal
Sample the inter-arrival time for the next class and node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nd
|
Node
|
The next node. |
required |
clss
|
Individual
|
The individual class to select next. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
The sampled inter-arrival time. |
Source code in hciw/exactnode.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |