#eq# !相等;
#ne# !不相等;
#gt#
#ge#
#lt#
#le#
#not#
#and#
#or#
@sin(x);
@cos(x);
@tan(x);
@log(x) ! x的自然对数值,其他应当使用换底公式;
@exp(x);
@bin(x) !x为0或者1;
@gin(x) !x为整数;
@free(x) !x为任意实数;
@bnd(v,x,u) !x的取值区间
!lingo 默认变量为非负实数
@for
@sum
@prod
@max
@min
@in
@size
max = x1 + 2*x2 + x3;
x1 > x2;
x1 + x2 <= 5;
x1 + x3 >= 2;
@bin(x3);
@gin(x2);
@bnd(2,x1,10);
sets:
s/1..6/: a,b,d;
T/1..2/: e,x,y;
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.25;
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));
model:
sets:
cities/S,A1,A2,A3,B1,B2,C1,C2,T/:L;
roads(cities,cities)/
S,A1 S,A2 S,A3
A1,B1 A1,B2 A2,B1 A2,B2 A3,B1 A3,B2
B1,C1 B1,C2 B2,C1 B2,C2
C1,T C2,T/:D;
endsets
data:
D = 6,3,3
6 5 8 6 7 4
6 7 8 9
5 6;
L = 0, , , , , , , , ;
enddata
@for(cities(i)|i#GT#@index(S):
L(i)=@min(roads(j,i):L(j)+D(j,i)););
end
Variable Value
L( S) 0.000000
L( A1) 6.000000
L( A2) 3.000000
L( A3) 3.000000
L( B1) 10.00000
L( B2) 7.000000
L( C1) 15.00000
L( C2) 16.00000
L( T) 20.00000
model:
init:
x1 = 0.0;
x2 = 0.0;
x3 = 0.0;
endinit
max = 4*x1^2 + x2*@sin(@sqrt(x3));
x1^3 + x3^3 <= 3;
x1^5 - x2^2 >= 0;
x2^2 - x3^2 >= 0;
end
@INTEGRAL(y1,x,0,5,y);
Lingo积分的使用就有点鸡肋了,很复杂
MODEL:
PROCEDURE y1:
y = 4*x^3;
ENDPROCEDURE
CALC:
PROB = @INTEGRAL(y1,x,0,5,y);
ENDCALC
END
MODEL:
sets:
U/1..3/:a,b;
endsets
data:
a = 1,2,3;
enddata
PROCEDURE y1:
y = b(2)*x^3;
ENDPROCEDURE
PROCEDURE y2:
y = b(1)*x^2;
ENDPROCEDURE
CALC:
PROB1 = @INTEGRAL(y1,x,0,5,y);
PROB2 = @INTEGRAL(y2,x,b(3),5,y);
ENDCALC
min = (PROB2-PROB1-(PROB2-b(3))^2)^b(1);
@bnd(2,b(3),4);
@bnd(1,b(2),4);
@bnd(3,b(1),7);
END
Local optimal solution found.
Objective value: -0.1582482E+11
Infeasibilities: 0.000000
Extended solver steps: 1
Best multistart solution found at step: 1
Total solver iterations: 4
Elapsed runtime seconds: 0.11
Model Class: NLP
Total variables: 4
Nonlinear variables: 2
Integer variables: 0
Total constraints: 1
Nonlinear constraints: 1
Total nonzeros: 2
Nonlinear nonzeros: 2
Variable Value Reduced Cost
Y 1.234568 0.000000
X 1.234568 0.000000
PROB1 192.9012 0.000000
PROB2 50.66597 0.000000
A( 1) 1.000000 0.000000
A( 2) 2.000000 0.000000
A( 3) 3.000000 0.000000
B( 1) 3.000000 0.000000
B( 2) 1.234568 0.000000
B( 3) 2.000000 0.1840500E+10
Row Slack or Surplus Dual Price
1 -0.1582482E+11 -1.000000
别的不说,就运算速度而言,0.11s
绝对完爆其他计算软件与程序啊!!!!
Model:
sets:
myset/@file(myfile.ldt)/:@file(myfile.ldt);
endsets
min = @sum(myset(i):ordered(i)*cost(i));
@for(myset(i):ordered(i)>need(i);
ordered(i)
其中myfile.lgt文件中的内容是
Seattle,Detroit,Chicago,Denver~
COST,NEED,SUPPLY,ORDERED~
12,28,15,20~
1600,1800,1200,1000~
1700,1900,1300,1100
这玩意它长这个样子
LP |
线性模型 |
QP |
二次模型 |
ILP |
整数线性模型 |
IQP |
整数二次模型 |
PILP |
纯整数线性模型 |
PIQP |
纯整数二次模型 |
NLP |
非线性模型 |
或者还有其他的。。一些怪怪的模型 |
Global Optimum |
全局最优 |
Local Optimum |
局部最优 |
Feasible |
可行的 |
Infeasible |
不可行的 |
Unbounded |
无界的 |
Interrupted |
|
Undetermined |
Local optimal solution found.
Objective value: 37.00000
Objective bound: 37.00000
Infeasibilities: 0.000000
Extended solver steps: 3
Total solver iterations: 71
Elapsed runtime seconds: 0.18
Model Class: MIQP
Total variables: 3
Nonlinear variables: 2
Integer variables: 2
Total constraints: 2
Nonlinear constraints: 2
Total nonzeros: 6
Nonlinear nonzeros: 2
Variable Value Reduced Cost
X1 1.000000 -1.000000
X2 4.000000 -9.000001
X3 9.000000 -4.000000
Row Slack or Surplus Dual Price
1 37.00000 1.000000
2 14.00000 0.000000