根放松:当我用gurobi cvx无限
等待用户输入我学会了“根放松:无界”的问题是无限变量最有可能造成的。我检查所有的变量,但没有发现现有问题的变量。我很困惑,因为我需要在有限的时间解决这个问题。我知道如果你能帮助我。
代理4是MIP优化。其他代理一般QP优化。当我运行到代理4,代码停止运行并保持忙碌。控制屏幕如下。
调用Gurobi_2 9.12: 1108变量,650等式约束
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Gurobi优化器,授权为废废
学术许可到期2023-03-10——仅供非商业使用
9.1.2 Gurobi优化器版本构建v9.1.2rc0 (win64)
线程数:2个物理核心,四个逻辑处理器,使用4线程
优化模型与650行、1108列,2740 0
x87c2d29d模型指纹:0
98二次约束模型
48岁的变量类型:1060连续整数(48二进制)
系数统计:
矩阵范围[9 e-04 9 e + 01]
QMatrix范围[1 e + 00 1 e + 00)
目标范围(7 e-25 1 e + 02)
边界范围[1 e + 00 1 e + 00)
RHS范围[3 e-01 9 e + 01]
Presolve删除433行和769列
Presolve时间:0.09秒
Presolved: 703行、1017列,1852 0
Presolved模型有290二次约束(s)
连续变量类型:897、120整数(二进制)24日
根放松:无界,48个迭代,0.00秒
我急切地想知道什么导致了问题。自你理解这个问题,我把完整代码如下。
清除所有;% #好< CLALL >
关闭所有;
clc;
n = 4; m = 24;
e_abs = 1的军医,e_rel = 1的军医;MAX_ITER = 500; %迭代次数
t = 0.01;ν= 2;v = 100;ρ= 0.01,变化百分比
毫米= 90;
X = 0 (n * m, n + 1);
X_new = 0 (n * m, n + 1);;λ= 0 (n * m 2 * (n + 1));
h = 1 (m, 1); h1 = 0 (m, 1);
PV =[0, 0, 0, 0, 0, 0, 0, 37.46, 51.45, 56.01, 58.06, 85年,93年,82.98,51.59,29.70,20.92,0,0,0,0,0,0,0);
WT =(46.54, 41.27, 60.5, 35岁,45岁,54岁,50岁,45岁,45.5,40岁,35岁,0、5、4、3、6,44.5,48.04,40.5,36.02,45.5,42.42,44岁,45.5);
,120 d = (120.5, 150, 110, 130131130, 150.2, 280, 320.5,340,350.4,366.6,341.5 240.2,220.6 320.6,302.4,320.7, 208180, 146.2, 119.6,105.3];
PW =光伏+ WT; Dd = d-PW;
% DG参数
a1 = 0.02 * h; a2 = 0.0175 * h; a3 = 0.0625 * h; a4 = 0.01 * h;
一个= (a1, a2, a3); a =诊断接头(一个);
A1 =诊断接头([A1, h1, h1, h1]);A2 =诊断接头([h1, A2, h1, h1]); A3 =诊断接头([h1, h1, A3, h1]); A4 =诊断接头([h1, h1, h1, A4]);
a5 = 2 * h; a6 = 1.75 * h; a7 = 1 * h;
B1 = (a5, h1, h1, h1); B2 = (h1、a6、h1, h1); B3 = (h1、h1、a7; h1);
B0 = (a5、a6、a7);
%贝丝参数
SOC_0 = 0.5; SOC_min = 0.15; SOC_max = 0.85; n_d = 0.95; n_c = 0.95;
delta_t = 1; E_r = 1000; M =下三角阵((24));
%上界和下界
lower1 = 50 * h; lower2 = 20 * h; lower3 = 15 * h; lower4 = 0 * h;Upper1 = 120 * h; Upper2 = 80 * h; Upper3 = 50 * h; Upper4 = 60 * h;
低= [lower1; lower2; lower3 lower4;];上= [Upper1; Upper2; Upper3 Upper4;];
% DG率
r1L = -20 * 1 (m - 1, - 1); r2L = -20 * 1 (m - 1, - 1); r3L = -20 * 1 (m - 1, 1);r1U = 20 * 1 (m - 1, - 1); r2U = 20 * 1 (m - 1, - 1); r3U = 20 * 1 (m - 1, - 1);
R1L = [R1L; 0]; R2L = [R2L; 0]; R3L = (R3L; 0);R1U = [R1U; 0]; R2U = [R2U; 0]; R3U = (R3U; 0);
m1 = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 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1 =诊断接头([h, H1, H1, H1]); H2 =诊断接头([H1; h, H1, H1]); H3 =诊断接头([H1, H1, h, H1]); H4 =诊断接头([H1, H1, H1; h]);
k = 1: MAX_ITER
%代理1
%这个系统
cvx_begin
变量x_1 (n * m)
其中obj1 = x_1“* * x_1 A1 + B1”* x_1;
因为我=一24
cs1 = inv_pos (-lower1 (1) + H1(我,:)* x_1) + inv_pos (Upper1 (1) H1(我,:)* x_1);
其中obj1 =其中obj1 + cs1 * (1 / t);
结束
methoda = 0;
j =收窄
rate1 = M1 * x_1;
cs2 = inv_pos (-r1L (1) + rate1 (j,:)) + inv_pos (r1U (1) rate1 (j,:));
methoda = methoda + cs2 * (1 / t);
结束
最小化(其中obj1 + methoda +(λ(:1)λ(10):,)“* x_1 +(λ(:,2)λ(:,3))的* x_1 +
ρ* sum_square_abs (X (:, 5) (x_1) +ρ* sum_square_abs (X (:, 2) (x_1))
cvx_end
disp (x_1);
% lambda-update
X_new (: 1) = x_1;
λ(:1)=λ(:1)ρ* (X (:, 5) -X_new (: 1));
λ(:,2)=λ(:,2)ρ* (X (:, 2) -X_new (: 1));
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 1) =λ(:1);
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 2) =λ(:,2);
%剂2
%这个系统
cvx_begin
变量x_2 (n * m)
其中obj1 = x_2 * * x_2 A2 + B2的* x_2;
因为我= 25:48
cs1 = inv_pos (-lower2 (1) + H2(我,:)* x_2) + inv_pos (Upper2 (1) H2(我,:)* x_2);
其中obj1 =其中obj1 + cs1 * (1 / t);
结束
methoda = 0;
j =收窄
rate2 = M2 * x_2;
cs2 = inv_pos (-r2L (1) + rate2 (j,:)) + inv_pos (r2U (1) rate2 (j,:));
methoda = methoda + cs2 * (1 / t);
结束
最小化(其中obj1 + methoda +(λ(:,3)λ(:,2)‘* x_2 +(λ(:,4)λ(:,5))的* x_2 +
ρ* sum_square_abs (X (: 1) - x_2) +ρ* sum_square_abs (X (:, 3) - x_2))
cvx_end
disp (x_2);
% lambda-update
X_new (:, 2) = x_2;
λ(:,3)=λ(:,3)ρ* (X (: 1) -X_new (:, 2));
λ(:,4)=λ(:,4)ρ* (X (:, 3) -X_new (:, 2));
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 3) =λ(:,3);
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 4) =λ(:,4);
%剂3
%这个系统
cvx_begin
变量x_3 (n * m)
其中obj1 = x_3 * * x_3 A3 + B3的* x_3;
因为我= 49:72
cs1 = inv_pos (-lower3 (1) + H3(我,:)* x_3) + inv_pos (Upper3 (1) H3(我,:)* x_3);
其中obj1 =其中obj1 + cs1 * (1 / t);
结束
methoda = 0;
j =收窄
rate3 = M3 * x_3;
cs2 = inv_pos (-r3L (1) + rate3 (j,:)) + inv_pos (r3U (1) -rate3 (j,:));
methoda = methoda + cs2 * (1 / t);
结束
最小化(其中obj1 + methoda +(λ(:,5)λ(:,4)“* x_3 +(λ(:,6)λ(:,7))的* x_3 +
ρ* sum_square_abs (X (:, 2) - x_3) +ρ* sum_square_abs (X (:, 4) - x_3))
cvx_end
disp (x_3);
% lambda-update
X_new (:, 3) = x_3;
λ(:,5)=λ(:,5)ρ* (X (:, 2) -X_new (:, 3));
λ(:,6)=λ(:,6)ρ* (X (:, 4) -X_new (:, 3));
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 5) =λ(:,5);
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 6) =λ(:,6);
%代理4
%这个系统
cvx_begin
cvx_手机万博登录solver Gurobi_2
xx(1米)二进制的变量
二进制变量yy(1米)
变量x_41 (n * m) x_42 (n * m) x_4 (n *米)
变量z1(1米)z2(1米)
其中obj1 = 0;
因为我= 73:96
cs1 = inv_pos (-lower4 (1) + H4(我,:)* x_4) + inv_pos (Upper4 (1) H4(我,:)* x_4);
其中obj1 =其中obj1 + cs1 * (1 / t);
结束
methoda = 0;
j =一24
rate5 = - M (delta_t / E_r) * * (1 / n_d * z1 -n_c * z2);
cs2 = inv_pos (-SOC_min + SOC_0 + rate5 (j,:)) + inv_pos (SOC_max-SOC_0-rate5 (j,:));
methoda = methoda + cs2 * (1 / t);
结束
obj3 = z1 *的(m, 1) + z2 *的(m, 1);
最小化(其中obj1 + methoda + obj3 +(λ(:,7)λ(:,6))* x_4
+(λ(:8)λ(:,9)‘* x_4 +ρ* sum_square_abs (X (:, 3) (x_4) +ρ* sum_square_abs (X (:, 5) (x_4))
受
因为我=一24
z1 (i) < = xx(我)* Upper4 (1);
z1 (i) < = x_41 (72 + i);
z1 (i) > = x_41 (72 + i) - (1 xx(我))* Upper4 (1)
0 < = z1(我)< = Upper4 (1);
lower4 (1) < = x_41 (72 + i) < = Upper4 (1);
z2 (i) < = yy(我)* Upper4 (1);
z2 (i) < = x_42 (72 + i);
z2 (i) > = x_42 (72 + i) - (1-yy(我))* Upper4 (1)
0 < = z2(我)< = Upper4 (1);
lower4 (1) < = x_42 (72 + i) < = Upper4 (1);
毫米* (1 xx(我)< = x_4 (72 + i) -x_41 (72 + i) < =毫米* (1 xx(我));
毫米* (1-yy(我)< = x_4 (72 + i) + x_42 (72 + i) < =毫米* (1-yy(我));
xx(我)+ yy (i) = = 1;
结束
cvx_end
disp (x_4);
% lambda-update
X_new (:, 4) = x_4;
λ(:,7)=λ(:,7)ρ* (X (:, 3) -X_new (:, 4));
λ(:,8)=λ(:,8)ρ* (X (:, 5) -X_new (:, 4));
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 7) =λ(:,7);
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 8) =λ(:,8);
%代理5
%这个系统
cvx_begin
变量x_5 (n * m)
:F1 = x_5 (1) + x_5 (24 + 1,:) + x_5 (2 * 24 + 1,:) + x_5 (3 * 24 + 1,:); F6 = x_5 (6:) + x_5 (24 + 6:) + x_5 (2 * 24 + 6:) + x_5 (3 * 24 + 6:);
F2 = x_5 (2) + x_5 (24 + 2,:) + x_5 (2 * 24 + 2,:) + x_5 (3 * 24 + 2,:); F7 = x_5 (7:) + x_5 (24 + 7:) + x_5 (2 * 24 + 7:) + x_5 (3 * 24 + 7:);
F3 = x_5 (3) + x_5 (24 + 3:) + x_5 (2 * 24 + 3:) + x_5 (3 * 24 + 3:); F8 = x_5 (8:) + x_5 (24 + 8:) + x_5 (2 * 24 + 8:) + x_5(: 3 * 24 + 8日);
F4 = x_5 (4) + x_5 (24 + 4:) + x_5 (2 * 24 + 4:) + x_5 (3 * 24 + 4:); F9 = x_5(9日:)+ x_5 (24 + 9:) + x_5 (2 * 24 + 9:) + x_5(: 3 * 24 + 9日);
:F5 = x_5(5日)+ x_5 (24 + 5:) + x_5 (2 * 24 + 5:) + x_5 (3 * 24 + 5:); F10 = x_5 (10:) + x_5 (24 + 10:) + x_5 (2 * 24 + 10:) + x_5 (3 * 24 + 10:);
:F11 = x_5(11日)+ x_5(24 + 11日:)+ x_5(2 * 24 + 11日:)+ x_5(3 * 24 + 11日:);F16 = x_5(16日:)+ x_5(24 + 16日:)+ x_5(2 * 24 + 16日:)+ x_5(: 3 * 24 + 16日);
:F12 = x_5(12日)+ x_5(24 + 12日:)+ x_5(2 * 24 + 12日:)+ x_5(3 * 24 + 12日:);F17 = x_5(17日:)+ x_5(24 + 17日:)+ x_5(2 * 24 + 17日:)+ x_5(: 3 * 24 + 17日);
:F13 = x_5(13日)+ x_5(24 + 13日:)+ x_5(2 * 24 + 13日:)+ x_5(3 * 24 + 13日:);F18 = x_5(18日:)+ x_5(24 + 18日:)+ x_5(2 * 24 + 18日:)+ x_5(: 3 * 24 + 18日);
:F14 = x_5(14日)+ x_5(24 + 14日:)+ x_5(2 * 24 + 14日:)+ x_5(3 * 24 + 14日:);F19 = x_5(19日:)+ x_5(24 + 19日:)+ x_5(2 * 24 + 19日:)+ x_5(: 3 * 24 + 19日);
:F15 = x_5(15日)+ x_5(24 + 15日:)+ x_5(2 * 24 + 15日:)+ x_5(3 * 24 + 15日:);F20 = x_5(20日:)+ x_5(24 + 20日:)+ x_5(2 * 24 + 20日:)+ x_5(: 3 * 24 + 20日);
:F21 = x_5(21日)+ x_5(24 + 21日:)+ x_5(2 * 24 + 21日:)+ x_5(3 * 24 + 21日:);F23 = x_5(23日:)+ x_5(24 + 23日:)+ x_5(2 * 24 + 23日:)+ x_5(: 3 * 24 + 23日);
:——F22 = x_5(22日)+ x_5(24 + 22日:)+ x_5(2 * 24 + 22日:)+ x_5(: 3 * 24 + 22日);F24 = x_5(24日:)+ x_5(24 + 24日:)+ x_5(2 * 24 + 24日:)+ x_5(: 3 * 24 + 24日);
FF = [F1, F2, F3, F4, F5、F6, F7, F8, F9, F10,季,F12、F13, F14, F15, F16, F17, F18, F19, F20, F21,——F22, F23, F24);
最小化(v * sum_square_abs (FF-Dd) +(λ(:,9)λ(:,8))* x_5
+(λ(:10)λ(:1)‘* x_5 +ρ* sum_square_abs (X (:, 4) - x_5) +ρ* sum_square_abs (X (: 1) - x_5))
cvx_end
disp (x_5);
% lambda-update
X_new (:, 5) = x_5;
λ(:,9)=λ(:,9)ρ* (X (:, 4) -X_new (:, 5));
λ(:,10)=λ(:,10)ρ* (X (: 1) -X_new (:, 5));
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 9) =λ(:,9);
lambda_result1 (n * m * (k - 1) + 1: n * m * k, 10) =λ(:,10);
X = X_new;
因为我= 1:n + 1
X_result1 (n * m * (k - 1) + 1: n * m * k i) = X(:,我);
结束
结果(k) = x_1“* * x_1 A1 + B1”* x_1 + x_2 * * x_2 A2 + B2的* x_2 + x_3 * * x_3 A3 + B3的* x_3 + x_4 ' * A4 * x_4;
disp(结果(k));
%的停止标准
如果(k > 1)
j = 1: 5
如果(j = = 1)
e_p (j) =规范(X (:, 5) - X(: 1)) +规范(X (:, 2) - X (: 1));
e_pri (j) = e_abs + (max(规范(X(:, 5))马克斯(规范(X(: 1))规范(X (:, 2))))) * e_rel;
结束
如果(j = = 5)
e_p (j) =规范(X (:, 4) - X(:, 5)) +规范(X (: 1) - X (:, 5));
e_pri (j) = e_abs + (max(规范(X(:, 4))马克斯(规范(X(:, 5))规范(X (: 1))))) * e_rel;
结束
如果(j ~ = 1 & & ~ = 5)
e_p (j) =规范(X (:, j - 1) - X (:, j)) +规范(X (:, j + 1) - X (:, j));
e_pri (j) = e_abs + (max(规范(X (:, j - 1)),马克斯(规范(X (:, j))规范(X (:, j + 1))))) * e_rel;
结束
e_d (j) =ρ*规范(X_result1 (n * m * (k-2) + 1: n * m * (k - 1), j) - X (:, j));
e_dual (j) = e_abs + (max(规范(λ(:,2 * j - 1))、规范(λ(:,2 * j)))) * e_rel;
结束
如果(总和(e_p < = e_pri) = = 5) & & (sum (e_d < = e_dual) = = 5))
打破
结束
结束
t =ν* t;
结束
-
发布整个代码不帮助分析这个问题。它总是最好的提供最小的工作示例和使用Gurobi的本机api而不是CVXPY等第三方软件。
我不能看到你为你所有的变量设置有限的范围。你可以尝试设置对所有变量有限的上下界限吗?设置的上界,例如,1 e4应该够了。Gurobi设置一个默认的下界(0)所以你不需要这些。
最好的问候,
Jaromił0
请登录留下你的评论。
评论
1评论