LINGO中的集

The Sets Section of a Model

Sets are defined in an optional section of a LINGO model calledthe sets section. Before you use sets

in a LINGO model, you have to define them in the sets section of the model. Thesets 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 setssection may appear
anywhere in a model. The only restriction is you must define a set and itsattributes before they are
referenced in the model’s constraints.

 


模型的集部分

集合段是LINGO模型的可选部分。在LINGO模型中使用集之前,必须在模型的集合段先定义。集合段以关键字“SETS:”(关键字不包括引号,必须有冒号)开始,以关键字“ENDSETS” (关键字不包括引号)结束。一个LINGO模型可以没有集合段,一个或多个集合段。各集合段可以安置于LINGO模型程序的任何部分。唯一的限制是必须在模型约束中引用一个集及其属性之前先定义。

 

Defining Primitive Sets
To define a primitive set in a sets section, you specify:
¨ the name of the set,
¨ optionally, its members (objectscontained in the set), and
¨ optionally, any attributes themembers of the set may have.
A primitive set definition has the following syntax:
setname [/ member_list /] [: attribute_list];
Note: The use of square brackets indicates an item is optional.In this particular case, a primitive
set’s attribute_list and member_list are both optional.

 


定义原始集

在集合段定义原始集,你要指定:

¨集的名称

¨可选,集的成员,
¨可选,相应的属性

原始集的定义有以下的语法:

       setname [/ member_list /] [: attribute_list];

注意:使用方括号指定项目是可选的。在这特定的情况下,原始集的member_listattribute_list都是可选的。

 

The setname is a name you choose to designate the set. Itshould be a descriptive name that is easy to
remember. The set name must conform to standard LINGO naming conventions. Inother words, the
name must begin with an alphabetic character, which may be followed by up to 31alphanumeric
characters or the underscore (_). LINGO does not distinguish between upper andlowercase characters
in names.

setname是你选择的来标记集的名字。最好具有较强的可读性。集名字必须严格符合LINGO标准命名规则。换句话说,该名称必须以拉丁字母或下划线为首字母,其后由拉丁字母、下划线、阿拉伯数字组成的总长度不超过32个字符的字符串。LINGO不区分大小写。
A member_list is a list of the members that constitute the set. If theset members are included in the set
definition, they may be listed either explicitly or implicitly.If set members are not included in the set
definition, then they may be defined subsequently in a datasection of the model. For details on
defining set members in a data section, refer to Introduction to the DataSection.

member_list是集成员列表。如果集成员放在集定义中,那么对它们可采取显示罗列和隐式罗列两种方式。如果集成员不放在集定义中,那么可以在随后的模型的数据段定义它们。在数据段中定义集的详细信息,请参阅数据段的介绍。
When listing members explicitly, you enter a unique name for each member,optionally separated by
commas. As with set names, member names must also conform to standard namingconventions. In the
Wireless Widgets model, we could have used an explicit member list to definethe set WAREHOUSES
in the sets section as follows:
WAREHOUSES / WH1 WH2 WH3 WH4 WH5 WH6/:CAPACITY;

当显示罗列成员时,输入每个成员的唯一名称,中间用逗号隔开。与集合名一样,成员名也必须符合LINGO标准命名规则。在无线小部件模型中,我们可以使用显示成员列表在集合段定义集合WAREHOUSES,如下所示:

       WAREHOUSES / WH1 WH2 WH3 WH4 WH5 WH6/: CAPACITY;


When using implicit set member lists, you do not have to list aname for each set member. Use the
following syntax when using an implicit set member list:
setname / member1..memberN / [: attribute_list];

当使用隐式集合成员列表时,你不需列出每个成员的名称。使用隐式集合成员列表时,请使用以下语法:

       setname member1..memberN / [: attribute_list];

where member1 is the name of the first member in the set and memberN isthe name of the last
member. LINGO automatically generates all the intermediate member names betweenmember1 and
memberN. While this can be a very compact and convenient method forbuilding a primitive set, there
is one catch in that only certain formats of names are accepted for the initialand terminal member
names.

member1是集合的第一个成员名称,memberN是最后一个成员的名称。LINGO自动生成member1和memberN之间的所有中间成员名称。尽管这可以是建立原始集的一个非常紧凑、方便的方法,问题在于只有某些特定格式的名称能以这种首成员和尾成员的语法。

 


When using the 1..n format, n may be any positiveinteger value, and the initial member must always
be a 1.

