G-VRP-instance-generation
cplex_model.hpp
1 #ifndef CPLEX_MODEL_HPP_
2 #define CPLEX_MODEL_HPP_
3 
4 #include "models/cplex/mip_solution_info.hpp"
5 
6 #include <ilcplex/ilocplex.h>
7 #include <iostream>
8 
9 ILOSTLBEGIN
10 
11 namespace models {
12  namespace cplex {
13  template <class I, class S> class Cplex_model {
14  public:
15  explicit Cplex_model(const I& instance_, unsigned int time_limit_) : instance(instance_), solution(nullptr), time_limit(time_limit_), max_num_feasible_integer_sol(2100000000), VERBOSE(true) {}
16  virtual ~Cplex_model() {
17  if (solution != nullptr)
18  delete solution;
19  env.end();
20  }
21  virtual pair<S, Mip_solution_info> run() = 0;
22  const I& instance;
23  static constexpr double INTEGRALITY_TOL = 1e-5;
24  S* solution;
25  unsigned int time_limit;//seconds
26  unsigned int max_num_feasible_integer_sol;//0 to 2100000000
27  bool VERBOSE;
28  IloEnv env;
29  IloModel model;
30  protected:
31  IloCplex cplex;
32  void setParameters() {
33  try{
34  if (!VERBOSE)
35  cplex.setOut(env.getNullStream());
36  cplex.setParam(IloCplex::Param::TimeLimit, time_limit);
37  cplex.setParam(IloCplex::Param::ClockType, 2);
38  cplex.setParam(IloCplex::Param::MIP::Limits::Solutions, max_num_feasible_integer_sol);
39  } catch (IloException& e) {
40  throw e;
41  } catch (...) {
42  throw string("Error in setting parameters");
43  }
44  }
45  };
46  }
47 }
48 
49 #endif
Definition: cplex_model.hpp:11
Definition: cplex_model.hpp:13