Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-sourcing a single raw material from multiple predecessors #170

Closed
rusk-ey opened this issue May 30, 2024 · 3 comments
Closed

Multi-sourcing a single raw material from multiple predecessors #170

rusk-ey opened this issue May 30, 2024 · 3 comments
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@rusk-ey
Copy link
Collaborator

rusk-ey commented May 30, 2024

When a node has 2 or more predecessors with the same upstream product, running the simulation results in an error.

For example, in an network defined by:

network = network_from_edges(
edges=[(2, 1), (3, 1)],
node_order_in_lists=[1, 2, 3],
local_holding_cost=[2,4,2],
stockout_cost=[50, 25, 25],
demand_type='UD', # discrete uniform distribution, for easier debugging
lo=1,
hi=5,
shipment_lead_time=[1, 1, 0]
)

nodes = {n.index: n for n in network.nodes}

products = {10: SupplyChainProduct(index=10), 20: SupplyChainProduct(index=20)}
products[10].set_bill_of_materials(rm_index=20, num_needed=3)

nodes[1].add_product(products[10])
nodes[2].add_product(products[20])
nodes[3].add_product(products[20])

products[10].inventory_policy = Policy(type='BS', base_stock_level=10, node=nodes[1], product=products[10])
products[20].inventory_policy = Policy(type='BS', base_stock_level=12, node=nodes[2], product=products[20])
products[20].inventory_policy = Policy(type='BS', base_stock_level=22, node=nodes[3], product=products[20])

I get the error... :

Traceback (most recent call last):
File ..., line 157, in
total_cost = simulation(network, 100, rand_seed=17)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ..., line 115, in simulation
step(network=network, consistency_checks=consistency_checks)
File ..., line 253, in step
_generate_downstream_orders(n.index, network, t, visited, order_quantity_override=order_quantity_override)
File ..., line 431, in _generate_downstream_orders
rm_OQ = order_quantity_dict[p_index][rm_index]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: -5

@LarrySnyder
Copy link
Owner

@bruskey47 Are you using the most recent commit? I get a different error message than what you're reporting!

@rusk-ey
Copy link
Collaborator Author

rusk-ey commented Jun 3, 2024

Here is the correct code for the error I reported - sorry for the confusion! The change is in the line:
products[10].set_bill_of_materials(rm_index=20, num_needed=3) ---> products[10].set_bill_of_materials(raw_material=20, num_needed=3)

network = network_from_edges(
edges=[(2, 1), (3, 1)],
node_order_in_lists=[1, 2, 3],
local_holding_cost=[2,4,2],
stockout_cost=[50, 25, 25],
demand_type='UD', # discrete uniform distribution, for easier debugging
lo=1,
hi=5,
shipment_lead_time=[1, 1, 0]
)

nodes = {n.index: n for n in network.nodes}

products = {10: SupplyChainProduct(index=10), 20: SupplyChainProduct(index=20)}
products[10].set_bill_of_materials(raw_material=20, num_needed=3) ##changed here

nodes[1].add_product(products[10])
nodes[2].add_product(products[20])
nodes[3].add_product(products[20])

products[10].inventory_policy = Policy(type='BS', base_stock_level=10, node=nodes[1], product=products[10])
products[20].inventory_policy = Policy(type='BS', base_stock_level=12, node=nodes[2], product=products[20])
products[20].inventory_policy = Policy(type='BS', base_stock_level=22, node=nodes[3], product=products[20])
total_cost = simulation(network, 100, rand_seed=17)

@LarrySnyder
Copy link
Owner

@bruskey47 The problem is that you are setting products[20].inventory_policy twice, and the second assignment overwrites the first assignment. So when it finds the order quantity at node 2 it gets confused because the inventory policy at node 2 thinks it lives at node 3 because of the node=nodes[3] argument.

To fix it, replace with:

nodes[2].inventory_policy = {20: Policy(type='BS', base_stock_level=12, node=nodes[2], product=products[20])}
nodes[3].inventory_policy = {20: Policy(type='BS', base_stock_level=22, node=nodes[3], product=products[20])}

(Setting inventory policies is definitely annoying and non-intuitive. This also relates to #162.)

@LarrySnyder LarrySnyder self-assigned this Jun 3, 2024
@LarrySnyder LarrySnyder added bug Something isn't working wontfix This will not be worked on labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants