运筹领域有很多有趣的问题,比如中国邮递员问题,最短路问题等等。lingo在求解规划问题、图与网络问题,对策决策问题,以及存储论等方面的求解有很好的应用。
model: sets: cities/A,B1,B2,C1,C2,C3,D/; roads(cities,cities)/A B1,A B2,B1 C1,B1 C2,B1 C3,B2 C1, B2 C2,B2 C3,C1 D,C2 D,C3 D/:w,x; 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 #ne#1 #and# i #ne#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: Title Dynamic Programming; sets: vertex/A,B1,B2,C1,C2,C3,C4,D1,D2,D3,E1,E2,E3,F1,F2,G/:L; road(vertex,vertex)/A B1,A B2,B1 C1,B1 C2,B1 c3,B2 C2,B2 C3,B2 C4, C1 D1,C1 D2,C2 D1,C2 D2,C3 D2,C3 D3,C4 D2,C4 D3, D1 E1,D1 E2,D2 E2,D2 E3,D3 E2,D3 E3, E1 F1,E1 F2,E2 F1,E2 F2,E3 F1,E3 F2,F1 G,F2 G/:D; endsets data: D=5 3 1 3 6 8 7 6 6 8 3 5 3 3 8 4 2 2 1 2 3 3 3 5 5 2 6 6 4 3; L=0,,,,,,,,,,,,,,,; enddata @for(vertex(i)|i#GT#1:L(i)=@min(road(j,i):L(j)+D(j,i))); end
model:
sets:
node/1..6/;
road(node,node):w,a,f;
endsets
data:
a=0 1 1 0 0 0
0 0 0 1 1 0
0 0 0 1 1 0
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 0;
w=0 1 4 0 0 0
0 0 0 6 4 0
0 0 0 5 3 0
0 0 0 0 0 7
0 0 0 0 0 3
0 0 0 0 0 0;
enddata
max=vf;
@sum(road(i,j)|i#eq#1:f(i,j))=vf;
!��
;
!@sum(node(i):f(1,i))=vf;
@for(node(i)|i#gt#1 #and# i#ne#@size(node):
@sum(node(j):f(i,j)*a(i,j))=@sum(node(j):f(j,i)*a(j,i)));
@for(road(i,j):f(i,j)@for(road:@bnd(0,f,w));
end
为了缩短篇幅,代码请自行分行。