model:
sets:
cities/0,1,2,3,4,5,6,7/:level,h;
link(cities,cities):distance,time,x,a,s;
endsets;
data:
distance = 0 300 360 210 590 475 500 0
300 0 380 270 230 285 200 390
360 380 0 510 230 765 580 770
210 270 510 0 470 265 450 640
590 230 230 470 0 515 260 450
475 285 765 265 515 0 460 650
500 200 580 450 260 460 0 190
0 390 780 640 450 650 190 0;
enddata
time=(distance/2000)*60;
max=330-@sum(link:time*x)-h;
@for(cities(1)|@bnd(10,a(1),30));
@for(cities(2)|@bnd(20,a(2),60));
@for(cities(3)|a(3)<=30);
@for(cities(4)|@bnd(30,a(4),60));
@for(cities(5)|@bnd(20,a(5),60));
@for(cities(6)|@bnd(30,a(6),60));
@for(cities(7)|a(7)>=30);
@for(cities(k):
!进入城市k;
@sum(cities(i) | i #ne# k: x(i,k)) = 1;
!离开城市k;
@sum(cities(j) | j #ne# k: x(k,j)) = 1;
);
!保证不出现子圈;
@for(cities(i) | i #gt# 1:
@for(cities(j) | j #gt# 1 #and# i#ne#j:
level(i)-level(j) + n*x(i,j) <= n-1);
);
!限制u的范围以加速模型的求解,保证所加限制并不排除掉TSP问题的最优解;
@for(cities(i) | i #gt# 1: level(i) <= n-2);
@for(link:@bin(x));
@for(cities(k):
s(j)=@sum(link:(s(i)+time(i,j)+a(i))*x);
);
@for(cities(1)|s(1)<=230);
@for(cities(7)|s(7)<=300);
h=@if((s(3)mod30)#gt#0,0,30-(s(3)mod30));
end
软件提示说是缺少一定的运算符,是第15类错误,不知道到底是哪里错了