GAMS Example
来源:互联网 发布:火影忍者特效软件 编辑:程序博客网 时间:2024/04/26 10:44
题目:
Exercise # 3 (GAMS (2009))
Question 1 Given the transportation problem with the following parameters:
Distance in 1000s of miles New York Chicago Topeka
Seattle 2.5 1.7 1.8
San Diego 2.3 1.9 1.4
Demand at markets
Plant capacities
New York 400
Seattle 350
Chicago 300
San Diego 600
Topeka 275
Takethe freight to be 90 dollars per thousand miles. Unless otherwisestated, in each consecutive question use the setting from the previousone.
(c) Change the demand at New York to 375 cases and compare the results.
Considerthe setting from (c) again. Change the objective function fromcost minimization to profit maximization. To do this, maximize thedifference between revenue and cost. The revenue in each market can becomputed by multiplying the total quantity delivered to that markettimes the price. In addition to the transportation cost there is aproduction cost which is equal to a constant times the quantityproduced and the constants are different for each plant as given below.
Seattle 0.2
San Diego 0.4
The prices are given by:
New York Chicago Topeka
0.9 0.7 0.8
The values in both tables are given in thousands of dollars per case. Implement the changes in GAMS.
题解:
* initial Sets
set i markets / NewYork, Chicago, Topeka / ;
set j Plant capacities / Seattle, SanDiego / ;
* initial parameters
parameter a(i) Demand at markets
/ NewYork 375
Chicago 300
Topeka 275 / ;
parameter b(j) Plant capacities
/ Seattle 350
SanDiego 600 / ;
parameter ar(i) Market Preis in thousands of dollars per case
/ NewYork 0.9
Chicago 0.7
Topeka 0.8 / ;
parameter bc(j) Plant cost in thousands of dollars per case
/ Seattle 0.2
SanDiego 0.4 / ;
* initial table
table d(i,j) Distance in 1000s of miles
Seattle SanDiego
NewYork 2.5 2.3
Chicago 1.7 1.9
Topeka 1.8 1.4 ;
*initial scalar
scalar f the freight to be 90 dollars per thousand miles /90/ ;
parameter c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
* initial variables
positive variable x(i,j) quantities of freight ;
variable z total transport cost ;
variable z1 total production cost ;
variable rtotal revenue ;
variable rmzdifferent between z and r ;
*initial eqs
equations
cost total transport cost (1)
cost1 total production cost (1)
revenue total revenue (1)
diff revenue - cost (1)
demand(i) demand functions (3)
supply(j) supply functions (2) ;
* transportation cost * quantity
cost.. z =e= sum((i,j),c(i,j)*x(i,j)) ;
* st.
demand(i).. sum(j,x(i,j)) =g= a(i) ;
* st.
supply(j).. sum(i,x(i,j)) =l= b(j) ;
* production cost * quantity
cost1.. z1 =e= sum((i,j),bc(j)*x(i,j)) ;
* market price * quantity
revenue.. r =e= sum((i,j),x(i,j)*ar(i)) ;
* revenue
diff.. rmz =e= r - z - z1;
* modeling and solve
model transport /all/ ;
solve transport using lp maximizing rmz ;
display x.l,z.l,z1.l,r.l,rmz.l;
编译器:
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 1
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
C o m p i l a t i o n
1 * initial Sets
2 set i markets / NewYork, Chicago, Topeka / ;
3 set j Plant capacities / Seattle, SanDiego / ;
4
5 * initial parameters
6 parameter a(i) Demand at markets
7 / NewYork 375
8 Chicago 300
9 Topeka 275 / ;
10
11 parameter b(j) Plant capacities
12 / Seattle 350
13 SanDiego 600 / ;
14
15 parameter ar(i) Market Preis in thousands of dollars per case
16 / NewYork 0.9
17 Chicago 0.7
18 Topeka 0.8 / ;
19
20 parameter bc(j) Plant cost in thousands of dollars per case
21 / Seattle 0.2
22 SanDiego 0.4 / ;
23
24 * initial table
25 table d(i,j) Distance in 1000s of miles
26 Seattle SanDiego
27 NewYork 2.5 2.3
28 Chicago 1.7 1.9
29 Topeka 1.8 1.4 ;
30
31 *initial scalar
32 scalar f the freight to be 90 dollars per thousand miles /90/ ;
33
34 parameter c(i,j) transport cost in thousands of dollars per case ;
35 c(i,j) = f * d(i,j) / 1000 ;
36
37 * initial variables
38 positive variable x(i,j) quantities of freight ;
39 variable z total transport cost ;
40 variable z1 total production cost ;
41 variable r total revenue ;
42 variable rmz different between z and r ;
43
44 *initial eqs
45 equations
46 cost total transport cost (1)
47 cost1 total production cost (1)
48 revenue total revenue (1)
49 diff revenue - cost (1)
50 demand(i) demand functions (3)
51 supply(j) supply functions (2) ;
52
53 * transportation cost * quantity
54 cost.. z =e= sum((i,j),c(i,j)*x(i,j)) ;
55
56 * st.
57 demand(i).. sum(j,x(i,j)) =g= a(i) ;
58
59 * st.
60 supply(j).. sum(i,x(i,j)) =l= b(j) ;
61
62 * production cost * quantity
63 cost1.. z1 =e= sum((i,j),bc(j)*x(i,j)) ;
64
65 * market price * quantity
66 revenue.. r =e= sum((i,j),x(i,j)*ar(i)) ;
67
68 * revenue
69 diff.. rmz =e= r - z - z1;
70
71 * modeling and solve
72 model transport /all/ ;
73 solve transport using lp maximizing rmz ;
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
C o m p i l a t i o n
74
75 display x.l,z.l,z1.l,r.l,rmz.l;
76
77
COMPILATION TIME = 0.002 SECONDS 3 Mb LEX233-233 Oct 30, 2009
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 3
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Equation Listing SOLVE transport Using LP From line 73
---- cost =E= total transport cost (1)
cost.. - 0.225*x(NewYork,Seattle) - 0.207*x(NewYork,SanDiego) - 0.153*x(Chicago,Seattle) - 0.171*x(Chicago,SanDiego)
- 0.162*x(Topeka,Seattle) - 0.126*x(Topeka,SanDiego) + z =E= 0 ; (LHS = 0)
---- cost1 =E= total production cost (1)
cost1.. - 0.2*x(NewYork,Seattle) - 0.4*x(NewYork,SanDiego) - 0.2*x(Chicago,Seattle) - 0.4*x(Chicago,SanDiego)
- 0.2*x(Topeka,Seattle) - 0.4*x(Topeka,SanDiego) + z1 =E= 0 ; (LHS = 0)
---- revenue =E= total revenue (1)
revenue.. - 0.9*x(NewYork,Seattle) - 0.9*x(NewYork,SanDiego) - 0.7*x(Chicago,Seattle) - 0.7*x(Chicago,SanDiego)
- 0.8*x(Topeka,Seattle) - 0.8*x(Topeka,SanDiego) + r =E= 0 ; (LHS = 0)
---- diff =E= revenue - cost (1)
diff.. z + z1 - r + rmz =E= 0 ; (LHS = 0)
---- demand =G= demand functions (3)
demand(NewYork).. x(NewYork,Seattle) + x(NewYork,SanDiego) =G= 375 ; (LHS = 0, INFES = 375 ****)
demand(Chicago).. x(Chicago,Seattle) + x(Chicago,SanDiego) =G= 300 ; (LHS = 0, INFES = 300 ****)
demand(Topeka).. x(Topeka,Seattle) + x(Topeka,SanDiego) =G= 275 ; (LHS = 0, INFES = 275 ****)
---- supply =L= supply functions (2)
supply(Seattle).. x(NewYork,Seattle) + x(Chicago,Seattle) + x(Topeka,Seattle) =L= 350 ; (LHS = 0)
supply(SanDiego).. x(NewYork,SanDiego) + x(Chicago,SanDiego) + x(Topeka,SanDiego) =L= 600 ; (LHS = 0)
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 4
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Column Listing SOLVE transport Using LP From line 73
---- x quantities of freight
x(NewYork,Seattle)
(.LO, .L, .UP, .M = 0, 0, +INF, 0)
-0.225 cost
-0.2 cost1
-0.9 revenue
1 demand(NewYork)
1 supply(Seattle)
x(NewYork,SanDiego)
(.LO, .L, .UP, .M = 0, 0, +INF, 0)
-0.207 cost
-0.4 cost1
-0.9 revenue
1 demand(NewYork)
1 supply(SanDiego)
x(Chicago,Seattle)
(.LO, .L, .UP, .M = 0, 0, +INF, 0)
-0.153 cost
-0.2 cost1
-0.7 revenue
1 demand(Chicago)
1 supply(Seattle)
REMAINING 3 ENTRIES SKIPPED
---- z total transport cost
z
(.LO, .L, .UP, .M = -INF, 0, +INF, 0)
1 cost
1 diff
---- z1 total production cost
z1
(.LO, .L, .UP, .M = -INF, 0, +INF, 0)
1 cost1
1 diff
---- r total revenue
r
(.LO, .L, .UP, .M = -INF, 0, +INF, 0)
1 revenue
-1 diff
---- rmz different between z and r
rmz
(.LO, .L, .UP, .M = -INF, 0, +INF, 0)
1 diff
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 5
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Model Statistics SOLVE transport Using LP From line 73
MODEL STATISTICS
BLOCKS OF EQUATIONS 6 SINGLE EQUATIONS 9
BLOCKS OF VARIABLES 5 SINGLE VARIABLES 10
NON ZERO ELEMENTS 37
GENERATION TIME = 0.003 SECONDS 4 Mb LEX233-233 Oct 30, 2009
EXECUTION TIME = 0.003 SECONDS 4 Mb LEX233-233 Oct 30, 2009
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 6
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Solution Report SOLVE transport Using LP From line 73
S O L V E S U M M A R Y
MODEL transport OBJECTIVE rmz
TYPE LP DIRECTION MAXIMIZE
SOLVER CPLEX FROM LINE 73
**** SOLVER STATUS 1 Normal Completion
**** MODEL STATUS 1 Optimal
**** OBJECTIVE VALUE 298.4250
RESOURCE USAGE, LIMIT 0.000 1000.000
ITERATION COUNT, LIMIT 2 2000000000
ILOG CPLEX Nov 1, 2009 23.3.1 LEX 13908.14234 LEI x86_64/Linux
Cplex 12.1.0, GAMS Link 34
LP status(1): optimal
Optimal solution found.
Objective : 298.425000
LOWER LEVEL UPPER MARGINAL
---- EQU cost . . . -1.0000
---- EQU cost1 . . . -1.0000
---- EQU revenue . . . 1.0000
---- EQU diff . . . 1.0000
cost total transport cost (1)
cost1 total production cost (1)
revenue total revenue (1)
diff revenue - cost (1)
---- EQU demand demand functions (3)
LOWER LEVEL UPPER MARGINAL
NewYork 375.0000 375.0000 +INF .
Chicago 300.0000 300.0000 +INF -0.1280
Topeka 275.0000 275.0000 +INF -0.0190
---- EQU supply supply functions (2)
LOWER LEVEL UPPER MARGINAL
Seattle -INF 350.0000 350.0000 0.4750
SanDiego -INF 600.0000 600.0000 0.2930
---- VAR x quantities of freight
LOWER LEVEL UPPER MARGINAL
NewYork.Seattle . 50.0000 +INF .
NewYork.SanDiego . 325.0000 +INF .
Chicago.Seattle . 300.0000 +INF .
Chicago.SanDiego . . +INF -0.0360
Topeka .Seattle . . +INF -0.0180
Topeka .SanDiego . 275.0000 +INF .
LOWER LEVEL UPPER MARGINAL
---- VAR z -INF 159.0750 +INF .
---- VAR z1 -INF 310.0000 +INF .
---- VAR r -INF 767.5000 +INF .
---- VAR rmz -INF 298.4250 +INF .
z total transport cost
z1 total production cost
r total revenue
rmz different between z and r
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 7
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Solution Report SOLVE transport Using LP From line 73
**** REPORT SUMMARY : 0 NONOPT
0 INFEASIBLE
0 UNBOUNDED
GAMS Rev 233 LEX-LEI 23.3.1 x86_64/Linux 11/19/09 02:44:49 Page 8
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
E x e c u t i o n
---- 75 VARIABLE x.L quantities of freight
Seattle SanDiego
NewYork 50.000 325.000
Chicago 300.000
Topeka 275.000
---- 75 VARIABLE z.L = 159.075 total transport cost
VARIABLE z1.L = 310.000 total production cost
VARIABLE r.L = 767.500 total revenue
VARIABLE rmz.L = 298.425 different between z and r
EXECUTION TIME = 0.001 SECONDS 3 Mb LEX233-233 Oct 30, 2009
USER: GAMS Development Corporation, Washington, DC G871201/0000CA-ANY
Free Demo, 202-342-0180, sales@gams.com, www.gams.com DC0000
**** FILE SUMMARY
Input /home/raymond/Desktop/TODO/gams/HW2.gms
Output /home/raymond/Desktop/TODO/gams/HW2.lst
- GAMS Example
- GAMS Solution for Ex5.
- C#程序调用GAMS
- GAMS的使用
- notepad++ 编辑GAMS文件
- GNUPLOT和GAMS的画图
- example
- example
- Example
- example
- Example
- Example
- Example
- Example
- example
- Example
- Example
- 使用GAMS读取Excel和保存Excel
- 输入输出重定向
- inverse="true" 放弃维护关联关系=true
- verilog 实现DES密码算法
- 视频格式、音频格式详细分析与讲解
- C# WinForm开发系列 - Excel
- GAMS Example
- 开博了
- 单击BindingNavigator上的删除按钮时弹出确认对话框
- 自己有点疯了
- Programming Windows (一)_ Windows 的运行机制
- Asp.net生命周期
- (zz)C++类的继承与多重继承的访问控制
- css层的定位position、absolute、relative层叠加的五条叠加法则
- 夏令时到底是个什么东西?