15 for (
auto const& otherVariableCoefficientPair : other.variableToCoefficientMapping) {
16 this->variableToCoefficientMapping[otherVariableCoefficientPair.first] += otherVariableCoefficientPair.second;
18 constantPart += other.constantPart;
23 for (
auto const& otherVariableCoefficientPair : other.variableToCoefficientMapping) {
24 this->variableToCoefficientMapping[otherVariableCoefficientPair.first] -= otherVariableCoefficientPair.second;
26 constantPart -= other.constantPart;
31 STORM_LOG_THROW(variableToCoefficientMapping.size() == 0 || other.variableToCoefficientMapping.size() == 0, storm::exceptions::InvalidArgumentException,
32 "Expression is non-linear.");
33 if (other.variableToCoefficientMapping.size() > 0) {
34 variableToCoefficientMapping = std::move(other.variableToCoefficientMapping);
35 std::swap(constantPart, other.constantPart);
37 for (
auto& variableCoefficientPair : this->variableToCoefficientMapping) {
38 variableCoefficientPair.second *= other.constantPart;
40 constantPart *= other.constantPart;
45 STORM_LOG_THROW(other.variableToCoefficientMapping.size() == 0, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
46 for (
auto& variableCoefficientPair : this->variableToCoefficientMapping) {
47 variableCoefficientPair.second /= other.constantPart;
49 constantPart /= other.constantPart;
54 for (
auto& variableCoefficientPair : variableToCoefficientMapping) {
55 variableCoefficientPair.second = -variableCoefficientPair.second;
57 constantPart = -constantPart;
61 variableToCoefficientMapping[variable] = coefficient;
65 return variableToCoefficientMapping[variable];
69 return variableToCoefficientMapping.size();
73 return this->constantPart;
77 for (
auto const& rhsVariableCoefficientPair : rhs.variableToCoefficientMapping) {
78 this->variableToCoefficientMapping[rhsVariableCoefficientPair.first] -= rhsVariableCoefficientPair.second;
80 rhs.variableToCoefficientMapping.clear();
81 rhs.constantPart -= this->constantPart;
85 return this->variableToCoefficientMapping.begin();
89 return this->variableToCoefficientMapping.end();
97 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
101 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
109 leftResult += std::move(rightResult);
111 leftResult -= std::move(rightResult);
113 leftResult *= std::move(rightResult);
115 leftResult /= std::move(rightResult);
117 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
123 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
131 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
137 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
147 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
152 STORM_LOG_THROW(
false, storm::exceptions::InvalidArgumentException,
"Expression is non-linear.");
virtual boost::any accept(ExpressionVisitor &visitor, boost::any const &data) const =0
Accepts the given visitor by calling its visit method.
Type const & getType() const
Retrieves the type of the expression.
std::shared_ptr< BaseExpression const > const & getSecondOperand() const
Retrieves the second operand of the expression.
std::shared_ptr< BaseExpression const > const & getFirstOperand() const
Retrieves the first operand of the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with the expression.
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
int_fast64_t getValue() const
Retrieves the value of the integer literal.
VariableCoefficients getLinearCoefficients(Expression const &expression)
Computes the (double) coefficients of all identifiers appearing in the expression if the expression w...
virtual boost::any visit(IfThenElseExpression const &expression, boost::any const &data) override
double getValueAsDouble() const
Retrieves the value of the double literal.
bool isNumericalType() const
Checks whether this type is a numerical type.
virtual std::shared_ptr< BaseExpression const > getOperand(uint_fast64_t operandIndex) const override
Retrieves the given operand from the expression.
OperatorType getOperatorType() const
Retrieves the operator associated with this expression.
Variable const & getVariable() const
Retrieves the variable associated with this expression.
#define STORM_LOG_THROW(cond, exception, message)
VariableCoefficients & operator-=(VariableCoefficients &&other)
std::map< storm::expressions::Variable, double >::const_iterator end() const
void separateVariablesFromConstantPart(VariableCoefficients &rhs)
Brings all variables of the right-hand side coefficients to the left-hand side by negating them and m...
double getCoefficient(storm::expressions::Variable const &variable)
VariableCoefficients & operator*=(VariableCoefficients &&other)
std::map< storm::expressions::Variable, double >::const_iterator begin() const
VariableCoefficients(double constantPart=0)
void setCoefficient(storm::expressions::Variable const &variable, double coefficient)
VariableCoefficients & operator/=(VariableCoefficients &&other)
double getConstantPart() const
VariableCoefficients & operator+=(VariableCoefficients &&other)