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 SupplyChainNode class contains the data, state variables, and performance measures for a supply chain node.

network

The network that contains the node.

Type

SupplyChainNetwork

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_cost is None, then the stage’s local_holding_cost is used. To ignore in-transit holding costs, set in_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

DemandSource

initial_inventory_level

Initial inventory level.

Type

float

initial_orders

Initial outbound order quantity.

Type

float

initial shipments

Initial inbound shipment quantity.

Type

float

inventory_policy

Inventory policy to be used to make inventory decisions.

Type

Policy

supply_type

Supply type , as a string. Currently supported strings are:

  • None

  • ‘U’: unlimited

Type

str

disruption_process

Disruption process object (if any).

Type

DisruptionProcess

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

True if the node has an external supplier (i.e., if its supply_type is not None), False otherwise.

property has_external_customer

True if the node has an external customer (i.e., if its demand_source is not None), False otherwise.

predecessors(include_external=False)[source]

Return a list of all predecessors of the node, as SupplyChainNode objects.

Parameters

include_external (bool, optional) – Include the external supplier (if any)? Default = False.

Returns

List of all predecessors, as SupplyChainNode objects.

Return type

list

Raises

AttributeError – If network attribute is None.

successors(include_external=False)[source]

Return a list of all successors of the node, as SupplyChainNode objects.

Parameters

include_external (bool, optional) – Include the external customer (if any)? Default = False.

Returns

List of all successors, as SupplyChainNode objects.

Return type

list

Raises

AttributeError – If network attribute is None.

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 SupplyChainNode objects. 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 SupplyChainNode objects. 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 SupplyChainNode objects. Read only.

Raises

AttributeError – If network attribute is None.

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 predecessor is a valid predecessor of node:

  • If predecessor is a SupplyChainNode object, confirms that it is a

    predecessor of the node, and returns the predecessor node and its index.

  • If predecessor is an int, confirms that it is the index of a predecessor

    of the node, and returns the predecessor node and its index.

  • If predecessor is None and the node has a single predecessor node

    (regardless of whether it also has an external supplier), returns the predecessor node and its index.

  • If predecessor is None and the node has 0 or more than 1 predecessor node and has

    an external supplier, returns None, None. (This represents the external supplier.)

  • Raises a ValueError in most other cases.

  • If raw_material is not None, also checks that the predecessor provides that raw

    material, and raises an exception if not. (This only works if preecessor is not None.)

Parameters
  • predecessor (SupplyChainNode, int, or None) – The predecessor to validate.

  • raw_material (SupplyChainProduct or int, optional) – If not None and predecessor is not None, the function will check that raw_material is provided by predecessor and 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 if predecessor is None and the node has multiple predecessors (or multiple predecessors that provide raw_material).

Returns

  • |class_node| – The node object.

  • int – The node index.

Raises
  • TypeError – If predecessor is not a SupplyChainNode, int, or None.

  • ValueError – If predecessor is not a predecessor of the node.

  • ValueError – If predecessor is None and the node has no external supplier and has 0 or >1 predecessor nodes.

  • ValueError – If predecessor and raw_material are both not None and predecessor does not supply this node with raw_material.

validate_successor(successor)[source]

Confirm that successor is a valid successor of node:

  • If successor is a SupplyChainNode object, confirms that it is a

    successor of the node, and returns the successor node and its index.

  • If successor is an int, confirms that it is the index of a successor

    of the node, and returns the successor node and its index.

  • If successor is None and the node has a single successor node

    (regardless of whether it also has an external customer), returns the successor node and its index.

  • If successor is None and the node has 0 or more than 1 successor node and has

    an external customer, returns None, None. (This represents the external customer.)

  • Raises a ValueError in most other cases.

Parameters

successor (SupplyChainNode, int, or None) – The successor to validate.

Returns

  • |class_node| – The node object.

  • int – The node index.

Raises
  • TypeError – If successor is not a SupplyChainNode, int, or None.

  • ValueError – If successor is not a successor of the node.

  • ValueError – If successor is None and 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 SupplyChainProduct objects. For example, self.products_by_index[4] is a SupplyChainProduct object for the product with index 4. Read only.

