5#ifndef IDOL_OPTIMIZERS_CPLEX_H 
    6#define IDOL_OPTIMIZERS_CPLEX_H 
    9#include <ilcplex/ilocplex.h> 
   13#include "idol/general/optimizers/OptimizerWithLazyUpdates.h" 
   14#include "idol/mixed-integer/optimizers/callbacks/Callback.h" 
   15#include "CplexCallbackI.h" 
   17namespace idol::Optimizers {
 
   25struct idol::Optimizers::impl::CplexEnvKiller {
 
   27    ~CplexEnvKiller() { env.end(); }
 
   30class idol::Optimizers::Cplex : 
public OptimizerWithLazyUpdates<IloNumVar, IloRange, IloRange, std::variant<IloSOS1, IloSOS2>> {
 
   31    static std::unique_ptr<impl::CplexEnvKiller> s_global_env;
 
   36    IloObjective m_objective;
 
   37    bool m_continuous_relaxation;
 
   38    unsigned int m_solution_index = 0;
 
   39    bool m_lazy_cut = 
false;
 
   41    std::unique_ptr<CplexCallbackI> m_cplex_callback;
 
   43    IloNumVar::Type cplex_var_type(
int t_type);
 
   44    static double cplex_numeric(
double t_value);
 
   46    void hook_build() 
override;
 
   47    void hook_optimize() 
override;
 
   48    void hook_write(
const std::string &t_name) 
override;
 
   49    IloNumVar hook_add(
const Var& t_var, 
bool t_add_column) 
override;
 
   50    IloRange hook_add(
const Ctr& t_ctr) 
override;
 
   51    IloRange hook_add(
const QCtr& t_ctr) 
override;
 
   52    std::variant<IloSOS1, IloSOS2> hook_add(
const SOSCtr& t_ctr) 
override;
 
   53    void hook_update(
const Var& t_var) 
override;
 
   54    void hook_update(
const Ctr& t_ctr) 
override;
 
   55    void hook_update_objective_sense() 
override;
 
   56    void hook_update_matrix(
const Ctr &t_ctr, 
const Var &t_var, 
double t_constant) 
override;
 
   57    void hook_update_objective() 
override;
 
   58    void hook_update_rhs() 
override;
 
   59    void hook_update() 
override;
 
   60    void hook_remove(
const Var& t_var) 
override;
 
   61    void hook_remove(
const Ctr& t_ctr) 
override;
 
   62    void hook_remove(
const QCtr& t_ctr) 
override;
 
   63    void hook_remove(
const SOSCtr& t_ctr) 
override;
 
   64    void update_objective_constant();
 
   66    [[nodiscard]] SolutionStatus get_status() 
const override;
 
   67    [[nodiscard]] SolutionReason get_reason() 
const override;
 
   68    [[nodiscard]] 
double get_best_obj() 
const override;
 
   69    [[nodiscard]] 
double get_best_bound() 
const override;
 
   70    [[nodiscard]] 
double get_var_primal(
const Var &t_var) 
const override;
 
   71    [[nodiscard]] 
double get_var_reduced_cost(
const Var &t_var) 
const override;
 
   72    [[nodiscard]] 
double get_var_ray(
const Var &t_var) 
const override;
 
   73    [[nodiscard]] 
double get_ctr_dual(
const Ctr &t_ctr) 
const override;
 
   74    [[nodiscard]] 
double get_ctr_farkas(
const Ctr &t_ctr) 
const override;
 
   75    [[nodiscard]] 
double get_relative_gap() 
const override;
 
   76    [[nodiscard]] 
double get_absolute_gap() 
const override;
 
   77    [[nodiscard]] 
unsigned int get_n_solutions() 
const override;
 
   78    [[nodiscard]] 
unsigned int get_solution_index() 
const override;
 
   80    void set_solution_index(
unsigned int t_index) 
override;
 
   82    void create_callback_if_not_exists();
 
   84    Cplex(
const Model& t_model, 
bool t_continuous_relaxation);
 
   88    IloEnv& env() { 
return m_env; }
 
   90    [[nodiscard]] 
const IloEnv& env()
 const { 
return m_env; }
 
   92    IloModel& model() { 
return m_model; }
 
   94    [[nodiscard]] 
const IloModel& model()
 const { 
return m_model; }
 
   96    [[nodiscard]] std::string name()
 const override { 
return "Cplex"; }
 
   98    [[nodiscard]] 
bool lazy_cuts()
 const { 
return m_lazy_cut; }
 
  100    void set_lazy_cuts(
bool t_lazy_cut);
 
  102    void set_param_time_limit(
double t_time_limit) 
override;
 
  104    void set_param_threads(
unsigned int t_thread_limit) 
override;
 
  106    void set_param_best_obj_stop(
double t_best_obj_stop) 
override;
 
  108    void set_param_best_bound_stop(
double t_best_bound_stop) 
override;
 
  110    void set_param_presolve(
bool t_value) 
override;
 
  112    void set_param_infeasible_or_unbounded_info(
bool t_value) 
override;
 
  114    void add_callback(Callback* t_ptr_to_callback);
 
  116    void set_max_n_solution_in_pool(
unsigned int t_value);
 
  118    void set_param_logs(
bool t_value) 
override;
 
  120    void set_tol_mip_relative_gap(
double t_relative_gap_tolerance) 
override;
 
  122    void set_tol_mip_absolute_gap(
double t_absolute_gap_tolerance) 
override;
 
  124    void set_tol_feasibility(
double t_tol_feasibility) 
override;
 
  126    void set_tol_optimality(
double t_tol_optimality) 
override;
 
  128    void set_tol_integer(
double t_tol_integer) 
override;
 
  130    static Model read_from_file(Env& t_env, 
const std::string& t_filename);
 
  132    CplexCallbackI& get_cplex_callback_interface();