当使用1..n格式,n可以是任意正整数,并且首成员必须总是1。
The stringM..stringN format allows you to use any string to start boththe initial and terminal member
names as long as the string conforms to standard LINGO naming conventions. Mand N must be
nonnegative and integer, such that M N.

StringM..stringN格式允许你使用任何字符串开始首、末成员名称,只要字符串符合LINGO标准命名约定。M和N必须是非负整数,如≤ N
The dayM..dayN format allows you to choose the initial and terminalmember names for the names of
the days of the week. All names are abbreviated to three characters. Thus, theavailable options are:
Mon, Tue, Wed, Thu, Fri, Sat, and Sun.

dayM..dayN格式允许你选择首、末成员名的星期数。所有名称缩写成三个字母。因此,可用的选项是:Mon, Tue, Wed, Thu, Fri, Sat,和 Sun。
The monthM..monthN format allows you to select from the months of theyear, where all names are
abbreviated to three characters. The available options are: Jan, Feb, Mar, Apr,May, Jun, Jul, Aug, Sep,
Oct, Nov, and Dec.

monthM..monthN格式允许你选择首、末成员名的月数,所有的名称缩写成三个字母。可用的选项是:Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep,Oct, Nov, 和Dec。
The monthYearM..monthYearN option allows you to specify a month and afour digit year.

monthYearM..monthYearN选项允许你指定月份和四位数字的年份。

As further illustration, in the Wireless Widgets example,we could have also defined the
WAREHOUSES set as:
WAREHOUSES / 1..6/: CAPACITY;
As an alternative, when using this 1..n form of implicitdefinition, you may also place the length of the
set in a data section, and then reference this length in a subsequent setssection as we do here:
DATA:
NUMBER_OF_WH = 6;
ENDDATA
SETS:
WAREHOUSES / 1..NUMBER_OF_WH/: CAPACITY;
ENDSETS

为了进一步说明,在无线小部件示例中,我们也可以定义集合WAREHOUSES为:

       WAREHOUSES/ 1..6/: CAPACITY;

作为替代方法,使用1..n隐式定义,你也可以在数据段说明集合的长度,然后在随后集合段中引用此长度,如我们这里所做:

DATA:
NUMBER_OF_WH = 6;
ENDDATA
SETS:
WAREHOUSES / 1..NUMBER_OF_WH/: CAPACITY;
ENDSETS


Set members may have one or more attributes specified inthe attribute_list of the set definition. An
attribute is simply some property each member of the set displays. Forinstance, in the WAREHOUSES
set above, there is a single attribute titled CAPACITY, which is used torepresent the shipping capacity
of the WAREHOUSES. Attribute names must follow standard namingconventions and be separated by
commas.

集成员可能有一个或多个指定在集合定义中的attribute_list(属性列表)attributes(属性)。属性只是每个成员展示的一些性质。例如,在WAREHOUSES集合中,只有一个用来表示WAREHOUSES运输能力的CAPACITY属性。属性名称必须符合LINGO标准命名规则,用逗号隔开。

 


For illustration, suppose our warehouses had additional attributesrelated to their location and the
number of loading docks. These additional attributes could be added to theattribute list of the set
declaration as follows:
WAREHOUSES / 1..6/: CAPACITY, LOCATION,DOCKS;
In addition to listing a primitive set's members in a model's setssection, primitive set members may
also be listed in a model's data section. Some users may prefer thisalternative approach in that a set's
members are actually input data for the model. Therefore, listing set membersin a model's data
section, along with all other data, is a more natural approach that makes amodel more readable. All
the various techniques listed above for enumerating a primitive set's membersare also valid in a data
section. Some examples of defining primitive set members in a data sectionfollow:
SETS:
WAREHOUSES: CAPACITY;
ENDSETS
DATA:
WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;
ENDDATA
Example 1: Listing aPrimitive Set in a Data Section
SETS:
WAREHOUSES: CAPACITY;
ENDSETS
DATA:
NUMBER_OF_WH = 6;
WAREHOUSES = 1..NUMBER_OF_WH;
ENDDATA
Example 2: Listing aPrimitive Set in a Data Section

 

举例说明,假设我们的仓库有他们的位置和装货码头数目的的附加属性。这些额外的属性能添加到集合声明的属性列表中,如下:

       WAREHOUSES / 1..6/: CAPACITY, LOCATION, DOCKS;

