11template<
typename ValueType>
13 : relationType(relationType), rhs(rhs) {
18template<
typename ValueType>
20 lhsCoefficients.push_back(coefficient);
21 lhsVariableIndices.push_back(variable);
24template<
typename ValueType,
bool RawMode>
30template<
typename ValueType,
bool RawMode>
32 : manager(new
storm::expressions::ExpressionManager()), currentModelHasBeenOptimized(false), optimizationDirection(optimizationDir) {
36template<
typename ValueType,
bool RawMode>
39 ValueType objectiveFunctionCoefficient) {
40 return addVariable(name, VariableType::Continuous, lowerBound, upperBound, objectiveFunctionCoefficient);
43template<
typename ValueType,
bool RawMode>
45 ValueType objectiveFunctionCoefficient) {
46 return addVariable(name, VariableType::Continuous, lowerBound, std::nullopt, objectiveFunctionCoefficient);
49template<
typename ValueType,
bool RawMode>
51 ValueType objectiveFunctionCoefficient) {
52 return addVariable(name, VariableType::Continuous, std::nullopt, upperBound, objectiveFunctionCoefficient);
55template<
typename ValueType,
bool RawMode>
57 ValueType objectiveFunctionCoefficient) {
58 return addVariable(name, VariableType::Continuous, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
61template<
typename ValueType,
bool RawMode>
63 std::optional<ValueType>
const& lowerBound,
64 std::optional<ValueType>
const& upperBound,
65 ValueType objectiveFunctionCoefficient) {
66 return addVariable(name, VariableType::Continuous, lowerBound, upperBound, objectiveFunctionCoefficient);
69template<
typename ValueType,
bool RawMode>
72 ValueType objectiveFunctionCoefficient) {
73 return addVariable(name, VariableType::Integer, lowerBound, upperBound, objectiveFunctionCoefficient);
76template<
typename ValueType,
bool RawMode>
78 ValueType objectiveFunctionCoefficient) {
79 return addVariable(name, VariableType::Integer, lowerBound, std::nullopt, objectiveFunctionCoefficient);
82template<
typename ValueType,
bool RawMode>
84 ValueType objectiveFunctionCoefficient) {
85 return addVariable(name, VariableType::Integer, std::nullopt, upperBound, objectiveFunctionCoefficient);
88template<
typename ValueType,
bool RawMode>
90 ValueType objectiveFunctionCoefficient) {
91 return addVariable(name, VariableType::Integer, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
94template<
typename ValueType,
bool RawMode>
96 std::optional<ValueType>
const& lowerBound,
97 std::optional<ValueType>
const& upperBound,
98 ValueType objectiveFunctionCoefficient) {
99 return addVariable(name, VariableType::Integer, lowerBound, upperBound, objectiveFunctionCoefficient);
101template<
typename ValueType,
bool RawMode>
103 ValueType objectiveFunctionCoefficient) {
104 return addVariable(name, VariableType::Binary, std::nullopt, std::nullopt, objectiveFunctionCoefficient);
107template<
typename ValueType,
bool RawMode>
109 if constexpr (RawMode) {
112 return manager->rational(value);
116template<
typename ValueType,
bool RawMode>
118 if (optimizationDirection != this->optimizationDirection) {
119 currentModelHasBeenOptimized =
false;
121 this->optimizationDirection = optimizationDirection;
124template<
typename ValueType,
bool RawMode>
126 return optimizationDirection;
129template<
typename ValueType,
bool RawMode>
131 STORM_LOG_ASSERT(!RawMode,
"Asking for a manager in raw mode which does not make sense.");
135template<
typename ValueType,
bool RawMode>
138 case VariableType::Continuous:
139 return this->manager->declareOrGetVariable(name, this->manager->getRationalType());
140 case VariableType::Integer:
141 case VariableType::Binary:
142 return this->manager->declareOrGetVariable(name, this->manager->getIntegerType());
144 STORM_LOG_ASSERT(
false,
"Unable to declare or get expression variable: Unknown type");
148template struct RawLpConstraint<double>;
149template struct RawLpConstraint<storm::RationalNumber>;
150template class LpSolver<double, true>;
151template class LpSolver<double, false>;
152template class LpSolver<storm::RationalNumber, true>;
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