~jdpipe/ascend/trunk-old

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