为了在模型的集合段罗列原始集成员,原始集成员也可在模型数据段中列出。有些用户可能喜欢这种替代方式,这一组成员是模型实际输入的数据。因此,和所有其他数据一样,在模型的数据段列出集合成员,这是一种更自然的方法,使模型更具可读性。上面列出的用于枚举原始集成员的各种方式在数据段也是有效的。在数据段中定义原始集的成员的一些示例如下:

SETS:

WAREHOUSES

: CAPACITY;

ENDSETS

DATA:

WAREHOUSES = WH1 WH2 WH3 WH4 WH5 WH6;

ENDDATA

例1: 在数据段罗列原始集段罗列原始集

SETS:

WAREHOUSES: CAPACITY;

ENDSETS

DATA:

NUMBER_OF_WH = 6;

WAREHOUSES = 1..NUMBER_OF_WH;

ENDDATA

例 2: 在数据段罗列原始集

 


Defining Derived Sets
To define a derived set, you specify:
¨ the name of the set,
¨ its parent sets,
¨ optionally, its members,and
¨ optionally, any attributes theset members may have.

定义派生集:

定义派生集,你要指定:

¨集合名
¨父集的名称
¨可选,集成员
¨可选,集属性


A derived set definition has the following syntax:
setname(parent_set_list) [ / member_list /] [: attribute_list];

派生集定义的语法为:

       setname(parent_set_list)[/member_list/][:attribute_list];


The setname is a standard LINGO name you choose to name the set.

setname是你选择命名集的标准LINGO名字。
The parent_set_list is a list of previously defined sets, separated bycommas. Without specifying a
member_list element, LINGO constructs all combinations of members fromeach parent set to create
the members of the new derived set. As an example, consider the following setssection:
SETS:
PRODUCT / A B/;
MACHINE / M N/;
WEEK / 1..2/;
ALLOWED(PRODUCT, MACHINE, WEEK);
ENDSETS

parent_set_list是已定义的集的列表,多个时必须用逗号隔开。如果没有指定member_list(成员列表),那么LINGO会自动创建父集成员的所有组合作为派生集的成员。作为一个例子,请考虑以下的集合段:

SETS:
PRODUCT / A B/;
MACHINE / M N/;
WEEK / 1..2/;
ALLOWED(PRODUCT, MACHINE, WEEK);
ENDSETS

Sets PRODUCT, MACHINE, and WEEK are primitivesets, while ALLOWED is derived from parent
sets, PRODUCT, MACHINE, and WEEK.

集合PRODUCT,MACHINE和WEEK是原始集,而ALLOWED来自父集PRODUCT,MACHINE和WEEK。

 


The member_list is optional, and is used when you want tolimit the set to being some subset of the full
set of combinations derived from the parent sets. The member_list mayalternatively be specified in a
model’s data section (for details on this see Introduction to the DataSection in Chapter 4, Data and
Init Sections
).

member_list是可选的,在你想要限制来自父集的某个子集时使用。member_list可指定模型的数据段(有关此请看第4章数据段的介绍,数据和初始化部分中的信息)。
If the member_list is omitted, the derived set will consist of allcombinations of the members from the
parent sets. When a set does not have a member_list and, therefore,contains all possible combinations
of members, it is referred to as being a dense set. When a set includesa member_list that limits it to
being a subset of its dense form, we say the set is sparse.

member_list(成员列表)被忽略时,派生集成员由父集成员所有的组合构成。当集合没有member_list时,因此,包含所有可能组合的成员,这样的派生集成为稠密集。如果限制派生集的成员,使它成为父集成员的所有组合构成的集合的一个子集,这样的派生集成为稀疏集。

A derived set’s member_list may be constructed usingeither:
¨ an explicit member list,or
¨ a membership filter.

派生集的成员列表(member_list)有两种方式生成:

¨ 显示罗列
¨设置成员资格过滤器


When using the explicit member list method to specify a derived set’s member_list,you must
explicitly list all the members you want to include in the set. Each listedmember must be a member of
the dense set formed from all possible combinations of the parent sets.Returning to our small example
above, if we had used an explicit member list in the definition of the derivedset, ALLOWED, as
follows:
ALLOWED(PRODUCT, MACHINE, WEEK)
/ A M 1, A N 2, B N 1/;

当使用显示罗列方式指定派生集的member_list时,必须显式罗列出所有要包含在派生集中的成员。罗列的每个成员必须属于稠密集。使用前面的例子,如果我们使用显式成员列表中派生集的定义,ALLOWED,如下:

ALLOWED(PRODUCT,MACHINE, WEEK)

/ A M 1, A N 2, B N 1/;


