manbet体育手机客户端


QCP_C ++。CPP


/ *版权所有2019,Gurobi优狗万app足彩化,LLC * / / *此示例制定并解决以下简单的QCP模型:最大化X对X + Y + Z = 1 x ^ 2 + y ^ 2 <= z ^ 2(第二 -顺序锥形)x ^ 2 <= yz(旋转二阶锥)x,y,z非负* / #include使用命名空间std的“gurobi_c ++。h”;int main(int argc,char * argv []){try {grbenv env = grbenv();grbmodel model = grbmodel(env);//创建变量grbvar x = model.addvar(0.0,grb_infinity,0.0,grb_continuous,“x”);grbvar y = model.addvar(0.0,grb_infinity,0.0,grb_continuous,“y”);grbvar z = model.addvar(0.0,grb_infinity,0.0,grb_conured,“z”);//设置目标GrblineXPR obj = x;model.setobjective(obj,grb_maximize);//添加线性约束:x + y + z = 1 model.addconstr(x + y + z == 1,“c0”);//添加二阶锥:x ^ 2 + y ^ 2 <= z ^ 2 model.addqconstr(x * x + y * y <= z * z,“qc0”); // Add rotated cone: x^2 <= yz model.addQConstr(x*x <= y*z, "qc1"); // Optimize model model.optimize(); cout << x.get(GRB_StringAttr_VarName) << " " << x.get(GRB_DoubleAttr_X) << endl; cout << y.get(GRB_StringAttr_VarName) << " " << y.get(GRB_DoubleAttr_X) << endl; cout << z.get(GRB_StringAttr_VarName) << " " << z.get(GRB_DoubleAttr_X) << endl; cout << "Obj: " << model.get(GRB_DoubleAttr_ObjVal) << endl; } catch(GRBException e) { cout << "Error code = " << e.getErrorCode() << endl; cout << e.getMessage() << endl; } catch(...) { cout << "Exception during optimization" << endl; } return 0; }