What if total supply < total demand?
Chapter: VIII — Transportation · lesson id transportation-shortage · practice lesson
Real distribution problems are often unbalanced. If sources can't fully cover demand, you have to relax the demand constraint from = to ≤ — destinations get at most their demand, possibly less. Add a penalty term to the objective for unmet demand, or just maximise what gets shipped.
Here total supply is 80 and demand is 110. Maximise total shipped value (per-destination prices p_j) minus transport cost.
Total supply 80 < total demand 110. Which destinations get fully served?
model transport
set I = {1, 2}
set J = {1, 2, 3}
const c = {{3, 5, 7}, {6, 4, 2}}, forall i in I, forall j in J
const supply = {40, 40}, forall i in I
const demand = {30, 40, 40}, forall j in J
const price = {10, 12, 9}, forall j in J
var 0 <= x, forall i in I, forall j in J
constr sum_{j in J}{x_{i,j}} <= supply_{i}, forall i in I
constr sum_{i in I}{x_{i,j}} <= demand_{j}, forall j in J
max sum_{i in I}{sum_{j in J}{[price_{j} - c_{i,j}] * x_{i,j}}}
end
import elytica
def main():
elytica.init_model("transport")
elytica.run_model("transport")
for i in [1,2]:
for j in [1,2,3]:
name = "x"+str(i)+","+str(j)
print(name, "=", elytica.get_variable_value("transport", name))
print("obj =", elytica.get_best_primal_bound("transport"))
return 0
Switch to max. Use ≤ on destination demand. Solver will favour high-price destinations.
no-error — Model solvesstdout-contains — Output reports an objectivecode-contains — Reads the objective from the solver (no hardcoding)Different prices and a tighter shortfall. Same ≤ relaxation lets demand go unmet.
model transport_v
set I = {1, 2}
set J = {1, 2, 3}
const c = {{4, 2, 5}, {3, 5, 1}}, forall i in I, forall j in J
const supply = {30, 30}, forall i in I
const demand = {25, 35, 25}, forall j in J
const price = {8, 9, 7}, forall j in J
var 0 <= x, forall i in I, forall j in J
constr sum_{j in J}{x_{i,j}} <= supply_{i}, forall i in I
constr sum_{i in I}{x_{i,j}} <= demand_{j}, forall j in J
max sum_{i in I}{sum_{j in J}{[price_{j} - c_{i,j}] * x_{i,j}}}
end
import elytica
def main():
elytica.init_model("transport_v")
elytica.run_model("transport_v")
for i in [1,2]:
for j in [1,2,3]:
name = "x"+str(i)+","+str(j)
print(name, "=", elytica.get_variable_value("transport_v", name))
print("obj =", elytica.get_best_primal_bound("transport_v"))
return 0
Read this through MCP: read with path: "lessons/transportation-shortage", or resource hlpl://lessons/transportation-shortage.