GAMS Example

2024-01-19 04:48
文章标签 example gams

本文主要是介绍GAMS Example,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目:

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
Take the freight to be 90 dollars per thousand miles. Unless otherwise stated, in each consecutive question use the setting from the previous one.

(c) Change the demand at New York to 375 cases and compare the results.
Consider the setting from (c) again. Change the objective function from cost minimization to profit maximization. To do this, maximize the difference between revenue and cost. The revenue in each market can be computed by multiplying the total quantity delivered to that market times the price. In addition to the transportation cost there is a production cost which is equal to a constant times the quantity produced 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 r total revenue ;
variable rmz different 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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/621304

相关文章

Vitis AI 综合实践(DPU example: dpu_resnet50.ipynb)

目录 1. 简介 2. 代码解析 2.1 导入库 2.2 图像预处理 2.3 读取标签 2.4 读取图像 2.5 获取IO形状 2.6 申请内存 2.7 运行推理 2.8 后处理 3. 相关类的介绍 3.1 DpuOverlay 类 3.2 Overlay 类 3.3 Bitsteam 类 3.4 Device 类 3.5 DeviceMeta 元类 3.6 ty

QNN:基于QNN+example重构之后的yolov8det部署

QNN是高通发布的神经网络推理引擎,是SNPE的升级版,其主要功能是: 完成从Pytorch/TensorFlow/Keras/Onnx等神经网络框架到高通计算平台的模型转换; 完成模型的低比特量化(int8),使其能够运行在高通神经网络芯片上; 提供测试工具(qnn-net-run),可以运行网络并保存输出; 提供测试工具(qnn-profile-viewer),可以进行FLOPS、参数量、每

Bluetooth: gatt server example 解读

在 core spec 中有 Example ATT Server contents,这里对此进行解读; Assigned_Numbers.pdf 需要提前准备,可以从 SIG 下载; Step-1 从这个服务看,server handle 是1, 但是第一个 characteristic clare handle是 4,所以不能预设handle 是按顺序连续的; Step-2

example-apisix-1 清空日志之后启动异常处理

异常信息 2024/08/27 11:34:33 [emerg] 1#1: bind() to unix:/usr/local/apisix/conf/config_listen.sock failed (98: Address already in use)nginx: [emerg] bind() to unix:/usr/local/apisix/conf/config_listen.s

Qt Example Callout Extention(about QChart/QGraphicsView/QGraphicsItem)

问题 Qt Example callout 展示了在平面直角坐标系中画tips。知识点涉及到QChart/QGraphicsView/QGraphicsItem。如何在平面直角坐标系中画点、折线、圆、长方形? Example路径 D:\Qt\5.15.2\Src\qtcharts\examples\charts\callout\callout.cpp 代码 main #include

MPC5 software example list

MPC5 software example list

五 Example 3: Connections to Remote Nodes using a Registry

QRemoteObjectRegistry类有什么用?可以参考下图: 在某些应用程序中,需要有多个源,而为每个副本分别连接到每个源则显得很冗余,因此QRemoteObjectRegistryHost的任务是为多个源提供一个连接点,并通过它连接每个副本。 QRemoteObjectRegistry类型的registry属性。而它有两个关键信号: void remoteObjectAdded(c

Java --- serial port communication example codes

/** public SerialBean(int PortID) 本函数构造一个指向特定串口的SerialBean,该串口由参数PortID所指定。PortID = 1 表示COM1,PortID = 2 表示COM2,由此类推。 public int Initialize() 本函数初始化所指定的串口并返回初始化结果。如果初始化成功返回1,否则返回-1。初始化的结果是该串口被Serial

RAG_Example

今天尝试基于langchain进行LLM RAG搭建,感觉使用难度没有想象中大。具体流程参考末尾链接。 主要流程包括下面几个模块,每一个模块都有很多选择,而不是唯一解。 但这里可以感受到潜在的几个问题 1. 文本转换过程中,PDF的信息可能会丢失和损坏。比如对于一个只包含很多小标题的文档,我怀疑是否能够获得足够多的有效信息。此外,一些文档中的信息,是通过图文结合的方式,这种信息是否能有效获取

PLC Tutorial 1 An example

在教程给出的示例工程中,变量区申明的变量 如果带有%Q或者%I会自动添加在PLC instance中 Q表示这个变量是一个输出变量,*表示自动分配地址 I表示这个变量是一个输出入量,*表示自动分配地址 虚拟轴的运动 点击轴,在enable中,点击set,在点击all,使得该轴的所有参数都能够被控制。这一步是使能操作。 在这一步结束之后,可以在Status看到状态 下方2的所有按钮是对这个轴的