Browse Source

mergeFailedStates and some updates for SEQs

Former-commit-id: 128a7e0da5
tempestpy_adaptions
sjunges 9 years ago
parent
commit
dde9af6c44
  1. 61
      src/builder/ExplicitDFTModelBuilder.cpp
  2. 5
      src/builder/ExplicitDFTModelBuilder.h
  3. 1
      src/storage/dft/DFTBuilder.cpp
  4. 4
      src/storage/dft/DFTElements.cpp
  5. 12
      src/storage/dft/elements/DFTRestriction.h
  6. 2
      src/storm-dyftee.cpp

61
src/builder/ExplicitDFTModelBuilder.cpp

@ -57,36 +57,47 @@ namespace storm {
template <typename ValueType>
std::shared_ptr<storm::models::sparse::Model<ValueType>> ExplicitDFTModelBuilder<ValueType>::buildModel(LabelOptions const& labelOpts) {
// Initialize
DFTStatePointer state = std::make_shared<storm::storage::DFTState<ValueType>>(mDft, *mStateGenerationInfo, newIndex++);
mStates.findOrAdd(state->status(), state->getId());
std::queue<DFTStatePointer> stateQueue;
stateQueue.push(state);
bool deterministicModel = false;
ModelComponents modelComponents;
std::vector<uint_fast64_t> tmpMarkovianStates;
storm::storage::SparseMatrixBuilder<ValueType> transitionMatrixBuilder(0, 0, 0, false, !deterministicModel, 0);
if(mergeFailedStates) {
newIndex++;
transitionMatrixBuilder.newRowGroup(failedIndex);
transitionMatrixBuilder.addNextValue(failedIndex, failedIndex, storm::utility::one<ValueType>());
STORM_LOG_TRACE("Added self loop for " << failedIndex);
modelComponents.exitRates.push_back(storm::utility::one<ValueType>());
tmpMarkovianStates.push_back(failedIndex);
}
DFTStatePointer state = std::make_shared<storm::storage::DFTState<ValueType>>(mDft, *mStateGenerationInfo, newIndex++);
mStates.findOrAdd(state->status(), state->getId());
initialStateIndex = state->getId();
std::queue<DFTStatePointer> stateQueue;
stateQueue.push(state);
// Begin model generation
bool deterministic = exploreStates(stateQueue, transitionMatrixBuilder, tmpMarkovianStates, modelComponents.exitRates);
STORM_LOG_DEBUG("Generated " << mStates.size() << " states");
STORM_LOG_DEBUG("Generated " << mStates.size() + (mergeFailedStates ? 1 : 0) << " states");
STORM_LOG_DEBUG("Model is " << (deterministic ? "deterministic" : "non-deterministic"));
size_t stateSize = mStates.size() + (mergeFailedStates ? 1 : 0);
// Build Markov Automaton
modelComponents.markovianStates = storm::storage::BitVector(mStates.size(), tmpMarkovianStates);
modelComponents.markovianStates = storm::storage::BitVector(stateSize, tmpMarkovianStates);
// Build transition matrix
modelComponents.transitionMatrix = transitionMatrixBuilder.build();
modelComponents.transitionMatrix = transitionMatrixBuilder.build(stateSize, stateSize);
STORM_LOG_DEBUG("Transition matrix: " << std::endl << modelComponents.transitionMatrix);
STORM_LOG_DEBUG("Exit rates: " << modelComponents.exitRates);
STORM_LOG_DEBUG("Markovian states: " << modelComponents.markovianStates);
assert(!deterministic || modelComponents.transitionMatrix.getRowCount() == modelComponents.transitionMatrix.getColumnCount());
// Build state labeling
modelComponents.stateLabeling = storm::models::sparse::StateLabeling(mStates.size());
modelComponents.stateLabeling = storm::models::sparse::StateLabeling(mStates.size() + (mergeFailedStates ? 1 : 0));
// Initial state is always first state without any failure
modelComponents.stateLabeling.addLabel("init");
modelComponents.stateLabeling.addLabelToState("init", 0);
modelComponents.stateLabeling.addLabelToState("init", initialStateIndex);
// Label all states corresponding to their status (failed, failsafe, failed BE)
if(labelOpts.buildFailLabel) {
modelComponents.stateLabeling.addLabel("failed");
@ -103,10 +114,13 @@ namespace storm {
}
}
if(mergeFailedStates) {
modelComponents.stateLabeling.addLabelToState("failed", failedIndex);
}
for (auto const& stateIdPair : mStates) {
storm::storage::BitVector state = stateIdPair.first;
size_t stateId = stateIdPair.second;
if (labelOpts.buildFailLabel && mDft.hasFailed(state, *mStateGenerationInfo)) {
if (!mergeFailedStates && labelOpts.buildFailLabel && mDft.hasFailed(state, *mStateGenerationInfo)) {
modelComponents.stateLabeling.addLabelToState("failed", stateId);
}
if (labelOpts.buildFailSafeLabel && mDft.isFailsafe(state, *mStateGenerationInfo)) {
@ -151,13 +165,12 @@ namespace storm {
template <typename ValueType>
bool 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 directly as bitvector?
std::map<size_t, ValueType> outgoingTransitions;
size_t rowOffset = 0; // Captures number of non-deterministic choices
bool deterministic = true;
while (!stateQueue.empty()) {
// Initialization
outgoingTransitions.clear();
@ -189,6 +202,7 @@ namespace storm {
// Let BE fail
while (smallest < failableCount) {
assert(!mDft.hasFailed(state));
STORM_LOG_TRACE("exploring from: " << mDft.getStateString(state));
// Construct new state as copy from original one
@ -207,12 +221,24 @@ namespace storm {
queues.propagateFailure(parent);
}
}
for (DFTRestrictionPointer restr : nextBE->restrictions()) {
queues.checkRestrictionLater(restr);
}
while (!queues.failurePropagationDone()) {
DFTGatePointer next = queues.nextFailurePropagation();
next->checkFails(*newState, queues);
}
while(!queues.restrictionChecksDone()) {
DFTRestrictionPointer next = queues.nextRestrictionCheck();
next->checkFails(*newState, queues);
}
if(newState->isInvalid()) {
continue;
}
while (!queues.failsafePropagationDone()) {
DFTGatePointer next = queues.nextFailsafePropagation();
next->checkFailsafe(*newState, queues);
@ -226,7 +252,11 @@ namespace storm {
// Update failable dependencies
newState->updateFailableDependencies(nextBE->id());
bool dftFailed = newState->hasFailed(mDft.getTopLevelIndex());
size_t newStateId;
if(dftFailed && mergeFailedStates) {
newStateId = failedIndex;
} else {
if (mStates.contains(newState->status())) {
// State already exists
newStateId = mStates.getValue(newState->status());
@ -240,6 +270,7 @@ namespace storm {
// Add state to search queue
stateQueue.push(newState);
}
}
// Set transitions
if (hasDependencies) {

5
src/builder/ExplicitDFTModelBuilder.h

@ -23,6 +23,8 @@ namespace storm {
using DFTElementCPointer = std::shared_ptr<storm::storage::DFTElement<ValueType> const>;
using DFTGatePointer = std::shared_ptr<storm::storage::DFTGate<ValueType>>;
using DFTStatePointer = std::shared_ptr<storm::storage::DFTState<ValueType>>;
using DFTRestrictionPointer = std::shared_ptr<storm::storage::DFTRestriction<ValueType>>;
// A structure holding the individual components of a model.
struct ModelComponents {
@ -52,6 +54,9 @@ namespace storm {
std::shared_ptr<storm::storage::DFTStateGenerationInfo> mStateGenerationInfo;
storm::storage::BitVectorHashMap<size_t> mStates;
size_t newIndex = 0;
bool mergeFailedStates = true;
size_t failedIndex = 0;
size_t initialStateIndex = 0;
public:
struct LabelOptions {

1
src/storage/dft/DFTBuilder.cpp

@ -130,6 +130,7 @@ namespace storm {
mElements[name] = restr;
mRestrictionChildNames[restr] = children;
mRestrictions.push_back(restr);
return true;
}
template<typename ValueType>

4
src/storage/dft/DFTElements.cpp

@ -10,6 +10,7 @@ namespace storm {
if (state.dontCare(mId)) {
return false;
}
// Check that no outgoing dependencies can be triggered anymore
for (DFTDependencyPointer dependency : mOutgoingDependencies) {
if (state.isOperational(dependency->dependentEvent()->id()) && state.isOperational(dependency->triggerEvent()->id())) {
@ -23,6 +24,9 @@ namespace storm {
}
}
state.setDontCare(mId);
return true;
}

12
src/storage/dft/elements/DFTRestriction.h

@ -116,10 +116,6 @@ namespace storm {
}
virtual bool checkDontCareAnymore(storm::storage::DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) const override {
if(DFTElement<ValueType>::checkDontCareAnymore(state, queues)) {
childrenDontCare(state, queues);
return true;
}
return false;
}
@ -134,10 +130,6 @@ namespace storm {
}
void childrenDontCare(DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) const {
queues.propagateDontCare(mChildren);
}
bool hasFailsafeChild(DFTState<ValueType>& state) const {
for(auto const& child : mChildren) {
if(state.isFailsafe(child->id()))
@ -189,6 +181,10 @@ namespace storm {
void checkFailsafe(storm::storage::DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) const override {
}
bool checkDontCareAnymore(storm::storage::DFTState<ValueType>& state, DFTStateSpaceGenerationQueues<ValueType>& queues) {
}
virtual DFTElementType type() const override {

2
src/storm-dyftee.cpp

@ -48,7 +48,7 @@ void analyzeDFT(std::string filename, std::string property, bool symred = false)
std::cout << "Bisimulation..." << std::endl;
if (model->isOfType(storm::models::ModelType::Ctmc)) {
if (model->getNumberOfStates() > 500 && model->isOfType(storm::models::ModelType::Ctmc)) {
model = storm::performDeterministicSparseBisimulationMinimization<storm::models::sparse::Ctmc<ValueType>>(model->template as<storm::models::sparse::Ctmc<ValueType>>(), formulas, storm::storage::BisimulationType::Weak)->template as<storm::models::sparse::Ctmc<ValueType>>();
}

Loading…
Cancel
Save