这个lingo哪里错了?D例2.1.1 如图中A,B,…,G表示7个城市,连线表示城市之间有一条路相通,连线旁的数字表示路的长度wij,要从城市A到城市G找出一条最短的路线.B31GEA2 2 3FC4 3 1 41设起点为1,终点为n,W为里程,引入0-1型决策变量Xij,如果弧(i,j)在最短路上,则Xij=1,否则Xij=0编写lingo程序如下:model:sets:cities/A,B,C,D,E,F,G/; 定义7个城市;roads(cities,cities)/A,B A,C B,D B,E B,F C,D C,E C,F D,G E,G F,G/:W,X;定义哪些城市之间有路相连,W为里程,X为0-1型决策变量;endsetsdata:W=2 4 3 3 1 2 3 1 1 3 4;enddataN=@SIZE(CITIES);MIN=@SUM(roads:W*X);@FOR(cities(i) | i #GT# 1 #AND# i #LT# N:@SUM(roads(i,j) :
这个lingo哪里错了?
D
例2.1.1 如图中A,B,…,G表示7个城市,连线表示城市之间有一条路相通,连线旁的数字表示路的长度wij,要从城市A到城市G找出一条最短的路线.
B
3
1
G
E
A
2 2 3
F
C
4 3
1 4
1
设起点为1,终点为n,W为里程,引入0-1型决策变量Xij,如果弧(i,j)在最短路上,则Xij=1,否则Xij=0
编写lingo程序如下:
model:
sets:
cities/A,B,C,D,E,F,G/; 定义7个城市;
roads(cities,cities)/
A,B A,C B,D B,E B,F C,D C,E C,F D,G E,G F,G/:W,X;
定义哪些城市之间有路相连,W为里程,X为0-1型决策变量;
endsets
data:
W=2 4 3 3 1 2 3 1 1 3 4;
enddata
N=@SIZE(CITIES);
MIN=@SUM(roads:W*X);
@FOR(cities(i) | i #GT# 1 #AND# i #LT# N:
@SUM(roads(i,j) :X(i,j))=@SUM(roads(j,i) :X(j,i)));
@SUM(roads(i,j) | i #EQ# 1:X(i,j))=1;
@SUM(roads(i,j) | j #EQ# N:X(i,j))=1;
end
标点请用英文的
model:
sets:
cities/A,B,C,D,E,F,G/; !定义7个城市;
roads(cities,cities)/
A,B A,C B,D B,E B,F C,D C,E C,F D,G E,G F,G/:W,X;
!定义哪些城市之间有路相连,W为里程,X为0-1型决策变量;
endsets
data:
W=2 4 3 3 1 2 3 1 1 3 4;
enddata
N=@SIZE(CITIES);
MIN=@SUM(roads:W*X);
@FOR(cities(i) | i #GT# 1 #AND# i #LT# N:
@SUM(roads(i,j) : X(i,j))=@SUM(roads(j,i) : X(j,i)));
@SUM(roads(i,j) | i #EQ# 1:X(i,j))=1;
@SUM(roads(i,j) | j #EQ# N:X(i,j))=1;
end