diff --git a/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.cpp b/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.cpp new file mode 100644 index 000000000..f484cee52 --- /dev/null +++ b/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.cpp @@ -0,0 +1,34 @@ +#include "SparseDtmcInstantiationModelChecker.h" + +#include "storm/exceptions/InvalidArgumentException.h" +#include "storm/modelchecker/prctl/SparseDtmcPrctlModelChecker.h" + +namespace storm { + namespace modelchecker { + namespace parametric { + + template + SparseDtmcInstantiationModelChecker::SparseDtmcInstantiationModelChecker(SparseModelType const& parametricModel) : SparseInstantiationModelChecker(parametricModel), modelInstantiator(parametricModel) { + //Intentionally left empty + } + + template + bool SparseDtmcInstantiationModelChecker::canHandle(storm::modelchecker::CheckTask const& checkTask) const { + storm::modelchecker::SparseDtmcPrctlModelChecker> mc(this->parametricModel); + return mc.canHandle(checkTask); + } + + template + std::unique_ptr SparseDtmcInstantiationModelChecker::check(storm::utility::parametric::Valuation const& valuation) { + auto const& instantiatedModel = modelInstantiator.instantiate(valuation); + storm::modelchecker::SparseDtmcPrctlModelChecker> mc(instantiatedModel); + + // todo check whether the model checker supports hints on the specified property and if this is the case, + + return mc.check(*this->currentCheckTask); + } + + + } + } +} \ No newline at end of file diff --git a/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.h b/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.h index 933e67df0..affa734c4 100644 --- a/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.h +++ b/src/storm/modelchecker/parametric/SparseDtmcInstantiationModelChecker.h @@ -1,37 +1,32 @@ #pragma once -#include "storm/logic/Formulas.h" -#include "storm/modelchecker/CheckTask.h" -#include "storm/modelchecker/results/CheckResult.h" -#include "storm/utility/parametric.h" +#include + +#include "storm/models/sparse/Dtmc.h" +#include "storm/modelchecker/parametric/SparseInstantiationModelChecker.h" +#include "storm/utility/ModelInstantiator.h" namespace storm { namespace modelchecker { namespace parametric { - template - /*! - * Class to efficiently check a formula on a parametric model on different parameter instantiations + * Class to efficiently check a formula on a parametric model with different parameter instantiations */ - class SparseInstantiationModelChecker { + template + class SparseDtmcInstantiationModelChecker : public SparseInstantiationModelChecker { public: - SparseInstantiationModelChecker(SparseModelType const& parametricModel); + SparseDtmcInstantiationModelChecker(SparseModelType const& parametricModel); - virtual bool canHandle(CheckTask const& checkTask) = 0; + virtual bool canHandle(CheckTask const& checkTask) const override; - virtual void specifyFormula(CheckTask const& checkTask) = 0; + virtual void specifyFormula(CheckTask const& checkTask) override; - virtual std::unique_ptr check(storm::utility::parametric::Valuation const& valuation) = 0; + virtual std::unique_ptr check(storm::utility::parametric::Valuation const& valuation) override; - private: - - SparseModelType const& parametricModel; - + protected: + storm::utility::ModelInstantiator> modelInstantiator; }; } } } - - -#endif //STORM_SPARSEINSTANTIATIONMODELCHECKER_H diff --git a/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.cpp b/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.cpp index b4f0a759c..feb34eeba 100644 --- a/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.cpp +++ b/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.cpp @@ -1,5 +1,26 @@ -// -// Created by Tim Quatmann on 23/02/2017. -// - #include "SparseInstantiationModelChecker.h" + +#include "storm/exceptions/InvalidArgumentException.h" + +namespace storm { + namespace modelchecker { + namespace parametric { + + template + SparseInstantiationModelChecker::SparseInstantiationModelChecker(SparseModelType const& parametricModel) : parametricModel(parametricModel) { + //Intentionally left empty + } + + + template + void SparseInstantiationModelChecker::specifyFormula(storm::modelchecker::CheckTask const& checkTask) { + storm::logic::Formula const& formula = checkTask.getFormula(); + STORM_LOG_THROW(this->canHandle(checkTask), storm::exceptions::InvalidArgumentException, "The model checker is not able to check the formula '" << formula << "'."); + + currentCheckTask = std::make_unique>(checkTask.getFormula(), checkTask.isOnlyInitialStatesRelevantSet()); + currentCheckTask->setProduceSchedulers(checkTask.isProduceSchedulersSet()); + } + + } + } +} \ No newline at end of file diff --git a/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.h b/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.h index e5559f347..c77341edd 100644 --- a/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.h +++ b/src/storm/modelchecker/parametric/SparseInstantiationModelChecker.h @@ -1,16 +1,34 @@ -// -// Created by Tim Quatmann on 23/02/2017. -// - -#ifndef STORM_SPARSEINSTANTIATIONMODELCHECKER_H -#define STORM_SPARSEINSTANTIATIONMODELCHECKER_H - - - -class SparseInstantiationModelChecker { - -}; - - - -#endif //STORM_SPARSEINSTANTIATIONMODELCHECKER_H +#pragma once + +#include "storm/logic/Formulas.h" +#include "storm/modelchecker/CheckTask.h" +#include "storm/modelchecker/results/CheckResult.h" +#include "storm/utility/parametric.h" + +namespace storm { + namespace modelchecker { + namespace parametric { + + /*! + * Class to efficiently check a formula on a parametric model with different parameter instantiations + */ + template + class SparseInstantiationModelChecker { + public: + SparseInstantiationModelChecker(SparseModelType const& parametricModel); + + virtual bool canHandle(CheckTask const& checkTask) const = 0; + + void specifyFormula(CheckTask const& checkTask); + + virtual std::unique_ptr check(storm::utility::parametric::Valuation const& valuation) = 0; + + protected: + + SparseModelType const& parametricModel; + std::unique_ptr> currentCheckTask; + + }; + } + } +} diff --git a/src/storm/utility/ModelInstantiator.cpp b/src/storm/utility/ModelInstantiator.cpp index df8dc025a..c994b129c 100644 --- a/src/storm/utility/ModelInstantiator.cpp +++ b/src/storm/utility/ModelInstantiator.cpp @@ -132,7 +132,7 @@ namespace storm { } template - ConstantSparseModelType const& ModelInstantiator::instantiate(std::mapconst& valuation){ + ConstantSparseModelType const& ModelInstantiator::instantiate(storm::utility::parametric::Valuation const& valuation){ //Write results into the placeholders for(auto& functionResult : this->functions){ functionResult.second=storm::utility::convertNumber( diff --git a/src/storm/utility/ModelInstantiator.h b/src/storm/utility/ModelInstantiator.h index 17de0ea21..bfb4f687e 100644 --- a/src/storm/utility/ModelInstantiator.h +++ b/src/storm/utility/ModelInstantiator.h @@ -53,7 +53,7 @@ namespace storm { * @param valuation Maps each occurring variables to the value with which it should be substituted * @return The instantiated model */ - ConstantSparseModelType const& instantiate(std::mapconst& valuation); + ConstantSparseModelType const& instantiate(storm::utility::parametric::Valuation const& valuation); /*! * Check validity diff --git a/src/storm/utility/parametric.cpp b/src/storm/utility/parametric.cpp index 67a9b791e..e1fe06a85 100644 --- a/src/storm/utility/parametric.cpp +++ b/src/storm/utility/parametric.cpp @@ -25,7 +25,7 @@ namespace storm { #ifdef STORM_HAVE_CARL template<> - typename CoefficientType::type evaluate(storm::RationalFunction const& function, std::map::type, typename CoefficientType::type> const& valuation){ + typename CoefficientType::type evaluate(storm::RationalFunction const& function, Valuation const& valuation){ return function.evaluate(valuation); } diff --git a/src/storm/utility/parametric.h b/src/storm/utility/parametric.h index 46846f2f9..d07bb9046 100644 --- a/src/storm/utility/parametric.h +++ b/src/storm/utility/parametric.h @@ -1,10 +1,3 @@ -// -// parametric.h -// -// Created by Tim Quatmann on 08/03/16. -// -// - #ifndef STORM_UTILITY_PARAMETRIC_H #define STORM_UTILITY_PARAMETRIC_H @@ -21,6 +14,7 @@ namespace storm { */ template struct VariableType { typedef void type; }; + /*! * Acess the type of coefficients from a given function type */ @@ -33,12 +27,14 @@ namespace storm { template<> struct CoefficientType { typedef storm::RationalNumber type; }; #endif - + + template using Valuation = std::map::type, typename CoefficientType::type>; + /*! * Evaluates the given function wrt. the given valuation */ template - typename CoefficientType::type evaluate(FunctionType const& function, std::map::type, typename CoefficientType::type> const& valuation); + typename CoefficientType::type evaluate(FunctionType const& function, Valuation const& valuation); /*! * Retrieves the constant part of the given function.