7 changed files with 154 additions and 103 deletions
			
			
		- 
					1src/storm/adapters/CarlAdapter.h
 - 
					63src/storm/analysis/GraphConditions.cpp
 - 
					75src/storm/analysis/GraphConditions.h
 - 
					8src/storm/cli/entrypoints.h
 - 
					42src/storm/models/sparse/Dtmc.cpp
 - 
					54src/storm/models/sparse/Dtmc.h
 - 
					14src/storm/utility/storm.h
 
@ -0,0 +1,63 @@ | 
				
			|||
 | 
				
			|||
#include "GraphConditions.h"
 | 
				
			|||
#include "storm/utility/constants.h"
 | 
				
			|||
#include "storm/exceptions/NotImplementedException.h"
 | 
				
			|||
 | 
				
			|||
namespace storm { | 
				
			|||
    namespace analysis { | 
				
			|||
        template <typename ValueType> | 
				
			|||
        ConstraintCollector<ValueType>::ConstraintCollector(storm::models::sparse::Dtmc<ValueType> const& dtmc) { | 
				
			|||
            process(dtmc); | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        template <typename ValueType> | 
				
			|||
        std::unordered_set<typename ConstraintType<ValueType>::val> const& ConstraintCollector<ValueType>::getWellformedConstraints() const { | 
				
			|||
            return this->wellformedConstraintSet; | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        template <typename ValueType> | 
				
			|||
        std::unordered_set<typename ConstraintType<ValueType>::val> const& ConstraintCollector<ValueType>::getGraphPreservingConstraints() const { | 
				
			|||
            return this->graphPreservingConstraintSet; | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        template <typename ValueType> | 
				
			|||
        void ConstraintCollector<ValueType>::process(storm::models::sparse::Dtmc<ValueType> const& dtmc) { | 
				
			|||
            for(uint_fast64_t state = 0; state < dtmc.getNumberOfStates(); ++state) { | 
				
			|||
                ValueType sum = storm::utility::zero<ValueType>(); | 
				
			|||
                for (auto const& transition : dtmc.getRows(state)) { | 
				
			|||
                    sum += transition.getValue(); | 
				
			|||
                    if (!storm::utility::isConstant(transition.getValue())) { | 
				
			|||
                        if (transition.getValue().denominator().isConstant()) { | 
				
			|||
                            if (transition.getValue().denominatorAsNumber() > 0) { | 
				
			|||
                                wellformedConstraintSet.emplace((transition.getValue().nominator() - transition.getValue().denominator()).polynomial(), storm::CompareRelation::LEQ); | 
				
			|||
                                wellformedConstraintSet.emplace(transition.getValue().nominator().polynomial(), storm::CompareRelation::GEQ); | 
				
			|||
                            } else if (transition.getValue().denominatorAsNumber() < 0) { | 
				
			|||
                                wellformedConstraintSet.emplace((transition.getValue().nominator() - transition.getValue().denominator()).polynomial(), storm::CompareRelation::GEQ); | 
				
			|||
                                wellformedConstraintSet.emplace(transition.getValue().nominator().polynomial(), storm::CompareRelation::LEQ); | 
				
			|||
                            } else { | 
				
			|||
                                assert(false); // Should fail before.
 | 
				
			|||
                            } | 
				
			|||
                        } else { | 
				
			|||
                            wellformedConstraintSet.emplace(transition.getValue().denominator().polynomial(), storm::CompareRelation::NEQ); | 
				
			|||
                            STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Rational functions at edges not yet supported."); | 
				
			|||
                        } | 
				
			|||
                        graphPreservingConstraintSet.emplace(transition.getValue().nominator().polynomial(), storm::CompareRelation::NEQ); | 
				
			|||
                    } | 
				
			|||
                } | 
				
			|||
                STORM_LOG_ASSERT(!storm::utility::isConstant(sum) || storm::utility::isOne(sum), "If the sum is a constant, it must be equal to 1."); | 
				
			|||
                if(!storm::utility::isConstant(sum)) { | 
				
			|||
                    wellformedConstraintSet.emplace((sum.nominator() - sum.denominator()).polynomial(), storm::CompareRelation::EQ); | 
				
			|||
                } | 
				
			|||
 | 
				
			|||
            } | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
        template <typename ValueType> | 
				
			|||
        void ConstraintCollector<ValueType>::operator()(storm::models::sparse::Dtmc<ValueType> const& dtmc) { | 
				
			|||
            process(dtmc); | 
				
			|||
        } | 
				
			|||
 | 
				
			|||
 | 
				
			|||
        template class ConstraintCollector<storm::RationalFunction>; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,75 @@ | 
				
			|||
#pragma once | 
				
			|||
 | 
				
			|||
#include <type_traits> | 
				
			|||
#include <unordered_set> | 
				
			|||
#include "storm/adapters/CarlAdapter.h" | 
				
			|||
#include "storm/models/sparse/Dtmc.h" | 
				
			|||
 | 
				
			|||
namespace storm { | 
				
			|||
    namespace analysis { | 
				
			|||
 | 
				
			|||
template <typename ValueType, typename Enable=void> | 
				
			|||
struct ConstraintType { | 
				
			|||
    typedef storm::ArithConstraint<ValueType> val; | 
				
			|||
}; | 
				
			|||
 | 
				
			|||
template<typename ValueType> | 
				
			|||
struct ConstraintType<ValueType, typename std::enable_if<std::is_same<storm::RationalFunction, ValueType>::value>::type> { | 
				
			|||
   typedef carl::Formula<typename ValueType::PolyType::PolyType> val; | 
				
			|||
}; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * Class to collect constraints on parametric Markov chains. | 
				
			|||
 */ | 
				
			|||
template<typename ValueType> | 
				
			|||
class ConstraintCollector { | 
				
			|||
private: | 
				
			|||
    // A set of constraints that says that the DTMC actually has valid probability distributions in all states. | 
				
			|||
    std::unordered_set<typename ConstraintType<ValueType>::val> wellformedConstraintSet; | 
				
			|||
 | 
				
			|||
    // A set of constraints that makes sure that the underlying graph of the model does not change depending | 
				
			|||
    // on the parameter values. | 
				
			|||
    std::unordered_set<typename ConstraintType<ValueType>::val> graphPreservingConstraintSet; | 
				
			|||
 | 
				
			|||
public: | 
				
			|||
    /*! | 
				
			|||
     * Constructs the a constraint collector for the given DTMC. The constraints are built and ready for | 
				
			|||
     * retrieval after the construction. | 
				
			|||
     * | 
				
			|||
     * @param dtmc The DTMC for which to create the constraints. | 
				
			|||
     */ | 
				
			|||
    ConstraintCollector(storm::models::sparse::Dtmc<ValueType> const& dtmc); | 
				
			|||
 | 
				
			|||
    /*! | 
				
			|||
     * Returns the set of wellformed-ness constraints. | 
				
			|||
     * | 
				
			|||
     * @return The set of wellformed-ness constraints. | 
				
			|||
     */ | 
				
			|||
    std::unordered_set<typename ConstraintType<ValueType>::val> const&  getWellformedConstraints() const; | 
				
			|||
 | 
				
			|||
    /*! | 
				
			|||
     * Returns the set of graph-preserving constraints. | 
				
			|||
     * | 
				
			|||
     * @return The set of graph-preserving constraints. | 
				
			|||
     */ | 
				
			|||
    std::unordered_set<typename ConstraintType<ValueType>::val> const&  getGraphPreservingConstraints() const; | 
				
			|||
 | 
				
			|||
    /*! | 
				
			|||
     * Constructs the constraints for the given DTMC. | 
				
			|||
     * | 
				
			|||
     * @param dtmc The DTMC for which to create the constraints. | 
				
			|||
     */ | 
				
			|||
    void process(storm::models::sparse::Dtmc<ValueType> const& dtmc); | 
				
			|||
 | 
				
			|||
    /*! | 
				
			|||
     * Constructs the constraints for the given DTMC by calling the process method. | 
				
			|||
     * | 
				
			|||
     * @param dtmc The DTMC for which to create the constraints. | 
				
			|||
     */ | 
				
			|||
    void operator()(storm::models::sparse::Dtmc<ValueType> const& dtmc); | 
				
			|||
 | 
				
			|||
}; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue