lpmod_c + + . cpp


/ * 2023年版权,Gurobi优狗万app足彩化,LLC * / / *这个例子从文件读取一个LP模型并解决它。如果模型可以解决,那么它找到最小的积极的变量,其上限设置为零,并解决了模型两个方面:首先是一个先进的开始,那么没有一个先进的(即开始。“从头开始”)。* / # include“gurobi_c + +。使用名称空间std h”;int主要(int命令行参数个数,char * argv[]){如果(命令行参数个数< 2){cout < <“用法:lpmod_c + +文件名”< < endl;返回1;}GRBEnv * env = 0;GRBVar * v = 0;尝试{/ /读取模型和确定它是一个LP env = new GRBEnv ();GRBModel模型= GRBModel (* env, argv [1]); if (model.get(GRB_IntAttr_IsMIP) != 0) { cout << "The model is not a linear program" << endl; 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; }

尝试Gurobi免费

选择最适合你的评估许可,开始使用我们的专家团队提供技术指导和支持。

评估许可
得到一个免费的,功能齐全的许可证的Gurobi性能优化经验,支持,基准测试和调优服务我们提供我们产品的一部分。
学术许可
Gurobi支持教学和学术机构内使用的优化。我们提供免费的,功能齐全的Gurobi用于类的副本,并进行研究。
云试验

申请免费试用时间,所以你可以看到一个模型可以解决如何快速而方便地在云上。

<\/i>","library":"fa-solid"}}" data-widget_type="nav-menu.default">

Gurobi通讯

RSS提要

狗万app足彩
Jupyter模型
案例研究
常见问题