property is_multiproduct

Returns True if the node handles multiple products, False otherwise. Read only.

property is_singleproduct

Returns True if the node handles a single product, False otherwise. Read only.

add_product(product)[source]

Add product to the node. If product is 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_products to 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 SupplyChainProduct objects) – The list of products to add to the node.

remove_product(product)[source]

Remove product from the node. product may be either a SupplyChainProduct object or the index of the product. If product is not in the node (as determined by the index), do nothing.

Parameters

product (SupplyChainProduct or int) – The product to remove from the node.

remove_products(list_of_products)[source]

Remove each product in list_of_products from the node. Products in list_of_products may be either SupplyChainProduct objects or product indices, or a mix. Alternatively, set list_of_products to 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 SupplyChainProduct objects, 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_material from predecessor that are required to make one unit of product at 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, and raw_material may be indices or objects. Set predecessor to None to determine the predecessor automatically: Either the external supplier (if raw_material is None or the dummy product at the external supplier) or the unique predecessor that provides a given dummy product (if raw_material is a dummy product), or an arbitrary predecessor (if raw_material is 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 ValueError if product is not a product at the node, raw_material is not a product at predecessor, or predecessor is not a predecessor of the node.

NBOM() is a shortcut to this function.

Parameters
  • product (SupplyChainProduct or int, optional) – The product to get the BOM for, as a SupplyChainProduct or index. Set to None (the default) for the dummy product.

  • predecessor (SupplyChainNode or int, optional) – The predecessor to get the BOM for, as a SupplyChainNode object or index. Set to None (the default) to determine the predecessor automatically.

  • raw_material (SupplyChainProduct or int, optional) – The raw material to get the BOM for, as a SupplyChainProduct or index. Set to None (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 product is not a product at the node or raw_material is not a product at predecessor.

  • ValueError – If predecessor is 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 product at the node. If the node is single-product, either set product to the single product, or to None and the function will determine it automatically. Set product to 'all' to include all raw materials required to make all products at the node.

If return_indices is False, returns the raw materials as SupplyChainProduct objects, otherwise returns their indices.

If network_BOM is True, includes raw materials that don’t have a BOM relationship specified but are implied by the network structure. (See get_network_bill_of_materials().)

Parameters
  • product (SupplyChainProduct, int, or string, optional) – The product (as a SupplyChainProduct object or index), None if 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, True to 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 product is not found among the node’s products, and it’s not the case that product is None and 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 product at this node, according to the bill of materials. If the node is single-product, either set product to the single product, or to None and the function will determine it automatically.

If return_indices is False, returns the suppliers as SupplyChainNode objects, otherwise returns their indices.

If network_BOM is True, includes raw material suppliers that don’t have a BOM relationship specified but are implied by the network structure. (See get_network_bill_of_materials().)

Parameters
  • product (SupplyChainProduct or int, optional) – The product (as a SupplyChainProduct object or index), or None if the node is single-product.

  • return_indices (bool, optional) – Set to False (the default) to return node objects, True to 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 product at this node, according to the bill of materials, including None for the external supplier, if appropriate.

Return type

list

Raises

ValueError – If product is not found among the node’s products, and it’s not the case that product is None and 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 set raw_material to the single raw material, or to None and the function will determine it automatically.

If return_indices is False, returns the suppliers as SupplyChainNode objects, otherwise returns their indices.

If network_BOM is True, includes raw material suppliers that don’t have a BOM relationship specified but are implied by the network structure. (See get_network_bill_of_materials().)

Parameters
  • raw_material (SupplyChainProduct or int, optional) – The raw material (as a SupplyChainProduct object or index), or None if the node requires a single raw material.

  • return_indices (bool, optional) – Set to False (the default) to return product objects, True to 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, including None for the external supplier, if appropriate.

Return type

list

Raises

ValueError – If raw_material is not found among the node’s raw materials, and it’s not the case that raw_material is None and 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_material at the node. If the node has a single raw material (either dummy or real), either set raw_material to the single raw material, or to None and the function will determine it automatically.

Parameters
  • raw_material (SupplyChainProduct or int, optional) – The raw material (as a SupplyChainProduct object or index), or None if the node requires a single raw material.

  • return_indices (bool, optional) – Set to False (the default) to return product objects, True to 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_material is not found among the node’s raw materials, and it’s not the case that raw_material is None and 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). Set product to '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 set product to the single product, or to None and the function will determine it automatically.

If return_indices is False, returns a list with the predecessors as SupplyChainNode objects (or None for the external supplier) and the products as SupplyChainProduct objects. Otherwise, returns a list with the predecessor and product indices.

If network_BOM is True, includes predecessors and raw materials that don’t have a BOM relationship specified but are implied by the network structure. (See get_network_bill_of_materials().)

Parameters
  • product (SupplyChainProduct, int, or string, optional) – The product (as a SupplyChainProduct object or index), None if 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, True to 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 product is not found among the node’s products, and it’s not the case that product is None and this is a single-product node.

customers_by_product(product=None, return_indices=False, network_BOM=True)[source]

A list of customers that order product from the node. If the node has a single product (either dummy or real), either set product to the single product, or to None and the function will determine it automatically.

If return_indices is False, returns the customers as SupplyChainNode objects (or None for the external customer), otherwise returns customer indices.

If network_BOM is True, includes customers that don’t have a BOM relationship specified but are implied by the network structure. (See get_network_bill_of_materials().)

Parameters
  • product (SupplyChainProduct or int, optional) – The product (as a SupplyChainProduct object or index), or None if the node has a single product.

  • return_indices (bool, optional) – Set to False (the default) to return node objects, True to 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 product is a valid product of node:

  • If product is a SupplyChainProduct object, confirms that it is a

    product of the node, and returns the product object and its index.

  • If product is an int, confirms that it is the index of a product

    of the node, and returns the product object and its index.

  • If product is None and the node has a single product

    (including a dummy product), returns the product node and its index.

  • Raises a ValueError in most other cases.

Parameters

product (SupplyChainProduct, int, or None) – The product to validate.

Returns

  • |class_product| – The product object.

  • int – The product index.

Raises
  • TypeError – If product is not a SupplyChainProduct, int, or None.

  • ValueError – If product is not a product of the node.

  • ValueError – If product is None and 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_material is a valid raw material used by the node:

  • If raw_material is a SupplyChainProduct object, confirms that it is a

    raw material of the node, and returns the raw material’s SupplyChainProduct object and its index.

  • If raw_material is an int, confirms that it is the index of a raw material

    of the node, and returns the raw material’s SupplyChainProduct object and its index.

  • If raw_material is None and the node has a single raw material

    (including an external supplier dummy raw material), returns the raw material node and its index.

  • Raises a ValueError in most other cases.

  • If predecessor is not None, also checks that the raw material is provided by that

    predecessor, and raises an exception if not. (This only works if raw_material is not None.)

Parameters
  • raw_material (SupplyChainProduct, int, or None) – The raw material to validate.

  • predecessor (SupplyChainNode or int, optional) – If not None and raw_material is not None, the function will check that raw_material is provided by predecessor and 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_material is not a SupplyChainProduct, int, or None.

  • ValueError – If raw_material is not a raw material of the node.

  • ValueError – If raw_material is None and either predecessor is supplied and the node receives more than 1 raw material from predecessor or predecesor is None and the node has more than 1 raw material (including the dummy raw materials).

  • ValueError – If raw_material and predecessor are both not None and predecessor does not supply this node with raw_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 DisruptionProcess object in its disruption_process attribute.)

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 index to None to keep the current index, if any. If index is already None, a ValueError is raised.

