我目前正在使用gurobi来解决最大流量问题,并且在运行代码时出现“Gurobi错误10020:Q矩阵不是正半定(PSD)”。但是由于问题的本质,Q矩阵实际上不是正半精度,还有一个注释我称之为MATLAB的gurobi
clear model;
names = {'x1','x2','x3','x4','x5','x6','x7','x8','x9','x10'};
model.varnames = names;
model.Q = sparse([0 1 3 0 0 0 0 0 0 0;
0 0 0 2 10 0 0 0 0 0;
0 0 0 0 6 1 0 0 0 0;
0 0 0 0 0 0 4 8 0 0;
0 0 0 0 0 0 0 2 0 0;
0 0 0 0 0 0 7 0 0 0;
0 0 0 0 0 0 0 0 4 0;
0 0 0 0 0 0 0 0 3 4;
0 0 0 0 0 0 0 0 0 5;
0 0 0 0 0 0 0 0 0 0]);
%model.A = sparse(eye(10)); no linear constraint in this problem.
model.obj = [0 0 0 0 0 0 0 0 0 0];
model.modelsense = 'max';
%model.rhs = [4 1];
%model.sense = '>';
model.A = sparse([0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.rhs = [0 0 0 0 0 0 0 0 0 0];
model.sense = '=';
% Add second-order cone: x1^2 = 1
model.quadcon(1).Qc = sparse([ 1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(1).q = zeros(10,1);% first degree vector
model.quadcon(1).rhs = 1;
% Add second-order cone: x2^2 = 1
model.quadcon(2).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(2).q = zeros(10,1);% first degree vector
model.quadcon(2).rhs = 1;
% Add second-order cone: x1^2 = 1
model.quadcon(3).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(3).q = zeros(10,1);% first degree vector
model.quadcon(3).rhs = 1;
% Add second-order cone: x4^2 = 1
model.quadcon(4).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(4).q = zeros(10,1);% first degree vector
model.quadcon(4).rhs = 1;
% Add second-order cone: x5^2 = 1
model.quadcon(5).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(5).q = zeros(10,1);% first degree vector
model.quadcon(5).rhs = 1;
% Add second-order cone: x6^2 = 1
model.quadcon(6).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(6).q = zeros(10,1);% first degree vector
model.quadcon(6).rhs = 1;
% Add second-order cone: x7^2 = 1
model.quadcon(7).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(7).q = zeros(10,1);% first degree vector
model.quadcon(7).rhs = 1;
% Add second-order cone: x8^2 = 1
model.quadcon(8).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(8).q = zeros(10,1);% first degree vector
model.quadcon(8).rhs = 1;
% Add second-order cone: x1^2 = 1
model.quadcon(9).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 0]);
model.quadcon(9).q = zeros(10,1);% first degree vector
model.quadcon(9).rhs = 1;
% Add second-order cone: x1^2 = 1
model.quadcon(10).Qc = sparse([ 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 1]);
model.quadcon(10).q = zeros(10,1);% first degree vector
model.quadcon(10).rhs = 1;