过滤内容,
版本
文本搜索
qcp.m
函数qcp() % 2023年版权,Gurobi优化,LLC % 狗万app足彩%这个例子中制定和解决以下简单的qcp模型:%最大化% x % 1% % x + y + z = x ^ 2 + y ^ 2 < = z ^ 2(二阶锥)% x ^ 2 < = yz(旋转二阶锥)% x, y, z非负的名字= {' x ', ' y ', ' z '};模型。varnames =名称;%设置目的:x模型。obj = (1 0 0);模型。modelsense =“max”;%添加约束:x + y + z = 1模型。一个=稀疏((1 1 1));模型。rhs = 1;模型。sense = '='; % Add second-order cone: x^2 + y^2 <= z^2 using a sparse matrix model.quadcon(1).Qc = sparse([ 1 0 0; 0 1 0; 0 0 -1]); model.quadcon(1).q = zeros(3,1); model.quadcon(1).rhs = 0.0; model.quadcon(1).name = 'std_cone'; % Add rotated cone: x^2 <= yz using sparse triplet representation % Equivalent sparse matrix data: %model.quadcon(2).Qc = sparse([ % 1 0 0; % 0 0 -1; % 0 0 0]); model.quadcon(2).Qrow = [1, 2] model.quadcon(2).Qcol = [1, 3] model.quadcon(2).Qval = [1, -1] % All-zero sparse 3-by-1 vector model.quadcon(2).q = sparse(3,1); model.quadcon(2).rhs = 0.0; model.quadcon(2).name = 'rot_cone'; gurobi_write(model, 'qcp.lp'); result = gurobi(model); for j=1:3 fprintf('%s %e\n', names{j}, result.x(j)) end fprintf('Obj: %e\n', result.objval); end