GAMS中文教程
(完整版)GAMS用户手册(中文翻译第2-15章)(可编辑修改word版)

目录第二章GAMS 指南 (2)2.1引言 (2)2.2GAMS 模型的结构 (4)2.3集合 (6)2.4数据 (7)2.4.1清单数据输入 (7)2.4.2表格数据输入 (8)2.4.3直接赋值数据输入 (8)2.5变量 (9)2.6 方程 (10)2.6.1方程声明 (10)2.6.2GAMS 的求和符号(乘积符号) (11)2.6.3方程定义 (11)2.7目标函数 (13)2.8模型和求解语句 (13)2.9显示语句 (14)2.10 .lo,.l,.up,.m 数据库 (14)2.10.1变量边界和初始值的赋值 (14)2.10.2最优值的转化和显示 (15)2.11 GAMS 输出 (16)2.11.1 复写 (16)2.11.2错误信息 (18)2.11.3引用地图 (20)2.11.4方程清单 (21)2.11.5模型统计数据 (22)2.11.6状态报告 (22)2.11.7解报告 (23)2.12 总结 (24)第三章GAMS 程序 (26)3.1 引言 (26)3.2GAMS 程序的结构 (26)3.2.1GAMS 输入的格式 (26)3.2.2GAMS 语句的分类 (27)3.2.3GAMS 程序的组织 (27)3.3数据类型和定义 (28)3.4语言项 (29)3.4.1 字符 (29)3.4.2保留词 (29)3.4.3标识符(Identifiers) (30)3.4.4 标签 (30)3.4.5 文本 (31)3.4.6 数字 (31)3.4.7 分隔符 (32)3.4.8 注释 (32)3.5 小结 (33)第四章集合定义 (34)4.1 引言 (34)4.2简单集合 (34)4.2.1 语法 (34)4.2.2集合名称 (34)4.2.3集合元素 (35)4.2.4相关文本 (36)4.2.5作为集合元素的序列 (36)4.2.6多集合声明 (37)4.3别名语句:一个集合多个名称 (37)4.4子集合和定义域检查 (38)4.5多维集合 (39)4.5.1一对一映射 (39)4.5.2多对多映射 (40)4.6 小结 (41)第五章数据输入:参数,标量和表格 (42)5.1 引言 (42)5.2 标量 (42)5.2.1 语法 (42)5.2.2 例子 (42)5.3 参数 (43)5.3.1 语法 (43)5.3.2 例子 (43)5.3.3 高维数据参数 (44)5.4 表格 (44)5.4.1 语法 (45)5.4.2 例子 (45)5.4.3 续表 (46)5.4.4超过两维的表格 (46)5.4.5浓缩表格 (47)5.4.6处理长行表格 (48)5.5 Acronyms (48)5.5.1 语法 (48)5.5.2 示例 (49)5.6 小结 (49)第六章参数的数据处理 (50)6.1 引言 (50)6.2赋值语句 (50)6.2.1标量赋值 (50)6.2.2指数化赋值 (50)6.2.3在赋值中直接采用标签 (51)6.2.4子集上的赋值 (51)6.2.5控制指数的相关问题 (51)6.2.6赋值中扩展值域的标识符 (52)6.2.7赋值中的Acronyms (52)6.3表达式 (52)6.3.1标准算术运算 (52)6.3.2指数化运算 (53)6.3.3 函数 (54)6.3.4 扩展值域算法和错误处理 (55)6.4 小结 (56)第七章变量 (57)7.1 引言 (57)7.2变量声明 (57)7.2.1 语法 (57)7.2.2变量类型 (58)7.2.3变量声明的方式 (58)7.3变量属性 (59)7.3.1变量的边界 (59)7.3.2定值变量 (59)7.3.3变量的活动水平 (60)7.4显示语句和赋值语句中的变量 (60)7.4.1对变量属性进行赋值 (60)7.4.2赋值语句中的变量属性 (60)7.4.3显示变量属性 (61)7.5 小结 (62)第八章方程 (63)8.1 引言 (63)8.2方程声明 (63)8.2.1 语法 (63)8.2.2 例子 (63)8.3方程定义 (64)8.3.1 语法 (64)8.3.2 例子 (64)8.3.3标量方程 (65)8.3.4指数化方程 (65)8.3.5在方程中明确使用标签 (65)8.4方程定义中的表达式 (66)8.4.1方程定义中的算术算子 (66)8.4.2方程定义中的函数 (66)8.4.3避免方程中的无定义操作 (67)8.5方程的数据处理问题 (67)第九章模型和求解语句 (69)9.1 引言 (69)9.2模型语句 (69)9.2.1 语法 (69)9.2.2模型的分类 (70)9.2.3模型属性 (70)9.3求解语句 (71)9.3.1 语法 (72)9.3.2合法求解语句的要求 (72)9.3.3求解语句触发的行动 (72)9.4多个求解语句的程序 (73)9.4.1几个模型 (73)9.4.2敏感性分析和场景分析 (73)9.4.3非标准算法的迭代执行 (74)9.5让GAMS 获得新的求解模块 (75)第十章GAMS 输出 (76)10.1 引言 (76)10.2示例模型 (76)10.3编辑输出 (77)10.3.1输入文件的复写 (77)10.3.2符号引用地图 (79)10.3.3符号清单地图 (80)10.3.4单元素清单地图 (81)10.3.5实用的dollar($)控制指令 (82)10.4执行输出 (82)10.5求解语句生成的输出 (83)10.5.1方程清单 (83)10.5.2列清单 (84)10.5.3模型统计数据 (85)10.5.4求解摘要 (86)10.5.5求解模块报告 (89)10.5.6解清单 (89)10.5.7报告摘要 (91)10.5.8文件概要 (91)10.6错误报告 (91)10.6.1编辑错误 (92)10.6.2编辑时间错误 (93)10.6.3执行错误 (94)10.6.4求解错误 (94)10.7 小结 (95)第十一章条件表达式,赋值和方程 (96)11.1 引言 (96)11.2逻辑条件 (96)11.2.1作为逻辑条件的数值表达式 (96)11.2.2数值关系算子 (96)11.2.3逻辑算子 (97)11.2.4集合元素 (97)11.2.5包含Acronyms 的逻辑条件 (97)11.2.6逻辑条件的数值 (98)11.2.7混合逻辑条件――算子优先顺序 (98)11.2.8混合逻辑条件――例子 (99)11.3Dollar 条件 (99)11.3.1 例子 (99)11.3.2 嵌套dollar 条件 (99)11.4条件赋值 (100)11.4.1dollar 置于赋值语句左边 (100)11.4.2dollar 置于赋值语句右边 (101)11.4.3在指数化运算中过滤控制指数 (101)11.4.4过滤赋值语句中的集合 (102)11.5条件指数化运算 (103)11.5.1在指数化运算中过滤控制指数 (104)11.6条件方程 (105)11.6.1代数表达式中的dollar 算子 (105)11.6.2定义域的dollar 控制 (105)11.6.3过滤定义域 (106)第十二章动态集合 (107)12.1 引言 (107)11.2 动态集合的元素赋值 (107)11.2.1 语法 (107)11.2.2 例子 (107)12.2.3 多指数动态集合 (108)11.2.4 动态集合定义域上赋值语句 (108)12.2.5 定义在动态集合定义域上的方程 (108)12.3使用带有动态集合的dollar 控制 (109)12.3.1 赋值 (109)12.3.2 指数化运算 (109)12.3.3 方程 (110)12.3.4 通过动态集合过滤 (110)12.4集合运算 (111)12.4.1 并集 (111)12.4.2 交集 (111)12.4.3 补集 (111)12.4.4 差集 (111)12.5 小结 (112)第十三章作为序列的集合:有序集合 (113)13.1 引言 (113)13.3ord 和card (114)13.3.1ord 算子 (114)13.3.2Card 算子 (115)13.4lag 和lead 算子 (115)13.5赋值语句中的lags 和leads (116)13.5.1线性lag 和lead 算子――引用 (116)13.5.2线性lag 和lead 算子――赋值 (116)13.5.3循环lag 和lead 算子 (117)13.6方程中的lags 和leads (118)13.6.1线性lag 和lead 算子――定义域控制 (118)13.6.2线性lag 和lead 算子――引用 (119)13.6.3循环lag 和lead 算子 (119)13.7 小结 (120)第十四章显示语句 (121)14.1 引言 (121)14.2 语法 (121)14.3 例子 (121)14.4显示语句中的标签顺序 (122)14.4.1 例子 (123)14.5显示控制 (124)14.5.1全局显示控制 (124)14.5.2局部显示控制 (124)14.5.3生成列表格式数据的显示语句 (125)第十五章put 书写工具 (127)15.1 引言 (127)15.2 语法 (127)15.3 例子 (127)15.4输出文件 (129)15.4.1定义文件 (129)15.4.2赋值文件 (130)15.4.3关闭文件 (130)15.4.4添加内容到文件 (130)15.5页面格式 (131)15.6页面区域 (132)15.6.1访问不同的页面区域 (132)15.5.2 分页 (133)15.7定位页面指针 (133)15.8系统后缀 (133)15.9 输出项 (134)15.9.1 文本项 (134)15.9.2 数字项 (135)15.9.3 集合值项 (136)15.10.1字段对齐 (136)15.10.2字段宽度 (136)15.11局部输出项格式 (137)15.12额外的数字显示控制 (137)15.12.1 例子 (138)15.13指针控制 (139)15.13.1当前指针列 (139)15.13.2当前指针行 (140)15.13.3末行控制 (140)15.14分页控制 (141)15.15例外处理 (141)15.16与put 语句相关的错误来源 (141)15.16.1语法错误 (141)15.16.2put 错误 (142)15.17简单的电子数据表/数据库应用 (142)15.17.1 例子 (142)第二章GAMS 指南2.1 引言本书的介绍部分将给出一个详细的例子,介绍如何使用GAMS 来描述、求解和分析一个简单的小型优化问题。
GAMS用户手册(中文翻译第2-15章)

