Inventory carries forward.
Chapter: IX — Resource allocation · lesson id multi-period · practice lesson
Add time. Demand changes period to period, and so does production capacity. You can pre-produce and carry inventory forward — at a cost per unit per period.
Demand {30, 50, 20} over three periods, capacity {60, 30, 25}. Period 2 demand (50) exceeds capacity (30) — you have to pre-produce 20 units in period 1 and carry them. Carrying cost = 2 per unit per period.
Minimum carry: 20 units from t1 to t2 → carry cost 2·20 = 40.
Period 2 demand 50 exceeds period 2 capacity 30. How does the solver cope?
model multi_period
set T = {1, 2, 3}
const demand = {30, 50, 20}, forall t in T
const capacity = {60, 30, 25}, forall t in T
const inv_cost = 2
var 0 <= prod, forall t in T
var 0 <= inv, forall t in T
constr prod_{t} <= capacity_{t}, forall t in T
constr inv_{1} = prod_{1} - demand_{1}
constr inv_{2} = inv_{1} + prod_{2} - demand_{2}
constr inv_{3} = inv_{2} + prod_{3} - demand_{3}
min sum_{t in T}{inv_cost * inv_{t}}
end
import elytica
def main():
elytica.init_model("multi_period")
elytica.run_model("multi_period")
for i in [1,2,3]:
print("prod"+str(i), "=", elytica.get_variable_value("multi_period", "prod"+str(i)))
for i in [1,2,3]:
print("inv"+str(i), "=", elytica.get_variable_value("multi_period", "inv"+str(i)))
print("obj =", elytica.get_best_primal_bound("multi_period"))
return 0
Inventory balance: inv_{t} = inv_{t-1} + prod_{t} − demand_{t}.
no-error — Model solvesnumeric-match — Minimum carrying cost is 40 (carry 20 units t1→t2)code-contains — Reads the objective from the solver (no hardcoding)Different demand, capacity, and a higher carrying cost. Where does the bottleneck sit?
model multi_period_v
set T = {1, 2, 3}
const demand = {20, 45, 30}, forall t in T
const capacity = {40, 25, 35}, forall t in T
const inv_cost = 3
var 0 <= prod, forall t in T
var 0 <= inv, forall t in T
constr prod_{t} <= capacity_{t}, forall t in T
constr inv_{1} = prod_{1} - demand_{1}
constr inv_{2} = inv_{1} + prod_{2} - demand_{2}
constr inv_{3} = inv_{2} + prod_{3} - demand_{3}
min sum_{t in T}{inv_cost * inv_{t}}
end
import elytica
def main():
elytica.init_model("multi_period_v")
elytica.run_model("multi_period_v")
for i in [1,2,3]:
print("prod"+str(i), "=", elytica.get_variable_value("multi_period_v", "prod"+str(i)))
for i in [1,2,3]:
print("inv"+str(i), "=", elytica.get_variable_value("multi_period_v", "inv"+str(i)))
print("obj =", elytica.get_best_primal_bound("multi_period_v"))
return 0
Read this through MCP: read with path: "lessons/multi-period", or resource hlpl://lessons/multi-period.