每日一题【20200822】

线性规划与非线性规划之间转换

线性规划

分析方案

1
2
3
4
5
f=[1 1 1 1 1 1 1]; % 目标函数的系数矩阵
intcon = [1 2 3 4 5 6 7]; % 整数所在位置,题目没有要求,所以是空
A = [4 3 2 1 1 0 0;0 1 0 2 1 3 0;0 0 1 0 1 0 2]; % 不等式约束的变量系数矩阵
b = [-50;-20,-15]; % 不等式约束的资源数
[x,fval] = intlinprog(f,intcon,-A,b); % fval代表最优解处的函数值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
model:
sets:
moshi/1..7/:x;
xuqiu/1..3/:b;
link(moshi,xuqiu):c;
endsets
data:
c=4 0 0 3 1 0 2 0 1 1 2 0 1 1 1 0 3 0 0 0 2;
b=50 20 15;
enddata
min=@sum(moshi:x);
@for(xuqiu(j):@sum(moshi(i):c(i,j)*x(i))>b(j));
@for(moshi(i):@gin(x(i)));
end

非线性规划





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
model:
sets:
moshi/1..3/:x;
xuqiu/1..3/:a,b;
link(moshi,xuqiu):r;
endsets
data:
a=4,6,8;b=50,20,15;
enddata
min=@sum(moshi:x);
@for(xuqiu(j):@sum(moshi(i):r(i,j)*x(i))>b(j));
@for(moshi(i):@sum(xuqiu(j):a(j)*r(i,j))<19;@sum(xuqiu(j):a(j)*r(i,j))>16);
@for(moshi(i):@gin(x(i));@for(link:@gin(r)));
@for(moshi(i)|i#le#2:x(i)>x(i+1));
@sum(moshi:x)<28;@sum(moshi:x)>23;
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Local optimal solution found.
Objective value: 27.00000
Objective bound: 27.00000
Infeasibilities: 0.000000
Extended solver steps: 22
Total solver iterations: 294
Elapsed runtime seconds: 0.85
Model Class: PIQP
Total variables: 12
Nonlinear variables: 12
Integer variables: 12
Total constraints: 14
Nonlinear constraints: 3
Total nonzeros: 49
Nonlinear nonzeros: 9
Variable Value Reduced Cost
X( 1) 15.00000 1.000000
X( 2) 12.00000 1.000000
X( 3) 0.000000 1.000000
A( 1) 4.000000 0.000000
A( 2) 6.000000 0.000000
A( 3) 8.000000 0.000000
B( 1) 50.00000 0.000000
B( 2) 20.00000 0.000000
B( 3) 15.00000 0.000000
R( 1, 1) 1.000000 0.000000
R( 1, 2) 1.000000 0.000000
R( 1, 3) 1.000000 0.000000
R( 2, 1) 3.000000 0.000000
R( 2, 2) 1.000000 0.000000
R( 2, 3) 0.000000 0.000000
R( 3, 1) 0.000000 0.000000
R( 3, 2) 3.000000 0.000000
R( 3, 3) 0.000000 0.000000

参考


每日一题【20200822】
https://blog.baixf.tk/2020/08/22/每日一题/每日一题【20200822】/
作者
白小飞
发布于
2020年8月22日
许可协议