then ALLOWED would not have had the full complement ofeight members. Instead, ALLOWED
would have consisted of the three member sparse set: (A,M,1), (A,N,2),and (B,N,1). Note that the
commas in the list of set members are optional and were added only forreadability purposes.

之后ALLOWED不会有完整的八名成员。相反,ALLOWED将有包括的三个成员稀疏集: (A,M,1)、 (A,N,2),和(B,N,1)。请注意集合成员的列表的逗号是可选的,只是为了提高可读性。
If you have a large, sparse set, explicitly listing all members can becomecumbersome. Fortunately, in
many sparse sets, the members all satisfy some condition that differentiatesthem from the
nonmembers. If you could just specify this condition, you could save yourself alot of effort. This is
exactly how the membership filter method works. Using the membership filtermethod of defining a
derived set’s member_list involves specifying a logical condition thateach potential set member must
satisfy for inclusion in the final set. You can look at the logical conditionas a filter to keep out
potential members that don’t satisfy some criteria.

如果需要生成一个大的、 稀疏集合,显式罗列就很繁琐。幸运的是,许多稀疏集成员都满足一些条件以和非成员区分。如果你可以指定这种情况,将轻松很多。这正是成员资格过滤器方法如何工作的。使用定义派生集member_list的成员过滤器方法涉及指定集成员的每个潜在的逻辑条件必须满足最后的集。我们可以把这些逻辑条件看作过滤器,在LINGO生成派生集的成员时把使逻辑条件为假的成员从稠密集中过滤掉。
As an example of a membership filter, suppose you have already defined a setcalled TRUCKS, and
each truck has an attribute called CAPACITY. You would like to derive asubset from TRUCKS that
contains only those trucks capable of hauling big loads. You could use anexplicit member list, and
explicitly enter each truck that can carry heavy loads. However, why do allthat work when you could
use a membership filter as follows:
HEAVY_DUTY(TRUCKS)|CAPACITY(&1) #GT#50000:

作为成员过滤示例,假设你已经定义了称为TRUCKS的集,每辆卡车有CAPACITY属性。你想要从只包含能够牵引大载荷的TRUCKS里派生子集。你可以使用显式成员列表,并显式输入每个能够承受重负荷的卡车。然而,为什么当你可以使用如下所示的成员资格过滤器时,做这样的所有工作呢:

         HEAVY_DUTY(TRUCKS)|CAPACITY(&1)#GT# 50000:


