GUROBISolver.hh 7.13 KB
Newer Older
David Bommes's avatar
David Bommes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//=============================================================================
//
//  CLASS GUROBISolver
//
//=============================================================================


#ifndef COMISO_GUROBISOLVER_HH
#define COMISO_GUROBISOLVER_HH


//== COMPILE-TIME PACKAGE REQUIREMENTS ========================================
#include <CoMISo/Config/config.hh>
#if COMISO_GUROBI_AVAILABLE

//== INCLUDES =================================================================

#include <CoMISo/Config/CoMISoDefines.hh>
#include <vector>
David Bommes's avatar
David Bommes committed
20
#include <string>
David Bommes's avatar
David Bommes committed
21 22 23 24 25 26
#include "NProblemInterface.hh"
#include "NConstraintInterface.hh"
#include "VariableType.hh"

//== FORWARDDECLARATIONS ======================================================

27

David Bommes's avatar
David Bommes committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
//== NAMESPACES ===============================================================

namespace COMISO {

//== CLASS DEFINITION =========================================================

	      

/** \class NewtonSolver GUROBISolver.hh

    Brief Description.
  
    A more elaborate description follows.
*/
class COMISODLLEXPORT GUROBISolver
{
public:
  // ********** SOLVE **************** //
46 47 48
  bool solve(NProblemInterface*                  _problem,                      // problem instance
             const std::vector<NConstraintInterface*>& _constraints,            // linear constraints
             const std::vector<PairIndexVtype>&        _discrete_constraints,   // discrete constraints
49 50 51
             const double                        _time_limit = 60,              // time limit in seconds
             const double                        _gap = 0.0);                   // stops when solution with optimality gap
                                                                                // lower than _gab is reached
David Bommes's avatar
David Bommes committed
52

53
  bool solve(NProblemInterface*                  _problem,                // problem instance
54 55
             const std::vector<NConstraintInterface*>& _constraints,      // linear constraints
             const double                        _time_limit = 60     )   // time limit in seconds
56
  {
57 58
    std::vector<PairIndexVtype> dc;
    return solve(_problem, _constraints, dc, _time_limit);
59 60 61 62 63 64 65 66
  }

  // same as previous but more control over stopping criteria
  // the optimizer runs in two phases
  // phase 1) stops if solution with a MIP gap lower than _gap0 is found or _time_limit0 is reached
  // phase 2) starts only if in phase 1 no solution with a MIP gap lower than _gap1 was found and
  //          uses _gap1 and _time_limit2 as parameters
  bool solve_two_phase(NProblemInterface*                  _problem,                // problem instance
67 68
             const std::vector<NConstraintInterface*>& _constraints,            // linear constraints
             const std::vector<PairIndexVtype>&        _discrete_constraints,   // discrete constraints
69 70 71 72
             const double                        _time_limit0 = 60, // time limit phase 1 in seconds
             const double                        _gap0 = 0.001,     // MIP gap phase 1
             const double                        _time_limit1 = 120, // time limit phase 2 in seconds
             const double                        _gap1 = 0.2 );       // MIP gap phase 2
Marcel Campen's avatar
Marcel Campen committed
73 74
  
  bool solve_two_phase(NProblemInterface*                  _problem,                // problem instance
75 76
                       const std::vector<NConstraintInterface*>& _constraints,            // linear constraints
                       const std::vector<PairIndexVtype>&        _discrete_constraints,   // discrete constraints
Marcel Campen's avatar
Marcel Campen committed
77 78 79 80 81
                       const double                        _time_limit0, // time limit phase 1 in seconds
                       const double                        _gap0 ,     // MIP gap phase 1
                       const double                        _time_limit1, // time limit phase 2 in seconds
                       const double                        _gap1,  // MIP gap phase 2
                       double&                             _final_gap);  //return final gap
82 83 84 85 86 87 88 89 90 91 92


  // optimization with additional lazy constraints that are only added iteratively to the problem if not satisfied
  bool solve(NProblemInterface*                        _problem,
                    const std::vector<NConstraintInterface*>& _constraints,
                    const std::vector<NConstraintInterface*>& _lazy_constraints,
                    std::vector<PairIndexVtype>&              _discrete_constraints,   // discrete constraints
                    const double                              _almost_infeasible = 0.5,
                    const int                                 _max_passes        = 5,
                    const double                              _time_limit = 60,
                    const bool                                _silent = false);
93 94 95 96 97 98

  bool solve(       NProblemInterface*                        _problem,
                    const std::vector<NConstraintInterface*>& _constraints,
                    const std::vector<NConstraintInterface*>& _lazy_constraints,
                    const std::vector<PairIndexVtype>&              _discrete_constraints,   // discrete constraints
                    const double                              _time_limit = 60,
99 100
                    const double                              _gap = 0.0,
                    const int                                 _lazy_level = 0); // lazy level between 0 and 3
101 102 103 104 105 106 107 108 109 110 111


  // same as above with additional lazy constraints that are only added iteratively to the problem if not satisfied
  bool solve(NProblemInterface*                        _problem,
                    const std::vector<NConstraintInterface*>& _constraints,
                    const std::vector<NConstraintInterface*>& _lazy_constraints,
                    const double                              _almost_infeasible = 0.5,
                    const int                                 _max_passes        = 5,
                    const double                              _time_limit = 60,
                    const bool                                _silent = false)
  {
112 113
    std::vector<PairIndexVtype> dc;
    return solve(_problem, _constraints, _lazy_constraints, dc, _almost_infeasible, _max_passes, _time_limit, _silent);
114 115 116
  }


Max Lyon's avatar
Max Lyon committed
117 118 119 120
  void set_problem_output_path       ( const std::string &_problem_output_path);
  void set_start_solution_output_path( const std::string &_start_solution_output_path);
  void set_problem_env_output_path   ( const std::string &_problem_env_output_path);
  void set_solution_input_path       ( const std::string &_solution_input_path);
David Bommes's avatar
David Bommes committed
121

David Bommes's avatar
David Bommes committed
122 123 124 125
protected:

private:

David Bommes's avatar
David Bommes committed
126 127 128
  // filenames for exporting/importing gurobi solutions
  // if string is empty nothing is imported or exported
  std::string problem_output_path_;
Max Lyon's avatar
Max Lyon committed
129
  std::string start_solution_output_path_;
David Bommes's avatar
David Bommes committed
130 131
  std::string problem_env_output_path_;
  std::string solution_input_path_;
David Bommes's avatar
David Bommes committed
132 133 134 135 136 137 138 139 140 141 142 143 144
};



//=============================================================================
} // namespace COMISO

//=============================================================================
#endif // COMISO_GUROBI_AVAILABLE
//=============================================================================
#endif // ACG_GUROBISOLVER_HH defined
//=============================================================================