20template<
typename PolynomialType>
21storm::expressions::Expression toExpression(PolynomialType
const& polynomial, std::shared_ptr<storm::expressions::ExpressionManager>
const& manager) {
33 return this->wellformedConstraintSet;
37 return this->graphPreservingConstraintSet;
41 return this->variableSet;
48 return toExpression(polynomial, expressionManager) < zero;
50 return toExpression(polynomial, expressionManager) <= zero;
52 return toExpression(-polynomial, expressionManager) < zero;
54 return toExpression(-polynomial, expressionManager) <= zero;
56 return toExpression(polynomial, expressionManager) == zero;
58 return toExpression(polynomial, expressionManager) != zero;
63bool ConstraintCollector::addConstraint(ConstraintSet& constraintSet, ConstraintIndex& constraintIndex,
storm::expressions::Expression const& constraint) {
64 auto& candidates = constraintIndex[hashVisitor.
hash(constraint)];
65 for (
auto const& candidate : candidates) {
66 if (candidate.isSyntacticallyEqual(constraint)) {
70 candidates.push_back(constraint);
71 constraintSet.push_back(constraint);
81 addConstraint(wellformedConstraintSet, wellformedConstraintIndex, expressionManager->boolean(
false));
86 auto valueVariables = value.gatherVariables();
87 variableSet.insert(valueVariables.begin(), valueVariables.end());
97 addConstraint(wellformedConstraintSet, wellformedConstraintIndex, relateToZero(nominator, relation));
102 addConstraint(wellformedConstraintSet, wellformedConstraintIndex,
112 addConstraint(wellformedConstraintSet, wellformedConstraintIndex, expressionManager->boolean(
false));
117 auto denominator = value.denominator().polynomialWithCoefficient();
129 addConstraint(wellformedConstraintSet, wellformedConstraintIndex, relateToZero(nominator - denominator, relation));
133 addConstraint(graphPreservingConstraintSet, graphPreservingConstraintIndex,
137void ConstraintCollector::process(storm::models::sparse::Model<storm::RationalFunction>
const& model) {
141 for (uint_fast64_t action = 0; action < model.
getTransitionMatrix().getRowCount(); ++action) {
145 auto const& value = transitionIt->getValue();
148 wellformedRequiresNonNegativeEntries(value);
149 wellformedRequiresAtMostOne(value);
152 graphPreservingRequiresNonZero(value);
158 variableSet.insert(sumVariables.begin(), sumVariables.end());
160 addConstraint(wellformedConstraintSet, wellformedConstraintIndex,
161 relateToZero(
sum.nominator().polynomialWithCoefficient() -
sum.denominator().polynomialWithCoefficient(),
168 wellformedRequiresNonNegativeEntries(transition.getValue());
171 graphPreservingRequiresNonZero(transition.getValue());
177 auto const& exitRateVector =
static_cast<storm::models::sparse::Ctmc<storm::RationalFunction> const&
>(model).getExitRateVector();
178 for (
auto const& exitRate : exitRateVector) {
179 wellformedRequiresNonNegativeEntries(exitRate);
182 auto const& exitRateVector =
static_cast<storm::models::sparse::MarkovAutomaton<storm::RationalFunction> const&
>(model).getExitRates();
183 for (
auto const& exitRate : exitRateVector) {
184 wellformedRequiresNonNegativeEntries(exitRate);
189 if (rewModelEntry.second.hasStateRewards()) {
190 for (
auto const& stateReward : rewModelEntry.second.getStateRewardVector()) {
191 wellformedRequiresNonNegativeEntries(stateReward);
194 if (rewModelEntry.second.hasStateActionRewards()) {
195 for (
auto const& stateActionReward : rewModelEntry.second.getStateActionRewardVector()) {
196 wellformedRequiresNonNegativeEntries(stateActionReward);
199 if (rewModelEntry.second.hasTransitionRewards()) {
200 for (
auto const& entry : rewModelEntry.second.getTransitionRewardMatrix()) {
201 wellformedRequiresNonNegativeEntries(entry.getValue());
ConstraintSet const & getGraphPreservingConstraints() const
Returns the set of graph-preserving constraints.
std::set< storm::RationalFunctionVariable > const & getVariables() const
Returns the set of variables in the model.
ConstraintCollector(storm::models::sparse::Model< storm::RationalFunction > const &model)
Constructs a constraint collector for the given model.
void operator()(storm::models::sparse::Model< storm::RationalFunction > const &model)
Constructs the constraints for the given model by calling the process method.
ConstraintSet const & getWellformedConstraints() const
Returns the set of wellformed-ness constraints.
std::vector< storm::expressions::Expression > ConstraintSet
The type of the collected constraints.
void gatherVariables(std::set< storm::expressions::Variable > &variables) const
Retrieves the set of all variables that appear in the expression.
std::size_t hash(storm::expressions::Expression const &expression)
Computes the hash of the given expression.
virtual ModelType getType() const
Return the actual type of the model.
Base class for all sparse models.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
#define STORM_LOG_THROW_UNCONDITIONALLY(exception, message)
#define STORM_LOG_ASSERT(cond, message)
Expression ite(Expression const &condition, Expression const &thenExpression, Expression const &elseExpression)
Expression sum(std::vector< storm::expressions::Expression > const &expressions)
RelationType
An enum type specifying the different relations applicable.
Expression polynomialToExpression(PolynomialType const &polynomial, std::shared_ptr< ExpressionManager > const &manager)
Converts the given polynomial into a Storm expression.
bool isOne(ValueType const &a)
NumberTraits< RationalType >::IntegerType denominator(RationalType const &number)
bool isConstant(ValueType const &)
carl::RationalFunction< Polynomial, true > RationalFunction
carl::MultivariatePolynomial< RationalFunctionCoefficient > RawPolynomial