GAMS示例——运输问题 【代码及演算过程】
<P><STRONG>GAMS示例</STRONG></P><P class=ptitle>下面这个问题主要是用来举例说明GAMS是如何让您以一种自然的方式建立模型.GAMS能够处理大的多和高度复杂的问题.在这里只展示了GAMS的很少一部分的基本特征.</P>
<TABLE cellSpacing=0 cellPadding=0 width="15%" border=0>
<TBODY>
<TR>
<TD width=5 bgColor=#cc3300> </TD>
<TD bgColor=#000066 height=20><STRONG> </STRONG><SPAN class=fontWhiteColor><FONT color=white>代数描述</FONT></SPAN></TD></TR></TBODY></TABLE>
<P class=ptitle>下面是问题的标准的代数描述,这是用来最小化把货物从2个工厂运输到3个市场的费用.受约束于供需约束.</P>
<P class=ptitle><STRONG>指标:</STRONG></P>
<P><SPAN class=fontBold><EM> i</EM></SPAN>=工厂(plants)<BR><SPAN class=fontBold><EM>j</EM></SPAN>=市场(markets)</P>
<P><STRONG>给定的数据:</STRONG></P>
<P><IMG height=17 src="http://www.cabit.com.cn/pic/gams/example/ai.gif" width=20 align=absMiddle border=0>=在工厂<SPAN class=fontBold>i</SPAN>日常供应量(批数cases)<BR><IMG height=18 src="http://www.cabit.com.cn/pic/gams/example/bj.gif" width=20 align=absMiddle border=0>=在市场<SPAN class=fontBold>j</SPAN>的日常需求量(批数cases) <BR><IMG height=21 src="http://www.cabit.com.cn/pic/gams/example/dij.gif" width=23 align=absMiddle border=0>=在工厂<SPAN class=fontBold>i</SPAN>和市场<SPAN class=fontBold>j</SPAN>之间的距离(千英里)<BR><IMG height=18 src="http://www.cabit.com.cn/pic/gams/example/cij.gif" width=22 align=absMiddle border=0>=在工厂<SPAN class=fontBold>i</SPAN>和市场<SPAN class=fontBold>j</SPAN>之间每单位的运输费用($/批/千英里)</P>
<TABLE cellSpacing=1 cellPadding=1 width="70%" border=1>
<TBODY>
<TR>
<TD align=middle colSpan=4 height=20>距离</TD>
<TD height=20> </TD></TR>
<TR>
<TD height=20> </TD>
<TD align=middle colSpan=3 height=20>市场</TD>
<TD height=20> </TD></TR>
<TR>
<TD align=middle width="20%" height=20>工厂</TD>
<TD align=left width="20%" height=20>New York</TD>
<TD align=left width="20%" height=20>Chicago</TD>
<TD align=left width="20%" height=20>Topeka</TD>
<TD align=left height=20>供应量</TD></TR>
<TR>
<TD align=middle width="20%" height=20>Seattle</TD>
<TD width="20%" height=20>2.5</TD>
<TD width="20%" height=20>1.7</TD>
<TD width="20%" height=20>1.8</TD>
<TD height=20>350</TD></TR>
<TR>
<TD align=middle width="20%" height=20>San Diego</TD>
<TD width="20%" height=20>2.5</TD>
<TD width="20%" height=20>1.8</TD>
<TD width="20%" height=20>1.4</TD>
<TD height=20>600</TD></TR>
<TR>
<TD align=middle width="20%" height=20>需求量</TD>
<TD width="20%" height=20>325</TD>
<TD width="20%" height=20>300</TD>
<TD width="20%" height=20>275</TD>
<TD height=20> </TD></TR></TBODY></TABLE>
<P class=ptitle><EM class=fontBold> F</EM>=每批每千英里的费用$</P>
<P><STRONG>决策变量:</STRONG></P>
<P><IMG height=19 src="http://www.cabit.com.cn/pic/gams/example/xij.gif" width=23 align=absMiddle border=0>=日常从工厂<SPAN class=fontBold>i</SPAN>运输到市场<SPAN class=fontBold>j</SPAN>的总量(批数cases)<BR>这里<IMG height=25 src="http://www.cabit.com.cn/pic/gams/example/xij0.gif" width=48 align=absMiddle border=0> 适用所有<SPAN class=fontBold>i</SPAN>,<SPAN class=fontBold>j</SPAN></P>
<P><STRONG>约束:</STRONG></P>
<P>在工厂<SPAN class=fontBold>i</SPAN>的供应量**(批数cases):<IMG height=30 src="http://www.cabit.com.cn/pic/gams/example/xijai.gif" width=81 align=absMiddle border=0>适用所有的<SPAN class=fontBold>i</SPAN><BR>在市场<SPAN class=fontBold>j</SPAN>的需求量:<IMG height=27 src="http://www.cabit.com.cn/pic/gams/example/xijbj.gif" width=79 align=absMiddle border=0>适用所有的<SPAN class=fontBold>j</SPAN></P>
<P><STRONG>目标函数:</STRONG></P>
<P><SPAN class=fontBold>Minimize <IMG height=28 src="http://www.cabit.com.cn/pic/gams/example/cijxij.gif" width=98 align=absMiddle border=0></SPAN> (千元)</P>
<TABLE cellSpacing=0 cellPadding=0 width="15%" border=0>
<TBODY>
<TR>
<TD width=5 bgColor=#cc3300><FONT color=white> </FONT></TD>
<TD bgColor=#000066 height=20><FONT color=white> <SPAN class=fontWhiteColor><SPAN class=ptitle>GAMS模型</SPAN></SPAN></FONT></TD></TR></TBODY></TABLE>
<P class=ptitle>同样的模型在GAMS中建模.简练的代数描述使得模型高度紧凑,并带有逻辑结构.内部的文档,比如对参数的解释和测量的单位,使得模型很容易读懂.<BR><IMG height=509 src="http://www.cabit.com.cn/pic/gams/example/sets1.gif" width=585 border=0>
<P class=ptitle><STRONG>集合(Sets)</STRONG></P>
<P class=ptitle><IMG height=62 src="http://www.cabit.com.cn/pic/gams/example/set2.gif" width=465></P>
<P class=ptitle>GAMS让您以直接的方式指定指标:声明和命名集合(这里是I和J),并列举它们的元素.</P>
<P class=ptitle><STRONG>参数</STRONG></P>
<P class=ptitle><IMG height=145 src="http://www.cabit.com.cn/pic/gams/example/parameter1.gif" width=366></P>
<P class=ptitle>这里的数据输入被作为指标参数A(I)和B(J),值简单的被列出.</P>
<P class=ptitle>GAMS让您可以在模型的任意位置放置解释性文本(以小写格式显示),当您在开发它时.您的注释自动被结合到输出报告中的合适位置.</P>
<P class=ptitle><STRONG>表格</STRONG></P>
<P class=ptitle><IMG height=79 src="http://www.cabit.com.cn/pic/gams/example/table1.gif" width=461 border=0><BR>数据同样能够以方便的表格形式输入.GAMS让您以数据的基本形式来输入数据-转换是特定的代数化的.</P>
<P class=ptitle><STRONG>标量(Scalar)</STRONG></P>
<P class=ptitle><IMG height=27 src="http://www.cabit.com.cn/pic/gams/example/scalar1.gif" width=534><BR>常量能够被声明为标量,它的值是指定的.
<P class=ptitle><STRONG>数据处理</STRONG></P>
<P class=ptitle><IMG height=47 src="http://www.cabit.com.cn/pic/gams/example/parameter2.gif" width=567 border=0></P>
<P class=ptitle>当数据值要被计算前,您首先要声明参数(比如,给它一个符号,随意给它编个指标),然后给它一个代数公式.GAMS将自动进行计算.</P>
<P class=ptitle><STRONG>变量</STRONG></P>
<P class=ptitle><IMG height=74 src="http://www.cabit.com.cn/pic/gams/example/variable1.gif" width=554 border=0></P>
<P class=ptitle>决策变量以代数的方式表达,带有特定的指标.从这种常见的形式,GAMS在域中生成变量的每个实例.</P>
<P class=ptitle>变量可以被指定为下列类型:任意(FREE),正值(POSITIVE),负值(NEGATIVE),二元(BINARY),或者整数(INTEGER).默认是任意(FREE).</P>
<P class=ptitle>目标变量(这里是z)仅被声明,没有指标(index).</P>
<P class=ptitle><STRONG>方程式</STRONG></P>
<P class=ptitle><IMG height=120 src="http://www.cabit.com.cn/pic/gams/example/equaration1.gif" width=421 border=0></P>
<P class=ptitle>目标函数和约束方程式首先被通过指定名字来声明.然后它们的概括的算术公式被声明.GAMS现在已经有了足够的信息(从上面的数据输入和从在方程式中指定的算术关系)来自动生成每个单独的约束声明-就像您能在下面的输出报告中看到的.</P>
<P class=ptitle>=E=表示'equal to' (等于)<BR>=L=表示 'less than or equal to' (小于或等于)<BR>=G=表示'greater than or equal to' (大于或等于)</P>
<P class=ptitle><STRONG>模型声明</STRONG></P>
<P class=ptitle><IMG height=30 src="http://www.cabit.com.cn/pic/gams/example/model1.gif" width=200></P>
<P class=ptitle>模型被指定了一个唯一的名字(这里是TRANSPORT),模型缔造者指定那个方程式应该被包含到这个特别的公式中.在这里我们指定了ALL,也就是说所有的方程式都是模型的一部分.就等于是MODEL TRANSPORT /COST, SUPPLY, DEMAND/ . 这个方程式选择使您能够在单个的GAMS输入文件中以公式表达不同的模型,基于相同或不同的给定数据.</P>
<P class=ptitle><STRONG>求解声明</STRONG></P>
<P class=ptitle><IMG height=31 src="http://www.cabit.com.cn/pic/gams/example/solve1.gif" width=333></P>
<P class=ptitle>求解声明(1)告诉GAMS那个模型要被求解,(2)选择要使用的求解器(在这里是LP求解器),(3)表明优化方向,或者是求最小值,或者是求最大值.(4)指定目标变量.</P>
<TABLE cellSpacing=0 cellPadding=0 width="28%" border=0>
<TBODY>
<TR>
<TD width=5 bgColor=#cc3300> </TD>
<TD bgColor=#000066 height=20> <SPAN class=fontWhiteColor><SPAN class=ptitle><FONT color=white>GAMS输出报告(部分摘录)</FONT></SPAN></SPAN></TD></TR></TBODY></TABLE>
<P class=ptitle>完整的GAMS输出报告比下面列出的部分摘录详细的多,包含了更多的帮助用于解释和诊断您的模型.甚至您能够修改输出格式来符合您的特定的需要.</P>
<P class=ptitle><STRONG>方程式列表</STRONG></P>
<P class=ptitle><STRONG><IMG height=666 src="http://www.cabit.com.cn/pic/gams/example/equarationlist1.gif" width=630 border=0></STRONG></P>
<P class=ptitle>方程式列表显示从在GAMS输入中指定的分区(block)生成的单独的约束.在GAMS中使用者可以以一种非常紧凑的形式写下被索引的方程式分区(block),这将产生大量的单个方程式.在我们的示例中,我们指定了3个方程式分区,生成了6个单独的方程式.</P>
<P class=ptitle><STRONG>列列表</STRONG></P>
<P class=ptitle><STRONG><IMG height=494 src="http://www.cabit.com.cn/pic/gams/example/coloumlist1.gif" width=564 border=0></STRONG></P>
<P class=ptitle>列列表提供信息到生成的单独的变量上.变量X(I,J)扩展出6个单独的变量.当许多变量从一个分区中被生成,默认的列表只显示最初的3个(用户可以修改).</P>
<TABLE cellSpacing=0 cellPadding=0 width="15%" border=0>
<TBODY>
<TR>
<TD width=5 bgColor=#cc3300> </TD>
<TD class=fontWhiteColor bgColor=#000066 height=20><FONT color=white> <SPAN class=fontWhiteBold><SPAN class=ptitle>求解信息</SPAN></SPAN></FONT></TD></TR></TBODY></TABLE>
<P class=ptitle><IMG height=607 src="http://www.cabit.com.cn/pic/gams/example/solvemessage1.gif" width=578 border=0></P>
<P class=ptitle>求解声明将生成模型(单个方程式和对应到特定模型的变量的产物).首先一些关于生成的模型的统计表将会被显示:方程式数,变量和非零元素.</P>
<P class=ptitle>在求解汇总信息部分,我们看到BDMLP被调用来求解这个模型.BDMLP经过4次反复,耗时0.18秒找到了这个问题的最优解.求解信息下列的消息来自求解器.</P>
<P><STRONG>解(Solution)</STRONG></P>
<P class=ptitle><IMG id=e_f_img_0.09959681253650282 height=761 src="http://www.cabit.com.cn/pic/gams/example/solution1.gif" width=543 border=0></P>
<P class=ptitle>解被显示在这里.边际值(marginals)对应方程式的重复和变量减少的花费.</P>
<P class=ptitle>写工具不需要学习一门其它的语言.在GAMS所有的数据处理,模型定义和报告编写都是在一个单独的环境中完成的.</P>
<TABLE cellSpacing=0 cellPadding=0 width="15%" border=0>
<TBODY>
<TR>
<TD width=5 bgColor=#cc3300> </TD>
<TD bgColor=#000066 height=20> <SPAN class=fontWhiteBold><SPAN class=fontWhiteColor><FONT color=white>参考</FONT></SPAN></SPAN></TD></TR></TBODY></TABLE>
<P class=ptitle>Dantzig G. B., Linear Programming and Extensions, Princeton University Press,Princeton, New Jersey, 1963, Chapter 3-3. </P> 呵呵 这个例子做入门非常不错啊 支持一下 辛苦版主了 非常感谢楼主分享 呵呵 这个例子做入门非常不错啊 支持一下 辛苦版主了
辛苦版主啊
非常不错,辛苦 辛苦了,正在学习gams的使用 好东西啊~~ 辛苦了,楼主 学习GAMS的路过,表示支持~
页:
[1]
2