manbet体育手机客户端


LPMOD_C ++。CPP


/ *版权所有2018,Gurobi优狗万app足彩化,LLC * / / *此示例从文件中读取LP模型并解决它。如果模型可以解决,那么它找到了最小的正变量,将其上限设置为零,并解决模型两种方式:首先具有高级开始,然后没有高级开始(即'从划痕')。* / #include“gurobi_c ++。h”使用命名空间std;int main(int argc,char * argv []){if(argc <2){cout <<“用法:lpmod_c ++ filename”<<端口;返回1;grbenv * env = 0;grbvar * v = 0;尝试{//读取模型并确定它是一个lp env = new grbenv();grbmodel model = grbmodel(* env,argv [1]);if(model.get(grb_intattr_ismip)!= 0){cout <<“模型不是线性程序”<<端口; return 1; } model.optimize(); int status = model.get(GRB_IntAttr_Status); if ((status == GRB_INF_OR_UNBD) || (status == GRB_INFEASIBLE) || (status == GRB_UNBOUNDED)) { cout << "The model cannot be solved because it is " << "infeasible or unbounded" << endl; return 1; } if (status != GRB_OPTIMAL) { cout << "Optimization was stopped with status " << status << endl; return 0; } // Find the smallest variable value double minVal = GRB_INFINITY; int minVar = 0; v = model.getVars(); for (int j = 0; j < model.get(GRB_IntAttr_NumVars); ++j) { double sol = v[j].get(GRB_DoubleAttr_X); if ((sol > 0.0001) && (sol < minVal) && (v[j].get(GRB_DoubleAttr_LB) == 0.0)) { minVal = sol; minVar = j; } } cout << "\n*** Setting " << v[minVar].get(GRB_StringAttr_VarName) << " from " << minVal << " to zero ***" << endl << endl; v[minVar].set(GRB_DoubleAttr_UB, 0.0); // Solve from this starting point model.optimize(); // Save iteration & time info double warmCount = model.get(GRB_DoubleAttr_IterCount); double warmTime = model.get(GRB_DoubleAttr_Runtime); // Reset the model and resolve cout << "\n*** Resetting and solving " << "without an advanced start ***\n" << endl; model.reset(); model.optimize(); // Save iteration & time info double coldCount = model.get(GRB_DoubleAttr_IterCount); double coldTime = model.get(GRB_DoubleAttr_Runtime); cout << "\n*** Warm start: " << warmCount << " iterations, " << warmTime << " seconds" << endl; cout << "*** Cold start: " << coldCount << " iterations, " << coldTime << " seconds" << endl; } catch (GRBException e) { cout << "Error code = " << e.getErrorCode() << endl; cout << e.getMessage() << endl; } catch (...) { cout << "Error during optimization" << endl; } delete[] v; delete env; return 0; }