alpar@1
|
1 |
# A TRANSPORTATION PROBLEM
|
alpar@1
|
2 |
#
|
alpar@1
|
3 |
# This problem finds a least cost shipping schedule that meets
|
alpar@1
|
4 |
# requirements at markets and supplies at factories.
|
alpar@1
|
5 |
#
|
alpar@1
|
6 |
# References:
|
alpar@1
|
7 |
# Dantzig G B, "Linear Programming and Extensions."
|
alpar@1
|
8 |
# Princeton University Press, Princeton, New Jersey, 1963,
|
alpar@1
|
9 |
# Chapter 3-3.
|
alpar@1
|
10 |
|
alpar@1
|
11 |
set I;
|
alpar@1
|
12 |
/* canning plants */
|
alpar@1
|
13 |
|
alpar@1
|
14 |
set J;
|
alpar@1
|
15 |
/* markets */
|
alpar@1
|
16 |
|
alpar@1
|
17 |
set K dimen 2;
|
alpar@1
|
18 |
/* transportation lane */
|
alpar@1
|
19 |
|
alpar@1
|
20 |
set L;
|
alpar@1
|
21 |
/* parameters */
|
alpar@1
|
22 |
|
alpar@1
|
23 |
param a{i in I};
|
alpar@1
|
24 |
/* capacity of plant i in cases */
|
alpar@1
|
25 |
|
alpar@1
|
26 |
param b{j in J};
|
alpar@1
|
27 |
/* demand at market j in cases */
|
alpar@1
|
28 |
|
alpar@1
|
29 |
param d{i in I, j in J};
|
alpar@1
|
30 |
/* distance in thousands of miles */
|
alpar@1
|
31 |
|
alpar@1
|
32 |
param e{l in L};
|
alpar@1
|
33 |
/* parameters */
|
alpar@1
|
34 |
|
alpar@1
|
35 |
param f;
|
alpar@1
|
36 |
/* freight in dollars per case per thousand miles */
|
alpar@1
|
37 |
|
alpar@1
|
38 |
table tab_plant IN "CSV" "plants.csv" :
|
alpar@1
|
39 |
I <- [plant], a ~ capacity;
|
alpar@1
|
40 |
|
alpar@1
|
41 |
table tab_market IN "CSV" "markets.csv" :
|
alpar@1
|
42 |
J <- [market], b ~ demand;
|
alpar@1
|
43 |
|
alpar@1
|
44 |
table tab_distance IN "CSV" "distances.csv" :
|
alpar@1
|
45 |
K <- [plant, market], d ~ distance;
|
alpar@1
|
46 |
|
alpar@1
|
47 |
table tab_parameter IN "CSV" "parameters.csv" :
|
alpar@1
|
48 |
L <- [parameter], e ~ value ;
|
alpar@1
|
49 |
|
alpar@1
|
50 |
param c{i in I, j in J} := e['transport cost'] * d[i,j] / 1000;
|
alpar@1
|
51 |
/* transport cost in thousands of dollars per case */
|
alpar@1
|
52 |
|
alpar@1
|
53 |
var x{(i,j) in K} >= 0;
|
alpar@1
|
54 |
/* shipment quantities in cases */
|
alpar@1
|
55 |
|
alpar@1
|
56 |
minimize cost: sum{(i,j) in K} c[i,j] * x[i,j];
|
alpar@1
|
57 |
/* total transportation costs in thousands of dollars */
|
alpar@1
|
58 |
|
alpar@1
|
59 |
s.t. supply{i in I}: sum{(i,j) in K} x[i,j] <= a[i];
|
alpar@1
|
60 |
/* observe supply limit at plant i */
|
alpar@1
|
61 |
|
alpar@1
|
62 |
s.t. demand{j in J}: sum{(i,j) in K} x[i,j] >= b[j];
|
alpar@1
|
63 |
/* satisfy demand at market j */
|
alpar@1
|
64 |
|
alpar@1
|
65 |
solve;
|
alpar@1
|
66 |
|
alpar@1
|
67 |
table tab_result{(i,j) in K} OUT "CSV" "result.csv" :
|
alpar@1
|
68 |
i ~ plant, j ~ market, x[i,j] ~ shipment;
|
alpar@1
|
69 |
|
alpar@1
|
70 |
end;
|