This repository contains code for a generalized version of a classic inventory control optimization problem presented in the book Dynamic Programming and Optimal Control by Dimitris Bertsekas.
This is a classic inventory control problem. We assume we are planning for a finite horizon (i.e., a finite number of time steps). In each time step, the inventory manager has to decide how many units of stock to buy based on the current stock levels. We can characterize the probability distribution of the demand using a general distribution, and we can use the backwards induction algorithm to minimize the expected long term cost and find and optimal control policy.
We assume that the cost is quadratic with respect to excess demand or excess inventory. If we let
The goal of the optimal control algorithm is to recursively optimize this cost by taking the expectation with respect to
from ICBackwardsInduction import InventoryControlSolver
# Inputs
time_horizon= 61
max_stock= 10
terminal_cost= [0 for k in range(max_stock+1)]
demand_dist= [0, 0, 0, 0, 0, 0.25, 0.025, 0.05, 0.05, 0.20, 0.20, 0.05, 0.05, 0.05, 0.025, 0.025, 0.025]
# Run Optimal Control Algorithm
# Define model
model= InventoryControlSolver(time_horizon, max_stock, terminal_cost, demand_dist)
# Solve Backwards Induction
policy, cost= model.fit()
The modular implementation also enables you to run simulations. This help you to see how would your algorithm perform in the real world assuming that the demand is randoml determined by the probability distribution that you initially provided.
demand= model.GenDemand()
sim_data= model.Simulation(demand=demand, initial_stock=0)