线性规划中的灵敏度分析
linprog "dual-simplex-highs" 算法在第六个输出中返回灵敏度信息。灵敏度信息是指目标函数值对问题参数的变化率,以及导致相同变化率的参数变化幅度。
建立并求解一个线性规划问题,然后分析灵敏度分析结果,并将其与拉格朗日乘数法所得的结果进行比较。
load sc50b.mat该问题有 48 个变量、30 个不等式和 20 个等式。
disp(size(A))
30 48
disp(size(Aeq))
20 48
该问题没有上界,因此将 ub 设置为 []。
ub = [];
通过调用 linprog 求解问题。
[x,fval,exitflag,output,lambda,sensitivity] = ...
linprog(f,A,b,Aeq,beq,lb,ub)Optimal solution found.
x = 48×1
30.0000
28.0000
42.0000
70.0000
70.0000
30.0000
28.0000
42.0000
30.0000
28.0000
42.0000
33.0000
30.8000
46.2000
77.0000
⋮
fval = -70.0000
exitflag = 1
output = struct with fields:
iterations: 17
constrviolation: 5.6843e-14
message: 'Optimal solution found.'
algorithm: 'dual-simplex-highs'
firstorderopt: 2.4869e-15
lambda = struct with fields:
lower: [48×1 double]
upper: [48×1 double]
eqlin: [20×1 double]
ineqlinLower: [30×1 double]
ineqlin: [30×1 double]
sensitivity =
SensitivityAnalysis with properties:
Variables Sensitivity:
ObjectiveCoefficient: [48×5 table]
LowerBound: [48×5 table]
UpperBound: [48×5 table]
Constraints Sensitivity:
InequalityLHS: [30×5 table]
InequalityRHS: [30×5 table]
EqualityRHS: [20×5 table]
分析下界系数的灵敏度。
sensitivity.LowerBound
ans=48×5 table
LowerLimit UpperLimit ObjectiveValueAtLowerLimit ObjectiveValueAtUpperLimit ObjectiveValueChangeRate
__________ __________ __________________________ __________________________ ________________________
-Inf 30 -70 -70 0
-Inf 28 -70 -70 0
-Inf 42 -70 -70 0
-Inf 70 -70 -70 0
-Inf 70 -70 -70 0
-Inf 30 -70 -70 0
-Inf 28 -70 -70 0
-Inf 42 -70 -70 0
-Inf 30 -70 -70 0
-Inf 28 -70 -70 0
-Inf 42 -70 -70 0
-Inf 33 -70 -70 0
-Inf 30.8 -70 -70 0
-Inf 46.2 -70 -70 0
-Inf 77 -70 -70 0
-Inf 147 -70 -70 0
⋮
ObjectiveValueChangeRate 在每一行中均为零,这意味着即使更改 lb,最终的目标值 (–70) 也不会改变。这一结论在 lambda.lower 数据中也有所体现。
lambda.lower
ans = 48×1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
⋮
分析其对线性等式约束的灵敏度。
sensitivity.EqualityRHS
ans=20×5 table
LowerLimit UpperLimit ObjectiveValueAtLowerLimit ObjectiveValueAtUpperLimit ObjectiveValueChangeRate
__________ __________ __________________________ __________________________ ________________________
-36.364 84.848 -63.636 -84.848 -0.175
-36.364 171.43 -63.636 -100 -0.175
-36.364 30.108 -63.636 -75.269 -0.175
-36.364 46.927 -63.636 -78.212 -0.175
-93.333 40 0 -100 -0.75
-40.647 89.993 -64.665 -81.812 -0.13125
-92.562 175.42 -57.851 -93.023 -0.13125
-40.647 32.688 -64.665 -74.29 -0.13125
-40.647 50.582 -64.665 -76.639 -0.13125
-124.44 40.93 0 -93.023 -0.5625
-45.316 96.153 -65.539 -79.465 -0.098437
-176.84 182.46 -52.592 -87.96 -0.098437
-45.316 35.575 -65.539 -73.502 -0.098437
-45.316 54.731 -65.539 -75.388 -0.098437
-165.93 42.573 -4.2633e-14 -87.96 -0.42187
-50.409 103.32 -66.278 -77.628 -0.073828
⋮
将 sensitivity.EqualityRHS 的最右侧一列与 lambda.eqlin 的输出结果进行比较。
lambda.eqlin
ans = 20×1
0.1750
0.1750
0.1750
0.1750
0.7500
0.1312
0.1312
0.1312
0.1312
0.5625
0.0984
0.0984
0.0984
0.0984
0.4219
⋮
这些向量的绝对值相等。然而,与拉格朗日乘子相比,灵敏度信息能更清晰地显示:当改变线性等式系数 beq 的值时,目标函数值会发生怎样的变化。
试着将 beq(1) 设置为当前值加 1。由于 ObjectiveValueChangeRate 的值为 –0.1750,因此可以预期目标函数的值将从 –70 变为 –70.1750。
beq(1) = beq(1) + 1; [x,fval] = linprog(f,A,b,Aeq,beq,lb,ub);
Optimal solution found.
fval
fval = -70.1750