We have named the set HEAVY_DUTY and have derived it fromthe parent set, TRUCKS. The vertical
bar character (|) is used to mark the beginning of a membership filter. Themembership filter allows
only those trucks that have a hauling capacity (CAPACITY(&1))greater than (#GT#) 50,000 into the
HEAVY_DUTY set. The &1 symbol in the filter is known as a setindex placeholder. When building a
derived set that uses a membership filter, LINGO generates all the combinationsof parent set
members. Each combination is then “plugged” into the membership condition tosee if it passes the
test. The first primitive parent set’s member is plugged into &1,the second into &2, and so on. In this
example, we have only one parent set (TRUCKS), so &2 wouldnot have made sense. The symbol
#GT# is a logical operator and means “greater than”.

我们已命名集HEAVY_DUTY ,它是源自父集TRUCKS。竖线字符(|)用来标记成员资格过滤器的开始。成员资格过滤器只允许那些牵引能力(CAPACITY(&1))大于(#GT#)50000的卡车进入HEAVY_DUTY集。过滤器中的&1符号被称为集合索引占位符。在创建成员资格过滤器的派生集时,LINGO生成父集成员的所有的组合。每个组合随后“插入”成员条件,来观察它是否通过测试。第一个原始父集的成员插入到& 1,第二个插入到& 2,依此类推。在此示例中,我们有唯一的父集(TRUCKS),所以&2没有意义。符号#GT#是逻辑运算符,意为“大于”。
The logical operators recognized by LINGO are:
#EQ# equal
#NE# not equal
#GE# greater-than-or-equal-to
#GT# greater than
#LT# less than
#LE# less-than-or-equal-to

LINGO的逻辑运算符如下:

         #EQ#         等于

         #NE#            不等于

         #GE#            大于等于

         #GT#            大于

         #LT#     小于

         #LE#     小于等于


In addition to listing a derived set's members in a model's sets section,derived set members may also
be listed in a model's data section. Some users may prefer this alternativeapproach in that a set's
members are actually input data for the model. Therefore, listing set membersin a model's data
section, along with all other data, is a more natural approach that makes amodel more readable. All
the various techniques listed above for enumerating a primitive set's membersare also valid in a data
section, with the exception of the membership filter method. An example ofdefining derived set
members in a data section follow:
SETS:
PRODUCT;
MACHINE;
WEEK;
ALLOWED( PRODUCT, MACHINE, WEEK);
ENDSETS
DATA:
PRODUCT = P1..P3;
MACHINE = M1..M3;
WEEK = W1..W4;
ALLOWED =
P1 M1 W1
P2 M1 W3
P3 M1 W2
P3 M3 W4
;
ENDDATA
Inputting a Derived Set in aData Section


除了列出的模型集合段的派生集的成员,派生集的成员也可能在模型数据段中列出。有些用户可能喜欢这种替代的方式,这一组成员是模型的实际输入的数据。因此,和所有其他数据在模型的数据段列出集合成员,是一种更自然的方法,使模型更具可读性。上面列出的用于枚举原始集成员各种方式在数据段也是有效的。在数据段中定义原始集的成员的一些示例如下:

SETS:

PRODUCT;

MACHINE;

WEEK;

ALLOWED(PRODUCT, MACHINE, WEEK);

ENDSETS

DATA:

PRODUCT = P1..P3;

MACHINE = M1..M3;

WEEK    = W1..W4;

ALLOWED =

P1 M1 W1

P2 M1 W3

P3 M1 W2

P3 M3 W4

;

ENDDATA

在数据段中输入派生集

 


Summary
In summary, keep in mind that LINGO recognizes two types of sets—primitiveand derived.

总结

总之,牢记LINGO识别两种类型的集合——原始集和派生集。


Primitive sets are the fundamental objects in a model and can't be broken downinto smaller
components. Primitive sets can be defined using either an explicit or implicitlist. When using an
explicit list, you enter each member individually in the set member list. Withan implicit list, you enter
the initial and terminal set members and LINGO generates all the intermediatemembers.

原始集是模型中的基本对象,不能再被拆分成更小的组分。原始集可以由显式罗列和隐式罗列两种方式定义。使用显示罗列方式时,需在集成员列表中逐个输入每个成员。使用隐式罗列方式时,只需在集成员列表中输入首、末成员即可,而中间的成员由LINGO产生。
Derived sets, on the other hand, are created from other component sets. Thesecomponent sets are
referred to as the parents of the derived set, and may be either primitive orderived. A derived set can
be either sparse or dense. Dense sets contain all combinations ofthe parent set members (sometimes
this is also referred to as the Cartesian product or cross of theparent sets). Sparse sets contain only a
subset of the cross of the parent sets, and may be defined by two methods¾¾explicit listing or

membership filter. The explicit listing method involveslisting the members of the sparse set. The
membership filter method allows you to specify the sparse set members compactlythrough the use of a
logical condition that all members must satisfy.

另一方面,派生集是由其他的集来创建。这些集被称为该派生集的父集,它们可能是原始集或其他的派生集。派生集基既可以是稀疏的,也可以是稠密的。稠密集包含父集成员的所有组合 (有时也称为父集的笛卡儿乘积)。稀疏集仅包含父集的笛卡儿乘积的一个子集,可由显示罗列和成员资格过滤器这两种方式来定义。显示罗列方法包括罗列稀疏集的成员。成员资格过滤器方法通过使用稀疏集成员必须满足的逻辑条件从稠密集成员中过滤出稀疏集的成员。

At this point, you are probably thinking that set definition is,at best, somewhat complicated. We will
be presenting you with plenty more examples in subsequent sections that shouldhelp to illustrate the
concepts introduced in this section, and demonstrate that set definition isnowhere near as difficult as it
may seem. For now, however, we will turn our attention to how data is inputinto a model. Then, we
will examine a group of functions that are designed to operate on set members.Once we have
accomplished this, we will be able to bring together all we have learned inorder to begin building
some interesting and relevant examples of set-based modeling.

 

在这一点上,你可能在想,集的定义,充其量,就是稍微有点复杂。我们在以后的章节中将向你提供更多的例子,这将有助于阐释在本节中介绍的概念,并且证明集的定义就和看起来的一样难。现在,然而我们将把注意力转向如何将数据输入到一个模型中。然后,我们将检查一组旨在对集成员操作的函数。一旦完成了,我们将能够运用我们所学的开始建立基于集合的建模的一些有趣、相关实例。

 

原文地址:https://www.cnblogs.com/Genesis2018/p/9079837.html