SupplyNetPy Components.core Module
The Components.core module provides the foundational building blocks for modeling and simulating supply chain networks in SupplyNetPy. It defines key classes representing entities and their interactions within a supply chain.
SupplyNetPy.Components.core
NodeType
Bases: str, Enum
Canonical node types accepted by Node and create_sc_net.
NodeType is a str subclass, so every existing comparison against a
literal string (node.node_type == "demand", "supplier" in node.node_type,
node.node_type.lower()) continues to work unchanged. Users can pass
either a plain string (case-insensitive, via _missing_) or a
NodeType member:
scm.Supplier(env=env, ID="S1", name="S1", node_type="supplier")
scm.Supplier(env=env, ID="S1", name="S1", node_type=scm.NodeType.SUPPLIER)
Some types are different names for the same kind of node:
"manufacturer" and "factory" both create a manufacturer, and
"warehouse", "distributor", "retailer", "store" and
"shop" all create an InventoryNode. "supplier" creates a
raw-material supplier and "infinite_supplier" an infinite supplier.
create_sc_net looks up which class to create for each type in a
table (_NODE_DISPATCH in utilities.py). To add a new node type,
add it to this enum and add an entry to that table.
NamedEntity
The NamedEntity class provides a standardized way to display names of the objects in the supply chain model.
When printed or displayed, the object will show its name (if defined), otherwise its ID, or the class name
as a fallback. This improves the readability and interpretability of simulation outputs by ensuring objects are
easily identifiable.
Methods:
| Name | Description |
|---|---|
__str__ |
returns the name of the object if available, otherwise returns the class name |
__repr__ |
returns the name of the object if available, otherwise returns the class name |
__str__
__str__() -> str
Returns the name of the object if available, otherwise returns the class name.
Source code in src/SupplyNetPy/Components/core.py
264 265 266 | |
__repr__
__repr__() -> str
Returns the name of the object if available, otherwise returns the class name.
Source code in src/SupplyNetPy/Components/core.py
268 269 270 | |
InfoMixin
The InfoMixin class allows objects to easily provide their key details and statistics as dictionaries.
This helps in quickly summarizing, logging, or analyzing object data in a structured and consistent way
across the simulation.
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
get_info |
returns a dictionary containing details of the object |
get_statistics |
returns a dictionary containing statistics of the object |
get_info
get_info() -> dict
Returns a dictionary containing details of the object.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
get_statistics
get_statistics() -> dict
Returns a dictionary containing statistics of the object.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
Statistics
Statistics(node: object, periodic_update: bool = False, period: float = 1)
Bases: InfoMixin
The Statistics class tracks and summarizes key performance indicators for each node in the supply chain.
It monitors essential metrics such as demand, inventory levels, shortages, backorders, costs, revenue, and profit.
The class supports both automatic periodic updates and manual updates through the update_stats method,
which can be called at any point in the simulation to immediately record changes.
The _info_keys / _stats_keys / _cost_components declarations are
class-level, making the tracked set of KPIs declaratively discoverable in
one place. Statistics.__init__ copies the _stats_keys and
_cost_components lists to the instance before any per-node extension
runs (Supplier.__init__ and Manufacturer.__init__ append their own
subclass-specific KPIs), so those appends never leak into the class-level
list and cross-contaminate other Statistics instances.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
reset |
Starts the running totals again from zero (for example after a warm-up), keeping the values that describe the present. |
update_stats |
Updates statistics based on provided values. |
update_stats_periodically |
Periodically updates statistics during simulation. |
disruption_started, disruption_ended |
Called by the node when a disruption starts and ends. |
Values worked out when read are None when there is nothing to divide by (no time has passed, or no order has been fulfilled yet). The four inventory values are None for an infinite inventory and for a customer demand, which has no inventory.
Initialize the statistics object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
elapsed_time
property
elapsed_time
Time since counting began (start_time): the creation of these statistics, or the last reset.
disrupted_time
property
disrupted_time
Time this node spent disrupted, including a disruption still going on now.
availability
property
availability
Share of time this node was not disrupted: 1 - disrupted_time / elapsed_time. None if no time has passed.
avg_waiting_time
property
avg_waiting_time
Average wait per order fulfilled, orders served at once counting as 0. None before any order is fulfilled.
inventory_level_time
property
inventory_level_time
Running sum of inventory level × time, up to now (see the class docstring). None without a finite inventory.
zero_inventory_time
property
zero_inventory_time
Time the inventory level was 0, up to now. None without a finite inventory.
avg_inventory_level
property
avg_inventory_level
Average inventory level over time: inventory_level_time / elapsed_time. None if it cannot be worked out.
zero_inventory_share
property
zero_inventory_share
Share of time the inventory level was 0: zero_inventory_time / elapsed_time. None if it cannot be worked out.
orders_shortage
property
writable
orders_shortage
Old name kept for compatibility — same as shortage. Returns the same list, so changing it also changes shortage.
reset
reset()
Start the statistics again from zero, for example after a warm-up.
A warm-up is an opening stretch of a run that is left out of the
statistics, because a run starts in an unusual state (nothing in
transit, no orders waiting). Run for the warm-up period, call
reset() on each node, and carry on running. The simulation itself
carries on unchanged; only the counting starts again:
- Running totals (orders, units, costs, shortage, expired units and
so on) are set to zero, including those a
SupplierorManufactureradds. - Values that describe the present (
_live_keys) are kept:backorder, what the node owes right now, andinventory_level, which is read again from the inventory. - The holding cost is brought up to date first, so that after the reset it covers only the time since the reset.
- The once-per-time-unit record of the inventory level
(
inventory.instantaneous_levels) starts again. - The inventory itself (inventory level, units in transit, waiting orders) is not touched.
Each event is counted when it happens. So an order placed before the
reset and received after it counts as received but not as placed, and
units bought before the reset that expire after it count as expired
units after it. A partial delivery to a customer takes 1 off the order
count of demand_fulfilled when it is sent and adds 1 back when it
arrives; if the reset falls in between, that customer order is counted
twice in the order count (the units are counted correctly).
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
disruption_started
disruption_started()
Record that this node's disruption starts now (called by Node.disruption).
Source code in src/SupplyNetPy/Components/core.py
683 684 685 686 | |
disruption_ended
disruption_ended()
Record that this node's disruption ends now (called by Node.disruption).
Source code in src/SupplyNetPy/Components/core.py
688 689 690 691 692 | |
update_stats
update_stats(**kwargs)
Update the statistics with the given keyword arguments.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
703 704 705 706 707 708 709 710 711 712 713 714 715 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 751 | |
update_stats_periodically
update_stats_periodically(period)
Update the statistics periodically.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
LinkStatistics
LinkStatistics(link)
Bases: InfoMixin
The LinkStatistics class records what flows over one link: the replenishment orders its buyer placed
over it, what arrived, how long the orders waited and travelled, what they cost, and the link's own
disruptions. Every link has one, as link.stats, created with the link.
Node statistics say how much a site ordered and received in total, but not from whom. A buyer with two
suppliers has a link to each, and each link counts only the orders sent over it. A site finds the links
it orders over in node.suppliers, and the links its buyers order over in node.buyers. The same
events are counted in the node statistics too, so the totals over a buyer's links add up to the buyer's
own figures. Customers do not order over links, so customer orders are not in any link (each
Demand has its own statistics).
Running totals are kept, not a record of each order. Values worked out when read are properties, and
are None when there is nothing to divide by (a fill rate of 0 would look like a very bad link).
Two spreads of order sizes. Both are sample standard deviations (how far values usually are from
their average, dividing by one less than the number of values), and both are None with fewer than
two values. order_size_std takes one value per order: the size of each order. units_per_time_unit_std
takes one value per time unit: the units ordered in that time unit, with time units in which nothing
was ordered counting as 0. The two can disagree completely. A distributor that orders 60 units at time
3 and 60 units at time 7, and nothing in between, has an order_size_std of 0 (every order is the
same size) but a large units_per_time_unit_std (the orders come in bursts). The bullwhip effect
(orders becoming more uneven as they pass from the customers towards the raw-material suppliers) is
measured per time unit: compare a link's units_per_time_unit_std with the spread of customer
demand per time unit.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
update_stats |
Adds the given amounts to the running totals. |
record_order |
Adds the size of one order placed to the two spreads of order sizes. |
disruption_started, disruption_ended |
Called by the link when a disruption starts and ends. |
reset |
Starts the running totals again from zero (for example after a warm-up), keeping the orders still waiting. |
Initialize the statistics object.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | |
elapsed_time
property
elapsed_time
Time since counting began (start_time): the creation of the link, or the last reset.
disrupted_time
property
disrupted_time
Time the link spent disrupted, including a disruption still going on now.
availability
property
availability
Share of time the link was not disrupted: 1 - disrupted_time / elapsed_time. None if no time has passed.
avg_waiting_time
property
avg_waiting_time
Average wait at the supplier per order received. None before any order arrives.
avg_lead_time
property
avg_lead_time
Average lead time per order received. None before any order arrives.
avg_order_cycle_time
property
avg_order_cycle_time
Average time from placing an order until it arrives: waiting time plus lead time. None before any order arrives.
fill_rate
property
fill_rate
Share of the units ordered that the supplier sent at once, without the order waiting. None before any order.
order_fill_rate
property
order_fill_rate
Share of the orders that the supplier sent at once, without waiting. None before any order.
orders_per_time_unit
property
orders_per_time_unit
Orders placed per time unit. None if no time has passed.
units_per_time_unit
property
units_per_time_unit
Units ordered per time unit. None if no time has passed.
order_size_mean
property
order_size_mean
Average size of the orders placed. None before any order.
order_size_std
property
order_size_std
Standard deviation of the size of the orders placed. None with fewer than two orders.
units_per_time_unit_std
property
units_per_time_unit_std
Standard deviation of the units ordered in each finished time unit. None with fewer than two finished time units.
record_order
record_order(quantity)
Add the size of one order placed over the link to the two spreads of
order sizes (see the class description). Called together with
update_stats(demand_placed=...).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
update_stats
update_stats(**kwargs)
Add the given amounts to the running totals, for example
update_stats(demand_placed=[1, 50], transportation_cost=5).
[number of orders, units] pairs are added pair by pair.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 | |
disruption_started
disruption_started()
Record that the link's disruption starts now (called by Link.disruption).
Source code in src/SupplyNetPy/Components/core.py
1024 1025 1026 1027 | |
disruption_ended
disruption_ended()
Record that the link's disruption ends now (called by Link.disruption).
Source code in src/SupplyNetPy/Components/core.py
1029 1030 1031 1032 1033 | |
reset
reset()
Start the statistics again from zero, for example after a warm-up (see
Statistics.reset). The simulation carries on unchanged; only the
counting starts again:
- Running totals and both spreads of order sizes are set to zero.
backorderis kept: orders waiting at the reset are still waiting after it.start_timebecomes now, so every average and every value per time unit covers only the time since the reset.- A disruption going on now is counted from now on. It does not add to
disruptions, because it started before the reset.
Each event is counted when it happens. So an order placed before the reset and received after it counts as received but not as placed. The averages stay correct, because each one divides by a count recorded at the same moment as its total.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 | |
RawMaterial
RawMaterial(ID: str, name: str, extraction_quantity: float, extraction_time: float, mining_cost: float, cost: float)
Bases: NamedEntity, InfoMixin
The RawMaterial class represents a raw material: what a raw-material supplier mines and a manufacturer
uses up. A raw-material supplier mines extraction_quantity units every extraction_time time units, at
mining_cost per unit, and sells them at cost per unit. (The parameter names say "extraction"; it means
the same as mining.)
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|
Initialize the raw material object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 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 1214 1215 1216 | |
Product
Product(ID: str, name: str, manufacturing_cost: float, manufacturing_time: float, sell_price: float, raw_materials: list, batch_size: int, buy_price: float = 0)
Bases: NamedEntity, InfoMixin
The Product class represents the product that a manufacturer makes and other sites buy and sell. It
defines the manufacturing cost, the manufacturing time, the sell price, and the raw materials needed to
make one unit. A manufacturer makes it in production batches: at most batch_size units at a time, each
production batch taking manufacturing_time.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|
Initialize the product object.
Performs input validation for positive and non-negative values, and ensures raw materials are provided.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 | |
InventoryReplenishment
InventoryReplenishment(env: Environment, node: object, params: dict)
Bases: InfoMixin, NamedEntity
The InventoryReplenishment class is the base for all replenishment policies in SupplyNetPy: the rules a
site follows to decide when to place a replenishment order and how many units to order.
This class is not used directly. Each policy is a subclass, such as the (s, S) policy (SSReplenishment),
the (R, Q) policy (RQReplenishment) and the periodic policy (PeriodicReplenishment).
A subclass overrides the run method with its rule. run runs as a SimPy process for the whole
simulation. A policy usually checks the node's inventory position each time the node's inventory drops
(the inventory_drop event), or at fixed intervals.
How a custom policy should talk to its node. A policy should use these four helper methods instead of reaching into the node's internal attributes:
self.node.position()— the inventory position: inventory level plus units in transit, minus units the node still owes (to other sites and to waiting customers).self.node.place_order(quantity)— picks a supplier using the node's supplier-selection policy and places the replenishment order. This replaces callingselection_policy.select(...)andenv.process(process_order(...))yourself.self.node.wait_for_drop()— used asyield from self.node.wait_for_drop()to wait until the inventory drops; on wake-up it safely replaces theinventory_dropevent with a fresh one.Link.available_quantity()— lets a supplier-selection policy check a supplier's inventory level without readinglink.source.inventory.leveldirectly.
Sticking to these helpers keeps a policy from depending on how a particular node is built, so it works with any
future Node type that offers the same methods.
| Parameters: |
|
|---|
Parameters a policy does not use. Each built-in policy lists the keys it reads from params in
_param_keys. Any other key is ignored by the policy, so a warning names it and asks whether another
policy was meant (for example, 'T' is read only by the periodic policy). A custom policy can set its
own _param_keys to get the same check; if it does not, nothing is checked.
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Placeholder method to be overridden by subclasses. |
Initialize the replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | |
run
run()
The policy's rule. Each subclass overrides this method.
Source code in src/SupplyNetPy/Components/core.py
1425 1426 1427 1428 1429 | |
SSReplenishment
SSReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements the (s, S) replenishment policy, with an optional safety stock.
When the inventory position falls to the reorder point s or below, the node places a replenishment order
big enough to bring its inventory position back up to the order-up-to level S. If a safety stock is
given, it is added to both s and S. The inventory position is checked each time the node's inventory
drops, or every period time units if a period is given, starting after an optional first review delay.
The supplier is chosen by the node's supplier-selection policy.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Checks the inventory position and places replenishment orders by the (s, S) rule. |
Initialize the replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 | |
run
run()
Runs the (s, S) policy for the whole simulation: checks the inventory position and places replenishment orders.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 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 | |
RQReplenishment
RQReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements the (R, Q) replenishment policy.
When the inventory position falls to the reorder point R or below, the node places a replenishment order
of a fixed Q units.
The inventory position is checked each time the node's inventory drops if period is 0 (the default), or
every period time units if a positive period is given. An optional first review delay sets how long to
wait before the first check.
The supplier is chosen by the node's supplier-selection policy. If the supplier cannot fill the order at once, a shortage is recorded at the supplier.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Checks the inventory position and places a replenishment order when it reaches the reorder point. |
Initialize the (R, Q) replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 | |
run
run()
Runs the (R, Q) policy for the whole simulation: places a replenishment order of Q units whenever
the inventory position is at the reorder point R or below.
If a period is given, the inventory position is checked every period time units. Otherwise it is
checked each time the node's inventory drops.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 | |
PeriodicReplenishment
PeriodicReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements the periodic replenishment policy: every T time units, the node places a replenishment order of
Q units, whatever its inventory position. If a safety stock is given and the inventory level is below it,
the order also includes the units needed to bring the inventory level back up to the safety stock. An
optional first review delay sets how long to wait before the first order.
The supplier is chosen by the node's supplier-selection policy. If the supplier cannot fill the order at once, a shortage is recorded at the supplier.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Places a replenishment order of Q units every T time units. |
Initialize the replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 | |
run
run()
Runs the periodic policy for the whole simulation: places a replenishment order every T time units.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 | |
SupplierSelectionPolicy
SupplierSelectionPolicy(node, mode='fixed', params=None)
Bases: InfoMixin, NamedEntity
The base for all supplier-selection policies: the rules a site follows to choose which of its suppliers receives a replenishment order.
A site reaches each of its suppliers over a link, so the policy works with links: the site's suppliers are
the links in node.suppliers, and select returns the link to the chosen supplier (the supplier itself is
link.source).
There are two modes: (1) "dynamic": the supplier is chosen afresh for every replenishment order. (2) "fixed": the first supplier chosen is remembered and used for every later order (another one is used only while the remembered supplier or the link to it is disrupted).
Every policy skips a supplier whose site or link is disrupted (see Link.can_take_order).
Node.place_order calls select only when at least one supplier can take the order.
Each policy is a subclass that overrides the select method with its own rule.
A site gives its policy the mode and the settings (supplier_selection_param) only when the user gives
them, so each policy keeps its own default mode. A policy lists the settings it reads in _param_keys; any
other setting is ignored, so a warning names it.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
The policy's rule for choosing a supplier; each subclass overrides it. |
validate_suppliers |
Checks that the node has at least one supplier. |
check_links |
Checks the policy's settings against the site's links; does nothing here. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 | |
check_links
check_links()
Check the policy's settings against the links to the site's suppliers.
create_sc_net calls it once every link is created. The built in
policies need no such check, so here it does nothing; a policy whose
settings name the suppliers (SelectProbabilistic) overrides it.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 | |
select
select(order_quantity)
The policy's rule for choosing a supplier. Each subclass overrides this method.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 | |
validate_suppliers
validate_suppliers()
Checks that the node has at least one supplier (a link into it).
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 | |
SelectFirst
SelectFirst(node, mode='fixed', params=None)
Bases: SupplierSelectionPolicy
A supplier-selection policy that chooses the first supplier in the node's list of suppliers (the order in which the links were created), skipping suppliers whose site or link is disrupted.
In dynamic mode, the choice is made afresh for each replenishment order. In fixed mode (the default for this policy), the first choice is remembered and used for later orders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Chooses the first supplier that can take the order. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 | |
select
select(order_quantity)
Chooses the first supplier that can take the order right now.
Suppliers whose site or link is disrupted are skipped.
In dynamic mode, the choice is made afresh for each order. In fixed mode, the first choice is remembered and used for later orders; while it or its link is disrupted, the policy uses another supplier, without forgetting the remembered one.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 | |
SelectAvailable
SelectAvailable(node, mode='fixed', params=None)
Bases: SupplierSelectionPolicy
A supplier-selection policy that chooses the first supplier whose inventory level can fill the whole order.
If no supplier can fill the whole order, it chooses the first supplier in the list. Suppliers whose site or link is disrupted are skipped. In dynamic mode the choice is made afresh for each replenishment order; in fixed mode the first choice is remembered and used for later orders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Chooses the first supplier whose inventory level can fill the whole order. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 | |
select
select(order_quantity)
Chooses the first supplier whose inventory level can fill the whole order.
Suppliers whose site or link is disrupted are skipped first. Among
those left, it chooses the first one whose inventory level is at least
order_quantity; if none is, it chooses the first of them (the order
then waits at that supplier until enough units arrive, and the supplier
records a shortage and a backorder).
In fixed mode, the first choice is remembered and used for later orders. While it or its link is disrupted, the policy uses another supplier, without forgetting the remembered one.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 | |
SelectCheapest
SelectCheapest(node, mode='fixed', params=None)
Bases: SupplierSelectionPolicy
A supplier-selection policy that chooses the supplier with the lowest transportation cost (the cost of
the link to it).
Suppliers whose site or link is disrupted are skipped. In dynamic mode the choice is made afresh for each replenishment order; in fixed mode the first choice is remembered and used for later orders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Chooses the supplier with the lowest transportation cost. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 | |
select
select(order_quantity)
Chooses the supplier with the lowest transportation cost.
Suppliers whose site or link is disrupted are skipped first.
In fixed mode, the first choice is remembered and used for later orders. While it or its link is disrupted, the policy uses another supplier, without forgetting the remembered one.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 | |
SelectFastest
SelectFastest(node, mode='fixed', params=None)
Bases: SupplierSelectionPolicy
A supplier-selection policy that chooses the supplier with the shortest lead time.
The lead time of each link is drawn once when the choice is made, so if lead times are random, the choice can differ from one order to the next. Suppliers whose site or link is disrupted are skipped. In dynamic mode the choice is made afresh for each replenishment order; in fixed mode the first choice is remembered and used for later orders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Chooses the supplier with the shortest lead time. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 | |
select
select(order_quantity)
Chooses the supplier with the shortest lead time.
Suppliers whose site or link is disrupted are skipped first.
In fixed mode, the first choice is remembered and used for later orders. While it or its link is disrupted, the policy uses another supplier, without forgetting the remembered one.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 | |
SelectProbabilistic
SelectProbabilistic(node, mode='dynamic', params=None)
Bases: SupplierSelectionPolicy
Chooses the supplier of each replenishment order at random, with a probability for each supplier.
For example, a retailer that sends half of its orders to distributor D1, 30% to D2 and 20% to D3 is given
supplier_selection_param={"probabilities": {"D1": 0.5, "D2": 0.3, "D3": 0.2}}. The probabilities are
keyed by supplier ID (link.source.ID), so they can be given before the links exist, and they must sum
to 1. A supplier with probability 0 is never chosen.
For every order the policy draws exactly one random number u between 0 and 1 and puts the probabilities side by side, in the order the links to the suppliers were created: with 0.5, 0.3 and 0.2, u below 0.5 chooses the first supplier, u from 0.5 to below 0.8 the second, and the rest the third. One number per order means that two runs with the same seed see the same numbers, so changing a probability a little changes only the few orders whose number falls near a boundary.
The probabilities are the shares of the orders while every supplier can take orders. When a supplier or
the link to it is disrupted, on_disruption decides what happens:
"rescale"(the default): the order goes to one of the other suppliers, which keep their ratios. With 0.5, 0.3 and 0.2 and the first supplier disrupted, the other two get 0.6 and 0.4."block": the draw uses the given probabilities as they are. If it chooses a disrupted supplier, the order is not placed and is counted asblocked; the site orders again when a supplier or a link recovers, or when its inventory drops.
So with disruptions, the shares of the orders at the end of a run differ from the probabilities. The link
statistics (link.stats) record the real shares. The stored probabilities never change.
The mode is always "dynamic" (a new choice for every order); "fixed" would keep the first random choice for ever, so it is rejected.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
set_probabilities |
Sets or replaces the probabilities. |
check_links |
Checks the probabilities against the links to the site's suppliers. |
select |
Chooses the supplier of one replenishment order. |
Initialize the policy.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 | |
set_probabilities
set_probabilities(probabilities)
Set or replace the probabilities of the suppliers.
The links are checked against them at the next order (not at once, because more links may still be added).
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 | |
check_links
check_links()
Check the probabilities against the links to the site's suppliers: the probabilities have been given,
every link has a probability, every probability has a link, and no supplier has two links to this site
(its ID would not say which link is meant). A link or ID left over is most likely a typo, so it is an
error, not a probability of 0. create_sc_net calls this once every link is created, and select
calls it before its first choice.
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 | |
select
select(order_quantity)
Chooses the supplier of one replenishment order at random.
With "rescale", the choice is made among the suppliers that can take the order (if none with a
probability above 0 can, the chosen supplier is disrupted and the order is blocked). With "block",
the choice is made among all suppliers with a probability above 0. A disrupted supplier returned here
is blocked by InventoryNode.process_order, which counts the order as blocked.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 | |
Node
Node(env: Environment, ID: str, name: str, node_type: str, failure_p: float = 0.0, node_disrupt_time: Callable = None, node_recovery_time: Callable = lambda: 1, logging: bool = True, rng: Random = None, disruption_impact=None, disruption_loss_fraction=1.0, disposal_cost: float = 0, **kwargs)
Bases: NamedEntity, InfoMixin
Represents a node in the supply chain network: a raw-material supplier, a manufacturer, a warehouse, distributor or retailer, or a customer demand. This is the base class they all share. It handles disruption and recovery, and logging.
A node can be disrupted at random (each time unit, a disruption starts with probability failure_p) or at
the times given by node_disrupt_time. While disrupted, its status is "inactive"; it recovers after
node_recovery_time. The subclasses also keep statistics (stats): orders, shortages, costs, revenue and
profit.
Sites can use the built-in replenishment policies ((s, S), (R, Q) and periodic) or a custom one made by
subclassing InventoryReplenishment, and the built-in supplier-selection policies (SelectFirst,
SelectAvailable, SelectCheapest, SelectFastest) or a custom one made by subclassing
SupplierSelectionPolicy.
For the node types, see NodeType.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
disruption |
Disrupts the node and recovers it, for the whole simulation. |
add_supplier_link |
Registers a link from one of this node's suppliers (called by Link.init). |
position |
The inventory position, used by replenishment policies. |
place_order |
Chooses a supplier with the supplier-selection policy and places a replenishment order. |
wait_for_drop |
Waits until the inventory drops (use with |
Initialize the node object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 | |
disruption
disruption()
Disrupts the node (its status becomes "inactive") and recovers it after the
recovery time, for the whole simulation. Disruptions start either at the
times given by node_disrupt_time, or at random: each time unit, a
disruption starts with probability failure_p.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 | |
add_supplier_link
add_supplier_link(link) -> None
Register a link from one of this node's suppliers (a link whose sink
is this node).
This is the one supported way to attach a Link to a Node.
Supplier-selection policies look through node.suppliers to choose
which supplier receives a replenishment order, so a Link must be
registered here for the node to send orders over it.
Link.__init__ calls this automatically for its sink — users of
the direct-instantiation API do not need to call it themselves.
It is also safe to call explicitly if a Link is constructed separately
from its sink and then attached later.
| Parameters: |
|
|---|
| Raises: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 | |
add_buyer_link
add_buyer_link(link) -> None
Register a link to one of this node's buyers (a link whose source
is this node).
The node uses this list when it recovers from a disruption, to wake
the replenishment policy of each buyer (see wake_replenishment).
Link.__init__ calls this automatically for its source.
| Parameters: |
|
|---|
| Raises: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 | |
wake_replenishment
wake_replenishment() -> None
Make this node's replenishment policy check its inventory position now.
A policy without a review period checks only when it is woken, normally when the node's inventory drops. A supplier or a link that recovers from a disruption calls this on its buyer, because an order the policy tried to place during the disruption was not placed. A node that recovers also calls it on itself, because units destroyed by the disruption did not wake its policy. The policy then checks again and orders if its inventory position is too low. An extra wake-up does no harm: if the position is fine, the policy just waits again. A policy with a review period checks on its own timer and is not affected.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 | |
position
position() -> float
The inventory position, used by replenishment policies.
The inventory position is what the node can count on: its inventory level plus the units in transit to it, minus the units it still owes (to other sites and to waiting customers). Replenishment policies use this one value instead of working it out themselves, so the arithmetic stays in one place.
inventory.on_hand already holds most of it. The node's backorders
hold two kinds of waiting orders, and only one of them is subtracted
here:
- Replenishment orders from other sites. They were taken off
on_handwhen they were placed (those still waiting are in the inventory's line, seeInventory.waiting_site_orders), so subtracting them again would count them twice and make the node order too much. - Customers waiting for units. They were not taken off
on_hand, so they are subtracted here.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 | |
place_order
place_order(quantity) -> None
Choose a supplier with this node's supplier-selection policy and place a replenishment order with it.
First it checks that some supplier can take the order (see
can_place_order). If none can, no order is placed. The replenishment
policy then goes back to waiting, and it is woken when a supplier or a
link recovers (see wake_replenishment), or when units leave the
inventory.
Otherwise it does in one call what a replenishment policy would
otherwise do in two steps: selection_policy.select(...), which
chooses among the suppliers that can take the order, and
env.process(process_order(...)). The order itself is handled by
process_order, which runs as its own SimPy process: it reduces the
order to fit the node's capacity and records the order at the
supplier. This method returns at once.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 | |
can_place_order
can_place_order() -> bool
Whether this node can place a replenishment order right now: at least
one supplier can take it, because neither the supplier's site nor the
link to it is disrupted. place_order checks this first.
Manufacturer replaces it with its own rule.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 | |
has_suppliers
has_suppliers() -> bool
Whether this site has a supplier to order from at all, disrupted or
not. When can_place_order is false, this tells the two cases apart:
every supplier is disrupted (the order is blocked, and the site orders
again after a recovery), or the site has no supplier (a mistake in how
the network is built). Manufacturer replaces it with its own rule.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 | |
wait_for_drop
wait_for_drop()
Wait until the node's inventory drops, then get ready for the next drop.
Replenishment policies use it as yield from node.wait_for_drop().
It waits on the node's inventory_drop event, which fires when the
inventory drops, and also when the node itself, one of its suppliers or
the link to it recovers from a disruption (see wake_replenishment). A SimPy event can fire only once, so after it fires it
is replaced with a fresh one, ready for the next drop. Doing this here
keeps that replacing step in one place.
| Yields: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 | |
Link
Link(env: Environment, ID: str, source: Node, sink: Node, cost: float, lead_time: Callable, link_failure_p: float = 0.0, link_disrupt_time: Callable = None, link_recovery_time: Callable = lambda: 1, rng: Random = None)
Bases: NamedEntity, InfoMixin
Represents a link: the transport connection that carries goods from one site, its source (the supplier), to another, its sink (the buyer).
Each link has a transportation cost (per order) and a lead time. A link can be disrupted at random (each
time unit, a disruption starts with probability link_failure_p) or at the times given by
link_disrupt_time; it recovers after link_recovery_time. While a link is disrupted, no new orders are
sent over it; orders already in transit still arrive.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
disruption |
Disrupts the link and recovers it, for the whole simulation. |
available_quantity |
The supplier's inventory level. |
Initialize the link.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 | |
disruption
disruption()
Disrupts the link (its status becomes "inactive") and recovers it after the recovery time, for the whole
simulation. Disruptions start either at the times given by link_disrupt_time, or at random: each time
unit, a disruption starts with probability link_failure_p.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 | |
available_quantity
available_quantity() -> float
The supplier's inventory level: how many units it has right now.
Supplier-selection policies (such as SelectAvailable) use it to
compare suppliers without reading link.source.inventory.level
directly.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 | |
can_take_order
can_take_order() -> bool
Whether an order can be sent over this link right now: neither the link nor its supplier's site is disrupted.
Node.place_order and the supplier-selection policies use it to skip
suppliers that cannot take an order.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 | |
Inventory
Inventory(env: Environment, capacity: float, initial_level: float, node: Node, replenishment_policy: InventoryReplenishment, holding_cost: float = 0.0, shelf_life: float = 0, inv_type: str = 'non-perishable', record_inv_levels=False)
Bases: NamedEntity, InfoMixin
The Inventory class holds the units at a node and its records about them. It keeps the inventory level
within the capacity, keeps the inventory position (on_hand), and tells the node when its inventory drops,
so that its replenishment policy can check whether to order. For perishable goods it keeps the list of
batches and throws away expired units. It also works out the holding cost, and can record the inventory
level once per time unit.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
waiting_orders |
Units asked for by orders still waiting at this inventory. |
waiting_site_orders |
The same, for replenishment orders from other sites only. |
record_inventory_levels |
Records the inventory level once per time unit. |
put |
Adds units (for perishable goods, as a new batch with its manufacturing date). |
get |
Takes units out for an order (oldest batch first, for perishable goods). |
remove_expired |
Throws away expired units (perishable goods only). |
update_carry_cost |
Adds the holding cost since the last update. |
destroy |
Removes units lost in a disruption. |
Initialize the Inventory object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 | |
level
property
level
Current inventory level, read from the SimPy container that holds the units.
capacity
property
capacity
The largest inventory level the node can hold, read from the SimPy container.
waiting_orders
waiting_orders()
How many units are asked for by orders still waiting at this inventory.
An order the inventory cannot fill right away (for example, a
replenishment order bigger than the inventory level) joins a line and
is served, in turn, when enough units arrive. Orders are served strictly
in the order they arrived, so an order can also wait behind an earlier
one. Besides replenishment orders from other sites, the line can hold
other orders made with get. All of these units have already been
taken off on_hand but have not left the inventory yet. (Expired and
destroyed units never wait in this line: they are removed at once.)
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 | |
waiting_site_orders
waiting_site_orders()
How many units are owed to other sites whose replenishment orders are still waiting at this inventory.
Only the orders made with get(..., site_order=True) count. These
orders are also part of the node's backorders.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 | |
record_inventory_levels
record_inventory_levels()
Record the inventory level once per time unit, in instantaneous_levels.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 | |
put
put(amount: float, manufacturing_date: float = None)
Add units to the inventory. For perishable goods, they are added as a new batch with their manufacturing date.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 | |
get
get(amount: float, site_order: bool = False)
Take units out of the inventory for an order. For perishable goods, the units come from the oldest batch first.
If the inventory level is too low, the order waits until enough units
arrive (see _InventoryContainer). Either way, the units are taken off
the inventory position (on_hand) straight away.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 | |
remove_expired
remove_expired()
Throw away expired units (perishable goods only).
This runs as a SimPy process for the whole simulation. Instead of
checking every time unit, it sleeps exactly until the oldest batch is
due to expire. It wakes up early through the perish_changed event
when put adds a batch that becomes the new oldest one (or arrives
while the list is empty), so a batch that expires sooner is handled
without waiting for the old timer. After each wake-up it creates a fresh perish_changed event so
an already-used one cannot fire again by mistake — the same pattern as
Node.wait_for_drop.
Source code in src/SupplyNetPy/Components/core.py
3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 | |
update_carry_cost
update_carry_cost()
Add the holding cost since the last update: inventory level × time units
since then × holding cost per unit per time unit. It is called before
every change of the inventory level, so each stretch of time is charged
at the level the inventory really had. The same stretch is also added,
without the holding cost, to level_time (inventory level × time) and,
if the level was 0, to zero_level_time.
Source code in src/SupplyNetPy/Components/core.py
3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 | |
destroy
destroy(amount: float = None, reason: str = 'disruption') -> float
Destroy units now, for a physical loss in a disruption (natural disaster, contamination, theft, etc.).
Removes the units right away, even when orders are waiting,
so the caller (usually a Node disruption handler) sees the new
level on the very next line. The method does not fire
inventory_drop for nodes with a replenishment policy. That event
wakes the policy, and a disrupted node can still place replenishment
orders, so the node would order while it is disrupted. Instead the node
wakes its own policy when it recovers (see Node.disruption), and the
policy then orders if its inventory position is too low. It does
wake a raw-material supplier (which then mines to refill its inventory,
as it does whenever its inventory drops) and a manufacturer (which can
make more now that there is free capacity).
For perishable goods the oldest batches are destroyed first, the same as
for orders: destroying part of the oldest batch lowers its quantity but
keeps its manufacturing date. waste (which counts only expired
units) is left unchanged — destroyed units are counted separately, in
Statistics.destroyed_qty / destroyed_value, which the caller
fills in.
For an infinite supplier (level == float('inf')) this does nothing:
it stands for an unlimited supply of raw material, not a real pile that
can be destroyed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 | |
Supplier
Supplier(env: Environment, ID: str, name: str, node_type: str = 'supplier', capacity: float = 0.0, initial_level: float = 0.0, inventory_holding_cost: float = 0.0, raw_material: RawMaterial = None, **kwargs)
Bases: Node
The Supplier class represents a raw-material supplier: a site at the start of the network that mines
one raw material and sells it to manufacturers. It has no supplier of its own. SupplyNetPy does not model
perishable raw materials yet, so its inventory is always non-perishable.
A raw-material supplier with finite inventory (node_type="supplier") mines
RawMaterial.extraction_quantity units every RawMaterial.extraction_time time units, as long as its
inventory is not full. When its inventory is full it stops, and starts mining again as soon as its
inventory drops. An infinite supplier (node_type="infinite_supplier") never runs out, so it does not
mine at all.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
behavior |
Mines raw material whenever the inventory is not full (finite inventory only). |
Initialize the supplier object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 | |
behavior
behavior()
Mine raw material for the whole simulation: extraction_quantity units every extraction_time time
units, as long as the inventory is not full. When it is full, wait until the inventory drops, then mine
again. A raw-material supplier mines a single raw material.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 | |
InventoryNode
InventoryNode(env: Environment, ID: str, name: str, node_type: str, capacity: float, initial_level: float, inventory_holding_cost: float, replenishment_policy: InventoryReplenishment, policy_param: dict, product_sell_price: float, product_buy_price: float, inventory_type: str = 'non-perishable', shelf_life: float = 0.0, manufacture_date: Callable = None, product: Product = None, supplier_selection_policy: SupplierSelectionPolicy = SelectFirst, supplier_selection_mode: str = None, supplier_selection_param: dict = None, **kwargs)
Bases: Node
The InventoryNode class represents a site that buys a product from its suppliers, holds it, and sells it
on: a distributor, warehouse or retailer. It sells to buyers (other sites) and to customers.
It places replenishment orders according to its replenishment policy, and when it has more than one supplier, it chooses one with its supplier-selection policy. Its inventory can be perishable or non-perishable.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
process_order |
Places a replenishment order with one supplier and adds the units when they arrive. |
Initialize the inventory node object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Behavior
The node holds units of the product so that buyers (other sites) and customers can order them. It places replenishment orders with its suppliers according to its replenishment policy, and chooses among its suppliers with its supplier-selection policy. The buy and sell prices are set here; the node is expected to sell at a higher price than it buys, but that is up to the user.
Source code in src/SupplyNetPy/Components/core.py
4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 | |
process_order
process_order(supplier, reorder_quantity)
Place a replenishment order with one supplier, and add the units to the
inventory when they arrive. This runs as a SimPy process (place_order
starts it).
place_order has already checked that some supplier can take the
order. This method checks the chosen supplier again when it starts,
because that is when the order is really placed. If the supplier's
site or the link to it is disrupted by then, the order is not placed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 | |
Manufacturer
Manufacturer(env: Environment, ID: str, name: str, capacity: float, initial_level: float, inventory_holding_cost: float, product_sell_price: float, replenishment_policy: InventoryReplenishment, policy_param: dict, product: Product = None, inventory_type: str = 'non-perishable', shelf_life: float = 0.0, supplier_selection_policy: SupplierSelectionPolicy = SelectFirst, supplier_selection_mode: str = None, supplier_selection_param: dict = None, **kwargs)
Bases: Node
The Manufacturer class represents a manufacturer: a site that turns raw materials into a product and
sells the product to buyers (other sites) and customers. It keeps its raw materials apart from its
inventory of the product. Its replenishment policy watches the product's inventory position and decides
when to plan production; the manufacturer then orders the raw materials needed from its raw-material
suppliers, one for each raw material.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
manufacture_product |
Makes one production batch, using up raw materials and adding the units made to the inventory. |
behavior |
Production loop that keeps making production batches while there are planned units left to make. |
wake_production |
Wakes the production loop if it is waiting. |
process_order |
Plans production and orders the raw materials needed for it. |
process_order_raw |
Places one replenishment order for one raw material with one raw-material supplier. |
Behavior
When the replenishment policy asks for more units, the manufacturer plans that many units and orders the
raw materials needed to make them. It then makes the planned units in production batches: each makes at
most product.batch_size units and takes product.manufacturing_time. Production batches follow one
another until every planned unit is made. If one cannot start (no raw material yet, or no free
capacity), the manufacturer waits until raw material arrives, a new plan comes in, or units leave its
inventory, and then carries on.
Assumptions
The manufacturer makes a single product. Raw materials are kept apart from the inventory of the product. Only the product's inventory position is watched by the replenishment policy. Raw materials are ordered when production is planned, for exactly the planned units. The manufacturer starts with no raw materials.
Initialize the manufacturer object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 | |
manufacture_product
manufacture_product()
Make one production batch.
A production batch makes at most product.batch_size units and takes product.manufacturing_time. It
can be smaller when there is only raw material, free capacity, or planned units left for fewer units. The
raw materials are used up when the production batch starts, and the units made are added to the
inventory when it ends.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 | |
wake_production
wake_production()
Wake the production loop if it is waiting because it could not make anything. Called when raw material arrives, when a new production plan comes in, and when units leave the inventory (which frees capacity). Calling it while the loop is busy does no harm: the loop just checks once more when it next stops.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 | |
behavior
behavior()
The production loop, for the whole simulation: make one production batch after another while there are
planned units left to make; when nothing can be made, wait until something may change that (see
wake_production). It first checks the manufacturer's suppliers: each must be a raw-material supplier
with a raw material, and there should be at least one for each raw material of the product.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 | |
process_order_raw
process_order_raw(raw_mat_id, supplier, reorder_quantity)
Place a replenishment order for one raw material with one raw-material supplier, and add the units to
the manufacturer's raw materials when they arrive. This runs as a SimPy process (process_order
starts it).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 | |
can_place_order
can_place_order() -> bool
Whether this manufacturer can plan production right now: every raw
material of the product has a raw-material supplier that can take an
order. If even one raw material cannot be ordered, the units could
never be made, so nothing is planned (see process_order).
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 | |
has_suppliers
has_suppliers() -> bool
Whether every raw material of the product has at least one
raw-material supplier connected to this manufacturer, disrupted or not
(see Node.has_suppliers).
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 | |
process_order
process_order(supplier, reorder_quantity)
Plan the production of more product units and order the raw materials needed to make them.
Each raw material is ordered from the first raw-material supplier of that raw material whose link and
site are both not disrupted. place_order starts this as a SimPy process only when every raw material
has such a supplier (see can_place_order).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 | |
Demand
Demand(env: Environment, ID: str, name: str, order_arrival_model: Callable, order_quantity_model: Callable, demand_node: Node, tolerance: float = 0.0, order_min_split_ratio: float = 1.0, delivery_cost: Callable = lambda: 0, lead_time: Callable = lambda: 0, consume_available: bool = False, **kwargs)
Bases: Node
The Demand class represents a customer demand: a stream of customer orders arriving at one site (the
demand_node). The time between orders and the units in each order are given by functions, so they
can be random. When a site cannot fill an order at once, the customer either leaves without the units or,
if a tolerance is set, waits for them.
It supports:
-
a lead time and a delivery cost for each customer order,
-
partial deliveries for customers who wait (
order_min_split_ratio), -
backorders at the site for customers who wait.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
_process_delivery |
Delivers one customer order: records the delivery cost and waits for the lead time. |
wait_for_order |
Lets a customer wait for units, up to their tolerance, when the order cannot be filled at once. |
customer |
Handles one customer order. |
behavior |
Creates customer orders for the whole simulation. |
Behavior
Customer orders arrive at the site with the times and sizes given by order_arrival_model and
order_quantity_model. If the site's inventory can fill an order, it is delivered at once. If not,
a shortage is recorded at the site, and
-
with no tolerance (the default), the customer leaves without the units;
-
with
consume_available, the customer takes the units that are there and leaves; -
with a tolerance, the customer waits for the units, up to the tolerance, and the order counts as a backorder at the site while they wait. They may accept partial deliveries, if
order_min_split_ratiois below 1. If the tolerance runs out, they leave without the rest.
Assumptions
- The time between customer orders follows
order_arrival_model; the first order arrives at time 0. - The units in each order follow
order_quantity_model. - The delivery cost and lead time are drawn afresh for each customer order.
- The site (
demand_node) cannot be a raw-material supplier; it is usually a retailer or a distributor.
Initialize the customer demand object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 | |
wait_for_order
wait_for_order(customer_id, order_quantity)
Let a customer wait for the units of their order, up to their tolerance. While waiting, the customer's order is counted as a backorder at the site. The customer checks again each time units are added to the site's inventory. If the tolerance is infinite, the customer waits until the order is filled. Otherwise, the customer leaves as soon as their tolerance runs out, even if no new units have arrived, and whatever they were still owed is taken off the site's backorders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 | |
customer
customer(customer_id, order_quantity)
Handle one customer order, by passing it to the helper for its case:
- the site is disrupted: the order is not placed. A disrupted site takes no new orders, so this is a
sale it loses because of the disruption, recorded in its
disruption_lost_sales(not as demand received, shortage or backorder). Customers who were already waiting when the disruption started keep waiting, and deliveries already on their way still arrive; - the site can fill the whole order:
_serve_in_full; - otherwise, with
consume_availableand some units there:_serve_partial_consume; - otherwise, for a customer with a tolerance:
_enqueue_for_tolerance(or_discard_unservableif the order is too big for the site ever to hold); - otherwise:
_serve_no_tolerance.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 | |
behavior
behavior()
Create customer orders for the whole simulation: start a customer with an order of
order_quantity_model() units, wait order_arrival_model() time units, and repeat. So the first
customer order arrives at time 0.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 | |
set_seed
set_seed(seed)
Seed the library-wide default RNG used for probabilistic node/link disruption.
Components built without an explicit rng argument draw from this RNG, so
seeding it once before constructing the network is enough to make a run
reproducible. Components that were passed an explicit rng are unaffected.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
validate_positive
validate_positive(name: str, value)
Check if the value is positive and raise ValueError if not.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
validate_non_negative
validate_non_negative(name: str, value)
Check if the value is non-negative and raise ValueError if not.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
validate_number
validate_number(name: str, value) -> None
Check if the value is a number and raise ValueError if not.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
ensure_numeric_callable
ensure_numeric_callable(name: str, value)
Turn a value that is "a number, or a zero-arg function returning a number" into a zero-arg function.
Many constructors accept either a plain number or a zero-arg function (lead times, arrival intervals, recovery times). The earlier version simply did
if not callable(value):
value = lambda val=value: val
which accepted any function at all — even a class like int or a
generator function — so the later value() call could fail deep inside a
running simulation, far from where the mistake was made. This helper avoids
that by calling the function once when it is set up and checking the result
is a real number, so a bad value is reported right away, at construction,
with a clear message naming the parameter at fault.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Note
The validation invocation samples the callable once at construction time. For stateful generators or iterators (rather than pure functions) this advances state before the simulation starts; if that matters, wrap the iterator in a closure that materialises the first sample lazily, or pass a numeric scalar instead.
Source code in src/SupplyNetPy/Components/core.py
185 186 187 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 | |