12template<
typename ValueType>
14 : relationType(relationType), rhs(rhs) {
19template<
typename ValueType>
21 lhsCoefficients.push_back(coefficient);
22 lhsVariableIndices.push_back(variable);
25template<
typename ValueType,
bool RawMode>
31template<
typename ValueType,
bool RawMode>
33 : manager(new
storm::expressions::ExpressionManager()), currentModelHasBeenOptimized(false), optimizationDirection(optimizationDir) {
37template<
typename ValueType,
bool RawMode>
40 ValueType objectiveFunctionCoefficient) {
41 return addVariable(name, VariableType::Continuous, lowerBound, upperBound, objectiveFunctionCoefficient);
44template<
typename ValueType,
bool RawMode>
46 ValueType objectiveFunctionCoefficient) {
47 return addVariable(name, VariableType::Continuous, lowerBound, std::nullopt, objectiveFunctionCoefficient);
50template<
typename ValueType,
bool RawMode>
52 ValueType objectiveFunctionCoefficient) {
53 return addVariable(name, VariableType::Continuous, std::nullopt, upperBound, objectiveFunctionCoefficient);
56template<
typename ValueType,
bool RawMode>
58 ValueType objectiveFunctionCoefficient) {
59 return addVariable(name, VariableType::Continuous, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
62template<
typename ValueType,
bool RawMode>
64 std::optional<ValueType>
const& lowerBound,
65 std::optional<ValueType>
const& upperBound,
66 ValueType objectiveFunctionCoefficient) {
67 return addVariable(name, VariableType::Continuous, lowerBound, upperBound, objectiveFunctionCoefficient);
70template<
typename ValueType,
bool RawMode>
73 ValueType objectiveFunctionCoefficient) {
74 return addVariable(name, VariableType::Integer, lowerBound, upperBound, objectiveFunctionCoefficient);
77template<
typename ValueType,
bool RawMode>
79 ValueType objectiveFunctionCoefficient) {
80 return addVariable(name, VariableType::Integer, lowerBound, std::nullopt, objectiveFunctionCoefficient);
83template<
typename ValueType,
bool RawMode>
85 ValueType objectiveFunctionCoefficient) {
86 return addVariable(name, VariableType::Integer, std::nullopt, upperBound, objectiveFunctionCoefficient);
89template<
typename ValueType,
bool RawMode>
91 ValueType objectiveFunctionCoefficient) {
92 return addVariable(name, VariableType::Integer, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
95template<
typename ValueType,
bool RawMode>
97 std::optional<ValueType>
const& lowerBound,
98 std::optional<ValueType>
const& upperBound,
99 ValueType objectiveFunctionCoefficient) {
100 return addVariable(name, VariableType::Integer, lowerBound, upperBound, objectiveFunctionCoefficient);
102template<
typename ValueType,
bool RawMode>
104 ValueType objectiveFunctionCoefficient) {
105 return addVariable(name, VariableType::Binary, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
108template<
typename ValueType,
bool RawMode>
110 if constexpr (RawMode) {
113 return manager->rational(value);
117template<
typename ValueType,
bool RawMode>
119 if (optimizationDirection != this->optimizationDirection) {
120 currentModelHasBeenOptimized =
false;
122 this->optimizationDirection = optimizationDirection;
125template<
typename ValueType,
bool RawMode>
127 return optimizationDirection;
130template<
typename ValueType,
bool RawMode>
132 STORM_LOG_ASSERT(!RawMode,
"Asking for a manager in raw mode which does not make sense.");
136template<
typename ValueType,
bool RawMode>
139 case VariableType::Continuous:
140 return this->manager->declareOrGetVariable(name, this->manager->getRationalType());
141 case VariableType::Integer:
142 case VariableType::Binary:
143 return this->manager->declareOrGetVariable(name, this->manager->getIntegerType());
145 STORM_LOG_ASSERT(
false,
"Unable to declare or get expression variable: Unknown type");
149template struct RawLpConstraint<double>;
150template struct RawLpConstraint<storm::RationalNumber>;
151template class LpSolver<double, true>;
152template class LpSolver<double, false>;
This class is responsible for managing a set of typed variables and all expressions using these varia...
An interface that captures the functionality of an LP solver.
Variable addUnboundedIntegerVariable(std::string const &name, ValueType objectiveFunctionCoefficient=0)
Registers an unbounded integer variable, i.e.
OptimizationDirection getOptimizationDirection() const
Retrieves whether the objective function of this model is to be minimized or maximized.
Variable addIntegerVariable(std::string const &name, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0)
Registers an integer variable, i.e.
Variable addContinuousVariable(std::string const &name, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0)
Registers a continuous variable, i.e.
Variable addUpperBoundedIntegerVariable(std::string const &name, ValueType upperBound, ValueType objectiveFunctionCoefficient=0)
Registers an upper-bounded integer variable, i.e.
storm::expressions::Variable declareOrGetExpressionVariable(std::string const &name, VariableType const &type)
Variable addBoundedIntegerVariable(std::string const &name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient=0)
Registers an upper- and lower-bounded integer variable, i.e.
storm::expressions::ExpressionManager const & getManager() const
Retrieves the manager for the variables created for this solver.
void setOptimizationDirection(OptimizationDirection const &optimizationDirection)
Sets whether the objective function of this model is to be minimized or maximized.
LpSolver()
Creates an empty LP solver.
std::conditional_t< RawMode, ValueType, storm::expressions::Expression > Constant
Variable addLowerBoundedContinuousVariable(std::string const &name, ValueType lowerBound, ValueType objectiveFunctionCoefficient=0)
Registers a lower-bounded continuous variable, i.e.
std::conditional_t< RawMode, typename RawLpConstraint< ValueType >::VariableIndexType, storm::expressions::Variable > Variable
Constant getConstant(ValueType value) const
Retrieves an expression that characterizes the given constant value.
Variable addLowerBoundedIntegerVariable(std::string const &name, ValueType lowerBound, ValueType objectiveFunctionCoefficient=0)
Registers a lower-bounded integer variable, i.e.
Variable addBoundedContinuousVariable(std::string const &name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient=0)
Registers an upper- and lower-bounded continuous variable, i.e.
VariableType
Enumerates the different types of variables.
Variable addUnboundedContinuousVariable(std::string const &name, ValueType objectiveFunctionCoefficient=0)
Registers a unbounded continuous variable, i.e.
Variable addUpperBoundedContinuousVariable(std::string const &name, ValueType upperBound, ValueType objectiveFunctionCoefficient=0)
Registers an upper-bounded continuous variable, i.e.
Variable addBinaryVariable(std::string const &name, ValueType objectiveFunctionCoefficient=0)
Registers a boolean variable, i.e.
#define STORM_LOG_ASSERT(cond, message)
RelationType
An enum type specifying the different relations applicable.
std::vector< VariableIndexType > lhsVariableIndices
uint64_t VariableIndexType
void addToLhs(VariableIndexType const &variable, ValueType const &coefficient)
Adds the summand 'coefficient * variable' to the left hand side.
RawLpConstraint(storm::expressions::RelationType relationType, ValueType const &rhs={}, uint64_t reservedSize=0)
Creates a RawLpConstraint which represents a linear (in)equality of the form a_1*x_1 + ....
std::vector< ValueType > lhsCoefficients