從幾個lingo的示例來看lingo在運籌學當中的使用

zzu小陸發表於2016-08-24

從幾個lingo的示例來看lingo在運籌學當中的使用

  • 0-1規劃問題
Model:
Max=2*x1+3*x2+4*x3;   !;
2*X1-5*x2+3*x3<=4;
4*x1+x2+3*x3<=3;
X1+x3>=1;
@bin(x1);@bin(x2);@bin(x3);!bin表示取值只能為01.;
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: 
s=1;lamda=4;mu=10;rho=lamda/mu; Pwait=@peb(rho,s); p0=1-Pwait; Pt_gt_10=@exp(-1); end







model: 
s=3;lamda=0.9;mu=0.4;rho=lamda/mu;rho_s=rho/s; P_wait=@peb(rho,s);  p0=6*(1-rho_s)/rho^3*P_wait;   L_q=P_wait*rho_s/(1-rho_s); L_s=L_q+rho; W_q=L_q/lamda; W_s=L_s/lamda; end 




model: s=1;lamda=0.6;mu=1/1.25;rho=lamda/mu; Plost=@pel(rho,s); Q=1-Plost; lamda_e=Q*lamda;A=Q*lamda_e; L_s=lamda_e/mu; eta=L_s/s; end




model: lamda=200; mu=60/3;rho=lamda/mu; Plost=@pel(rho,s);Plost<0.05; Q=1-Plost; lamda_e=Q*lamda;A=Q*lamda_e; L_s=lamda_e/mu; eta=L_s/s; min=s;@gin(s); end 




model: lamda=200; mu=60/3;rho=lamda/mu; @pel(rho,s)=0.05; end 




model: lamda=200; mu=60/3;rho=lamda/mu; s=15;Plost=@pel(rho,s); Q=1-Plost; lamda_e=Q*lamda;A=Q*lamda_e; L_s=lamda_e/mu; eta=L_s/s; end




model: sets: state/1..4/:p; endsets lamda=1;mu=1/1.25;rho=lamda/mu;k=4; lamda*p0=mu*p(1); (lamda+mu)*p(1)=lamda*p0+mu*p(2); @for(state(i)|i #gt#1 #and# i #lt# k:(lamda+mu)*p(i)=lamda*p(i-1)+mu*p(i+1)); lamda*p(k-1)=mu*p(k); p0+@sum(state:p)=1; P_lost=p(k);lamda_e=lamda*(1-P_lost); L_s=@sum(state(i)|i #le#k:i*p(i)); L_q=L_s-(1-p0); W_s=L_s/lamda_e; W_q=W_s-1/mu; end 




model: sets: state/1..5/:p; endsets lamda=2;mu=0.5;rho=lamda/mu;s=2;k=5; lamda*p0=mu*p(1); (lamda+mu)*p(1)=lamda*p0+2*mu*p(2); @for(state(i)|i #gt#1 #and# i #lt# s: (lamda+i*mu)*p(i)=lamda*p(i-1)+(i+1)*mu*p(i+1)); 
@for(state(i)|i #ge# s #and# i #lt# k: (lamda+s*mu)*p(i)=lamda*p(i-1)+s*mu*p(i+1)); lamda*p(k-1)=s*mu*p(k); p0+@sum(state:p)=1; P_lost=p(k);lamda_e=lamda*(1-P_lost); L_s=@sum(state(i):i*p(i)); L_q=L_s-lamda_e/mu; W_s=L_s/lamda_e; W_q=W_s-1/mu; end 




model: lamda=1/15;mu=1/12;rho=lamda/mu;s=1;m=5; load=m*rho; L_s=@pfs(load,s,m); p_0=1-(m-L_s)*rho; lamda_e=lamda*(m-L_s); p_5=@exp(@lgm(6))*0.8^5*p_0; L_q=L_s-(1-p_0); w_s=L_s/lamda_e;w_q=L_q/lamda_e; end 




model: s=1;k=4;lamda=1; L_s=@pfs(k*lamda/mu,s,k); max=100*(k-L_s)-75*mu; end




model: sets: state/1..3/:p; endsets lamda=3.6;k=3; lamda*p0=p(1)/t; (lamda+1/t)*p(1)=lamda*p0+p(2)/t; @for(state(i)|i #gt# 1 #and# i #lt# k: (lamda+1/t)*p(i)=lamda*p(i-1)+p(i+1)/t); lamda*p(k-1)=p(k)/t; p0+@sum(state:p)=1; max=2*lamda*(1-p(k))-0.5/t; end     




model: lamda=48;mu=25;rho=lamda/mu; P_wait=@peb(rho,s);  L_q=P_wait*rho/(s-rho); L_s=L_q+rho; min=4*s+6*L_s; @gin(s);@bnd(2,s,5); end
  • 求解DEA問題lingo模板
1] sets:
2] DMU/1..6/:S,T,P;  ! Decision Making Unit;
3] II/1..2/:w;       ! Input Index;
4] OI/1..2/:u;       ! Output Index;
5] IV(II,DMU):X;     ! Input Variable;
6] OV(OI,DMU):Y;     ! Output Variable;
7] endsets
8] data:
9] p=?;
10]X=具體數字 ;
11]Y=具體數字 ;
12]enddata
13]max=@sum(DMU:P*T);
14]@for(DMU(j));
15]S(j)=@sum(II(i): w(i)*X(i,j));
16]T(j)=@sum(OI(i): u(i)*Y(i,j));
17]S(j)>=T(j);
18]@sum(DMU: P*S)=1;
END
  • 求解求和類規劃問題
