supply_chain_node Module¶
Overview¶
This module contains the SupplyChainNode class, which is a stage or node
in a supply chain network.
Note
The terms “node” and “stage” are used interchangeably in the documentation.
Note
The notation and references (equations, sections, examples, etc.) used below refer to Snyder and Shen, Fundamentals of Supply Chain Theory (FoSCT), 2nd edition (2019).
A SupplyChainNode is used primarily for multi-echelon inventory optimization (MEIO)
or simulation. SupplyChainNode objects are rarely, if ever, used as standalone objects;
rather, they are included in SupplyChainNetwork objects, which describe the complete instance
to be optimized or simulated.
The node object contains many attributes, and different functions use different sets of attributes.
For example, the stockpyl.ssm_serial.optimize_base_stock_levels() function takes a
SupplyChainNetwork whose nodes contain values for echelon_holding_cost, lead_time, stockout_cost,
and demand_source attributes, while stockpyl.gsm_serial.optimize_committed_service_times()
uses local_holding_cost, processing_time, etc.
Therefore, to determine which attributes are needed, refer to the documentation for the function
you are using.
For multi-product models, most attributes may be either at the node level (by setting the attribute
in the SupplyChainNode object), or at the product level (by setting the attribute in the SupplyChainProduct object),
or at the node-product level (by setting the SupplyChainNode’s attribute to a dict whose keys are product
indices and whose values are the attribute values). In particular:
If the attribute is a dict, the node will first attempt to access the value of
<attribute>[<product id>].Else, if the attribute is a dict but does not contain a value for a given product, the product’s value for the attribute is used, if it exists.
Else the node’s value of the attribute is used. (It should be a singleton in this case.)
To add a product to the node, use add_product(). To retrieve the products at the node, use
the products property, which is a dict whose keys are product indices and whose values are the
corresponding SupplyChainProduct objects. (For example, node.products[4] is the product at node with index 4.)
API Reference¶
- class SupplyChainNode(index, name=None, network=None, **kwargs)[source]¶
The
SupplyChainNodeclass contains the data, state variables, and performance measures for a supply chain node.- network¶
The network that contains the node.
- Type
- local_holding_cost¶
Local holding cost, per unit per period. [\(h'\)]
- Type
float
- echelon_holding_cost¶
Echelon holding cost, per unit per period. (Note: not currently supported.) [\(h\)]
- Type
float
- local_holding_cost_function¶
Function that calculates local holding cost per period, as a function of ending inventory level. Function must take exactly one argument, the ending IL. Function should check that IL > 0.
- Type
function
- in_transit_holding_cost¶
Holding cost coefficient used to calculate in-transit holding cost for shipments en route from the node to its downstream successors, if any. If
in_transit_holding_costisNone, then the stage’s local_holding_cost is used. To ignore in-transit holding costs, setin_transit_holding_cost= 0.- Type
float
- stockout_cost¶
Stockout cost, per unit (per period, if backorders). [\(p\)]
- Type
float
- stockout_cost_function¶
Function that calculates stockout cost per period, as a function of ending inventory level. Function must take exactly one argument, the ending IL. Function should check that IL < 0.
- Type
function
- purchase_cost¶
Cost incurred per unit. (Note: not currently supported.)
- Type
float
- revenue¶
Revenue earned per unit of demand met. (Note: not currently supported.) [\(r\)]
- Type
float
- shipment_lead_time¶
Shipment lead time. [\(L\)]
- Type
int
- lead_time¶
An alias for
shipment_lead_time.- Type
int
- order_lead_time¶
Order lead time. (Note: not currently supported.)
- Type
int
- demand_source¶
Demand source object.
- Type
- initial_inventory_level¶
Initial inventory level.
- Type
float
- initial_orders¶
Initial outbound order quantity.
- Type
float
- initial shipments
Initial inbound shipment quantity.
- Type
float
- supply_type¶
Supply type , as a string. Currently supported strings are:
None
‘U’: unlimited
- Type
str
- disruption_process¶
Disruption process object (if any).
- Type
- order_capacity¶
Maximum size of an order.
- Type
float
- state_vars¶
List of
NodeStateVars, one for each period in a simulation.- Type
list of
NodeStateVars
- problem_specific_data¶
Placeholder for object that is used to provide data for specific problem types.
- Type
object
- property holding_cost¶
An alias for
local_holding_cost. Read only.
- property has_external_supplier¶
Trueif the node has an external supplier (i.e., if itssupply_typeis notNone),Falseotherwise.
- property has_external_customer¶
Trueif the node has an external customer (i.e., if itsdemand_sourceis notNone),Falseotherwise.
- predecessors(include_external=False)[source]¶
Return a list of all predecessors of the node, as
SupplyChainNodeobjects.- Parameters
include_external (bool, optional) – Include the external supplier (if any)? Default =
False.- Returns
List of all predecessors, as
SupplyChainNodeobjects.- Return type
list
- Raises
AttributeError – If
networkattribute isNone.
- successors(include_external=False)[source]¶
Return a list of all successors of the node, as
SupplyChainNodeobjects.- Parameters
include_external (bool, optional) – Include the external customer (if any)? Default =
False.- Returns
List of all successors, as
SupplyChainNodeobjects.- Return type
list
- Raises
AttributeError – If
networkattribute isNone.
- predecessor_indices(include_external=False)[source]¶
Return a list of indices of all predecessors of the node.
- Parameters
include_external (bool, optional) – Include the external supplier (if any)? Default =
False.- Returns
List of all predecessor indices.
- Return type
list
- successor_indices(include_external=False)[source]¶
Return a list of indices of all successors of the node.
- Parameters
include_external (bool, optional) – Include the external customer (if any)? Default =
False.- Returns
List of all successor indices.
- Return type
list
- property descendants¶
A list of all descendants of the node, as
SupplyChainNodeobjects. A descendant is a node that is downstream from the node but not necessarily directly adjacent; that is, a node that can be reached from the node via a directed path. Read only.
- property ancestors¶
A list of all ancestors of the node, as
SupplyChainNodeobjects. An ancestor is a node that is upstream from the node but not necessarily directly adjacent; that is, a node from which we can reach the node via a directed path. Read only.
- property neighbors¶
A list of all neighbors (successors and predecessors) of the node, as
SupplyChainNodeobjects. Read only.- Raises
AttributeError – If
networkattribute isNone.
- property neighbor_indices¶
A list of indices of all neighbors (successors and predecessors) of the node. Read only.
- validate_predecessor(predecessor, raw_material=None, network_BOM=True, err_on_multiple_preds=True)[source]¶
Confirm that
predecessoris a valid predecessor of node:- If
predecessoris aSupplyChainNodeobject, confirms that it is a predecessor of the node, and returns the predecessor node and its index.
- If
- If
predecessoris an int, confirms that it is the index of a predecessor of the node, and returns the predecessor node and its index.
- If
- If
predecessorisNoneand the node has a single predecessor node (regardless of whether it also has an external supplier), returns the predecessor node and its index.
- If
- If
predecessorisNoneand the node has 0 or more than 1 predecessor node and has an external supplier, returns
None, None. (This represents the external supplier.)
- If
Raises a
ValueErrorin most other cases.- If
raw_materialis notNone, also checks that the predecessor provides that raw material, and raises an exception if not. (This only works if
preecessoris notNone.)
- If
- Parameters
predecessor (
SupplyChainNode, int, orNone) – The predecessor to validate.raw_material (
SupplyChainProductor int, optional) – If notNoneandpredecessoris notNone, the function will check thatraw_materialis provided bypredecessorand raise an exception if not.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.err_on_multiple_preds (bool, optional) – If
True(default), raises an exception ifpredecessorisNoneand the node has multiple predecessors (or multiple predecessors that provideraw_material).
- Returns
|class_node| – The node object.
int – The node index.
- Raises
TypeError – If
predecessoris not aSupplyChainNode, int, orNone.ValueError – If
predecessoris not a predecessor of the node.ValueError – If
predecessorisNoneand the node has no external supplier and has 0 or >1 predecessor nodes.ValueError – If
predecessorandraw_materialare both notNoneandpredecessordoes not supply this node withraw_material.
- validate_successor(successor)[source]¶
Confirm that
successoris a valid successor of node:- If
successoris aSupplyChainNodeobject, confirms that it is a successor of the node, and returns the successor node and its index.
- If
- If
successoris an int, confirms that it is the index of a successor of the node, and returns the successor node and its index.
- If
- If
successorisNoneand the node has a single successor node (regardless of whether it also has an external customer), returns the successor node and its index.
- If
- If
successorisNoneand the node has 0 or more than 1 successor node and has an external customer, returns
None, None. (This represents the external customer.)
- If
Raises a
ValueErrorin most other cases.
- Parameters
successor (
SupplyChainNode, int, orNone) – The successor to validate.- Returns
|class_node| – The node object.
int – The node index.
- Raises
TypeError – If
successoris not aSupplyChainNode, int, orNone.ValueError – If
successoris not a successor of the node.ValueError – If
successorisNoneand the node has no external customer and has 0 or >1 successor nodes.
- property products¶
A list containing products handled by the node. Read only.
- property product_indices¶
A list of indices of all products handled at the node. Read only.
- property products_by_index¶
A dict containing products handled by the node. The keys of the dict are product indices and the values are the corresponding
SupplyChainProductobjects. For example,self.products_by_index[4]is aSupplyChainProductobject for the product with index 4. Read only.
- property is_multiproduct¶
Returns
Trueif the node handles multiple products,Falseotherwise. Read only.
- property is_singleproduct¶
Returns
Trueif the node handles a single product,Falseotherwise. Read only.
- add_product(product)[source]¶
Add
productto the node. Ifproductis already in the node (as determined by the index), do nothing.- Parameters
product (
SupplyChainProduct) – The product to add to the node.
- add_products(list_of_products)[source]¶
Add each product in
list_of_productsto the node. If a given product is already in the node (as determined by the index), do not add it.- Parameters
list_of_products (list of
SupplyChainProductobjects) – The list of products to add to the node.
- remove_product(product)[source]¶
Remove
productfrom the node.productmay be either aSupplyChainProductobject or the index of the product. Ifproductis not in the node (as determined by the index), do nothing.- Parameters
product (
SupplyChainProductor int) – The product to remove from the node.
- remove_products(list_of_products)[source]¶
Remove each product in
list_of_productsfrom the node. Products inlist_of_productsmay be eitherSupplyChainProductobjects or product indices, or a mix. Alternatively, setlist_of_productsto the string'all'to remove all products. If a given product is not in the node (as determined by the index), do not remove it.- Parameters
list_of_products (list of
SupplyChainProductobjects, or string) – The list of products to remove from the node, or'all'to remove all products.
- get_network_bill_of_materials(product=None, predecessor=None, raw_material=None)[source]¶
Return the “network bill of materials” (NBOM) i.e., the number of units of
raw_materialfrompredecessorthat are required to make one unit ofproductat this node, accounting for network structure. In particular, if _no_ raw materials at the predecessor have a BOM relationship with _any_ product at the node, then _every_ raw material at the predecessor is assigned a BOM number of 1 for _every_ product at the node. (In particular, this allows single-product networks to be constructed without adding any products to the network.)product,predecessor, andraw_materialmay be indices or objects. SetpredecessortoNoneto determine the predecessor automatically: Either the external supplier (ifraw_materialisNoneor the dummy product at the external supplier) or the unique predecessor that provides a given dummy product (ifraw_materialis a dummy product), or an arbitrary predecessor (ifraw_materialis not a dummy product, because in this case the NBOM equals the BOM–it is product-specific, not node-specific, so the predecessor is irrelevant).Returns a
ValueErrorifproductis not a product at the node,raw_materialis not a product atpredecessor, orpredecessoris not a predecessor of the node.NBOM()is a shortcut to this function.- Parameters
product (
SupplyChainProductor int, optional) – The product to get the BOM for, as aSupplyChainProductor index. Set toNone(the default) for the dummy product.predecessor (
SupplyChainNodeor int, optional) – The predecessor to get the BOM for, as aSupplyChainNodeobject or index. Set toNone(the default) to determine the predecessor automatically.raw_material (
SupplyChainProductor int, optional) – The raw material to get the BOM for, as aSupplyChainProductor index. Set toNone(the default) for the dummy product at the external supplier.
- Returns
The network BOM number for the (raw material, product) pair at these nodes.
- Return type
int
- Raises
ValueError – If
productis not a product at the node orraw_materialis not a product atpredecessor.ValueError – If
predecessoris not a predecessor of the node.
- NBOM(product=None, predecessor=None, raw_material=None)[source]¶
A shortcut to
get_network_bill_of_materials().
- raw_materials_by_product(product=None, return_indices=False, network_BOM=True)[source]¶
Return a list of all raw materials required to make
productat the node. If the node is single-product, either setproductto the single product, or toNoneand the function will determine it automatically. Setproductto'all'to include all raw materials required to make all products at the node.If
return_indicesisFalse, returns the raw materials asSupplyChainProductobjects, otherwise returns their indices.If
network_BOMisTrue, includes raw materials that don’t have a BOM relationship specified but are implied by the network structure. (Seeget_network_bill_of_materials().)- Parameters
product (
SupplyChainProduct, int, or string, optional) – The product (as aSupplyChainProductobject or index),Noneif the node is single-product, or'all'to get raw materials for all products.return_indices (bool, optional) – Set to
False(the default) to return product objects,Trueto return product indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
List of all raw materials required to make the product at the node.
- Return type
list
- Raises
ValueError – If
productis not found among the node’s products, and it’s not the case thatproduct is Noneand this is a single-product node.
- raw_material_suppliers_by_product(product=None, return_indices=False, network_BOM=True)[source]¶
Return a list of all predecessors from which a raw material must be ordered in order to make
productat this node, according to the bill of materials. If the node is single-product, either setproductto the single product, or toNoneand the function will determine it automatically.If
return_indicesisFalse, returns the suppliers asSupplyChainNodeobjects, otherwise returns their indices.If
network_BOMisTrue, includes raw material suppliers that don’t have a BOM relationship specified but are implied by the network structure. (Seeget_network_bill_of_materials().)- Parameters
product (
SupplyChainProductor int, optional) – The product (as aSupplyChainProductobject or index), orNoneif the node is single-product.return_indices (bool, optional) – Set to
False(the default) to return node objects,Trueto return node indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
List of all predecessors from which a raw material must be ordered in order to make
productat this node, according to the bill of materials, includingNonefor the external supplier, if appropriate.- Return type
list
- Raises
ValueError – If
productis not found among the node’s products, and it’s not the case thatproduct is Noneand this is a single-product node.
- raw_material_suppliers_by_raw_material(raw_material=None, return_indices=False, network_BOM=True)[source]¶
Return a list of all predecessors that supply the node with
raw_material. Every predecessor that _can_ supply the raw material, including the external supplier, is included in the list, regardless of whether the node actually orders the raw material from the supplier. If the node has a single raw material, either setraw_materialto the single raw material, or toNoneand the function will determine it automatically.If
return_indicesisFalse, returns the suppliers asSupplyChainNodeobjects, otherwise returns their indices.If
network_BOMisTrue, includes raw material suppliers that don’t have a BOM relationship specified but are implied by the network structure. (Seeget_network_bill_of_materials().)- Parameters
raw_material (
SupplyChainProductor int, optional) – The raw material (as aSupplyChainProductobject or index), orNoneif the node requires a single raw material.return_indices (bool, optional) – Set to
False(the default) to return product objects,Trueto return product indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
List of all predecessors that can supply the node with
raw_material, according to the bill of materials, includingNonefor the external supplier, if appropriate.- Return type
list
- Raises
ValueError – If
raw_materialis not found among the node’s raw materials, and it’s not the case thatraw_material is Noneand this node has a single raw material.
- products_by_raw_material(raw_material=None, return_indices=False, network_BOM=True)[source]¶
Return a list of all products that use
raw_materialat the node. If the node has a single raw material (either dummy or real), either setraw_materialto the single raw material, or toNoneand the function will determine it automatically.- Parameters
raw_material (
SupplyChainProductor int, optional) – The raw material (as aSupplyChainProductobject or index), orNoneif the node requires a single raw material.return_indices (bool, optional) – Set to
False(the default) to return product objects,Trueto return product indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
List of all products that use the raw material at the node, according to the bill of materials.
- Return type
list
- Raises
ValueError – If
raw_materialis not found among the node’s raw materials, and it’s not the case thatraw_material is Noneand this node has a single raw material.
- supplier_raw_material_pairs_by_product(product=None, return_indices=False, network_BOM=True)[source]¶
A list of all predecessors and raw materials for
product, as tuples(pred, rm). Setproductto'all'to get predecessors and raw materials for all products at the node. If the node has a single product (either dummy or real), either setproductto the single product, or toNoneand the function will determine it automatically.If
return_indicesisFalse, returns a list with the predecessors asSupplyChainNodeobjects (orNonefor the external supplier) and the products asSupplyChainProductobjects. Otherwise, returns a list with the predecessor and product indices.If
network_BOMisTrue, includes predecessors and raw materials that don’t have a BOM relationship specified but are implied by the network structure. (Seeget_network_bill_of_materials().)- Parameters
product (
SupplyChainProduct, int, or string, optional) – The product (as aSupplyChainProductobject or index),Noneif the node is single-product, or'all'to get predecessors and raw materials for all products.return_indices (bool, optional) – Set to
False(the default) to return node and product objects,Trueto return node and product indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
List of (predecessor, raw material) tuples.
- Return type
list
- Raises
ValueError – If
productis not found among the node’s products, and it’s not the case thatproduct is Noneand this is a single-product node.
- customers_by_product(product=None, return_indices=False, network_BOM=True)[source]¶
A list of customers that order
productfrom the node. If the node has a single product (either dummy or real), either setproductto the single product, or toNoneand the function will determine it automatically.If
return_indicesisFalse, returns the customers asSupplyChainNodeobjects (orNonefor the external customer), otherwise returns customer indices.If
network_BOMisTrue, includes customers that don’t have a BOM relationship specified but are implied by the network structure. (Seeget_network_bill_of_materials().)- Parameters
product (
SupplyChainProductor int, optional) – The product (as aSupplyChainProductobject or index), orNoneif the node has a single product.return_indices (bool, optional) – Set to
False(the default) to return node objects,Trueto return node indices.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- validate_product(product)[source]¶
Confirm that
productis a valid product of node:- If
productis aSupplyChainProductobject, confirms that it is a product of the node, and returns the product object and its index.
- If
- If
productis an int, confirms that it is the index of a product of the node, and returns the product object and its index.
- If
- If
productisNoneand the node has a single product (including a dummy product), returns the product node and its index.
- If
Raises a
ValueErrorin most other cases.
- Parameters
product (
SupplyChainProduct, int, orNone) – The product to validate.- Returns
|class_product| – The product object.
int – The product index.
- Raises
TypeError – If
productis not aSupplyChainProduct, int, orNone.ValueError – If
productis not a product of the node.ValueError – If
productisNoneand the node has more than 1 product (including the dummy product).
- validate_raw_material(raw_material, predecessor=None, network_BOM=True)[source]¶
Confirm that
raw_materialis a valid raw material used by the node:- If
raw_materialis aSupplyChainProductobject, confirms that it is a raw material of the node, and returns the raw material’s
SupplyChainProductobject and its index.
- If
- If
raw_materialis an int, confirms that it is the index of a raw material of the node, and returns the raw material’s
SupplyChainProductobject and its index.
- If
- If
raw_materialisNoneand the node has a single raw material (including an external supplier dummy raw material), returns the raw material node and its index.
- If
Raises a
ValueErrorin most other cases.- If
predecessoris notNone, also checks that the raw material is provided by that predecessor, and raises an exception if not. (This only works if
raw_materialis notNone.)
- If
- Parameters
raw_material (
SupplyChainProduct, int, orNone) – The raw material to validate.predecessor (
SupplyChainNodeor int, optional) – If notNoneandraw_materialis notNone, the function will check thatraw_materialis provided bypredecessorand raise an exception if not.network_BOM (bool, optional) – If
True(default), function uses network BOM instead of product-only BOM.
- Returns
|class_product| – The raw material as an object.
int – The raw material index.
- Raises
TypeError – If
raw_materialis not aSupplyChainProduct, int, orNone.ValueError – If
raw_materialis not a raw material of the node.ValueError – If
raw_materialisNoneand eitherpredecessoris supplied and the node receives more than 1 raw material frompredecessororpredecesorisNoneand the node has more than 1 raw material (including the dummy raw materials).ValueError – If
raw_materialandpredecessorare both notNoneandpredecessordoes not supply this node withraw_material.
- property forward_echelon_lead_time¶
Total shipment lead time for node and all of its descendants. Rosling (1989) calls this \(M_i\); Zipkin (2000) calls it \(\underline{L}_j\). Some assembly-system algorithms assume that the nodes are indexed in order of forward echelon lead time. Read only.
- property equivalent_lead_time¶
Difference between forward echelon lead time for the node (node \(i\)) and for node \(i-1\), where the nodes are indexed in non-decreasing order of forward_echelon_lead_time, consecutively. (If nodes are not indexed in this way, results will be unreliable.)
If node is the smallest-indexed node in the network, equivalent lead time equals forward echelon lead time, which also equals shipment lead time.
Rosling (1989) calls this \(L_i\); Zipkin (2000) calls it \(L''_j\).
Read only.
- property derived_demand_mean¶
Mean of derived demand, i.e., external demand at node and all of its descendants. Read only.
- property derived_demand_standard_deviation¶
Standard deviation of derived demand, i.e., external demand at node and all of its descendants. Read only.
- property state_vars_current¶
An alias for the most recent set of state variables, i.e., for the current period. (Period is determined from
self.network.period). Read only.
- property disrupted¶
Is the node currently disrupted?
(Works even if the node has no
DisruptionProcessobject in itsdisruption_processattribute.)
- initialize(index=None)[source]¶
Initialize the parameters in the object to their default values and sets index attribute. Initializes attributes that are objects (
demand_source,disruption_process,_inventory_policy). Adds dummy product and sets external supplier dummy product index, both of which are used in simulations.Set
indextoNoneto keep the current index, if any. If index is alreadyNone, aValueErroris raised.- Parameters
index (int, optional) – The index for the node, or
None(default) to keep the current index.- Raises
ValueError – If
indexandself.indexare bothNone, or ifindexis not an integer.
- deep_equal_to(other, rel_tol=1e-08)[source]¶
Check whether node “deeply equals”
other, i.e., if all attributes are equal, including attributes that are themselves objects.Note the following caveats:
Does not check equality of
network.Checks predecessor and successor equality by index only.
Checks product equality by index only, i.e., checks
_product_indicesbut not_productsor_products_by_index.Does not check equality of
local_holding_cost_functionorstockout_cost_function.Does not check equality of
state_vars.
- Parameters
other (
SupplyChainNode) – The node to compare this one to.rel_tol (float, optional) – Relative tolerance to use when comparing equality of float attributes.
- Returns
Trueif the two nodes are equal,Falseotherwise.- Return type
bool
- to_dict()[source]¶
Convert the
SupplyChainNodeobject to a dict. Converts the object recursively, callingto_dict()on each object that is an attribute of the node (DemandSource, etc.).The following substitutions are made:
_productsand_products_by_indexattributes are not converted; only_product_indices.Dummy product attributes are replaced with indices only, not
SupplyChainProductobjects.networkobject is not filled.
These should be replaced with the corresponding node objects if this function is called recursively from a
SupplyChainNetwork’sfrom_dict()method.- Returns
The dict representation of the node.
- Return type
dict
- classmethod from_dict(the_dict)[source]¶
Return a new
SupplyChainNodeobject with attributes copied from the values inthe_dict. List attributes are deep-copied so changes to the original dict do not get propagated to the object.Note that:
_product_indicesattribute is loaded into the product, but_productsand_products_by_indexattributes are not. (They are set to their default values.) These should be filled by theSupplyChainNetwork’sfrom_dict()method._dummy_productand_external_supplier_dummy_productare set to indices, like they are in the dict.networkobject is not filled.
These attributes should be completed (i.e., indices replaced by objects, etc.) by the network object if this function is called recursively from a
SupplyChainNetwork’sfrom_dict()method.- Parameters
the_dict (dict) – Dict representation of a
SupplyChainNode, typically created usingto_dict().- Returns
The object converted from the dict.
- Return type
SupplyChainProduct
- add_successor(successor)[source]¶
Add
successorto the node’s set of successors.Important
This method simply updates the node’s set of successors. It does not add
successorto the network or addselfas a predecessor ofsuccessor. Typically, this method is called by the network rather than directly. Use theadd_successor()method inSupplyChainNetworkinstead.- Parameters
successor (
SupplyChainNode) – The node to add as a successor.
- add_predecessor(predecessor)[source]¶
Add
predecessorto the node’s set of predecessors.Important
This method simply updates the node’s set of predecessors. It does not add
predecessorto the network or addselfas a successor ofpredecessor. Typically, this method is called by the network rather than directly. Use theadd_predecessor()method inSupplyChainNetworkinstead.- Parameters
predecessor (
SupplyChainNode) – The node to add as a predecessor.
- remove_successor(successor)[source]¶
Remove
successorfrom the node’s set of successors.successormay be aSupplyChainNodeor its index. Does nothing ifsuccessoris not a successor of the nodeImportant
This method simply updates the node’s set of successors. It does not remove
successorfrom the network or removeselfas a predecessor ofsuccessor. Typically, this method is called by theremove_node()method of theSupplyChainNetworkrather than directly.- Parameters
successor (
SupplyChainNodeor int) – The node to remove as a successor.
- remove_predecessor(predecessor)[source]¶
Remove
predecessorfrom the node’s set of predecessors.predecessormay be aSupplyChainNodeor its index. Does nothing ifpredecessoris not a predecessor of the nodeImportant
This method simply updates the node’s set of predecessors. It does not remove
predecessorfrom the network or removeselfas a successor ofpredecessor. Typically, this method is called by theremove_node()method of theSupplyChainNetworkrather than directly.- Parameters
predecessor (
SupplyChainNodeor int) – The node to remove as a predecessor.
- get_one_successor()[source]¶
Get one successor of the node. If the node has more than one successor, return the first in the list. If the node has no successors, return
None.- Returns
successor – A successor of the node.
- Return type
- get_one_predecessor()[source]¶
Get one predecessor of the node. If the node has more than one predecessor, return the first in the list. If the node has no predecessor, return
None.- Returns
predecessor – A predecessor of the node.
- Return type
- get_attribute(attr, product=None)[source]¶
Return the value of the attribute
attrforproduct. This is a way to easily access an attribute without knowing ahead of time whether it is a singleton or a product-keyed dict.productmay be either aSupplyChainProductobject or the index of the product.If
self.attris a dict and contains the keyproduct, returnsself.attr[product].productmust be the product index, in this case. (This returns a (node, product)-specific value of the attribute.)Else if
self.attrequals its default value (e.g.,None), or is a dict but does not contain the keyproduct, returnsself.products[product].attr. (This returns a product-specific value of the attribute.)Else (
self.attris a singleton), returnsself.attr. (This returns a node-specific value of the attribute.)
(Here, we are assuming
productis an index. If it is aSupplyChainProductobject, replaceproductwithproduct.index.)- Parameters
attr (str) – The name of the attribute to get.
product (
SupplyChainProductor int, optional) – The product to get the attribute for, either as aSupplyChainProductobject or as an index. If the node has a single product, setproductto its index, or toNone(or omit it) to determine the index automatically.
- Returns
The value of the attribute for the product (if any).
- Return type
any
- Raises
ValueError – If
productisNonebut the node has multiple products.
- reindex_all_state_variables(old_to_new_dict, old_to_new_prod_dict)[source]¶
Change indices of all node-based keys in all state variables using
old_to_new_dictand all product-based keys usingold_to_new_prod_dict.- Parameters
old_to_new_dict (dict) – Dict in which keys are old node indices and values are new node indices.
old_to_new_prod_dict (dict) – Dict in which keys are old product indices and values are new product indices.