HLPL / VerTeX Modelling Language Documentation

← lessons

Shipping — one source

Distribute a fixed supply.

Chapter: VIII — Transportation · lesson id shipping-one-source · practice lesson


Simplest transportation: one warehouse with 100 units to distribute across three destinations. Each destination has a minimum demand. Shipping to destination j costs c_j per unit. Minimise total cost.

Demands {20, 30, 40} sum to 90; you have 100 to send. Where does the slack of 10 go? Onto the cheapest route.

Predict before running

Supply 100 must all ship; minimum demands {20, 30, 40} sum to 90, costs {3, 5, 4}. Where do the 10 slack units land?

Starter code

model shipping
var 0 <= x1
var 0 <= x2
var 0 <= x3
constr x1 >= 20
constr x2 >= 30
constr x3 >= 40
constr x1 + x2 + x3 = 100
min 3*x1 + 5*x2 + 4*x3
end

import elytica
def main():
  elytica.init_model("shipping")
  elytica.run_model("shipping")
  for i in [1,2,3]:
    print("x"+str(i), "=", elytica.get_variable_value("shipping", "x"+str(i)))
  print("obj =", elytica.get_best_primal_bound("shipping"))
  return 0

Hint

c₁ = 3 is the cheapest. The extra 10 units pile onto destination 1.

What counts as correct

Mastery variant

New demands and costs. Where does the slack land this time?

model shipping_v
var 0 <= x1
var 0 <= x2
var 0 <= x3
constr x1 >= 15
constr x2 >= 25
constr x3 >= 30
constr x1 + x2 + x3 = 80
min 4*x1 + 6*x2 + 2*x3
end

import elytica
def main():
  elytica.init_model("shipping_v")
  elytica.run_model("shipping_v")
  for i in [1,2,3]:
    print("x"+str(i), "=", elytica.get_variable_value("shipping_v", "x"+str(i)))
  print("obj =", elytica.get_best_primal_bound("shipping_v"))
  return 0

Read this through MCP: read with path: "lessons/shipping-one-source", or resource hlpl://lessons/shipping-one-source.