无法使用YALMIP在MATLAB中找到QP编码的解决方案

时间:2016-03-30 02:44:23

标签: matlab optimization gurobi quadratic-programming

这是我在这里的第一篇文章!

我已经在附件image中对QP算法进行了编码,但遗憾的是我没有得到任何解决方案。我的错误信息是"警告:解算器不适用(gurobi)"。所以看起来我不知道有没有QP,因为gurobi解决了QP ...我努力找到我的错误但不是。任何人都可以看看代码吗?

谢谢!

% This function returns losses of the grid in addition to matrices of
% active power, reactive power, and status of the lines. Each element of
% each matrix represent the corresponding value for the (i,j) line
%
% Parameters:
% R: (i,j) element indicates resistance of line composed with bus i and j
% P_bus: element i indicates real power load or real power from substation
% Q_bus: same logic for reactive power
% B_F: contains subset of buses which are substations
% B_notF: contains subset of buses which are not substations
%
%
%-------------------------------------------------------------------------%

function [Losses, val_P, val_Q, val_Y] = Quadratic_Programming(R,P_bus,Q_bus,B_F,B_notF,switches,non_switches)

% Active_Power: matrix which its (i,j) elements correspond to active power 
% going from bus i to bus j
% Reactive_Power: same logic, but for reactive power
% Configuration: matrix indicating in which direction the power flow travels for each
% line

P = sdpvar(length(R),length(R));
Q = sdpvar(length(R),length(R));
Z = sdpvar(length(R),length(R));

Constraints = [];

% Constraints 5
Constraints = [Constraints, sum(P(:,B_notF),1)' - sum(P(B_notF,:),2) == P_bus(B_notF)];

% Constraints 6
Constraints = [Constraints, sum(Q(:,B_notF),1)' - sum(Q(B_notF,:),2) == Q_bus(B_notF)];

% Constraints 7
Constraints = [Constraints, sum(P(B_F,:),2) == P_bus(B_F)];

% Constraints 8
Constraints = [Constraints, sum(Q(B_F,:),2) == Q_bus(B_F)];

M = 5000; %big-M constraint : how to formulate this properly??

% Constraints 9
Constraints = [Constraints, 0 <= P <= M*Z];

% Constraints 10
Constraints = [Constraints, 0 <= Q <= M*Z];

% Constraints 11
Constraints = [Constraints, Z >= 0];

% Constraints 12
Constraints = [Constraints, Z(:,B_F) == 0];

% Constraints 13
if (length(non_switches)>=1)
    Constraints = [Constraints, Z(sub2ind(size(Z),non_switches(1,:),non_switches(2,:)))' + Z(sub2ind(size(Z),non_switches(2,:),non_switches(1,:)))' == 1];
end

% Constraints 14
Y = binvar(size(switches,2),1);
Constraints = [Constraints, (Z(sub2ind(size(Z),switches(1,:),switches(2,:)))' + Z(sub2ind(size(Z),switches(2,:),switches(1,:)))') == Y(:)];

% Constraints 15
Constraints = [Constraints, sum(Z(:,B_notF),1)' == ones(length(B_notF),1)];

% objective
obj = sum(sum(R.*(P.^2 + Q.^2)));

optimize(Constraints,obj,sdpsettings('solver','gurobi'));

0 个答案:

没有答案