Parameters

index (int, optional) – The index for the node, or None (default) to keep the current index.

Raises

ValueError – If index and self.index are both None, or if index is 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_indices but not _products or _products_by_index.

  • Does not check equality of local_holding_cost_function or stockout_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

True if the two nodes are equal, False otherwise.

Return type

bool

to_dict()[source]

Convert the SupplyChainNode object to a dict. Converts the object recursively, calling to_dict() on each object that is an attribute of the node (DemandSource, etc.).

The following substitutions are made:

  • _products and _products_by_index attributes are not converted; only _product_indices.

  • Dummy product attributes are replaced with indices only, not SupplyChainProduct objects.

  • network object is not filled.

These should be replaced with the corresponding node objects if this function is called recursively from a SupplyChainNetwork’s from_dict() method.

Returns

The dict representation of the node.

Return type

dict

classmethod from_dict(the_dict)[source]

Return a new SupplyChainNode object with attributes copied from the values in the_dict. List attributes are deep-copied so changes to the original dict do not get propagated to the object.

Note that:

  • _product_indices attribute is loaded into the product, but _products and _products_by_index attributes are not. (They are set to their default values.) These should be filled by the SupplyChainNetwork’s from_dict() method.

  • _dummy_product and _external_supplier_dummy_product are set to indices, like they are in the dict.

  • network object 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’s from_dict() method.

