【问题标题】:How to get number of constraints from Cplex如何从 Cplex 获取约束数量
【发布时间】:2013-04-12 01:56:53
【问题描述】:

我有一个用 C++ 编写的很长的程序,我正在使用 ILOG Cplex12.5 Solver 来解决它。 如何获得约束的总数?有它的功能吗?

【问题讨论】:

    标签: c++ modeling linear-programming cplex


    【解决方案1】:

    有一个类 IloModel::Iterator 类可让您访问 IloModel 对象中的 IloExtractable 对象。 IloExtractable 有一个 asConstraint 方法,如果可提取对象不是约束,该方法将返回一个空句柄。任何 ILOG 音乐会句柄的 getImpl() 方法都将返回 0。因此您可以遍历所有可提取对象并计算 asConstraint 函数不返回空句柄的对象。

    #include <ilconcert/ilomodel.h>
    
    unsigned getNumConstraints(IloModel m)
    {
      unsigned count = 0;
      IloModel::Iterator iter(m);
      while (iter.ok()) {
        if ((*iter).asConstraint().getImpl()) {
          ++count;
        }
        ++iter;
      }
      return count;
    }
    

    【讨论】:

      【解决方案2】:

      IloCplex 对象中提取模型 (IloModel) 后(您应该在程序中的某个时刻这样做以求解模型),您可以调用 IloCplex::getNrows 来获取总行数 (约束)你的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-12
        相关资源
        最近更新 更多