Lingo摸鱼
Posted 图灵奖未来得主
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lingo摸鱼相关的知识,希望对你有一定的参考价值。
速成
!max = 4*x1 + 3*x2;
!2*x1 + x2 <= 10;
! x1 + x2 <= 8;
! x2 <= 7;
!@gin(x1);
!@gin(x2);
!sets:
S/1..6/: a, b ,d ;
!T/1,2/: x ,y ,e ;
!U(S,T): c ;
!endsets
data:
a=1.25 8.75 0.5 5.75 3 7.25;
!b=1.25 0.75 4.75 5 6.5 7.75;
!d=3 5 4 7 6 11;
!x=5 2;
!y=1 7;
!e=20 20;
!enddata
min = @sum(T(j):@sum(S(i):
c(i,j)*@sqrt((x(j)-a(i))^2 + (y(j)-b(i))^2)));
!@for(S(i):@sum(T(j):c(i,j))=d(i));
!@for(T(j):@sum(S(i):c(i,j))<=e(j));
!@bin(x)表示x为0或1
@gin(x)表示x整数
@free(x)表示x为任意实数
@bnd(l,x,u)表示x为[l,u]之间的实数
默认变量为非负数;
!矩阵工厂
!sets:
A/1..3/:x,y;
!B/1..4/:m,n;
!endsets
data:
x=1,2,3;
!y=2,3,1/10;
!m=5,6,7,8;
!enddata
!x就是求解的值,不能赋值分数;
!循环与求和 @for(a(i):);
!暴力枚举法的例子;
!sets:
P/1..5/:a,x;
!endsets
max=s;
!@for(P(i):a(i)=i);
!@for(P(i):a(i)*x(i)=s);
!@sum(P(i):x(i))=5000;
!约束条件后面有i=1,2,...,5,一定在最后套上for
约束条件前面是求和,一定在中间加上sum;
!工厂合并;
!sets:
P/1..2/:a;
!Q/1..3/:b;
!PQ(p,Q):c;
!endsets
data:
c=1,2,3,4
5,6;
!enddata
;
!合并工厂
sets:
P/1..6/:a;
!Q/1..8/:d;
!W(P,Q):c,x;
!endsets
data:
a=60,55,51,43,41,52;
!d=35,37,22,32,41,32,43,38;
!c=6,2,6,7,4,2,5,8
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
!min=@sum(W(i,j):c(i,j)*x(i,j));
!min=@sum(P(i):@sum(Q(j):c(i,j)*x(i,j)));
!@for(P(i):@sum(Q(j):x(i,j))<a(i));
!@for(Q(j):@sum(P(i):x(i,j))=d(j));
!@for(W(i,j):x(i,j)>=0);
!运算符;
!算数运算符;
!x=2;
!y=3*x^10+6/(15-@sqrt(x));
!关系运算符,只有<= >= = 如果写>表示省略了=;
!严格表示;
!B=10;
!e=0.00000000001;
!A-e>=B;
!逻辑运算符
;
!model:
sets:
Q/1..6/: a;
!endsets
data:
a=6,5,4,3,2,1;
!enddata
y=@sum(Q(i)|i#le#4:a(i));
!end
;
!model:
sets:
Q/1..6/:a;
!endsets
data:
enddata
min=@sum(Q(i):a(i));
!@for(Q(i)|i#ne#3 #and# i#ne#4 :a(i)>5);
!end
;
!model:
sets:
m/1..3/:;
!P(m,m):a;
!endsets
data:
a=1,2,3
4,5,6
7,8,9;
!enddata
@sum(P(i,j)|i#le#j:a(i,j));
!end
;
!lingo内置函数;
!if 一般只出现在有分段函数的时候求解;
!@free(x);
!@free(y);
!x=10;
!y=@if(x#ge#10,x+10,x-10);
!变量定界函数--非常重要!!!!!
;
!min=(x+2)^2+(y-2)^2;
!@free(x);
!@free(y);
!@free(z);
!max=2*x;
!@bnd(1,x,3);
!sets:
P/1..8/:a,b,x;
!endsets
data:
a=2,9,3,8,10,6,4,10;
!b=1,3,4,3,3,1,5,10;
!enddata
max=@sum(P(i):a(i)*x(i));
!@sum(P(i):b(i)*x(i))<=15;
!@for(P(i):@bin(x(i)));
!sets:
P/1..6/:a,x;
!Q/1..5/:b;
!W(P,Q):c;
!endsets
data:
a=2.1,1.0,1.8,1.2,2.0,1.2;
!b=6,125,12500,345,5;
!C=0.45,20,415,22,0.3
0,45,28,4065,5,0.35
0,65,40,850,43,0.6
0.4,25,75,27,0.2
0.5,26,76,48,0.4
0.5,75,235,8,0.6
enddata
max=@sum(P(i):a(i)*x(i));
!@sum(P(i):x(i)14
!@for(Q(j):@sum(P(i):x(i)*c(i,j))<=b(j));
!x(2)<=3;
!x(4)<=2;
!@for(P(i)|i#ne#2 #and# i#ne#4 :@bnd(1,x(i),4));
!@for(P(i):@gin(x(i)));
!数学函数
;
!y=@sin(3.14159)+@log(1024)/@log(2)+@abs(-10)+@exp(0);
!集合操作函数
;
以上是关于Lingo摸鱼的主要内容,如果未能解决你的问题,请参考以下文章