model:
sets:
variables/1..10/:s,cost;
endsets
data:
cost=5 8 10 6 9 5 7 6 10 8;
enddata
min=@sum(variables:cost*s);
(s(1)+s(7)-2)*(s(9)-1)=0;
s(3)*s(5)+s(4)*s(5)=0;
@sum(variables(i)|i#ge#5#and#i#le#8:s(i))<=2;
@sum(variables:s)=5;
@for(variables:@bin(s));
end
  • 線性規劃問題一般寫法

Model:
Min=x1+x4+x5+100;
1.04*x1-x2-x6>=150;
1.04*x2+1.25*x5-x3>=120;
1.04*x3+1.4*x4+1.3*x6>=110;
x4<=60;
x5<=90;
x6<=50;
End

  • 線性規劃求最大值
Model:
Max=-3*x1+x3;
X1+x2+x3<=4;
-2*x1+x2-x3>=1;
3*X2+x3=9;
End
  • 運籌課程中的線性規劃習題
Model:
Max=x1-2*x2+3*(x4-x5);
x1+x2+x4-x5+x6=7;
x1-x2+x4-x5-x7=2;
-3*x1+x2+2*(x4-x5)=5;
x1>=0;
End
  • 運籌學中的線性規劃求最小值
Model:
Min=-x1+2*x2-3*x3;
x1+x2+x3<=7;
x1-x2+x3>=2;
-3*x1+x2+2*x3=5;
@free(x3);
End
  • 運輸模型
model:
!3發點4收點運輸問題;
sets:
  warehouses/wh1..wh3/: capacity;
  vendors/v1..v4/: demand;
  links(warehouses,vendors): cost, volume;
endsets
!目標函式;
  min=@sum(links: cost*volume);
!需求約束;
  @for(vendors(J):
    @sum(warehouses(I): volume(I,J))=demand(J));
!產量約束;
  @for(warehouses(I):
    @sum(vendors(J): volume(I,J))<=capacity(I));
!這裡是資料;
data:
  capacity=16 10 22;
  demand=8 14 12 14;
  cost=4 12 4 11
       2 10 3 9
       8 5 11 6; 

enddata

end
  • 再看運輸問題
model: 
!6發點8收點運輸問題; 
sets: 
warehouses/wh1..wh6/: capacity; 
vendors/v1..v8/: demand; 
links(warehouses,vendors): cost, volume; 
endsets 
!目標函式; 
min=@sum(links: cost*volume); 
!需求約束; 
@for(vendors(J): 
@sum(warehouses(I): volume(I,J))=demand(J)); 
!產量約束; 
@for(warehouses(I): 
@sum(vendors(J): volume(I,J))<=capacity(I)); 
!這裡是資料; 
data: 
capacity=60 55 51 43 41 52; 
demand=35 37 22 32 41 32 43 38; 
cost=6 2 6 7 4 2 9 5 
4 9 5 3 8 5 8 2 
5 2 1 9 7 4 3 3 
7 6 7 3 9 2 7 1 
2 3 9 5 7 2 6 5 
5 5 2 2 8 1 4 3; 
enddata 
end 
  • 指派問題
model: 
  !5 個工人,5 個工作的分配問題; 
sets: 
  workers/w1..w5/; 
  jobs/j1..j5/; 
  links(workers,jobs): cost,volume; 
endsets 
  !目標函式; 
  min=@sum(links: cost*volume); 
  !每個工人只能有一份工作; 
  @for(workers(I): 
    @sum(jobs(J): volume(I,J))=1; 
  ); 
  !每份工作只能有一個工人; 
  @for(jobs(J): 
    @sum(workers(I): volume(I,J))=1; 
  ); 
data: 
  cost= 4  8  7  15  12 
        7  9  17  14  10 
        6  9  12  8  7  
        6  7  14  6  10 
       6  9  12  10  6 ;
enddata 
end
  • 一道智力題
Model:
x1+x2-9=4;
x3-x4*x5=4;
x6+x7-x8=4;
x1+x3/x6=4;
x2-x4*x7=4;
9-x5-x8=4;
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)<w(i,j));
!�� 

 ;
!@for(road:@bnd(0,f,w));
end
  • 最短路問題
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 

學了幾個lingo程式,拿了數學建模美賽的M獎。祝大家建模成功。

相關文章