1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
REQUIRE "atoms.a4l";
(*
Solution of the 'toy' problem given in the GAMS documentation at
http://www.gams.com/docs/example.htm
"Here is a standard algebraic description of the problem, which is to
minimize the cost of shipping goods from 2 plants to 3 markets, subject
to supply and demand constraints."
This model doesn't currently agree with the GAMS solution when solving using
CONOPT. We're still debugging it.
*)
MODEL markets;
(* canning plants *)
I IS_A set OF symbol_constant;
I :== ['Seattle','San Diego'];
(* markets *)
J IS_A set OF symbol_constant;
J :== ['New York','Chicago','Topeka'];
(* plant capacities *)
A[I] IS_A mass_rate_constant;
A['Seattle'] :== 350 {kg/d};
A['San Diego'] :== 600 {kg/d};
(* market demands *)
B[J] IS_A mass_rate_constant;
B['New York'] :== 325 {kg/d};
B['Chicago'] :== 300 {kg/d};
B['Topeka'] :== 275 {kg/d};
(* distances *)
D[I][J] IS_A distance_constant;
D['Seattle']['New York'] :== 2500 {mi}; (* thousands of miles *)
D['Seattle']['Chicago'] :== 1700 {mi};
D['Seattle']['Topeka'] :== 1800 {mi};
D['San Diego']['New York'] :== 2500 {mi};
D['San Diego']['Chicago'] :== 1800 {mi};
D['San Diego']['Topeka'] :== 1400 {mi};
(* freight costs *)
F IS_A cost_per_mass_per_distance_constant;
F :== 90 {USD/kg} / 1000 {mi};
C[I][J] IS_A cost_per_mass_constant; (* shipping cost per mass, for each route *)
FOR i IN I CREATE
FOR j IN J CREATE
C[i][j] :== F * D[i][j] ;
END FOR;
END FOR;
(* variables *)
X[I][J] IS_A mass_rate;
Z IS_A cost_per_time;
(* equations *)
COST: Z = SUM[SUM[C[i][j]*X[i][j] | i IN I] | j IN J];
supplyslack[I] IS_A mass_rate;
FOR i IN I CREATE
SUPPLY[i]: SUM[X[i][j] | j IN J] = A[i] + supplyslack[i];
END FOR;
demandslack[J] IS_A mass_rate;
FOR j IN J CREATE
DEMAND[j]: SUM[X[i][j] | i IN I] = B[j] + demandslack[j];
END FOR;
MINEXPR: MINIMIZE Z;
METHODS
METHOD on_load;
Z := 0 {USD/d};
END on_load;
METHOD self_test;
ASSERT abs(Z - 153.675 {USD/d}) < 0.001 {USD/d};
ASSERT abs(X['Seattle']['New York'] - 50 {kg/d}) < 0.1 {kg/d};
ASSERT abs(X['Seattle']['Chicago'] - 300 {kg/d}) < 0.1 {kg/d};
ASSERT abs(X['Seattle']['Topeka'] - 0 {kg/d}) < 0.1 {kg/d};
END self_test;
END markets;
|