目录第二章GAMS指南 (8)2.1 引言 (8)2.2 GAMS模型的结构 (10)2.3 集合 (12)2.4 数据 (13)2.4.1 清单数据输入 (13)2.4.2 表格数据输入 (14)2.4.3 直接赋值数据输入 (14)2.5 变量 (15)2.6 方程 (16)2.6.1 方程声明 (16)2.6.2 GAMS的求和符号(乘积符号) (17)2.6.3 方程定义 (17)2.7 目标函数 (19)2.8 模型和求解语句 (19)2.9 显示语句 (20)2.10 .lo,.l,.up,.m数据库 (20)2.10.1 变量边界和初始值的赋值 (20)2.10.2 最优值的转化和显示 (21)2.11 GAMS输出 (22)2.11.1 复写 (22)2.11.2 错误信息 (24)2.11.3 引用地图 (26)2.11.4 方程清单 (27)2.11.5 模型统计数据 (28)2.11.6 状态报告 (28)2.11.7 解报告 (29)2.12 总结 (30)第三章GAMS 程序 (32)3.1 引言 (32)3.2 GAMS程序的结构 (32)3.2.1 GAMS输入的格式 (32)3.2.2 GAMS语句的分类 (33)3.2.3 GAMS程序的组织 (33)3.3 数据类型和定义 (34)3.4 语言项 (35)3.4.1 字符 (35)3.4.2 保留词 (35)3.4.3 标识符(Identifiers) (36)3.4.4 标签 (36)3.4.5 文本 (37)3.4.6 数字 (37)3.4.7 分隔符 (38)3.4.8 注释 (38)3.5 小结 (39)第四章集合定义 (40)4.1 引言 (40)4.2 简单集合 (40)4.2.1 语法 (40)4.2.2 集合名称 (40)4.2.3 集合元素 (41)4.2.4 相关文本 (42)4.2.5 作为集合元素的序列 (42)4.2.6 多集合声明 (43)4.3 别名语句:一个集合多个名称 (43)4.4 子集合和定义域检查 (44)4.5 多维集合 (45)4.5.1 一对一映射 (45)4.5.2 多对多映射 (46)4.6 小结 (47)第五章数据输入:参数,标量和表格 (48)5.1 引言 (48)5.2 标量 (48)5.2.1 语法 (48)5.2.2 例子 (48)5.3 参数 (49)5.3.1 语法 (49)5.3.2 例子 (49)5.3.3 高维数据参数 (50)5.4 表格 (50)5.4.1 语法 (51)5.4.2 例子 (51)5.4.3 续表 (52)5.4.4 超过两维的表格 (52)5.4.5 浓缩表格 (53)5.4.6 处理长行表格 (54)5.5 Acronyms (54)5.5.1 语法 (54)5.5.2 示例 (55)5.6 小结 (55)第六章参数的数据处理 (56)6.1 引言 (56)6.2 赋值语句 (56)6.2.1 标量赋值 (56)6.2.2 指数化赋值 (56)6.2.3 在赋值中直接采用标签 (57)6.2.4 子集上的赋值 (57)6.2.5 控制指数的相关问题 (57)6.2.6 赋值中扩展值域的标识符 (58)6.2.7 赋值中的Acronyms (58)6.3 表达式 (58)6.3.1 标准算术运算 (58)6.3.2 指数化运算 (59)6.3.3 函数 (60)6.3.4 扩展值域算法和错误处理 (61)6.4 小结 (62)第七章变量 (63)7.1 引言 (63)7.2 变量声明 (63)7.2.1 语法 (63)7.2.2 变量类型 (64)7.2.3变量声明的方式 (64)7.3 变量属性 (65)7.3.1 变量的边界 (65)7.3.2 定值变量 (65)7.3.3 变量的活动水平 (66)7.4 显示语句和赋值语句中的变量 (66)7.4.1 对变量属性进行赋值 (66)7.4.2 赋值语句中的变量属性 (66)7.4.3 显示变量属性 (67)7.5 小结 (68)第八章方程 (69)8.1 引言 (69)8.2 方程声明 (69)8.2.1 语法 (69)8.2.2 例子 (69)8.3 方程定义 (70)8.3.1 语法 (70)8.3.2 例子 (70)8.3.3 标量方程 (71)8.3.4 指数化方程 (71)8.3.5 在方程中明确使用标签 (71)8.4 方程定义中的表达式 (72)8.4.1 方程定义中的算术算子 (72)8.4.2 方程定义中的函数 (72)8.4.3 避免方程中的无定义操作 (73)8.5 方程的数据处理问题 (73)第九章模型和求解语句 (75)9.1 引言 (75)9.2 模型语句 (75)9.2.1 语法 (75)9.2.2 模型的分类 (76)9.2.3 模型属性 (76)9.3 求解语句 (77)9.3.1 语法 (78)9.3.2 合法求解语句的要求 (78)9.3.3 求解语句触发的行动 (78)9.4 多个求解语句的程序 (79)9.4.1 几个模型 (79)9.4.2 敏感性分析和场景分析 (79)9.4.3 非标准算法的迭代执行 (80)9.5 让GAMS获得新的求解模块 (81)第十章GAMS输出 (82)10.1 引言 (82)10.2 示例模型 (82)10.3 编辑输出 (83)10.3.1 输入文件的复写 (83)10.3.2 符号引用地图 (85)10.3.3 符号清单地图 (86)10.3.4 单元素清单地图 (87)10.3.5 实用的dollar($)控制指令 (88)10.4 执行输出 (88)10.5 求解语句生成的输出 (89)10.5.1 方程清单 (89)10.5.2 列清单 (90)10.5.3 模型统计数据 (91)10.5.4 求解摘要 (92)10.5.5 求解模块报告 (95)10.5.6 解清单 (95)10.5.7 报告摘要 (97)10.5.8 文件概要 (97)10.6 错误报告 (97)10.6.1 编辑错误 (98)10.6.2 编辑时间错误 (99)10.6.3 执行错误 (100)10.6.4 求解错误 (100)10.7 小结 (101)第十一章条件表达式,赋值和方程 (102)11.1 引言 (102)11.2 逻辑条件 (102)11.2.1 作为逻辑条件的数值表达式 (102)11.2.2 数值关系算子 (102)11.2.3 逻辑算子 (103)11.2.4 集合元素 (103)11.2.5 包含Acronyms的逻辑条件 (103)11.2.6 逻辑条件的数值 (104)11.2.7 混合逻辑条件――算子优先顺序 (104)11.2.8 混合逻辑条件――例子 (105)11.3 Dollar条件 (105)11.3.1 例子 (105)11.3.2 嵌套dollar条件 (105)11.4 条件赋值 (106)11.4.1 dollar置于赋值语句左边 (106)11.4.2 dollar置于赋值语句右边 (107)11.4.3 在指数化运算中过滤控制指数 (107)11.4.4 过滤赋值语句中的集合 (108)11.5 条件指数化运算 (109)11.5.1 在指数化运算中过滤控制指数 (110)11.6 条件方程 (111)11.6.1 代数表达式中的dollar算子 (111)11.6.2 定义域的dollar控制 (111)11.6.3 过滤定义域 (112)第十二章动态集合 (113)12.1 引言 (113)11.2 动态集合的元素赋值 (113)11.2.1 语法 (113)11.2.2 例子 (113)12.2.3 多指数动态集合 (114)11.2.4 动态集合定义域上赋值语句 (114)12.2.5 定义在动态集合定义域上的方程 (114)12.3 使用带有动态集合的dollar控制 (115)12.3.1 赋值 (115)12.3.2 指数化运算 (115)12.3.3 方程 (116)12.3.4 通过动态集合过滤 (116)12.4 集合运算 (117)12.4.1 并集 (117)12.4.2 交集 (117)12.4.3 补集 (117)12.4.4 差集 (117)12.5 小结 (118)第十三章作为序列的集合:有序集合 (119)13.1 引言 (119)13.2 有序和无序集合 (119)13.3 ord和card (120)13.3.1 ord算子 (120)13.3.2 Card算子 (121)13.4 lag和lead算子 (121)13.5 赋值语句中的lags和leads (122)13.5.1 线性lag和lead算子――引用 (122)13.5.2 线性lag和lead算子――赋值 (122)13.5.3 循环lag和lead算子 (123)13.6 方程中的lags和leads (124)13.6.1 线性lag和lead算子――定义域控制 (124)13.6.2 线性lag和lead算子――引用 (125)13.6.3 循环lag和lead算子 (125)13.7 小结 (126)第十四章显示语句 (127)14.1 引言 (127)14.2 语法 (127)14.3 例子 (127)14.4 显示语句中的标签顺序 (128)14.4.1 例子 (129)14.5 显示控制 (130)14.5.1 全局显示控制 (130)14.5.2 局部显示控制 (130)14.5.3 生成列表格式数据的显示语句 (131)第十五章put书写工具 (133)15.1 引言 (133)15.2 语法 (133)15.3 例子 (133)15.4 输出文件 (135)15.4.1 定义文件 (135)15.4.2 赋值文件 (136)15.4.3 关闭文件 (136)15.4.4 添加内容到文件 (136)15.5 页面格式 (137)15.6 页面区域 (138)15.6.1 访问不同的页面区域 (138)15.5.2 分页 (139)15.7 定位页面指针 (139)15.8 系统后缀 (139)15.9 输出项 (140)15.9.1 文本项 (140)15.9.2 数字项 (141)15.9.3 集合值项 (142)15.10 全局输出项格式 (142)15.10.1 字段对齐 (142)15.10.2 字段宽度 (142)15.11 局部输出项格式 (143)15.12 额外的数字显示控制 (143)15.12.1 例子 (144)15.13 指针控制 (145)15.13.1 当前指针列 (145)15.13.2 当前指针行 (146)15.13.3 末行控制 (146)15.14 分页控制 (147)15.15 例外处理 (147)15.16 与put语句相关的错误来源 (147)15.16.1 语法错误 (147)15.16.2 put错误 (148)15.17 简单的电子数据表/数据库应用 (148)15.17.1 例子 (148)第二章 GAMS 指南2.1 引言本书的介绍部分将给出一个详细的例子,介绍如何使用GAMS 来描述、求解和分析一个简单的小型优化问题。
GAMS软件各模块介绍

