LINGO的数据段

The DATA Section
Typically, you willwant to initialize the members of certain sets and assign values to certain set
attributes. For this purpose, LINGO uses a second optional section called the datasection. The data
section
allows you to isolate data from the equations of your model.This is a useful practice in that it
leads to easier model maintenance and facilitates scaling up a model to largerdimensions.

数据段

通常情况下,你想初始化某些集的成员并将值赋给某些特定集的属性。为此,LINGO使用另一个称为数据段的可选部分。数据段允许你从你的模型方程中抽象出数据。这是有用的做法,因为它促进维护更简单的模型并使模型扩大到更大规模。


Similar to the sets section, the data section begins with the keyword DATA: (includingthe colon) and
ends with the keyword ENDDATA. In the data section, you can havestatements to initialize the sets
and/or attributes you defined in a sets section. These expressions have thesyntax:
object_list = value_list;

类似于集合段,数据段以关键字DATA:(包括冒号)开始, 以ENDDATA关键字结束。在数据段中,你可以初始化集合、在集合段中定义的属性。其语法为:

         object_list = value_list;


The object_list contains the names of a set and/or attributes you wantto initialize, optionally separated
by commas. If there is more than one attribute name on in the object list, thenall attributes must be
defined on the same set. Furthermore, if a set name appears in the object list,then it must be the parent
set of any attributes also in the object list. The value_list containsthe values to assign to the objects in
the object list, optionally separated by commas. For example, considerthe following model:
MODEL:
SETS:
SET1: X, Y;
ENDSETS
DATA:
SET1 = A B C;
X = 1 2 3;
Y = 4 5 6;
ENDDATA
END
We have twoattributes, X and Y, defined on the set SET1. The threevalues of X are set to 1, 2, and 3,
while Y is set to 4, 5, and 6. We could have also used the followingcompound data statement to the
same end:
MODEL:
SETS:
SET1: X, Y;
ENDSETS
DATA:
SET1 X Y = A 1 4
B 2 5
C 3 6;
ENDDATA
END

对象列(object_list)包含要设置集成员的集名、要指定值的属性名,用逗号隔开。如果对象列中有多个属性名,那么它们的类型必须一致。此外,如果对象列中有一个集名,那么对象列中所有的属性的类型就是这个集。数值列(value_list)包含要分配给对象列中的对象的值,用逗号隔开。例如,考虑以下模型:

MODEL:

SETS:

SET1:X, Y;

ENDSETS

DATA:

SET1 =A B C;

X = 1 23;

Y = 4 56;

ENDDATA

END

在集SET1中定义了两个属性X和Y。X的三个值设置为 1、 2 和 3,Y的三个值是4、 5 和 6。也可以使用如下的复合数据声明实现同样的功能:

MODEL:

SETS:

SET1:X, Y;

ENDSETS

DATA:

SET1 XY = A 1 4

B 2 5

C 3 6;

ENDDATA

END


An important factto remember is that when LINGO reads a compound data statement's value list, it
assigns the first n values in the list to the first position of each ofthe n objects in the object list, the
second n values to the second position of each of the n objects,and so on. In other words, LINGO is
expecting the input data in column format rather than row format, which mirrorsthe flat file approach
used in relational databases. 

要记住的重要一点是,当LINGO读取复合数据语句的数值列,它指定列表中的第一次n值的每个在对象列中的n对象,到第二次出现的n对象、每第二次n值的第二个位置等等。换句话说,LINGO期待反映在关系数据库中使用的平面文件方法的输入数据的列格式,而不是行格式。


This section hasserved to give you a brief introduction into the use of the data section. In Dataand
Init Sections
, you will learn more about the capabilities of the datasection. You will learn data does
not have to actually reside in the data section as shown in examples here. Infact, your data section can
have OLE links to Excel, ODBC links to databases, and connections to text baseddata files.


这一节给你简要介绍数据段的使用。在数据和初始化部分,你将学习更多关于数据段的功能。你将了解数据而不必拘束在示例的数据段中。事实上,你的数据段中可以有链接到 Excel的OLE,链接到数据库的ODBC,以及链接到文本数据文件的连接。

 

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