作业帮 > 综合 > 作业

LINGO程序哪里出错了

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/05 17:25:32
LINGO程序哪里出错了
model:
sets:
city/1..6/:u;
link(city,city):d,x;
endsets
data:
d=0 70 50 40 50 30
70 0 30 40 60 50
50 30 0 50 70 80
40 40 50 0 60 60
50 60 70 50 0 40
30 50 80 60 40 0;
enddata
N=@size(city);
min=@sum(link:d*x);
@for(city(j):@sum(city(i)|i #ne# j:x(i,j))=1;
@sum(city(j)|j #ne# i:x(i,j))=1;);
@for(city(i):@for(city(j)|j #gt# 1 #and# i #ne# j:u(i)-u(j):N*x(i,j)=N-1):);
@for(city(i):u(i)=N-1);
@for(link:@bin(x):);
end
这个程序中哪里出错了,
这里主要是讲TSP问题的
在lingo的程序中,最后的限定城市的约束“@for(city(j):@sum(city(i)|i #ne# j:x(i,j))=1;             @sum(city(j)|j #ne# i:x(i,j))=1;);@for(city(i):@for(city(j)|j #gt# 1 #and# i #ne# j:u(i)-u(j):N*x(i,j)=N-1):);”有误.正确的方式如图.将你的程序修改了下,正确的程序:MODEL:    sets:   city/1..6/:u;      link(city, city):        d, x;          endsets    data:      d = 0 70 50 40 50 30  70 0 30 40 60 50  50 30 0 50 70 80   40 40 50 0 60 60   50 60 70 50 0 40  30 50 80 60 40 0;   enddata   n=@size(city);   min=@sum(link(i,j)|i #ne# j: d(i,j)*x(i,j));   @for(city(i) :      @sum(city(j)| j #ne# i: x(j,i))=1;      @sum(city(j)| j #ne# i: x(i,j))=1;     @for(city(j)| j #gt# 1 #and# j #ne# i :         u(j) >= u(i) + x(i,j)                 - (n-2)*(1-x(i,j)) + (n-3)*x(j,i);      );   );   @for(link : @bin(x));   @for(city(i) | i #gt# 1 :      u(i)<=n-1-(n-2)*x(1,i);      u(i)>=1+(n-2)*x(i,1);   ); END结果:   Global optimal solution found.   Objective value:                              240.0000   Extended solver steps:                               0   Total solver iterations:                            34                       X( 1, 1)        0.000000            0.000000                       X( 1, 2)        0.000000            70.00000                       X( 1, 3)        0.000000            50.00000                       X( 1, 4)        0.000000            40.00000                       X( 1, 5)        0.000000            50.00000                       X( 1, 6)        1.000000            30.00000                       X( 2, 1)        0.000000            70.00000                       X( 2, 2)        0.000000            0.000000                       X( 2, 3)        1.000000            30.00000                       X( 2, 4)        0.000000            40.00000                       X( 2, 5)        0.000000            60.00000                       X( 2, 6)        0.000000            50.00000                       X( 3, 1)        1.000000            50.00000                       X( 3, 2)        0.000000            30.00000                       X( 3, 3)        0.000000            0.000000                       X( 3, 4)        0.000000            50.00000                       X( 3, 5)        0.000000            70.00000                       X( 3, 6)        0.000000            80.00000                       X( 4, 1)        0.000000            40.00000                       X( 4, 2)        1.000000            40.00000                       X( 4, 3)        0.000000            50.00000                       X( 4, 4)        0.000000            0.000000                       X( 4, 5)        0.000000            60.00000                       X( 4, 6)        0.000000            60.00000                       X( 5, 1)        0.000000            50.00000                       X( 5, 2)        0.000000            60.00000                       X( 5, 3)        0.000000            70.00000                       X( 5, 4)        1.000000            50.00000                       X( 5, 5)        0.000000            0.000000                       X( 5, 6)        0.000000            40.00000                       X( 6, 1)        0.000000            30.00000                       X( 6, 2)        0.000000            50.00000                       X( 6, 3)        0.000000            80.00000                       X( 6, 4)        0.000000            60.00000                       X( 6, 5)        1.000000            40.00000                       X( 6, 6)        0.000000            0.000000