manbet体育手机客户端


lp_c + + . cpp


/* This example rea狗万app足彩d an LP model from a file and solve it. / /*这个例子从一个文件中读取LP模型并解决它。如果模型是不可行的或无界的,则该示例关闭presolve并重新求解模型。如果模型不可行,示例计算一个不可约不一致子系统(IIS),并将其写入一个文件*/ #include "gurobi_c++.h"使用命名空间std;int main(int argc, char *argv[]) {if (argc < 2) {cout << "用法:lp_c++ filename" << endl;返回1;} try {GRBEnv env = GRBEnv();GRBModel model = GRBModel(env, argv[1]);model.optimize ();int optimstatus = model.get(GRB_IntAttr_Status);if (optimstatus == GRB_INF_OR_UNBD){模型。集(GRB_IntParam_Presolve, 0); model.optimize(); optimstatus = model.get(GRB_IntAttr_Status); } if (optimstatus == GRB_OPTIMAL) { double objval = model.get(GRB_DoubleAttr_ObjVal); cout << "Optimal objective: " << objval << endl; } else if (optimstatus == GRB_INFEASIBLE) { cout << "Model is infeasible" << endl; // compute and write out IIS model.computeIIS(); model.write("model.ilp"); } else if (optimstatus == GRB_UNBOUNDED) { cout << "Model is unbounded" << endl; } else { cout << "Optimization was stopped with status = " << optimstatus << endl; } } catch(GRBException e) { cout << "Error code = " << e.getErrorCode() << endl; cout << e.getMessage() << endl; } catch (...) { cout << "Error during optimization" << endl; } return 0; }