Skip to content

Commit

Permalink
mwor_system() fails when setting demand_source #146
Browse files Browse the repository at this point in the history
  • Loading branch information
LarrySnyder committed May 19, 2024
1 parent 3aba5e2 commit 8a5afb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All significant changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Option to suppress dummy-product indices in simulation output.

## [1.0.0] -- 2024-05-13

### Introducing: Products
Expand Down
10 changes: 8 additions & 2 deletions src/stockpyl/supply_chain_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,14 @@ def mwor_system(num_warehouses, node_order_in_system=None, node_order_in_lists=N
# Set demand_source parameter so it only occurs at retailer node.
if 'demand_source' not in local_kwargs:
local_kwargs['demand_source'] = {}
for n in node_order_in_system[0:-1]:
local_kwargs['demand_source'][n] = DemandSource()
elif isinstance(local_kwargs['demand_source'], DemandSource):
# demand_source provided as singleton; convert to dict.
local_kwargs['demand_source'] = {n: DemandSource() for n in node_order_in_system[0:-1]}
local_kwargs['demand_source'].update({node_order_in_system[-1]: kwargs['demand_source']})
else:
# demand_source provided as list; overwrite all except retailer node.
for n in node_order_in_system[0:-1]:
local_kwargs['demand_source'][n] = DemandSource()

# Determine node_order_in_lists.
if node_order_in_lists is None:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_supply_chain_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,20 @@ def test_4_node_mwor_index_list(self):
self.assertEqual(wh2.local_holding_cost, 2)
self.assertEqual(wh3.local_holding_cost, 1)

def test_145(self):
"""Test instance in issue #165 (mwor_system() fails when setting demand_source).
"""
print_status('TestReindexNodes', 'test_145()')

network = mwor_system(3, demand_source=DemandSource(type='P', mean=5))

self.assertIsInstance(network.get_node_from_index(0).demand_source, DemandSource)
self.assertEqual(network.get_node_from_index(0).demand_source.type, 'P')
self.assertEqual(network.get_node_from_index(0).demand_source.mean, 5)
for n in range(1, 4):
self.assertIsInstance(network.get_node_from_index(n).demand_source, DemandSource)
self.assertIsNone(network.get_node_from_index(n).demand_source.type)


class TestOWMRSystem(unittest.TestCase):
@classmethod
Expand Down

0 comments on commit 8a5afb6

Please sign in to comment.