sos.m


sos()函数% 2023年版权,Gurobi优化,LLC % %狗万app足彩这个例子创建了一个非常简单的特殊有序集模型(sos) %。3的模型由连续变量,没有线性%的约束,和一双SOS约束1型。模型。乌兰巴托= [1 1 2];模型。obj = (2 1 1);模型。modelsense =“Max”;模型。一个=稀疏(1、3); model.rhs = 0; model.sense = '='; % Add first SOS: x1 = 0 or x2 = 0 model.sos(1).type = 1; model.sos(1).index = [1 2]; model.sos(1).weight = [1 2]; % Add second SOS: x1 = 0 or x3 = 0 model.sos(2).type = 1; model.sos(2).index = [1 3]; model.sos(2).weight = [1 2]; % Write model to file gurobi_write(model, 'sos.lp'); result = gurobi(model); for i=1:3 fprintf('x%d %e\n', i, result.x(i)) end fprintf('Obj: %e\n', result.objval); end