Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
HighsLpSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <optional>
5#include <string>
6#include <vector>
7
9// To detect whether the usage of HiGHS is possible, this include is necessary.
10#include "storm-config.h"
11
12#ifdef STORM_HAVE_HIGHS
13#include "Highs.h"
14#endif
15
16namespace storm {
17namespace solver {
18
25template<typename ValueType, bool RawMode = false>
26class HighsLpSolver : public LpSolver<ValueType, RawMode> {
27 public:
32
39 HighsLpSolver(std::string const& name, OptimizationDirection const& optDir);
40
47 HighsLpSolver(std::string const& name);
48
55
61
62 virtual ~HighsLpSolver();
63
64 // Methods to add variables.
65 virtual Variable addVariable(std::string const& name, VariableType const& type, std::optional<ValueType> const& lowerBound = std::nullopt,
66 std::optional<ValueType> const& upperBound = std::nullopt, ValueType objectiveFunctionCoefficient = 0) override;
67
68 // Methods to incorporate recent changes.
69 virtual void update() const override;
70
71 // Methods to add constraints
72 virtual void addConstraint(std::string const& name, Constraint const& constraint) override;
73 virtual void addIndicatorConstraint(std::string const& name, Variable indicatorVariable, bool indicatorValue, Constraint const& constraint) override;
74
75 // Methods to optimize and retrieve optimality status.
76 virtual void optimize() const override;
77 virtual bool isInfeasible() const override;
78 virtual bool isUnbounded() const override;
79 virtual bool isOptimal() const override;
80
81 // Methods to retrieve values of variables and the objective function in the optimal solutions.
82 virtual ValueType getContinuousValue(Variable const& variable) const override;
83 virtual int_fast64_t getIntegerValue(Variable const& variable) const override;
84 virtual bool getBinaryValue(Variable const& variable) const override;
85 virtual ValueType getObjectiveValue() const override;
86
87 // Methods to print the LP problem to a file.
88 virtual void writeModelToFile(std::string const& filename) const override;
89
90 virtual void push() override;
91 virtual void pop() override;
92
93 virtual void setMaximalMILPGap(ValueType const& gap, bool relative) override;
94 virtual ValueType getMILPGap(bool relative) const override;
95
96 private:
97#ifdef STORM_HAVE_HIGHS
98 // Translates an internally used (possibly infinite) bound value into the representation HiGHS expects for infinity.
99 // Internally, unboundedness is tracked using actual infinity (rather than HiGHS' finite infinity sentinel) so that
100 // std::isfinite can be used to detect genuinely unbounded variables, e.g. when computing big-M coefficients.
101 double toHighsBound(double value) const;
102
103 // The HiGHS LP/MILP solver instance. HiGHS offers no incremental solving interface, hence we always (re)solve the full model.
104 mutable Highs highs;
105
106 // The index of the next variable. In RawMode, this is also the index of the variable in the HiGHS model.
107 uint64_t nextVariableIndex;
108
109 // A mapping from variables to their indices. Only used in non-RawMode.
110 std::map<storm::expressions::Variable, uint64_t> variableToIndexMap;
111
112 // The bounds (lower, upper) of all variables that have been added so far, indexed by their column index.
113 // This is used to compute big-M coefficients for indicator constraints.
114 std::vector<std::pair<double, double>> variableBounds;
115
116 // The model status after the last call to optimize().
117 mutable HighsModelStatus modelStatus;
118#endif
119};
120
121} // namespace solver
122} // namespace storm
virtual void optimize() const override
Optimizes the LP problem previously constructed.
virtual void update() const override
Updates the model to make the variables that have been declared since the last call to update usable.
HighsLpSolver(std::string const &name, OptimizationDirection const &optDir)
Constructs a solver with the given name and model sense.
virtual void addConstraint(std::string const &name, Constraint const &constraint) override
Adds a the given constraint to the LP problem.
virtual void setMaximalMILPGap(ValueType const &gap, bool relative) override
Specifies the maximum difference between lower- and upper objective bounds that triggers termination.
typename LpSolver< ValueType, RawMode >::Constraint Constraint
virtual void pop() override
Pops a backtracking point from the solver's stack.
typename LpSolver< ValueType, RawMode >::Constant Constant
virtual int_fast64_t getIntegerValue(Variable const &variable) const override
Retrieves the value of the integer variable with the given name.
virtual Variable addVariable(std::string const &name, VariableType const &type, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0) override
typename LpSolver< ValueType, RawMode >::Variable Variable
virtual ValueType getMILPGap(bool relative) const override
Returns the obtained gap after a call to optimize().
virtual void writeModelToFile(std::string const &filename) const override
Writes the current LP problem to the given file.
virtual void addIndicatorConstraint(std::string const &name, Variable indicatorVariable, bool indicatorValue, Constraint const &constraint) override
Adds the given indicator constraint to the LP problem: "If indicatorVariable == indicatorValue,...
HighsLpSolver()
Constructs a solver without a name.
virtual void push() override
Pushes a backtracking point on the solver's stack.
typename LpSolver< ValueType, RawMode >::VariableType VariableType
virtual bool isOptimal() const override
Retrieves whether the model was found to be optimal, i.e.
virtual bool getBinaryValue(Variable const &variable) const override
Retrieves the value of the binary variable with the given name.
virtual bool isInfeasible() const override
Retrieves whether the model was found to be infeasible.
virtual ValueType getContinuousValue(Variable const &variable) const override
Retrieves the value of the continuous variable with the given name.
virtual ValueType getObjectiveValue() const override
Retrieves the value of the objective function.
virtual bool isUnbounded() const override
Retrieves whether the model was found to be infeasible.
std::conditional_t< RawMode, RawLpConstraint< ValueType >, storm::expressions::Expression > Constraint
Definition LpSolver.h:54
std::conditional_t< RawMode, ValueType, storm::expressions::Expression > Constant
Definition LpSolver.h:53
std::conditional_t< RawMode, typename RawLpConstraint< ValueType >::VariableIndexType, storm::expressions::Variable > Variable
Definition LpSolver.h:52
VariableType
Enumerates the different types of variables.
Definition LpSolver.h:59
ViOperator LraDistributionEquations Highs