Browse Source
Merge pull request 'Shields for MDPs' (#24) from mdp_shields into main
Merge pull request 'Shields for MDPs' (#24) from mdp_shields into main
Reviewed-on: https://git.pranger.xyz/TEMPEST/tempest-devel/pulls/24tempestpy_adaptions
Stefan Pranger
4 years ago
15 changed files with 343 additions and 122 deletions
-
60src/storm/modelchecker/helper/finitehorizon/SparseNondeterministicStepBoundedHorizonHelper.cpp
-
6src/storm/modelchecker/helper/finitehorizon/SparseNondeterministicStepBoundedHorizonHelper.h
-
33src/storm/modelchecker/prctl/SparseMdpPrctlModelChecker.cpp
-
8src/storm/modelchecker/prctl/helper/MDPModelCheckingHelperReturnType.h
-
69src/storm/modelchecker/prctl/helper/SparseMdpPrctlHelper.cpp
-
2src/storm/modelchecker/prctl/helper/SparseMdpPrctlHelper.h
-
4src/storm/modelchecker/rpatl/SparseSmgRpatlModelChecker.cpp
-
12src/storm/modelchecker/rpatl/helper/SparseSmgRpatlHelper.cpp
-
47src/storm/shields/ShieldHandling.cpp
-
32src/storm/shields/ShieldHandling.h
-
60src/storm/shields/shield-handling.h
-
41src/storm/solver/Multiplier.cpp
-
7src/storm/solver/Multiplier.h
-
5src/storm/solver/SolveGoal.cpp
-
5src/storm/solver/SolveGoal.h
@ -0,0 +1,47 @@ |
|||
#include "ShieldHandling.h"
|
|||
|
|||
namespace tempest { |
|||
namespace shields { |
|||
std::string shieldFilename(std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression) { |
|||
return shieldingExpression->getFilename() + ".shield"; |
|||
} |
|||
|
|||
template<typename ValueType, typename IndexType> |
|||
void createShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<ValueType> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates) { |
|||
std::ofstream stream; |
|||
storm::utility::openFile(shieldFilename(shieldingExpression), stream); |
|||
if(shieldingExpression->isPreSafetyShield()) { |
|||
PreSafetyShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), choiceValues, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else if(shieldingExpression->isPostSafetyShield()) { |
|||
PostSafetyShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), choiceValues, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Unknown Shielding Type: " + shieldingExpression->typeToString()); |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
|
|||
template<typename ValueType, typename IndexType> |
|||
void createQuantitativeShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<uint64_t> const& precomputedChoices, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates) { |
|||
std::ofstream stream; |
|||
storm::utility::openFile(shieldFilename(shieldingExpression), stream); |
|||
if(shieldingExpression->isOptimalShield()) { |
|||
OptimalShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), precomputedChoices, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Unknown Shielding Type: " + shieldingExpression->typeToString()); |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
// Explicitly instantiate appropriate
|
|||
template void createShield<double, typename storm::storage::SparseMatrix<double>::index_type>(std::shared_ptr<storm::models::sparse::Model<double>> model, std::vector<double> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
template void createQuantitativeShield<double, typename storm::storage::SparseMatrix<double>::index_type>(std::shared_ptr<storm::models::sparse::Model<double>> model, std::vector<uint64_t> const& precomputedChoices, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
#ifdef STORM_HAVE_CARL
|
|||
template void createShield<storm::RationalNumber, typename storm::storage::SparseMatrix<storm::RationalNumber>::index_type>(std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> model, std::vector<storm::RationalNumber> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
template void createQuantitativeShield<storm::RationalNumber, typename storm::storage::SparseMatrix<storm::RationalNumber>::index_type>(std::shared_ptr<storm::models::sparse::Model<storm::RationalNumber>> model, std::vector<uint64_t> const& precomputedChoices, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
#endif
|
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <boost/optional.hpp> |
|||
#include <memory> |
|||
|
|||
#include "storm/storage/Scheduler.h" |
|||
#include "storm/storage/BitVector.h" |
|||
|
|||
#include "storm/logic/ShieldExpression.h" |
|||
|
|||
#include "storm/shields/AbstractShield.h" |
|||
#include "storm/shields/PreSafetyShield.h" |
|||
#include "storm/shields/PostSafetyShield.h" |
|||
#include "storm/shields/OptimalShield.h" |
|||
|
|||
#include "storm/io/file.h" |
|||
#include "storm/utility/macros.h" |
|||
|
|||
#include "storm/exceptions/InvalidArgumentException.h" |
|||
|
|||
namespace tempest { |
|||
namespace shields { |
|||
std::string shieldFilename(std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression); |
|||
|
|||
template<typename ValueType, typename IndexType = storm::storage::sparse::state_type> |
|||
void createShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<ValueType> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
|
|||
template<typename ValueType, typename IndexType = storm::storage::sparse::state_type> |
|||
void createQuantitativeShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<uint64_t> const& precomputedChoices, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates); |
|||
} |
|||
} |
@ -1,60 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <boost/optional.hpp> |
|||
#include <memory> |
|||
|
|||
#include "storm/storage/Scheduler.h" |
|||
#include "storm/storage/BitVector.h" |
|||
|
|||
#include "storm/logic/ShieldExpression.h" |
|||
|
|||
#include "storm/shields/AbstractShield.h" |
|||
#include "storm/shields/PreSafetyShield.h" |
|||
#include "storm/shields/PostSafetyShield.h" |
|||
#include "storm/shields/OptimalShield.h" |
|||
|
|||
#include "storm/io/file.h" |
|||
#include "storm/utility/macros.h" |
|||
|
|||
#include "storm/exceptions/InvalidArgumentException.h" |
|||
|
|||
|
|||
namespace tempest { |
|||
namespace shields { |
|||
std::string shieldFilename(std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression) { |
|||
return shieldingExpression->getFilename() + ".shield"; |
|||
} |
|||
|
|||
template<typename ValueType, typename IndexType = storm::storage::sparse::state_type> |
|||
void createShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<ValueType> const& choiceValues, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates) { |
|||
std::ofstream stream; |
|||
storm::utility::openFile(shieldFilename(shieldingExpression), stream); |
|||
if(shieldingExpression->isPreSafetyShield()) { |
|||
PreSafetyShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), choiceValues, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else if(shieldingExpression->isPostSafetyShield()) { |
|||
PostSafetyShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), choiceValues, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Unknown Shielding Type: " + shieldingExpression->typeToString()); |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
|
|||
template<typename ValueType, typename IndexType = storm::storage::sparse::state_type> |
|||
void createOptimalShield(std::shared_ptr<storm::models::sparse::Model<ValueType>> model, std::vector<uint64_t> const& precomputedChoices, std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression, storm::OptimizationDirection optimizationDirection, storm::storage::BitVector relevantStates, boost::optional<storm::storage::BitVector> coalitionStates) { |
|||
std::ofstream stream; |
|||
storm::utility::openFile(shieldFilename(shieldingExpression), stream); |
|||
if(shieldingExpression->isOptimalShield()) { |
|||
OptimalShield<ValueType, IndexType> shield(model->getTransitionMatrix().getRowGroupIndices(), precomputedChoices, shieldingExpression, optimizationDirection, relevantStates, coalitionStates); |
|||
shield.construct().printToStream(stream, shieldingExpression, model); |
|||
} else { |
|||
STORM_LOG_THROW(false, storm::exceptions::InvalidArgumentException, "Unknown Shielding Type: " + shieldingExpression->typeToString()); |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
storm::utility::closeFile(stream); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue