0%

Gams 结果输出解读

简介

GMAS的输出包含以下几部分: 1. 编译结果 编译结果包含输入文件的打印,可能的错误提示以及GMAS对象和交叉引用图列表。 2. 执行结果 执行结果包含展示声明的结果和可能的执行错误提示。 3. 模型生成 该结果在模型生成过程给出,包含等式和变量列表以及模型统计和可可能的生成执行时的错误提示。 4. 解 外部求解器程序处理模型时生成的解报告包括:求解总结,求解器的报告,解列表以及报告总结。 5. 解后输出 输出的最后部分包括最终执行总结和文件总结。

模型示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$Title A Quadratic Programming Model for Portfolio Analysis (ALAN,SEQ=124a)

$onsymlist onsymxref onuellist onuelxref

$Ontext
This is a mini mean-variance portfolio selection problem described in
'GAMS/MINOS:Three examples' by Alan S. Manne, Department of Operations
Research, Stanford University, May 1986.
$Offtext

* This model has been modified for use in the documentation

Set i securities /hardware, software, show-biz, t-bills/;
alias (i,j);

Scalar target target mean annual return on portfolio % /10/,
lowyield yield of lowest yielding security,
highrisk variance of highest security risk ;

Parameters mean(i) mean annual returns on individual securities (%)
/ hardware 8
software 9
show-biz 12
t-bills 7 /

Table v(i,j) variance-covariance array (%-squared annual return)
hardware software show-biz t-bills
hardware 4 3 -1 0
software 3 6 1 0
show-biz -1 1 10 0
t-bills 0 0 0 0 ;

lowyield = smin(i, mean(i)) ;
highrisk = smax(i, v(i,i)) ;
display lowyield, highrisk ;

Variables x(i) fraction of portfolio invested in asset i
variance variance of portfolio
Positive Variable x;

Equations fsum fractions must add to 1.0
dmean definition of mean return on portfolio
dvar definition of variance;

fsum.. sum(i, x(i)) =e= 1.0;
dmean.. sum(i, mean(i)*x(i)) =e= target;
dvar.. sum(i, x(i)*sum(j,v(i,j)*x(j))) =e= variance;

Model portfolio / fsum, dmean, dvar / ;
Solve portfolio using nlp minimizing variance;
display x.l, variance.l;

1.编译输出

该结果在程序初始检查时生成。包括:输入文件的打印,符号引用图,符号清单图,特殊元素清单图和包含的文件总结。 ## 1.1 输入文件的打印 基本就是把输入的模型文本重新打印一遍。

1
2
3
4
5
6
7
8
9
10
A Quadratic Programming Model for Portfolio Analysis (ALAN,SEQ=124a)
C o m p i l a t i o n

2
4
This is a mini mean-variance portfolio selection problem described in
'GAMS/MINOS:Three examples' by Alan S. Manne, Department of Operations
Research, Stanford University, May 1986.
10
11 * This model has been modified for use in the documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
12
13 Set i securities /hardware, software, show-biz, t-bills/;
14 alias (i,j);
15
16 Scalar target target mean annual return on portfolio % /10/,
17 lowyield yield of lowest yielding security,
18 highrisk variance of highest security risk ;
19
20 Parameters mean(i) mean annual returns on individual securities (%)
21 / hardware 8
22 software 9
23 show-biz 12
24 t-bills 7 / ;
25
26 Table v(i,j) variance-covariance array (%-squared annual return)
27 hardware software show-biz t-bills
28 hardware 4 3 -1 0
29 software 3 6 1 0
30 show-biz -1 1 10 0
31 t-bills 0 0 0 0 ;
32
33 lowyield = smin(i, mean(i)) ;
34 highrisk = smax(i, v(i,i)) ;
35 display lowyield, highrisk ;
36
37 Variables x(i) fraction of portfolio invested in asset i
38 variance variance of portfolio ;
39 Positive Variable x ;
40
41 Equations fsum fractions must add to 1.0
42 dmean definition of mean return on portfolio
43 dvar definition of variance;
44
45 fsum.. sum(i, x(i)) =e= 1.0;
46 dmean.. sum(i, mean(i)*x(i)) =e= target;
47 dvar.. sum(i, x(i)*sum(j,v(i,j)*x(j))) =e= variance;
48
49 Model portfolio / fsum, dmean, dvar / ;
50 Solve portfolio using nlp minimizing variance;
51 display x.l, variance.l;

1.2 符号引用图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Symbol Listing


SYMBOL TYPE REFERENCES

dmean EQU declared 42 defined 46 impl-asn 50 ref 49
dvar EQU declared 43 defined 47 impl-asn 50 ref 49
fsum EQU declared 41 defined 45 impl-asn 50 ref 49
highrisk PARAM declared 18 assigned 34 ref 35
i SET declared 13 defined 13 ref 14 20 26 33 2*34
37 45 2*46 2*47 control 33 34 45 46 47
j SET declared 14 ref 26 2*47 control 47
lowyield PARAM declared 17 assigned 33 ref 35
mean PARAM declared 20 defined 21 ref 33 46
portfolio MODEL declared 49 defined 49 impl-asn 50 ref 50
target PARAM declared 16 defined 16 ref 46
v PARAM declared 26 defined 26 ref 34 47
variance VAR declared 38 impl-asn 50 ref 47 50 51
x VAR declared 37 impl-asn 50 ref 39 45 46 2*47 51

头两列给出了符号的名字和类型。数据类型和简写如下:

Shorthand Symbol GAMS Data Type
ACRNM acronym
EQU equation
FILE put file
MODEL model
PARAM parameter
SET set
VAR variable

后面几列会给出符号在第几行声明(declared),在第几行隐式的制定,第几行被引用。

1
2
3
declared       37
impl-asn 50
ref 39 45 46 2*47 51
完整的引用类型列表和对应的简写如下:

Shorthand Symbol Reference Type Description
declared Declaration The identifier is declared as to type. This must be the first appearance of the identifier.
defined Definition An initialization (for a table or a data list between slashes) or symbolic definition (for an equation) starts for the identifier.
assigned Assignment Values are replaced because the identifier appears on the left-hand side of an assignment statement.
impl-asn Implicit Assignment An equation or variable will be updated as a result of being referred to implicitly in a solve statement.
control Control A set is used as (part of) the driving index in an assignment, equation, loop or indexed operation.
ref Reference The symbol has been referenced on the right-hand side of an assignment or in a display, equation, model, solve statement or put statetement.
index Index Like control, but used only for set labels. Appears only in the cross reference map of unique elements. See section The Unique Element Listing Map for details.