【C++/Cplex/Benders】vs2015调用cplex自带benders algorithm

【benders strategy】

OFF -1 默认分支定界求解

AUTO 0

USER 1 完全按照用户设定的annotation

WORKERS 2 先按照用户的annotation,再自动优化

FULL 3 自动确定主问题(整数变量部分)和子问题(连续型变量部分)

【key】

	IloCplex::LongAnnotation bendersdec = _solver.newLongAnnotation(IloCplex::BendersAnnotation,0);
	for (int i = 0; i < MFUtil::scnNum; i++)
	{
		for (int j = 0; j < _legList.size(); j++)
		{
			_solver.setAnnotation(bendersdec, _z_si[i][j], i+1);
		}
	}

	_solver.setParam(IloCplex::Param::Benders::Strategy,
		IloCplex::BendersUser);

【..\cplex\examples\src\cpp\ilobenders.cpp】

(默认:C:\Program Files\IBM\ILOG\CPLEX_Studio127\cplex\examples\src)

model和ann文件均读入,cplex全自动模式(FULL)

// Example:
//     ilobenders  UFL_30_120_1.mps.gz  UFL_30_120_1.ann
//

#include <ilcplex/ilocplex.h>
ILOSTLBEGIN

static void usage (const char *progname);

int
main (int argc, char **argv)
{
   IloEnv env;
   try {
      IloModel model(env);
      IloCplex cpx(env);
      bool hasannofile = false;

      // Check the arguments.
      if ( argc == 3 ) {
	 hasannofile = true;
      }
      else if ( argc != 2 ) {
         usage (argv[0]);
         throw(-1);
      }

      IloObjective   obj;
      IloNumVarArray var(env);
      IloRangeArray  rng(env);

      // Read the problem file.
      cpx.importModel(model, argv[1], obj, var, rng);

      // Extract the model.
      cpx.extract(model);

      // If provided, read the annotation file.
      if ( hasannofile ) {
	 cpx.readAnnotations(argv[2]);
      }
      else {
	 // Set benders stra
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值