资源预览内容
第1页 / 共34页
第2页 / 共34页
第3页 / 共34页
第4页 / 共34页
第5页 / 共34页
第6页 / 共34页
第7页 / 共34页
第8页 / 共34页
第9页 / 共34页
第10页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
精品文档,仅供学习与交流,如有侵权请联系网站删除最小费用运输问题单位 销地运价产地B1B2B3B4B5B6B7B8产量A16267425960A24953858255A35219743351A47673927143A52395726541A65522814352销量3537223241324338280/302i.e:model:!6发点8收点运输问题;sets: warehouses/wh1.wh6/: capacity; vendors/v1.v8/: demand; links(warehouses,vendors): cost, volume;endsets!目标函数; min=sum(links: cost*volume);!需求约束; for(vendors(J): sum(warehouses(I): volume(I,J)=demand(J);!产量约束; for(warehouses(I): sum(vendors(J): volume(I,J)=capacity(I);!这里是数据;data: capacity=60 55 51 43 41 52; demand=35 37 22 32 41 32 43 38; cost=6 2 6 7 4 2 9 5 4 9 5 3 8 5 8 2 5 2 1 9 7 4 3 3 7 6 7 3 9 2 7 1 2 3 9 5 7 2 6 5 5 5 2 2 8 1 4 3;enddata1 LINGO中的集1.1 The Sets Section of a ModelSets are defined in an optional section of a LINGO model, called the sets section. Before you use sets in a LINGO model, you have to define them in the sets section of the model. The sets section begins with the keyword SETS: (including the colon), and ends with the keyword ENDSETS. A model may have no sets section, a single sets section, or multiple sets sections. A sets section may appear anywhere in a model. The only restriction is you must define a set and its attributes before they are referenced in the models constraints.1.2 Defining Primitive SetsTo define a primitive set in a sets section, you specify: the name of the set, optionally, its members (objects contained in the set), and optionally, any attributes the members of the set may have.A primitive set definition has the following syntax: setname / member_list / : attribute_list;When using implicit set member lists, you do not have to list a name for each set member. Use the following syntax when using an implicit set member list:setname / member1.memberN / : attribute_list;where member1 is the name of the first member in the set and memberN is the name of the last member. LINGO automatically generates all the intermediate member names between member1 and memberN. While this can be a very compact and convenient method for building a primitive set, there is one catch in that only certain formats of names are accepted for the initial and terminal member names. The following table details the available options:Implicit MemberList FormatExample Set Members1.n1.51, 2, 3, 4, 5stringM.stringNTRUCKS3.TRUCKS204TRUCK3, TRUCK4, ., TRUCK204dayM.dayNMON.FRIMON, TUE, WED, THU, FRImonthM.monthNOCT.JANOCT, NOV, DEC, JANmonthYearM.monthYearNOCT2001.JAN2002OCT2001, NOV2001, DEC2001, JAN2002i.e1:!集部分;sets: students:sex,age;endsets!数据部分;data: students,sex,age= John 1 16 Jill 0 14 Rose 0 17 Mike 1 13;enddatai.e2:data: NUMBER_OF_WH = 6;enddatasets: WAREHOUSES / 1.NUMBER_OF_WH/: CAPACITY;endsets1.3 Defining Derived SetsTo define a derived set, you specify: the name of the set, its parent sets, optionally, its members, and optionally, any attributes the set members have.A derived set definition has the following syntax:setname( parent_set_list) / member_list / : attribute_list;i.e3:sets: product/ A ,B/; machine / M, N/; week/ 1.2/; allowed(product,machine,week);endsetsallowed Set Membership:IndexMember1(A,M,1)2(A,M,2)3(A,N,1)4(A,N,2)5(B,M,1)6(B,M,2)7(B,N,1)8(B,N,2)i.e:sets: !学生集:性别属性sex,1表示男性,0表示女性;年龄属性age. ; students/John,Jill,Rose,Mike/:sex,age; !男学生和女学生的联系集:友好程度属性friend,0,1之间的数。 ; linkmf(students,students)|sex(&1) #eq# 1 #and# sex(&2) #eq# 0: friend; !男学生和女学生的友好程度大于0.5的集; linkmf2(linkmf) | friend(&1,&2) #ge# 0.5 : x;endsetsdata: sex,age = 1 16 0 14 0 17 0 13; friend = 0.3 0.5 0.6;enddataNote:竖线是用来标记一个成员资格过滤器的开始。#eq#表示逻辑运算符,相等为真,&1表示派生集的第1个原始父集的索引,它取遍该原始父集的所有成员;,&2表示派生集的第2个原始父集的索引,它取遍该原始父集的所有成员;以此类推。2 LINGO中的数据部分数据部分提供了模型相对静止部分和数据分离的可能性。数据部分以关键字“data:”开始,以关键字“enddata”结束。在这里,可以指定集成员、集的属性。其语法如下:object_list = value_list;对象列(object_list)包含要指定值的属性名、要设置集成员的集名,用逗号或空格隔开。一个对象列中至多有一个集名,而属性名可以有任意多。如果对象列中有多个属性名,那么它们的类型必须一致。如果对象列中有一个集名,那么对象列中所有的属性的类型就是这个集。数值列(value_list)包含要分配给对象列中的对象的值,用逗号或空格隔开。注意属性值的个数必须等于集成员的个数。i.e:sets: set1/A,B,C/: X,Y;endsetsdata: X=1,2,3; Y=4,5,6;enddata也可采用复合数据声明(data statement)实现同样的功能。i.e:sets: set1/A,B,C/: X,Y;endsetsdata: X,Y=1 4 2 5 3 6;enddata看到这个例子,可能会认为X被指定了1、4和2三个值,因为它们是数值列中前三个,而正确的答案是1、2和3。假设对象列有n个对象,LINGO在为对象指定值时,首先在n个对象的第1个索引处依次分配数值列中的前n个对象,然后在n个对象的第2个索引处依次分配数值列中紧接着的n个对象,以此类推。模型的所有数据属性值和集成员被单独放在数据部分,这可能是最规范的数据输入方式。3 LINGO中的函数3.1 逻辑运算符(Logical Operators)LogicalOperatorReturn Value#NOT#
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号