GLPK:访问可变长度的数据数组
GLPK: access to data array with variable length
set ORIG;
set DEST;
set LINKS within {ORIG,DEST};
printf {i in ORIG, j in DEST} "LINKS[%s,%s] = %g \n",i,j,LINKS[i][j];
data;
set ORIG := GARY CLEV PITT;
set DEST := FRA DET LAN WIN STL FRE LAF;
set LINKS :=
(GARY,*) DET LAN STL LAF
(CLEV,*) FRA DET LAN WIN STL LAF
(PITT,*) FRA WIN STL FRE;
end;
这将停止并显示此错误消息:
LINKS cannot be subscripted
如何定义 LINKS
以便可以使用 LINKS[i][j]
访问它?
根据 gnu-help 的一些建议,这似乎是一个更好的语法
对于这个问题:
set ORIG;
set DEST;
param LINKS{ORIG, DEST} default 0;
for {i in ORIG, j in DEST} printf "LINKS[%s,%s] = %g \n",i,j,LINKS[i,j];
data;
set ORIG := GARY CLEV PITT;
set DEST := FRA DET LAN WIN STL FRE LAF;
param LINKS : FRA DET LAN WIN STL FRE LAF :=
GARY 1 2 3 4 5 6 .
CLEV . 2 . 4 . 6 .
PITT 1 2 3 4 5 6 7;
end;
set ORIG;
set DEST;
set LINKS within {ORIG,DEST};
printf {i in ORIG, j in DEST} "LINKS[%s,%s] = %g \n",i,j,LINKS[i][j];
data;
set ORIG := GARY CLEV PITT;
set DEST := FRA DET LAN WIN STL FRE LAF;
set LINKS :=
(GARY,*) DET LAN STL LAF
(CLEV,*) FRA DET LAN WIN STL LAF
(PITT,*) FRA WIN STL FRE;
end;
这将停止并显示此错误消息:
LINKS cannot be subscripted
如何定义 LINKS
以便可以使用 LINKS[i][j]
访问它?
根据 gnu-help 的一些建议,这似乎是一个更好的语法 对于这个问题:
set ORIG;
set DEST;
param LINKS{ORIG, DEST} default 0;
for {i in ORIG, j in DEST} printf "LINKS[%s,%s] = %g \n",i,j,LINKS[i,j];
data;
set ORIG := GARY CLEV PITT;
set DEST := FRA DET LAN WIN STL FRE LAF;
param LINKS : FRA DET LAN WIN STL FRE LAF :=
GARY 1 2 3 4 5 6 .
CLEV . 2 . 4 . 6 .
PITT 1 2 3 4 5 6 7;
end;