wagner_whitin
Module¶
Overview¶
The wagner_whitin
module contains code for solving the Wagner-Whitin
problem using dynamic programming.
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).
See Also
For an overview of single-echelon inventory optimization in Stockpyl, see the tutorial page for single-echelon inventory optimization.
API Reference¶
- wagner_whitin(num_periods, holding_cost, fixed_cost, demand, purchase_cost=0)[source]¶
Solve the Wagner-Whitin problem using dynamic programming (DP).
The time periods are indexed 1, …,
num_periods
. Lists given in outputs use the same indexing, which means that element 0 will usually be ignored. (In some cases, element 0 is used to represent initial conditions.)Most parameters may be given as a singleton or a list. If given as a singleton, the parameter will be assumed to be the same in every time period. If given as a list, the list must be of length
num_periods
ornum_periods
+1.In the former case, the list is assumed to contain values for periods 1, …,
num_periods
in elements 0, …,num_periods
-1.In the latter case, the list is assumed to contain values for periods 1, …,
num_periods
in elements 1, …,num_periods
, and the 0th element is ignored.
The parameters may be mixed, some singletons and some lists.
- Parameters
num_periods (int) – Number of periods in time horizon. [\(T\)]
holding_cost (float or list) – Holding cost per item per period. [\(h\)]
fixed_cost (float or list) – Fixed cost per order. [\(K\)]
demand (float or list) – Demand in each time period. [\(d\)]
purchase_cost (float or list, optional) – Purchase cost per item. [\(c\)]
- Returns
order_quantities (list) – List of order quantities in each time period. [\(Q^*\)]
cost (float) – Optimal cost for entire horizon. [\(\theta_1\)]
costs_to_go (list) – List of “costs to go”. [\(\theta\)]
next_order_periods (list) – List of “next order” period. [\(s\)]
- Raises
ValueError – If
holding_cost
,fixed_cost
,demand
, orpurchase_cost
<= 0 for any time period.
Equation Used (modified from equation (3.39)):
\[\theta_t = \min_{t < s \le T+1} \left\{K + c_t\sum_{i=1}^{s-1}d_i + h\sum_{i=t}^{s-1}(i-t)d_i + \theta_s \right\}\]Algorithm Used: Wagner-Whitin algorithm (Algorithm 3.1)
Example (a Example 3.9):
>>> Q, cost, theta, s = wagner_whitin(4, 2, 500, [90, 120, 80, 70]) >>> Q [0, 210, 0, 150, 0] >>> cost 1380.0 >>> theta array([ 0., 1380., 940., 640., 500., 0.]) >>> s [0, 3, 5, 5, 5]