简体   繁体   中英

a replace for getImpl() when migrating from CPLEX to Gurobi

I have a big program in c++ that uses CPLEX as the solver, and I want to make changes to use Gurobi other than CPLEX. In one of the header files, I have the code below:

struct LessIloExtractable
{
  bool operator()( const IloExtractable& a, const IloExtractable& b) const
  {
     return a.getImpl() < b.getImpl();
  }
};

I have made some changes as below, but not sure how to handle getImpl() .

struct LessGRBExtractable
{
  bool operator()( const GRBModel& a, const GRBModel& b) const
  {
     return a.getImpl() < b.getImpl();
  }
};

Gurobi is not a clone of CPLEX, so I strongly recommend you refactor your code rather than trying to force this to work. For example, IloExtractable is a base class for CPLEX objects, but there is no single base class for Gurobi C++ objects. So if you absolutely must port the code as-is, you may need to implement the operator() method for multiple Gurobi objects, not just GRBModel.

If that hasn't dissuaded you already and you absolutely must implement this, then the best option is going to be to modify and compile the Gurobi C++ interface objects so that you can expose attributes that are private in the default implementation. For example, for GRBModel, you could expose the private GRBmodel attribute (note the capitalization). You can find the C++ source in the src/cpp subdirectory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM