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 :class:Node and :func: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 :meth:_missing_) or a
:class:NodeType member:
.. code-block:: python
scm.Supplier(env=env, ID="S1", name="S1", node_type="supplier")
scm.Supplier(env=env, ID="S1", name="S1", node_type=scm.NodeType.SUPPLIER)
:func:create_sc_net dispatches via a :class:NodeType-keyed table
(_NODE_DISPATCH in utilities.py), replacing the duplicated
hard-coded node["node_type"].lower() in [...] ladders. Adding a new
node type is a single-site change on this enum plus an entry in the
dispatch table — no more editing two hard-coded string lists.
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
251 252 253 | |
__repr__
__repr__() -> str
Returns the name of the object if available, otherwise returns the class name.
Source code in src/SupplyNetPy/Components/core.py
255 256 257 | |
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
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
get_statistics
get_statistics() -> dict
Returns a dictionary containing statistics of the object.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
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 |
Resets all statistics to initial values. |
update_stats |
Updates statistics based on provided values. |
update_stats_periodically |
Periodically updates statistics during simulation. |
Initialize the statistics object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
383 384 385 386 387 388 389 390 391 392 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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
orders_shortage
property
writable
orders_shortage
Back-compat alias for :attr:shortage. Returns the same list (mutating it mutates shortage).
reset
reset()
Reset the statistics to their initial values.
Drives the reset off _stats_keys so any KPI registered on a
Statistics instance (including subclass-specific ones added by
Supplier / Manufacturer) is zeroed without the caller having
to remember to extend reset. The legacy vars(self) scan is
kept as a fallback for instance attributes that aren't in
_stats_keys (e.g. user-injected scratch fields).
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 | |
update_stats
update_stats(**kwargs)
Update the statistics with the given keyword arguments.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
update_stats_periodically
update_stats_periodically(period)
Update the statistics periodically.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
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 in a supply chain. It defines key properties of a raw material,
including extraction rate, extraction time, mining cost, and selling price. This class helps model the extraction
processes at a raw material supplier node in the network.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|
Initialize the raw material object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
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 models a finished good in the supply chain. It defines essential properties such
as manufacturing cost, manufacturing time, selling price, and the raw materials required to produce it.
The class supports both buying and manufacturing workflows, allowing nodes to either purchase the product
directly or produce it using defined raw material combinations. Products are typically manufactured in
batches, with each batch size and cycle time configurable, making it easy to model real-world production processes.
| 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
673 674 675 676 677 678 679 680 681 682 683 684 685 686 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 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
InventoryReplenishment
InventoryReplenishment(env: Environment, node: object, params: dict)
Bases: InfoMixin, NamedEntity
The InventoryReplenishment class defines the abstract structure for inventory replenishment policies within
SupplyNetPy. It provides a common interface for managing how nodes place replenishment orders during the simulation.
This class is not intended for direct use. It must be subclassed to implement specific replenishment strategies, such as min-max (s, S), reorder point, quantity (RQ), or periodic review (TQ) policies.
The run method should be overridden to define the replenishment logic for the policy. The class integrates with
the SimPy environment to support time-driven inventory management. The inventory_drop event is used to signal stock
depletion, enabling the replenishment process to respond to changes in inventory levels in real time.
Node contract for custom subclasses. A policy should speak to its owning node through four helpers rather than reaching into node internals:
self.node.position()— backorder-aware inventory position (on_hand - stats.backorder[1]).self.node.place_order(quantity)— selects a supplier via the node's selection policy and spawns the dispatch process. Replaces theselection_policy.select(...)+env.process(process_order(...))pair.self.node.wait_for_drop()— generator used asyield from self.node.wait_for_drop()to block until the inventory drops; rotates theinventory_dropevent atomically on wake-up.Link.available_quantity()— for any supplier-selection policy, compares upstream stock without readinglink.source.inventory.leveldirectly.
Staying inside this contract keeps a policy subclass independent of the concrete node layout and makes it
compatible with any future Node subclass that provides the same methods.
| Parameters: |
|
|---|
| 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
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
run
run()
This method should be overridden by subclasses to implement the specific replenishment policy logic.
Source code in src/SupplyNetPy/Components/core.py
809 810 811 812 813 | |
SSReplenishment
SSReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements the (s, S) or min-max inventory replenishment policy with optional safety stock support.
When the inventory level falls to or below the reorder point (s), an order is placed to replenish stock up to the order-up-to level (S). If safety stock is provided, both the reorder point and the order-up-to level are adjusted accordingly. The policy supports both event-driven and periodic inventory checks, with an optional initial review delay. Supplier selection is automatically managed using the node’s supplier selection policy.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Monitors inventory and places orders based on the (s, S) policy. |
Initialize the replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
run
run()
Replenishes the inventory based on the sS policy.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | |
RQReplenishment
RQReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements a Reorder Quantity (RQ) Inventory Replenishment Policy with optional safety stock support.
This policy continuously monitors inventory levels and places a replenishment order when the inventory falls to or below the reorder point (R). The replenishment quantity is fixed at Q units per order.
The inventory can be checked continuously (event-based) if 'period' is set to 0 (default) and periodically if a positive 'period' is provided. An optional first review delay can be configured to introduce a delay before the first inventory check begins.
Supplier selection is managed automatically using the node's supplier selection policy. If the selected supplier does not have sufficient inventory, the shortage is recorded.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Continuously monitors inventory and places replenishment orders when the reorder point is reached. |
Initialize the RQ replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 | |
run
run()
Continuously monitors the inventory and places replenishment orders when the inventory level falls to or below the reorder point (R).
If a periodic review interval is provided, inventory is checked at that interval. Otherwise, the system waits for inventory drop events to trigger the next check.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
PeriodicReplenishment
PeriodicReplenishment(env, node, params)
Bases: InventoryReplenishment
Implements a time-based inventory replenishment policy where a fixed quantity Q is ordered at regular intervals
T with optional safety stock support.
This policy ensures consistent inventory reviews and replenishment, independent of the current stock level. Supports an optional initial review delay before starting periodic checks.
Supplier selection is automatically managed using the node’s defined supplier selection policy. Shortages are recorded if the supplier does not have enough stock.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
run |
Continuously manages periodic replenishment by placing orders of size Q every T time units. |
Initialize the replenishment policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 | |
run
run()
Replenishes the inventory based on the periodic policy.
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | |
SupplierSelectionPolicy
SupplierSelectionPolicy(node, mode='dynamic')
Bases: InfoMixin, NamedEntity
Defines the framework for supplier selection strategies in the supply chain.
Supports two modes: (1) "dynamic": Supplier selection is flexible and can change based on real-time conditions. (2) "fixed": Always selects a pre-assigned supplier.
The policy is applied at the node level, and this class serves as a base for implementing custom supplier selection policies. The 'select' method must be overridden in subclasses to define specific supplier selection logic.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Supplier selection logic to be implemented by subclasses. |
validate_suppliers |
Validates that the node has at least one connected supplier. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
select
select(order_quantity)
Supplier selection logic to be implemented by subclasses.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | |
validate_suppliers
validate_suppliers()
Validates that the node has at least one connected supplier.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
SelectFirst
SelectFirst(node, mode='fixed')
Bases: SupplierSelectionPolicy
Implements a supplier selection policy that always selects the first supplier in the supplier list.
In dynamic mode, the first supplier is selected at each order event. In fixed mode, the first selected supplier is locked for all subsequent orders.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Selects the first supplier, either dynamically or as a fixed supplier. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 | |
select
select(order_quantity)
Selects the first supplier whose transport link is currently active.
Disrupted links are filtered out; if every link is inactive, the policy
falls back to the first supplier in the list (the dispatch gate in
process_order then blocks it and the policy retries on the next
replenishment trigger).
In dynamic mode, the selection is evaluated for each order. In fixed mode, the first active supplier is locked for all subsequent selections. If the locked link later goes inactive, the policy temporarily routes around it without changing the lock.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 | |
SelectAvailable
SelectAvailable(node, mode='dynamic')
Bases: SupplierSelectionPolicy
Selects the first supplier that has sufficient available inventory to fulfill the requested order quantity.
If no supplier can fully meet the order, it defaults to the first supplier in the list. Supports both dynamic selection (evaluated at each order event) and fixed selection (locks the first selected supplier).
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Selects the first available supplier with sufficient inventory. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 | |
select
select(order_quantity)
Selects the first active supplier with sufficient available inventory.
Disrupted links are filtered out first. Among the active candidates the
first one whose upstream inventory can cover order_quantity is
chosen; if none can, the policy falls back to the first active
candidate (inventory shortage is then recorded by process_order as
a supplier backorder). If every link is inactive, falls back to the
first supplier in the list — the dispatch gate will block it.
In fixed mode, the first selection is locked for all subsequent orders. If the locked link later goes inactive, the policy temporarily routes around it without changing the lock.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 | |
SelectCheapest
SelectCheapest(node, mode='dynamic')
Bases: SupplierSelectionPolicy
Selects the supplier offering the lowest transportation cost for the order.
The supplier is chosen based on the minimum transportation cost among all connected suppliers. Supports both dynamic selection (evaluated at each order event) and fixed selection (locks the first selected supplier).
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Selects the supplier with the lowest transportation cost. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 | |
select
select(order_quantity)
Selects the active supplier with the lowest transportation cost.
Disrupted links are filtered out first; if every link is inactive,
the policy falls back to the cheapest among all suppliers (the dispatch
gate in process_order will block it and the policy retries on the
next trigger).
In fixed mode, the first selection is locked for all subsequent orders. If the locked link later goes inactive, the policy temporarily routes around it without changing the lock.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 | |
SelectFastest
SelectFastest(node, mode='dynamic')
Bases: SupplierSelectionPolicy
Selects the supplier with the shortest lead time to deliver the product.
The selection is based on minimizing lead time among all connected suppliers. Supports both dynamic selection (evaluated at each order event) and fixed selection (locks the first selected supplier for all subsequent orders).
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
select |
Selects the supplier with the shortest lead time based on the configured mode. |
Initialize the supplier selection policy object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 | |
select
select(order_quantity)
Selects the active supplier with the shortest lead time.
Disrupted links are filtered out first; if every link is inactive,
the policy falls back to the fastest among all suppliers (the dispatch
gate in process_order will block it and the policy retries on the
next trigger).
In fixed mode, the first selection is locked for all subsequent orders. If the locked link later goes inactive, the policy temporarily routes around it without changing the lock.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 | |
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, **kwargs)
Bases: NamedEntity, InfoMixin
Represents a node in the supply network, such as a supplier, manufacturer, warehouse, distributor, retailer, or demand point. Supports automatic disruption and recovery, dynamic logging, and performance tracking.
Each node can experience disruptions either probabilistically or based on custom-defined disruption and recovery times. During disruptions, the node becomes inactive and resumes operations after the specified recovery period. Tracks key performance metrics like transportation costs, node-specific costs, profit and net profit, products sold, demand placed, and shortages.
Supports integration with inbuilt replenishment policies: SS, RQ, Periodic and any custom policy created by extending
the ReplenishmentPolicy class.
Supplier selection policies: Available, Cheapest, Fastest and any custom policy created by extending the
SupplierSelectionPolicy class.
Supported node types: "infinite_supplier", "supplier", "manufacturer", "factory", "warehouse", "distributor", "retailer", "store", "demand"
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
disruption |
Simulates node disruption and automatic recovery over time. |
add_supplier_link |
Register an inbound Link with this node (called by Link.init). |
position |
Backorder-aware inventory position used by replenishment policies. |
place_order |
Pick a supplier via the selection policy and spawn the dispatch process. |
wait_for_drop |
Generator; block on |
Initialize the node object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 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 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 | |
disruption
disruption()
This method disrupts the node by changing the node status to "inactive" and recovers it after the specified recovery time.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 | |
add_supplier_link
add_supplier_link(link) -> None
Register an inbound transport link whose sink is this node.
This is the one supported entry point for attaching a Link to a Node.
Supplier-selection policies iterate over node.suppliers to choose
where to dispatch a replenishment order, so a Link must be registered
here for the node to route 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
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 | |
position
position() -> float
Backorder-aware inventory position used by replenishment policies.
Returns inventory.on_hand - stats.backorder[1] — i.e. the current
physical plus in-transit stock, minus units already committed to
customer backorders. Replenishment policies use this single value in
place of reaching into node.inventory.on_hand and
node.stats.backorder[1] independently, so the arithmetic stays in
one place.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 | |
place_order
place_order(quantity) -> None
Pick a supplier via this node's selection policy and spawn process_order.
Wraps the "choose supplier, then env.process(process_order(...))"
idiom so replenishment policies can express a dispatch as a single
call instead of reaching into selection_policy.select and
process_order independently. The spawned SimPy process handles
the capacity clamp, link-disruption gate, and supplier-side
bookkeeping; this method does not yield.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 | |
wait_for_drop
wait_for_drop()
Generator: block until the inventory-drop event fires, then rotate it.
Replenishment policies use yield from node.wait_for_drop() in
place of manually yielding on self.node.inventory_drop and
reassigning a fresh event afterwards. Rotating the event inside this
helper keeps the "yield then reset" pattern in exactly one place.
| Yields: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 | |
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 transportation connection between two nodes in the supply network.
Each link carries a transportation cost and lead time. Links can experience disruptions based on a failure probability or a disruption time distribution and will automatically recover after a specified recovery time.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
disruption |
Simulates link disruption and automatic recovery. |
Initialize the Link object representing a transportation connection between two nodes.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2018 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 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 | |
disruption
disruption()
This method disrupts the link by changing the link status to "inactive" and recovers it after the specified recovery time.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 | |
available_quantity
available_quantity() -> float
Amount of the upstream source's inventory currently available over this link.
Exposed so supplier-selection policies (e.g. SelectAvailable) can
compare candidate links without reaching into link.source.inventory.level.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 | |
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 models stock management within a node in the supply network. It supports both perishable and non-perishable items, enforces capacity limits, tracks on-hand levels, and notifies replenishment policy whenever inventory levels drops. For perishable inventories, it manages product shelf life and automatically removes expired items. The class also records inventory levels and calculates carrying costs over time.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
record_inventory_levels |
Records inventory levels at regular time intervals. |
put |
Adds items to the inventory, handling perishable item tracking. |
get |
Removes items from inventory, using FIFO for perishables. |
remove_expired |
Automatically removes expired items from perishable inventory. |
update_carry_cost |
Updates carrying cost based on inventory level and holding time. |
Initialize the Inventory object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 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 2301 2302 | |
level
property
level
Current inventory level, delegating to the underlying SimPy container.
capacity
property
capacity
Inventory capacity, delegating to the underlying SimPy container.
record_inventory_levels
record_inventory_levels()
Record inventory levels at regular intervals.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 | |
put
put(amount: float, manufacturing_date: float = None)
Add items to inventory. For perishable items, tracks manufacturing date.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2331 2332 2333 2334 2335 2336 2337 2338 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 2371 2372 2373 2374 | |
get
get(amount: float)
Remove items from inventory. For perishable items, oldest products are removed first.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 2406 2407 2408 2409 2410 2411 2412 | |
remove_expired
remove_expired()
Remove expired items from perishable inventory.
Event-driven: sleeps until the head batch's expiry rather than polling
every simulation tick. Wakes early via perish_changed when put
inserts a batch that displaces the heap head (or arrives into an empty
queue), so a fresher head with an earlier expiry is honoured without
waiting for the previous timer to elapse. The rotation-event idiom
(self.perish_changed = self.env.event() after each wake) mirrors
Node.wait_for_drop and avoids re-firing on a stale event.
Source code in src/SupplyNetPy/Components/core.py
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 | |
update_carry_cost
update_carry_cost()
Update the carrying cost of the inventory based on the current level and holding cost.
Source code in src/SupplyNetPy/Components/core.py
2468 2469 2470 2471 2472 2473 2474 | |
destroy
destroy(amount: float = None, reason: str = 'disruption') -> float
Wipe inventory at the current sim time, modeling physical loss from a disruption event (natural disaster, contamination, theft, etc.).
Synchronous: drains the underlying simpy.Container immediately so the
caller (typically a Node disruption hook) can observe the new
level on the next line. The method does not signal
inventory_drop — that event is the trigger for replenishment
policies, and the dispatch gate already blocks new orders while the
node is "inactive". Re-introducing the signal here would queue
replenishment orders that fire as soon as the node recovers (a wake
storm) and is the kind of coupling §4.3 removed.
For perishable inventories the oldest batches in perish_queue are
consumed first (FIFO), mirroring get: a partial destruction at the
head shortens the head batch's quantity rather than dropping its
mfg_date. waste (which tracks shelf-life expiry only) is left
untouched — destruction is a separate KPI exposed via
Statistics.destroyed_qty / destroyed_value, populated by the
caller.
Infinite inventories (level == float('inf')) are a no-op: an
infinite_supplier represents a logical, unbounded stream of raw
material rather than a physical pile that can be destroyed.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 | |
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 supplier in the supply network that continuously
extracts raw materials whenever the inventory is not full. Each supplier is associated
with a specific raw material and can have either finite or infinite inventory capacity.
For finite suppliers, raw materials are extracted in batches based on the extraction
quantity and extraction time specified by the instance of RawMaterial class. For infinite suppliers,
inventory is considered unlimited.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
behavior |
Simulates the continuous raw material extraction process. |
Initialize the supplier object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 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 | |
behavior
behavior()
Supplier behavior: The supplier keeps extracting raw material whenever the inventory is not full. Assume that a supplier can extract a single type of raw material.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 | |
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 = 'fixed', **kwargs)
Bases: Node
The InventoryNode class represents an inventory management node in the supply network,
such as a retailer, a store, a warehouse, or distributor. It manages inventory levels, replenishment policies,
supplier selection, and order processing dynamically.
The node can handle both perishable and non-perishable inventories and supports automatic replenishment using various replenishment policies. The node can also interact with multiple supplier links and selects suppliers based on the configured selection policy.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
process_order |
Places an order with the selected supplier and updates inventory upon delivery. |
Initialize the inventory node object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Behavior
The inventory node stocks the product in inventory to make it available to the consumer node or demand node (end customer). It orders product from its supplier node to maintain the right inventory levels according to the replenishment policy. The inventory node can have multiple suppliers. It chooses a supplier based on the specified supplier selection policy. The product buy and sell prices are set during initialization. The inventory node is expected to sell the product at a higher price than the buy price, but this is user-configured.
Source code in src/SupplyNetPy/Components/core.py
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 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 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 | |
process_order
process_order(supplier, reorder_quantity)
Place an order for the product from the suppliers.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 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 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 | |
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 = 'fixed', **kwargs)
Bases: Node
The Manufacturer class models a production unit in the supply network that consumes raw materials to manufacture finished products. It maintains separate inventories for raw materials and finished goods, applies replenishment policies to the product inventory, and places orders to suppliers dynamically.
The manufacturer can be connected to multiple suppliers and automatically produces products based on raw material availability. It continuously updates real-time statistics such as production volume, manufacturing cost, and revenue.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
manufacture_product |
Manufactures the product by consuming raw materials and updating product inventory. |
behavior |
Main behavior loop that checks inventory and triggers production if raw materials are available. |
process_order |
Places an order for raw materials based on the quantity of products to be manufactured. |
process_order_raw |
Places an individual order for a specific raw material from a supplier. |
Behavior
The manufacturer continuously monitors raw material inventory levels and initiates production when raw materials are available. Finished products are added to the inventory upon completion of a manufacturing cycle. If raw materials are insufficient, the manufacturer places replenishment orders with connected suppliers.
Assumptions
The manufacturer produces only a single type of product. Separate inventories are maintained for raw materials and finished products. Only the finished product inventory is actively monitored by the replenishment policy. Raw material inventories are replenished based on product inventory requirements. The raw material inventory is initially empty.
Initialize the manufacturer object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 | |
manufacture_product
manufacture_product()
Manufacture the product. This method handles the production of the product, consuming raw materials and adding the manufactured product to the inventory.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3103 3104 3105 3106 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 | |
behavior
behavior()
The manufacturer consumes raw materials and produces the product if raw materials are available. It maintains inventory levels for both raw materials and the product. Depending on the replenishment policy for product inventory, manufacturer decides when to replenish the raw material inventory. The manufacturer can be connected to multiple suppliers.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 | |
process_order_raw
process_order_raw(raw_mat_id, supplier, reorder_quantity)
Place an order for given raw material from the given supplier for replenishment.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 | |
process_order
process_order(supplier, reorder_quantity)
Place an order for raw materials and replenish raw materials inventory.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
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 | |
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 demand node that generates product orders within the supply network.
It models dynamic demand patterns using user-defined functions for order arrival times and order quantities, and manages
customer tolerance for waiting in case of product unavailability.
The demand node automatically places customer orders at configurable intervals and can handle situations where the requested
quantity is not immediately available. Customers can either wait (if tolerance is set) or leave the system unfulfilled.
The class supports:
-
Customizable lead time and delivery cost per order,
-
Dynamic order splitting based on the minimum split ratio,
-
Backorder management and real-time inventory check.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Methods:
| Name | Description |
|---|---|
_process_delivery |
Handles the delivery process, including lead time and delivery cost updates. |
wait_for_order |
Waits for required units based on customer tolerance when immediate fulfillment is not possible. |
customer |
Simulates customer order placement and fulfillment behavior. |
behavior |
Generates continuous customer demand based on the arrival and quantity models. |
Behavior
The demand node generates customer orders at random intervals and quantities using the specified arrival and quantity models. If the upstream inventory can satisfy the order, delivery is processed immediately. If not,
-
the customer may leave immediately (if tolerance is zero)
-
else, the customer waits for the order to be fulfilled within their tolerance time, possibly accepting partial deliveries if a split ratio is allowed. If the tolerance is exceeded, the unmet demand is recorded as a shortage.
Assumptions
- Customer orders arrive following the provided stochastic arrival model.
- Order quantities follow the specified stochastic quantity model.
- Customers may wait for the fulfillment of their orders up to the defined tolerance time.
- Customers can accept split deliveries based on the minimum split ratio.
- If customer tolerance is zero, customer returns without waiting for fulfillment.
- Delivery cost and lead time are sampled dynamically for each order (if specified).
- The connected upstream node must not be a supplier; it should typically be a retailer or distributor node.
Initialize the demand node object.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 | |
wait_for_order
wait_for_order(customer_id, order_quantity)
Wait for the required number of units based on customer tolerance. If the customer tolerance is infinite, the method waits until the order is fulfilled. Otherwise, it waits for the specified tolerance time and updates the unsatisfied demand if the order is not fulfilled.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 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 | |
customer
customer(customer_id, order_quantity)
Dispatcher: route a single customer order to the right fulfilment helper.
Four cases drive the dispatch — exactly the same set the original
inline branch handled — but the branches now delegate to named
helpers (see _serve_in_full / _serve_partial_consume /
_enqueue_for_tolerance / _serve_no_tolerance) so each path's
intent is named in one place and the dispatcher reads as a single
rule table.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 | |
behavior
behavior()
Generate demand by calling the order arrival and order quantity models. This method simulates the demand generation process, including order placement and handling shortages or unsatisfied demand.
| Returns: |
|
|---|
Source code in src/SupplyNetPy/Components/core.py
3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 | |
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
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
157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
ensure_numeric_callable
ensure_numeric_callable(name: str, value)
Normalise a scalar-or-callable parameter to a zero-arg numeric callable.
Many constructors accept either a number or a zero-arg callable (lead times, arrival intervals, recovery times). The previous auto-wrap was
.. code-block:: python
if not callable(value):
value = lambda val=value: val
which silently accepted any callable — including a class like int or
a generator function — turning the eventual value() call into a
runtime explosion deep inside a SimPy process (§6.4). This helper fixes
that by invoking the callable once at validation time and asserting the
result is a real number; non-numeric returns surface immediately at
construction with a clear error message naming the offending parameter.
| 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
173 174 175 176 177 178 179 180 181 182 183 184 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 | |