GAM软件各模块详细介绍中国科学软件网提供通用代数建模系统(GAMS是特别为建模线性、非线性和混合整数最优化问题而设计的。
GAM尤其对于大型的、复杂的、需要多次修订才能最终确定的精确模型的复杂问题有帮助。
GAM舸以运行在个人计算机、工作站、大型机和超级计算机上。
您可以快速、方便地更改公式,从一个求解器转到另一个,甚至很简单地就能从线性转换到非线性。
使用GAMS您只需一次就能在熟悉的列表和表格形式中输入您想要的数据。
模型以简洁的代数形式表示,简单明了,容易理解。
相关的约束数的整个集合都将被输入到一个代数形式中。
GAMS自动生成每个约束等式,您可以处理特殊情况,以防通用性的模型不适用。
当其他相似的或相关的问题出现时,您不需要更改代数式,再次使用模型中的表述即可,错误的位置和形式会在给出解决方案前被查明。
GAM处理的动态模型,包括时间序列、滞后、超前及时间终点的处理。
GAM炭活性强且功能强大。
只要 GAMS已经安装在每个平台,您就可以非常方便地把GAM模型从一个计算机平台移到另外一个平台。
GAMS很容易进行敏感度分析,您能够方便地编程模型去求解一个成分的不同值,然后生成一个报告,列出每种情况的解决方案。
GAMS勺模型能够同时被开发和文档化,因为GAMSt许用户包含解释性的文本来作为任意符号和等式的定义和解释。
GAMSfe持的模型类型GAMS能够以多种不同的问题来分类类型并公式化模型这意味着从一个模型类型跳转到另一个将毫不费力 . 您甚至能够同时在不同的模型类型中使用相同的数据、变量和方程式 .GAMSt持下列基本的模型类型:LP 线性规划MIP 混合整数规划NLP 非线性规划MCP混合互补问题MPEC带方程式约束的数学规划CNS 受约束的非线性系统DNLP带非连续导数的非线性规划MINLP 混合整数非线性规划QCP二次约束规划MIQCP混合整数二次约束规划GAM断有的模型介绍:GAMS基础模型包括GAMS^言编辑器和一系列系统:执行系统、 GAMSIDE (Win dows、系统文档化、模型库、转换工具、 UNIX和GDX功能、COIN-OR MILES、NLPEC以及在其他一些低版本中所有模块。
GAMS软件各模块介绍

GAMS软件各模块详细介绍中国科学软件网提供通用代数建模系统(GAMS)是特别为建模线性、非线性和混合整数最优化问题而设计的。
GAMS尤其对于大型的、复杂的、需要多次修订才能最终确定的精确模型的复杂问题有帮助。
GAMS可以运行在个人计算机、工作站、大型机和超级计算机上。
您可以快速、方便地更改公式,从一个求解器转到另一个,甚至很简单地就能从线性转换到非线性。
使用GAMS,您只需一次就能在熟悉的列表和表格形式中输入您想要的数据。
模型以简洁的代数形式表示,简单明了,容易理解。
相关的约束数的整个集合都将被输入到一个代数形式中。
GAMS自动生成每个约束等式,您可以处理特殊情况,以防通用性的模型不适用。
当其他相似的或相关的问题出现时,您不需要更改代数式,再次使用模型中的表述即可,错误的位置和形式会在给出解决方案前被查明。
GAMS处理的动态模型,包括时间序列、滞后、超前及时间终点的处理。
GAMS灵活性强且功能强大。
只要GAMS已经安装在每个平台,您就可以非常方便地把GAMS模型从一个计算机平台移到另外一个平台。
GAMS很容易进行敏感度分析,您能够方便地编程模型去求解一个成分的不同值,然后生成一个报告,列出每种情况的解决方案。
GAMS的模型能够同时被开发和文档化,因为GAMS允许用户包含解释性的文本来作为任意符号和等式的定义和解释。
GAMS支持的模型类型GAMS能够以多种不同的问题来分类类型并公式化模型这意味着从一个模型类型跳转到另一个将毫不费力.您甚至能够同时在不同的模型类型中使用相同的数据、变量和方程式.GAMS支持下列基本的模型类型:LP 线性规划MIP 混合整数规划NLP 非线性规划MCP 混合互补问题MPEC 带方程式约束的数学规划CNS 受约束的非线性系统DNLP 带非连续导数的非线性规划MINLP 混合整数非线性规划QCP 二次约束规划MIQCP 混合整数二次约束规划GAMS所有的模型介绍:GAMS 基础模型包括GAMS语言编辑器和一系列系统:执行系统、GAMSIDE (Windows)、系统文档化、模型库、转换工具、UNIX和GDX功能、COIN-OR、 MILES、 NLPEC 以及在其他一些低版本中所有模块。
第2章通用数学建模系统(GAMS)基本知识

第2章通用数学建模系统(GAMS)基本知识经过多年来的改进和完善,GAMS为用户表达、计算和求解大型和复杂模型提供了高水平的编程语言。
其突出特点是:允许模型的描述独立于求解算法,允许在规范化的标准模型中、在保证安全的条件下作少许变化,要求变量之间的代数关系表述明确。
本章用一个简单实例来说明GAMS系统在建立和求解优化模型中的用法,要熟练掌握GAMS的应用需要大量的建模实践,详细的GAMS语句说明请参考相关的用户说明书。
2.1 GAMS系统简介GAMS的设计融入了数学方程的设计思想和关系数据库理论,目的是满足战略建模者的需求。
数学方程设计提供了描述问题和多种求解问题的方法,而关系数据库理论为数据组织及其应对变化提供了一个框架结构。
因此具有数学模型基础和计算机程序设计基础将有利于对GAMS应用的理解。
2.1.1 GAMS基本特性GAMS模型的表达式人和计算机都能读懂,这说明GAMS程序本身就是模型的文件。
而且,GAMS的设计融入了以下的特性来满足用户的需要。
(1) GAMS的表达式充分利用了数学表达式的优点。
GAMS将算法与语言结合,因此所有现成的计算方法不用改变用户的模型表达形式就可以直接引入GAMS程序,引用新方法或者已有方法的新应用可以不改变现有的模型。
线性、非线性、整形、混合整形非线性的优化问题都包括在内。
(2)由于GAMS使用了关系数据库模型,因此计算过程中所需要的计算机的资源被自动地分配,这就意味着GAMS能够构造大型和复杂的模型,而用户不用考虑计算机的资源限制、利用和分配等细节问题。
所有数据以它们最基本的形式输入,数据的转换在构造模型的过程中进行。
(3)由于GAMS中优化问题的表达可以独立于使用的数据,这种逻辑和数据的分离允许用户在不增加表达形式复杂性的情况下改变模型的规模。
(4)变量的解释文本是符号定义中的一部分,而且无论何时,相关的变量和数值出现时解释文本都会再现。
(5)模型具有可移植性。
GAMS简明教程中文版

二 GAMS 简明教程 由Richard E. Rosenthal 编著(译者:该翻译由华中科技大学能源与动力工程学院小海完成,由于译者水平有限,其中肯定会有些问题,欢迎大家阅读并批评指正!)2.1 简介这本书的简介部分以一个详细的例子结束,这个例子是一个用GAMS 进行表达、解决和分析的小而简单的优化问题。
由来自蒙特利尔市Naval 研究生院的Richard E.Rownthal 编写。
通过这个例子我们可以对GAMS 有一个快速而全面的了解。
很多地方引用到本书其他章节的知识,方便大家进一步查阅;而阅读这一部分即使不看本书其他章节也能看懂并且有所收获。
例子是一个关于运输的线性规划问题,这个问题在最优化技术发展过程中曾经被当做实验对象。
用这个例子展示GAMS 这类代数建模语言的强大功能是很好的选择,因为不管手头要处理的问题有多大,运输问题本身具有一个简单的、可用的代数结构。
你可以发现,如果要解决一个非常大的运输问题,我们将呈现的用于解决小规模运输问题的GAMS 输入文件中的内容并不需要改变多少。
在熟悉的运输问题中,我们考虑几个工厂的供应和几个市场的需求的商品,我们也给出从工厂运输商品到市场的单位花费。
这其中的经济学问题是:怎样安排运输使得我们的总运输成本最小?这个问题的代数表达常常采用下列方式:Indices:i = plantsj = marketsGiven Data:i a = supply of commodity of plant i (in cases)ij b = demand for commodity at market jij c = cost per unit shipment between plant i and market j ($/case)Decision Variables:ij x = amount of commodity to ship from plant i to market j (cases),Where ij x ≥0, for all i, jConstraints:Observe supply limit at plant i: j ij j a x ≤∑ for all i (cases)Satisfy demand at market j: ij j i x b ≥∑ for all j (cases)Objective Function: Minimize ij ij i j c x∑∑ ($K)注意这个例子显示了一些一般情况下我们认为是好习惯的建模方式,这些在GAMS 里面被继承了。
gams使用心得 中文

GAMS 使用经验和技巧
能看到这篇文字的同学,恐怕大多数是在灯下苦读的学子。实际上学习某种 工具并不重要。真正要学习的是知识,是思维的方法。就像很多计算机系的学生 一样,把数据结构和算法精通了,任何工具都是一样的。所以,你用 GAMS 或者 不用 GAMS,都没有关系,要把握事物的本质,最关键的东西抓住了,任何语言 就是一种输入法。另外,学习一定要有兴趣,要认识到他的 beauty,不要把什 么都换算**民币,那样你会觉得很累。
GAMS 编程简单的说就是不很多相关的约束和目标函数组合到一起,然后调用不 同类型的 solver 来解决。 说到这里,大家对 GAMS 只能有一个大概的了解。我觉得写 GAMS code 并不难, 难的只有两点: 1.定义你的模型。要选取最 efficient 的方法 2.定义好你的 set。模型里面所有的东西都和它有关,正所谓牵一发动全身。; v) Q s7 k8 d* v( F7 ` 其他都是水到渠成。
GAMS模型文档提取工具说明书

Package‘goxygen’October13,2022Type PackageTitle In-Code Documentation for'GAMS'Version1.0.3Date2020-08-11DescriptionA collection of tools which extract a model documentation from'GAMS'code and comments.In order to use the package you need to install'pandoc'and'pandoc-citeproc'first(<https:///>).Imports pander,stringi,gms,citation,yamlURL https:///pik-piam/goxygen,https:///10.5281/zenodo.1411404BugReports https:///pik-piam/goxygen/issuesLicense BSD_2_clause+file LICENSEEncoding UTF-8LazyData noRoxygenNote7.1.0Suggests testthat,knitr,rmarkdownVignetteBuilder knitrNeedsCompilation noAuthor Jan Philipp Dietrich[aut,cre],Kristine Karstens[aut],David Klein[aut],Lavinia Baumstark[aut]Maintainer Jan Philipp Dietrich<***********************>Repository CRANDate/Publication2020-08-1614:40:03UTC12.empty R topics documented:.empty (2).header (3).interfaceplot (3).limitations (4).updateImagePaths (5).write (5)buildHTML (6)buildMarkdown (7)buildTEX (7)check_pandoc (8)createIndexPage (9)createListModularCode (9)createListSimpleCode (10)createModulePage (11)createSimplePage (12)extractDocumentation (13)gamsequation2tex (14)goxygen (14)oldBuildHTML (16)returnReferences (17)Index18 .empty.emptyDescriptionhelper function which adds an empty line in a markdown documentUsage.empty(zz)Argumentszz a connection object of class"textConnection"containing the markdown docu-mentAuthor(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage.header3 .header.headerDescriptionhelper function which writes a title for a markdown sectionUsage.header(zz,title,level,id=NULL)Argumentszz a connection object of class"textConnection"containing the markdown docu-menttitle the title to be used(character vector of length1)level level of the heading(1means main header,higher numbers reflect lower levels) id ID given to the title(relevant for anchors)Author(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage.interfaceplot.interfaceplotDescriptionhelper function which includes interface plotfigures in a markdown document,if available.The figures need to be created beforehand.Usage.interfaceplot(zz,name,docfolder)Argumentszz a connection object of class"textConnection"containing the markdown docu-mentname Name of the module for which the interfaceplot should be showndocfolder folder the documentation should be written to relative to model folder4.limitations Author(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage.limitations.limitationsDescriptionhelper function which adds a"limitations"section.Usage.limitations(zz,limitations,emptyIfNULL=FALSE)Argumentszz a connection object of class"textConnection"containing the markdown docu-mentlimitations A character vector containing the given limitationsemptyIfNULL switch which decides whether limitations section should be ignored,if limita-tions input is NULL or if it should state that there are no known limitations.Author(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage.updateImagePaths5 .updateImagePaths.updateImagePathsDescriptionhelper function which updates relative image paths so that they refer to a subfolder images instead of refering to the current folder.Usage.updateImagePaths(x)Argumentsx A character vector containing image paths.Author(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage.write.writeDescriptionhelper function which writes a character vector line by line in a markdown documentUsage.write(zz,data)Argumentszz a connection object of class"textConnection"containing the markdown docu-mentdata a character vector to be written to the markdown documentAuthor(s)Jan Philipp DietrichSee Alsogoxygen,createModulePage6buildHTML buildHTML buildHTMLDescriptionConverts a folder with markdownfiles and a corresponding literature library(if available)to HTML files and creates cross-links between them.UsagebuildHTML(style="classic",folder="html",mdfolder="markdown",literature="literature.bib",citation="../CITATION.cff",supplementary="images",debug=FALSE)Argumentsstyle visualization style to be used for the creation.Currently available styles are "classic"and"ming"folder location the HTMLfiles should be written tomdfolder path to the markdown folder to be used as sourceliterature path to a bibliography,if available(will be ignored iffile does not exist)citation Citation information in citationfile format(optional)supplementary a vector offiles and/or folders required for the conversion(e.g.an images sub-directory withfigures to be shown in the documents)debug logical which switches on/off a debug mode which will return additional status updates and keep buildfilesDetailsPandoc(https:///)together with pandoc-citeproc need to be installed on the system.Author(s)Jan Philipp DietrichSee Alsogoxygen,buildTEXbuildMarkdown7 buildMarkdown buildMarkdownDescriptionCreates a folderfilled with markdownfiles from a list object with markdown codeUsagebuildMarkdown(x,folder="markdown")Argumentsx a named list of markdown codes which should be written as markdownfiles.The name of each entry will become thefile name.folder folder the markdownfiles should be written toAuthor(s)Jan Philipp DietrichSee Alsogoxygen,buildHTMLbuildTEX buildTEXDescriptionConverts a folder with markdownfiles and a corresponding literature library(if available)to a tex fileUsagebuildTEX(file="documentation.tex",mdfolder="markdown",literature="literature.bib",citation="../CITATION.cff",supplementary=NULL,pdf=TRUE)8check_pandocArgumentsfile name of the texfile to be writtenmdfolder path to the markdown folder to be used as sourceliterature path to a bibliography,if available(will be ignored iffile does not exist)citation Citation information in citationfile format(optional)supplementary a vector offiles and/or folders required for the conversion(e.g.an images sub-directory withfigures to be shown in the documents)pdf boolean which specifies whether pdffile should be generated from texDetailsPandoc(https:///)together with pandoc-citeproc need to be installed on the system. Author(s)Jan Philipp Dietrich,Kristine KarstensSee Alsogoxygen,buildHTMLcheck_pandoc check_pandocDescriptionSupport function which checks pandoc availability and stops with an error in case that pandoc cannot be foundUsagecheck_pandoc(error=FALSE)Argumentserror boolean indicating whether function should throw an error in case of missing pandoc or return a boolean FALSE.Valueboolean indicating whether pandoc is available or not.Author(s)Jan Philipp DietrichcreateIndexPage9 createIndexPage createIndexPageDescriptionCreates markdown code from a supplied data listUsagecreateIndexPage(data)Argumentsdata a list of data entries for the resulting markdown page.Following entries can be provided:title Page titledescription General descriptioncitation A read in citation in Citation File Format(CFF)Valuea character vector containing the produced markdown textAuthor(s)Jan Philipp DietrichSee AlsogoxygencreateListModularCode createListModularCodeDescriptionsupport function to create documentation of modular GAMS code.10createListSimpleCodeUsagecreateListModularCode(cc,interfaces,path=".",citation=NULL,unitPattern=c("\\(","\\)"),includeCore=FALSE,mainfile="main.gms",docfolder="doc")Argumentscc codeCheck informationinterfaces interface informationpath path to the model to be documentedcitation citation data read from a CFFfileunitPattern pattern that is usedto identify the unit in the description,default=c("\(","\)") includeCore Boolean whether core should be included or not,default=FALSEmainfile mainfile of the modeldocfolder folder the documentation should be written to relative to model folderAuthor(s)Jan Philipp DietrichSee AlsocodeCheckcreateListSimpleCode createListSimpleCodeDescriptionsupport function to create documentation of non-modular GAMS code.UsagecreateListSimpleCode(path=".",citation=NULL,mainfile="main.gms")createModulePage11Argumentspath path to the model to be documentedcitation citation data read from a CFFfilemainfile mainfile of the modelAuthor(s)Jan Philipp DietrichSee AlsocodeCheckcreateModulePage createModulePageDescriptionCreates markdown code from a supplied data listUsagecreateModulePage(data,docfolder)Argumentsdata a list of data entries for the resulting markdown page.Following entries can be provided:name Name of the moduletitle Page titledescription General descriptioninput Table containing inputs to the moduleoutput Table containing outputs from the modulerealizations A list of realizations with entries"description"and"limitations"for each of themdeclarations Table of declarations for internal objectsstes Table containing sets used in the moduleauthors Module authorsseealso A vector with names of relevant other documentation pages.docfolder folder the documentation should be written to relative to model folderValuea character vector containing the produced markdown text12createSimplePage Author(s)Jan Philipp DietrichSee AlsogoxygencreateSimplePage createSimplePageDescriptionCreates markdown code from a supplied data listUsagecreateSimplePage(data)Argumentsdata a list of data entries for the resulting markdown page.Following entries can be provided:title Page titledescription General descriptionlimitations Limitations the implementation comes withauthors Module authorsValuea character vector containing the produced markdown textAuthor(s)Jan Philipp DietrichSee AlsogoxygenextractDocumentation13 extractDocumentation extractDocumentationDescriptionExtracts doxygen-like GAMS documentation.Entries are introduced with an@type at the begin-ning of the line.In case of@realization also GAMS code is read and interpreted,in all other cases only the specific documentation comment is evaluated.UsageextractDocumentation(path,start_type=NULL,comment="* ")Argumentspath path to thefile(s)which should be evaluatedstart_type set type forfirst line of code.This can be useful to extract documentation even if no documentation type has been set(e.g reading equations.gms as type real-ization)comment comment chars used for documentation commentsValuea list of documentation pieces with type as name of each elementAuthor(s)Jan Philipp DietrichSee AlsogoxygenExamplesmainfile<-paste0(system.file("dummymodel",package="gms"),"/main.gms")calcfile<-paste0(system.file("dummymodel",package="gms"),"/modules/02_crazymodule/complex/calculations.gms") #extracting information from the main file of the modelextractDocumentation(mainfile)#extracting information from a file with some equations in itextractDocumentation(calcfile)gamsequation2tex gamsequation2texDescriptionConvert a gams equation into latex codeUsagegamsequation2tex(x)Argumentsx GAMS equation provided as characterValueGAMS equation converted to latex codeAuthor(s)Jan Philipp DietrichSee AlsogoxygenExamplesx<-"eq_1..v_a=e=sum(j,v_b(j)*((1-s_c)+sum(cell(i,j),v_d(i)/f_d(i))));"cat(gamsequation2tex(x))goxygen goxygenDescriptionDocumentation function which extracts a full model documentation from a modularized gams model.The function extracts comments used as documentation,extracts code and can extract and convert GAMS equations as latex code.Output is returned in Markdown,HTML and PDF format.Usagegoxygen(path=".",docfolder="doc",cache=FALSE,output=c("html","tex","pdf"),htmlStyle="ming",cff="CITATION.cff",modularCode=is.modularGAMS(),unitPattern=c("\\(","\\)"),includeCore=FALSE,mainfile="main.gms",...)Argumentspath path to the model to be documenteddocfolder folder the documentation should be written to relative to model foldercache Boolean to allow read data from existing cachefileoutput List of output to be written,available are"html","pdf"and"tex"htmlStyle visualization style to be used for the HTML creation.Currently available styles are"classic"and"ming".Ignored for outputs other than HTML.cff path to a citationfile in citation-file-format(ignored if not existing)modularCode Boolean deciding whether code should be interpreted as modular GAMS code (only av)unitPattern pattern that is usedto identify the unit in the description,default=c("\(","\)") includeCore boolean whether core should be included or not,default=FALSEmainfile mainfile of the model...optional arguments to interfaceplot,passed via modules_interfaceplot. NoteDocumentation lines in the code must start with*’to be detected as documentation.Identifier at the beginning of each block describe what kind of documentation is given.All identifiers start with @followed by the name of the identifier.Currently,following identifiers are available •@title Title•@authors List of authors•@description Model description(only the documentation text will be interpreted)•@equations Equation description(documentation text will be extracted and gams equations will be converted to latex code)•@code Code description(documentation text and code will be extracted)•@limitations details about limitations of an implementation16oldBuildHTML •@stop everything following will be ignored until the next identifier is mentioned eful to stop a sectionIn addition you can store a model logo(100px height,100px weight)as logo.png in the main folder of the model which then will be used in the HTML version of the documentation.If you want to add citations to your documentation you can do so by adding a bibtexfile with the name literature.bib in the main folder of the model.To link these references in the text you can use the syntax@<id> in which"<id>"stands for the identifier given to the corresponding bibtex entry.Author(s)Jan Philipp DietrichSee AlsocodeCheck,interfaceplotExamples#make sure that pandoc is availableif(check_pandoc()){#run goxygen for dummy model and store documentation as HTML in a temporary directory docfolder<-paste0(tempdir(),"/doc")goxygen(system.file("dummymodel",package="gms"),docfolder=docfolder,output="html") }oldBuildHTML oldBuildHTMLDescriptionConverts a folder with markdownfiles and a corresponding literature library(if available)to HTML files and creates cross-links between them.UsageoldBuildHTML(folder="html",mdfolder="markdown",literature="literature.bib",citation="../CITATION.cff",supplementary=NULL,addHTML=NULL)returnReferences17Argumentsfolder location the HTMLfiles should be written tomdfolder path to the markdown folder to be used as sourceliterature path to a bibliography,if available(will be ignored iffile does not exist)citation Citation information in citationfile format(optional)supplementary a vector offiles and/or folders required for the conversion(e.g.an images sub-directory withfigures to be shown in the documents)addHTML character vector with HTML code which should be added to the body of each HTMLfile.DetailsPandoc(https:///)together with pandoc-citeproc need to be installed on the system. Author(s)Jan Philipp DietrichSee Alsogoxygen,buildTEXreturnReferences returnReferencesDescriptionSupport function to create a referencefile linking references with corresponding adresses.UsagereturnReferences(names,targets,file,level=2)Argumentsnames vector of reference namestargets vector of reference adresses(same order and lengths as names)file name of the referencefile to be writtenlevel level of the"References"title to be writtenAuthor(s)Jan Philipp DietrichIndex.empty,2.header,3.interfaceplot,3.limitations,4.updateImagePaths,5.write,5buildHTML,6,7,8buildMarkdown,7buildTEX,6,7,17check_pandoc,8codeCheck,10,11,16 createIndexPage,9 createListModularCode,9 createListSimpleCode,10 createModulePage,2–5,11 createSimplePage,12 extractDocumentation,13gamsequation2tex,14goxygen,2–9,12–14,14,17interfaceplot,15,16modules_interfaceplot,15 oldBuildHTML,16returnReferences,1718。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
二 GAMS简明教程由Richard E. Rosenthal编著(译者:该翻译由华中科技大学能源与动力工程学院小海完成,由于译者水平有限,其中肯定会有些问题,欢迎大家阅读并批评指正!)简介这本书的简介部分以一个详细的例子结束,这个例子是一个用GAMS进行表达、解决和分析的小而简单的优化问题。
由来自蒙特利尔市Naval研究生院的Richard 编写。
通过这个例子我们可以对GAMS有一个快速而全面的了解。
很多地方引用到本书其他章节的知识,方便大家进一步查阅;而阅读这一部分即使不看本书其他章节也能看懂并且有所收获。
例子是一个关于运输的线性规划问题,这个问题在最优化技术发展过程中曾经被当做实验对象。
用这个例子展示GAMS这类代数建模语言的强大功能是很好的选择,因为不管手头要处理的问题有多大,运输问题本身具有一个简单的、可用的代数结构。
你可以发现,如果要解决一个非常大的运输问题,我们将呈现的用于解决小规模运输问题的GAMS输入文件中的内容并不需要改变多少。
在熟悉的运输问题中,我们考虑几个工厂的供应和几个市场的需求的商品,我们也给出从工厂运输商品到市场的单位花费。
这其中的经济学问题是:怎样安排运输使得我们的总运输成本最小这个问题的代数表达常常采用下列方式:Indices:i = plantsj = marketsGiven Data:ia= supply of commodity of plant i (in cases)ijb= demand for commodity at market jijc = cost per unit shipment between plant i and market j ($/case)Decision Variables:ijx = amount of commodity to ship from plant i to market j (cases),Whereijx ≥0, for all i, jConstraints:Observe supply limit at plant i:jij ja x≤∑ for all i (cases)Satisfy demand at market j:ij jix b ≥∑ for all j (cases)Objective Function: Minimizeij ijijcx ∑∑ ($K)注意这个例子显示了一些一般情况下我们认为是好习惯的建模方式,这些在GAMS里面被继承了。
首先,模型程序中的各组成部分都按类型分组定义了。
其次,GAMS程序各组成部分先后次序已经定好了,因此没有标识符能在被定义之前使用。
第三,各组成部分都有特定的单位。
第四,选择的单位要使优化过程中得到的数值具有相对较小的绝对数量级。
(例如标识$K表示dollar的千倍)各组成部分类型的名称在不同的模型中可能不一样。
例如,经济学家分别用外生变量和内生变量来表示已知数据和决策变量。
(译者:在经济模型中,内生变量是指该模型所要决定的变量。
外生变量指由模型以外的因素所决定的已知变量,它是模型据以建立的外部条件。
内生变量可以在模型体系内得到说明,外生变量决定内生变量,而外生变量本身不能在模型体系中得到说明。
参数通常是由模型以外的因素决定的,因此也往往被看成外生变量。
例:P=a+bQ,表示价格与数量的关系,则a、b是参数,都是外生变量;P、Q是模型要决定的变量,所以是内生变量。
除此之外,譬如相关商品的价格,人们的收入等其他于模型有关的变量,都是外生变量)在GAMS中,被采用的相关术语是:sets表示指数下标,parameters表示已知数,variables 表示决策变量,equations表示约束方程和目标方程。
运输问题的GAMS语言表述紧密的联系了上述几个部分。
最主要的区别在于GAMS表述可以被电脑读取和运行。
作为运输问题的例子,假设有两个罐头厂和三个市场,已知数据如表所示。
运输距离的单位是千英里,运输成本是$每箱每千英里。
这个例子的GAMS表述是:Setsi canning plants / seattle, san-diego /j markets / new-york, chicago, topeka / ;Parametersa(i) capacity of plant i in cases/ seattle 350san-diego 600 /b(j) demand at market j in cases/ new-york 325chicago 300topeka 275 / ;Table d(i,j) distance in thousands of milesnew-york chicago topekaseattlesan-diego ;Scalar f freight in dollars per case per thousand miles /90/ ;Parameter c(i,j) transport cost in thousands of dollars per case ; c(i,j) = f * d(i,j) / 1000 ;Variablesx(i,j) shipment quantities in casesz total transportation costs in thousands of dollars ;Positive Variable x ;Equationscost define objective functionsupply(i) observe supply limit at plant idemand(j) satisfy demand at market j ;cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;supply(i) .. sum(j, x(i,j)) =l= a(i) ;demand(j) .. sum(i, x(i,j)) =g= b(j) ;Model transport /all/ ;Solve transport using lp minimizing z ;Display , ;如果你在GAMS中建立一个文件,将以上内容输入进去,运输模型就可以被建立和进行计算了。
要使GAMS在不同的计算机上运行需要改变一些细节,但是最简单的方法(不提供非必要服务的方法)是在输入文件的名字后面加上GAMS这几个字母。
在程序运行过程中,你将看到一些精练的描述GAMS运行过程的字符行,包括了写入输出结果的文件名。
当GAMS程序结束时,检查文件,如果一切正常的话,那么最优化运输方案将显示如下:new-york chicago topekaseattlesan-diego你还可以得到如下所示边际成本(单纯形乘数):chicago topekaseattlesan-diego这些结果表明,举例来说,采用最优化方案就不要从Seattle送货到Topeka,但是你坚持要这样做的话,你将比最优化方案多付$K($)每箱的成本。
(你能从优化运输方案和已知数据中证明这个数据的正确性吗)(译者:可以这样想,因为只能由Seattle和San Diego向Topeka送货,为了满足Topeka 市场275箱的需求,从SanDiego少送一箱就要从Seattle补送一箱,这样算来,多出的成本就等于(‐)*90=36) GAMS模型的结构本章的剩余部分我们将讨论GAMS模型的基本组成部分,还是以上面提到的运输问题为例。
表列出了基本组成部分。
GAMS中有可供用户选择的输入模块,例如编辑损坏数据的检查信息和要求显示客户结果列表。
其他可供选择的高级特征包括保存和恢复原模型,以及在一次运行中创建联合模型,但是这个教程仅仅讨论基本的部分。
在开始介绍各个部分之前,以下几点需要说明:1. GAMS模型是指一组GAMS语言表述的集合。
而组织这些表述的唯一规则是在模型的一个部分被声明之前它是无法被引用的。
2. GAMS的表述能以任何一种吸引人的排版方式呈现在用户眼前,一个表述占用多行,插入空白行,以及一行中多个表述都是可以的。
在这个教程中你可以了解那些是被允许的格式,但是一些更详细的规则将在下一章给出。
3. 如果你是GAMS新手,你应该在每一个表述的最后加上分号,如例中所示。
GAMS编译器不区分大小写字母,你可以随意使用。
4. 说明文档方便用户看懂数学模型。
说明文档整个集中的被包含在模型表述中比把它分开书写要更为有效(往往也更为准确)。
至少有两种方法向GAMS模型中插入此类说明文件。
第一,GAMS编译器将把以一个星号开头的行作为注解行。
第二,或许更为重要,可以用特定的GAMS语句插入说明文档。
在运输模型中所有的小写文字都是以第二种形式插入的说明文档。
Inputs:SetsDeclarationAssignment of membersData (Parameters, Tables, Scalars)DeclarationAssignment of valuesVariablesDeclarationAssignment of typeAssignment of bounds and/or initial values (optional)EquationsDeclarationDefinitionModel and Solve statementsDisplay statement (optional)Outputs:Echo PrintReference MapsEquation ListingsStatus ReportsResultsTable : The basic components of a GAMS model5. 正如你看到的以上输入部分,建构GAMS组成部分包括两个部分:声明以及赋值或者定义。
声明是指表明其存在性并且给其取个名字。
赋值或者定义是指给其赋予某个值或者格式。
以equations为例,你必须用单独的GAMS表述声明和定义它。
然而对于其他所有的GAMS组成部分,你可以选择在同一个表述中或者单独对其进行声明或赋值。
6. 模型各组成部分的名字必须以字母开头,并且长度不超过31个字符,除第一个字符外可以使用字母或数字。
Sets 指数下标Sets是GAMS模型基本的组成部分,它如同数学公式中的指数下标。
运输例子中该部分表述如下:Setsi canning plants / seattle, san-diego /j markets / new-york, chicago, topeka / ;本表述的作用很明显。
我们声明了两个指数下标并且给它们起名为i 和j。