|
@ -1,5 +1,5 @@ |
|
|
#include "src/builder/ExplicitDFTModelBuilder.h"
|
|
|
#include "src/builder/ExplicitDFTModelBuilder.h"
|
|
|
#include <src/models/sparse/Ctmc.h>
|
|
|
|
|
|
|
|
|
#include <src/models/sparse/MarkovAutomaton.h>
|
|
|
#include <src/utility/constants.h>
|
|
|
#include <src/utility/constants.h>
|
|
|
#include <src/exceptions/UnexpectedException.h>
|
|
|
#include <src/exceptions/UnexpectedException.h>
|
|
|
#include <map>
|
|
|
#include <map>
|
|
@ -7,13 +7,13 @@ |
|
|
namespace storm { |
|
|
namespace storm { |
|
|
namespace builder { |
|
|
namespace builder { |
|
|
|
|
|
|
|
|
template <typename ValueType, typename RewardModelType, typename IndexType> |
|
|
|
|
|
ExplicitDFTModelBuilder<ValueType, RewardModelType, IndexType>::ModelComponents::ModelComponents() : transitionMatrix(), stateLabeling(), rewardModels(), choiceLabeling() { |
|
|
|
|
|
|
|
|
template <typename ValueType> |
|
|
|
|
|
ExplicitDFTModelBuilder<ValueType>::ModelComponents::ModelComponents() : transitionMatrix(), stateLabeling(), markovianStates(), exitRates(), choiceLabeling() { |
|
|
// Intentionally left empty.
|
|
|
// Intentionally left empty.
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template<typename ValueType, typename RewardModelType, typename IndexType> |
|
|
|
|
|
std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>> ExplicitDFTModelBuilder<ValueType, RewardModelType, IndexType>::buildCTMC() { |
|
|
|
|
|
|
|
|
template <typename ValueType> |
|
|
|
|
|
std::shared_ptr<storm::models::sparse::Model<ValueType>> ExplicitDFTModelBuilder<ValueType>::buildMA() { |
|
|
// Initialize
|
|
|
// Initialize
|
|
|
DFTStatePointer state = std::make_shared<storm::storage::DFTState<ValueType>>(mDft, newIndex++); |
|
|
DFTStatePointer state = std::make_shared<storm::storage::DFTState<ValueType>>(mDft, newIndex++); |
|
|
mStates.findOrAdd(state->status(), state); |
|
|
mStates.findOrAdd(state->status(), state); |
|
@ -21,15 +21,17 @@ namespace storm { |
|
|
std::queue<DFTStatePointer> stateQueue; |
|
|
std::queue<DFTStatePointer> stateQueue; |
|
|
stateQueue.push(state); |
|
|
stateQueue.push(state); |
|
|
|
|
|
|
|
|
bool deterministicModel = true; |
|
|
|
|
|
|
|
|
bool deterministicModel = false; |
|
|
|
|
|
ModelComponents modelComponents; |
|
|
|
|
|
std::vector<uint_fast64_t> tmpMarkovianStates; |
|
|
storm::storage::SparseMatrixBuilder<ValueType> transitionMatrixBuilder(0, 0, 0, false, !deterministicModel, 0); |
|
|
storm::storage::SparseMatrixBuilder<ValueType> transitionMatrixBuilder(0, 0, 0, false, !deterministicModel, 0); |
|
|
|
|
|
|
|
|
// Begin model generation
|
|
|
// Begin model generation
|
|
|
exploreStates(stateQueue, transitionMatrixBuilder); |
|
|
|
|
|
|
|
|
exploreStates(stateQueue, transitionMatrixBuilder, tmpMarkovianStates, modelComponents.exitRates); |
|
|
STORM_LOG_DEBUG("Generated " << mStates.size() << " states"); |
|
|
STORM_LOG_DEBUG("Generated " << mStates.size() << " states"); |
|
|
|
|
|
|
|
|
// Build CTMC
|
|
|
|
|
|
ModelComponents modelComponents; |
|
|
|
|
|
|
|
|
// Build Markov Automaton
|
|
|
|
|
|
modelComponents.markovianStates = storm::storage::BitVector(mStates.size(), tmpMarkovianStates); |
|
|
// Build transition matrix
|
|
|
// Build transition matrix
|
|
|
modelComponents.transitionMatrix = transitionMatrixBuilder.build(); |
|
|
modelComponents.transitionMatrix = transitionMatrixBuilder.build(); |
|
|
STORM_LOG_DEBUG("TransitionMatrix: " << std::endl << modelComponents.transitionMatrix); |
|
|
STORM_LOG_DEBUG("TransitionMatrix: " << std::endl << modelComponents.transitionMatrix); |
|
@ -65,15 +67,17 @@ namespace storm { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>> model; |
|
|
|
|
|
model = std::shared_ptr<storm::models::sparse::Model<ValueType, RewardModelType>>(new storm::models::sparse::Ctmc<ValueType, RewardModelType>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling))); |
|
|
|
|
|
|
|
|
std::shared_ptr<storm::models::sparse::Model<ValueType>> model = std::make_shared<storm::models::sparse::MarkovAutomaton<ValueType>>(std::move(modelComponents.transitionMatrix), std::move(modelComponents.stateLabeling), std::move(modelComponents.markovianStates), std::move(modelComponents.exitRates)); |
|
|
model->printModelInformationToStream(std::cout); |
|
|
model->printModelInformationToStream(std::cout); |
|
|
return model; |
|
|
return model; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template<typename ValueType, typename RewardModelType, typename IndexType> |
|
|
|
|
|
void ExplicitDFTModelBuilder<ValueType, RewardModelType, IndexType>::exploreStates(std::queue<DFTStatePointer>& stateQueue, storm::storage::SparseMatrixBuilder<ValueType>& transitionMatrixBuilder) { |
|
|
|
|
|
|
|
|
template <typename ValueType> |
|
|
|
|
|
void ExplicitDFTModelBuilder<ValueType>::exploreStates(std::queue<DFTStatePointer>& stateQueue, storm::storage::SparseMatrixBuilder<ValueType>& transitionMatrixBuilder, std::vector<uint_fast64_t>& markovianStates, std::vector<ValueType>& exitRates) { |
|
|
|
|
|
|
|
|
|
|
|
assert(exitRates.empty()); |
|
|
|
|
|
assert(markovianStates.empty()); |
|
|
|
|
|
// TODO Matthias: set Markovian states
|
|
|
std::map<size_t, ValueType> outgoingTransitions; |
|
|
std::map<size_t, ValueType> outgoingTransitions; |
|
|
|
|
|
|
|
|
while (!stateQueue.empty()) { |
|
|
while (!stateQueue.empty()) { |
|
@ -90,6 +94,8 @@ namespace storm { |
|
|
if (mDft.hasFailed(state) || mDft.isFailsafe(state)) { |
|
|
if (mDft.hasFailed(state) || mDft.isFailsafe(state)) { |
|
|
transitionMatrixBuilder.addNextValue(state->getId(), state->getId(), storm::utility::one<ValueType>()); |
|
|
transitionMatrixBuilder.addNextValue(state->getId(), state->getId(), storm::utility::one<ValueType>()); |
|
|
STORM_LOG_TRACE("Added self loop for " << state->getId()); |
|
|
STORM_LOG_TRACE("Added self loop for " << state->getId()); |
|
|
|
|
|
exitRates.push_back(storm::utility::one<ValueType>()); |
|
|
|
|
|
assert(exitRates.size()-1 == state->getId()); |
|
|
// No further exploration required
|
|
|
// No further exploration required
|
|
|
continue; |
|
|
continue; |
|
|
} else { |
|
|
} else { |
|
@ -169,20 +175,23 @@ namespace storm { |
|
|
} // end while failing BE
|
|
|
} // end while failing BE
|
|
|
|
|
|
|
|
|
// Add all transitions
|
|
|
// Add all transitions
|
|
|
|
|
|
ValueType exitRate = storm::utility::zero<ValueType>(); |
|
|
for (auto it = outgoingTransitions.begin(); it != outgoingTransitions.end(); ++it) |
|
|
for (auto it = outgoingTransitions.begin(); it != outgoingTransitions.end(); ++it) |
|
|
{ |
|
|
{ |
|
|
transitionMatrixBuilder.addNextValue(state->getId(), it->first, it->second); |
|
|
transitionMatrixBuilder.addNextValue(state->getId(), it->first, it->second); |
|
|
|
|
|
exitRate += it->second; |
|
|
} |
|
|
} |
|
|
|
|
|
exitRates.push_back(exitRate); |
|
|
|
|
|
assert(exitRates.size()-1 == state->getId()); |
|
|
|
|
|
|
|
|
} // end while queue
|
|
|
} // end while queue
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Explicitly instantiate the class.
|
|
|
// Explicitly instantiate the class.
|
|
|
template class ExplicitDFTModelBuilder<double, storm::models::sparse::StandardRewardModel<double>, uint32_t>; |
|
|
|
|
|
|
|
|
template class ExplicitDFTModelBuilder<double>; |
|
|
|
|
|
|
|
|
#ifdef STORM_HAVE_CARL
|
|
|
#ifdef STORM_HAVE_CARL
|
|
|
template class ExplicitDFTModelBuilder<double, storm::models::sparse::StandardRewardModel<storm::Interval>, uint32_t>; |
|
|
|
|
|
template class ExplicitDFTModelBuilder<RationalFunction, storm::models::sparse::StandardRewardModel<RationalFunction>, uint32_t>; |
|
|
|
|
|
|
|
|
template class ExplicitDFTModelBuilder<storm::RationalFunction>; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
} // namespace builder
|
|
|
} // namespace builder
|
|
|