alpar@1: # A TRANSPORTATION PROBLEM alpar@1: # alpar@1: # This problem finds a least cost shipping schedule that meets alpar@1: # requirements at markets and supplies at factories. alpar@1: # alpar@1: # References: alpar@1: # Dantzig G B, "Linear Programming and Extensions." alpar@1: # Princeton University Press, Princeton, New Jersey, 1963, alpar@1: # Chapter 3-3. alpar@1: alpar@1: set I; alpar@1: /* canning plants */ alpar@1: alpar@1: set J; alpar@1: /* markets */ alpar@1: alpar@1: set K dimen 2; alpar@1: /* transportation lane */ alpar@1: alpar@1: set L; alpar@1: /* parameters */ alpar@1: alpar@1: param a{i in I}; alpar@1: /* capacity of plant i in cases */ alpar@1: alpar@1: param b{j in J}; alpar@1: /* demand at market j in cases */ alpar@1: alpar@1: param d{i in I, j in J}; alpar@1: /* distance in thousands of miles */ alpar@1: alpar@1: param e{l in L}; alpar@1: /* parameters */ alpar@1: alpar@1: param f; alpar@1: /* freight in dollars per case per thousand miles */ alpar@1: alpar@1: table tab_plant IN "CSV" "plants.csv" : alpar@1: I <- [plant], a ~ capacity; alpar@1: alpar@1: table tab_market IN "CSV" "markets.csv" : alpar@1: J <- [market], b ~ demand; alpar@1: alpar@1: table tab_distance IN "CSV" "distances.csv" : alpar@1: K <- [plant, market], d ~ distance; alpar@1: alpar@1: table tab_parameter IN "CSV" "parameters.csv" : alpar@1: L <- [parameter], e ~ value ; alpar@1: alpar@1: param c{i in I, j in J} := e['transport cost'] * d[i,j] / 1000; alpar@1: /* transport cost in thousands of dollars per case */ alpar@1: alpar@1: var x{(i,j) in K} >= 0; alpar@1: /* shipment quantities in cases */ alpar@1: alpar@1: minimize cost: sum{(i,j) in K} c[i,j] * x[i,j]; alpar@1: /* total transportation costs in thousands of dollars */ alpar@1: alpar@1: s.t. supply{i in I}: sum{(i,j) in K} x[i,j] <= a[i]; alpar@1: /* observe supply limit at plant i */ alpar@1: alpar@1: s.t. demand{j in J}: sum{(i,j) in K} x[i,j] >= b[j]; alpar@1: /* satisfy demand at market j */ alpar@1: alpar@1: solve; alpar@1: alpar@1: table tab_result{(i,j) in K} OUT "CSV" "result.csv" : alpar@1: i ~ plant, j ~ market, x[i,j] ~ shipment; alpar@1: alpar@1: end;