我写了个LINGO模型,如下,但是LINGO免费版的限制0-1约束最多30个,你这个题目有34个0-1约束,得用非免费版的才能求解,模型应该没啥问题,LINGO也可以直接关联excel从excel抓数据,具体哪里不懂可以加我VX:An374938857
!最短路径问题;
MODEL:
SETS:
CITY/A..T/;
!W弧的消耗量,X是否经过该弧;
ROAD(CITY,CITY)/
B A, I A,
A B, C B, E B,
B C, D C, F C,
C D, H D,
B E, G E,
C F, K F, M F,
E G,
D H, L H, T H,
A I, J I, P I,
I J,
F K,
H L,
F M,
O N,
N O, P O, Q O,
I P, O P, R P, S P,
O Q,
P R,
P S,
H T
/:W,X;
ENDSETS
DATA:
W =
1 1
1 1 1
1 1 1
1 1
1 1
1 1 1
1
1 1 1
1 1 1
1
1
1
1
1
1 1 1
1 1 1 1
1
1
1
1
;
ENDDATA
MIN=@SUM(ROAD:W*X);
!流量平衡约束;
@FOR(CITY(I)|I #NE# A #AND# I #NE# G:
@SUM(ROAD(I,J):X(I,J))
=
@SUM(ROAD(K,I):X(K,I))
);
@SUM(ROAD(I,J)|I #EQ# R: X(I,J)) = 1;
@SUM(ROAD(I,J)|J #EQ# L: X(I,J)) = 1;
@FOR(ROAD: @BIN(X));
END |