1 #ifndef OPENGM_LP_SOLVER_INTERFACE_HXX_
2 #define OPENGM_LP_SOLVER_INTERFACE_HXX_
11 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
69 void addContinuousVariables(
const SolverIndexType numVariables,
const SolverValueType lowerBound,
const SolverValueType upperBound);
70 void addIntegerVariables(
const SolverIndexType numVariables,
const SolverValueType lowerBound,
const SolverValueType upperBound);
75 void setObjectiveValue(
const SolverIndexType variable,
const SolverValueType value);
76 template<
class ITERATOR_TYPE>
78 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
79 void setObjectiveValue(VARIABLES_ITERATOR_TYPE variableIDsBegin,
const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin);
82 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
83 void addEqualityConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin,
const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin,
const SolverValueType bound,
const std::string& constraintName =
"");
84 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
85 void addLessEqualConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin,
const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin,
const SolverValueType bound,
const std::string& constraintName =
"");
86 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
87 void addGreaterEqualConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin,
const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin,
const SolverValueType bound,
const std::string& constraintName =
"");
93 template <
class PARAMETER_TYPE,
class PARAMETER_VALUE_TYPE>
94 void setParameter(
const PARAMETER_TYPE parameter,
const PARAMETER_VALUE_TYPE value);
98 bool solve(SolverTimingType& timing);
103 SolverValueType
solution(
const SolverIndexType variable)
const;
109 void exportModel(
const std::string& filename)
const;
631 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
633 : numberOfThreads_(
LPDef::default_numberOfThreads_),
634 verbose_(
LPDef::default_verbose_), cutUp_(
LPDef::default_cutUp_),
635 epOpt_(
LPDef::default_epOpt_), epMrk_(
LPDef::default_epMrk_),
636 epRHS_(
LPDef::default_epRHS_), epInt_(
LPDef::default_epInt_),
637 epAGap_(
LPDef::default_epAGap_), epGap_(
LPDef::default_epGap_),
638 workMem_(
LPDef::default_workMem_),
639 treeMemoryLimit_(
LPDef::default_treeMemoryLimit_),
640 timeLimit_(
LPDef::default_timeLimit_),
641 probingLevel_(
LPDef::default_probingLevel_),
642 rootAlg_(
LPDef::default_rootAlg_), nodeAlg_(
LPDef::default_nodeAlg_),
643 mipEmphasis_(
LPDef::default_mipEmphasis_),
644 presolve_(
LPDef::default_presolve_), cutLevel_(
LPDef::default_cutLevel_),
645 cliqueCutLevel_(
LPDef::default_cliqueCutLevel_),
646 coverCutLevel_(
LPDef::default_coverCutLevel_),
647 gubCutLevel_(
LPDef::default_gubCutLevel_),
648 mirCutLevel_(
LPDef::default_mirCutLevel_),
649 iboundCutLevel_(
LPDef::default_iboundCutLevel_),
650 flowcoverCutLevel_(
LPDef::default_flowcoverCutLevel_),
651 flowpathCutLevel_(
LPDef::default_flowpathCutLevel_),
652 disjunctCutLevel_(
LPDef::default_disjunctCutLevel_),
653 gomoryCutLevel_(
LPDef::default_gomoryCutLevel_) {
657 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
659 return SolverType::infinity_impl();
662 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
668 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
673 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
675 static_cast<SolverType*
>(
this)->addContinuousVariables_impl(numVariables, lowerBound, upperBound);
678 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
680 static_cast<SolverType*
>(
this)->addIntegerVariables_impl(numVariables, lowerBound, upperBound);
683 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
685 static_cast<SolverType*
>(
this)->addBinaryVariables_impl(numVariables);
688 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
690 static_cast<SolverType*
>(
this)->setObjective_impl(objective);
693 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
695 static_cast<SolverType*
>(
this)->setObjectiveValue_impl(variable, value);
698 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
699 template<
class ITERATOR_TYPE>
701 static_cast<SolverType*
>(
this)->setObjectiveValue_impl(begin, end);
704 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
705 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
707 static_cast<SolverType*
>(
this)->setObjectiveValue_impl(variableIDsBegin, variableIDsEnd, coefficientsBegin);
710 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
711 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
713 static_cast<SolverType*
>(
this)->addEqualityConstraint_impl(variableIDsBegin, variableIDsEnd, coefficientsBegin, bound, constraintName);
716 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
717 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
719 static_cast<SolverType*
>(
this)->addLessEqualConstraint_impl(variableIDsBegin, variableIDsEnd, coefficientsBegin, bound, constraintName);
722 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
723 template<
class VARIABLES_ITERATOR_TYPE,
class COEFFICIENTS_ITERATOR_TYPE>
725 static_cast<SolverType*
>(
this)->addGreaterEqualConstraint_impl(variableIDsBegin, variableIDsEnd, coefficientsBegin, bound, constraintName);
728 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
730 static_cast<SolverType*
>(
this)->addConstraintsFinished_impl();
733 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
735 static_cast<SolverType*
>(
this)->addConstraintsFinished_impl(timing);
738 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
739 template <
class PARAMETER_TYPE,
class PARAMETER_VALUE_TYPE>
741 static_cast<SolverType*
>(
this)->setParameter_impl(parameter, value);
744 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
746 return static_cast<SolverType*
>(
this)->solve_impl();
749 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
751 return static_cast<SolverType*
>(
this)->solve_impl(timing);
754 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
756 return static_cast<const SolverType*
>(
this)->solutionBegin_impl();
759 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
761 return static_cast<const SolverType*
>(
this)->solutionEnd_impl();
764 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
766 return static_cast<const SolverType*
>(
this)->solution_impl(variable);
769 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
771 return static_cast<const SolverType*
>(
this)->objectiveFunctionValue_impl();
774 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
776 return static_cast<const SolverType*
>(
this)->objectiveFunctionValueBound_impl();
779 template <
class LP_SOLVER_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class SOLUTION_ITERATOR_TYPE,
class SOLVER_TIMING_TYPE>
781 static_cast<const SolverType*
>(
this)->exportModel_impl(filename);
INDEX_TYPE SolverIndexType
Defines the index type used by the LP Solver.
void addBinaryVariables(const SolverIndexType numVariables)
Add new binary variables to the model.
LPDef::MIP_CUT flowcoverCutLevel_
Determines whether or not to generate flow cover cuts for the problem and how aggressively.
SolverValueType objectiveFunctionValueBound() const
Get the best known bound for the optimal solution of the current model.
void addLessEqualConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin, const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, const SolverValueType bound, const std::string &constraintName="")
Add a new less equal constraint to the model.
LPDef::MIP_CUT gubCutLevel_
Determines whether or not to generate generalized upper bound (GUB) cuts for the problem and how aggr...
LPDef::LP_SOLVER rootAlg_
Select which algorithm is used to solve continuous models or to solve the root relaxation of a MIP...
Objective function will be maximized.
int numberOfThreads_
The number of threads used for Optimization (0 = autoselect).
SolverValueType solution(const SolverIndexType variable) const
Get the solution value of a variable computed by the Solver.
double epRHS_
Feasibility tolerance.
double epMrk_
Markowitz tolerance.
SOLUTION_ITERATOR_TYPE SolverSolutionIteratorType
Defines the iterator type which can be used to iterate over the solution of the LP Solver...
LPDef::MIP_CUT flowpathCutLevel_
Determines whether or not to generate flow path cuts for the problem and how aggressively.
LP_SOLVER_TYPE SolverType
Defines the type of the child class which inherits from LPSolverInterface.
VALUE_TYPE SolverValueType
Defines the value type used by the LP Solver.
void addContinuousVariables(const SolverIndexType numVariables, const SolverValueType lowerBound, const SolverValueType upperBound)
Add new continuous variables to the model.
LPSolverInterface(const Parameter ¶meter=Parameter())
Default constructor of class LPSolverInterface.
void addIntegerVariables(const SolverIndexType numVariables, const SolverValueType lowerBound, const SolverValueType upperBound)
Add new integer variables to the model.
double epOpt_
Optimality tolerance.
SOLVER_TIMING_TYPE SolverTimingType
Defines the timing type used by the LP Solver.
double epGap_
Relative MIP gap tolerance.
LPDef::MIP_CUT disjunctCutLevel_
Determines whether or not to generate disjunctive cuts for the problem and how aggressively.
LPDef::MIP_CUT cliqueCutLevel_
Determines whether or not to generate clique cuts for the problem and how aggressively.
void exportModel(const std::string &filename) const
Export model to file.
void addEqualityConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin, const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, const SolverValueType bound, const std::string &constraintName="")
Add a new equality constraint to the model.
void setParameter(const PARAMETER_TYPE parameter, const PARAMETER_VALUE_TYPE value)
Set Solver parameter.
void setObjective(const Objective objective)
Set objective to minimize or maximize.
SolverSolutionIteratorType solutionBegin() const
Get an iterator which is pointing to the begin of the solution computed by the Solver.
int probingLevel_
Amount of probing on variables to be performed before MIP branching.
static SolverValueType infinity()
Get the value which is used by the LP Solver to represent infinity.
LPDef::MIP_CUT mirCutLevel_
Determines whether or not mixed integer rounding (MIR) cuts should be generated for the problem and h...
LPDef::MIP_CUT coverCutLevel_
Determines whether or not to generate cover cuts for the problem and how aggressively.
double epAGap_
Absolute MIP gap tolerance.
Interface definition for wrapper of LP Solvers like CPLEX and Gurobi.
LPDef::MIP_EMPHASIS mipEmphasis_
Controls trade-offs between speed, feasibility, optimality, and moving bounds in a MIP...
double epInt_
Amount by which an integer variable can differ from an integer.
double treeMemoryLimit_
Maximal amount of memory in MB used for tree.
const Parameter parameter_
Storage for parameter.
double timeLimit_
Maximal time in seconds the solver has.
Parameter()
Default constructor of class Parameter. Sets default values provided by class LPDef for all options...
LPDef::MIP_CUT cutLevel_
Determines whether or not to generate cuts for the problem and how aggressively (will be overruled by...
Parameter class provides options to modify LP Solver behavior.
LPDef::LP_SOLVER nodeAlg_
Select which algorithm is used to solve the subproblems in a MIP after the initial relaxation has bee...
void addGreaterEqualConstraint(VARIABLES_ITERATOR_TYPE variableIDsBegin, const VARIABLES_ITERATOR_TYPE variableIDsEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, const SolverValueType bound, const std::string &constraintName="")
Add a new greater equal constraint to the model.
void setObjectiveValue(const SolverIndexType variable, const SolverValueType value)
Set the coefficient of a variable in the objective function.
~LPSolverInterface()
Default destructor of class LPSolverInterface.
bool verbose_
Enable verbose output if set to true.
bool solve()
Solve the current model.
Objective function will be minimized.
double cutUp_
Upper cutoff tolerance.
double workMem_
Maximal amount of memory in MB used for workspace.
SolverSolutionIteratorType solutionEnd() const
Get an iterator which is pointing to the end of the solution computed by the Solver.
LPDef::LP_PRESOLVE presolve_
Controls how aggressive presolve is performed during preprocessing.
LPDef::MIP_CUT iboundCutLevel_
Determines whether or not to generate implied bound cuts for the problem and how aggressively.
void addConstraintsFinished()
Join all constraints added via LPSolverInterface::addEqualityConstraint, LPSolverInterface::addLessEq...
SolverValueType objectiveFunctionValue() const
Get the objective function value from the Solver.
LPDef::MIP_CUT gomoryCutLevel_
Determines whether or not to generate gomory fractional cuts for the problem and how aggressively...