Parameters

the_dict (dict) – Dict representation of a SupplyChainNode, typically created using to_dict().

Returns

The object converted from the dict.

Return type

SupplyChainProduct

add_successor(successor)[source]

Add successor to the node’s set of successors.

Important

This method simply updates the node’s set of successors. It does not add successor to the network or add self as a predecessor of successor. Typically, this method is called by the network rather than directly. Use the add_successor() method in SupplyChainNetwork instead.

Parameters

successor (SupplyChainNode) – The node to add as a successor.

add_predecessor(predecessor)[source]

Add predecessor to the node’s set of predecessors.

Important

This method simply updates the node’s set of predecessors. It does not add predecessor to the network or add self as a successor of predecessor. Typically, this method is called by the network rather than directly. Use the add_predecessor() method in SupplyChainNetwork instead.

Parameters

predecessor (SupplyChainNode) – The node to add as a predecessor.

remove_successor(successor)[source]

Remove successor from the node’s set of successors. successor may be a SupplyChainNode or its index. Does nothing if successor is not a successor of the node

Important

This method simply updates the node’s set of successors. It does not remove successor from the network or remove self as a predecessor of successor. Typically, this method is called by the remove_node() method of the SupplyChainNetwork rather than directly.

Parameters

successor (SupplyChainNode or int) – The node to remove as a successor.

remove_predecessor(predecessor)[source]

Remove predecessor from the node’s set of predecessors. predecessor may be a SupplyChainNode or its index. Does nothing if predecessor is not a predecessor of the node

Important

This method simply updates the node’s set of predecessors. It does not remove predecessor from the network or remove self as a successor of predecessor. Typically, this method is called by the remove_node() method of the SupplyChainNetwork rather than directly.

Parameters

predecessor (SupplyChainNode or 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

SupplyChainNode

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

SupplyChainNode

get_attribute(attr, product=None)[source]

Return the value of the attribute attr for product. This is a way to easily access an attribute without knowing ahead of time whether it is a singleton or a product-keyed dict. product may be either a SupplyChainProduct object or the index of the product.

  • If self.attr is a dict and contains the key product, returns self.attr[product]. product must be the product index, in this case. (This returns a (node, product)-specific value of the attribute.)

  • Else if self.attr equals its default value (e.g., None), or is a dict but does not contain the key product, returns self.products[product].attr. (This returns a product-specific value of the attribute.)

  • Else (self.attr is a singleton), returns self.attr. (This returns a node-specific value of the attribute.)

(Here, we are assuming product is an index. If it is a SupplyChainProduct object, replace product with product.index.)

Parameters
  • attr (str) – The name of the attribute to get.

  • product (SupplyChainProduct or int, optional) – The product to get the attribute for, either as a SupplyChainProduct object or as an index. If the node has a single product, set product to its index, or to None (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 product is None but 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_dict and all product-based keys using old_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.