Browse Source
Further steps towards implementation of MEC decomposition.
Further steps towards implementation of MEC decomposition.
Former-commit-id: 8166b3b923
tempestpy_adaptions
dehnert
11 years ago
12 changed files with 358 additions and 49 deletions
-
4src/models/AbstractModel.h
-
15src/storage/BitVector.h
-
52src/storage/Decomposition.cpp
-
12src/storage/Decomposition.h
-
52src/storage/MaximalEndComponent.cpp
-
59src/storage/MaximalEndComponent.h
-
45src/storage/MaximalEndComponentDecomposition.cpp
-
47src/storage/MaximalEndComponentDecomposition.h
-
72src/storage/StronglyConnectedComponentDecomposition.cpp
-
28src/storage/StronglyConnectedComponentDecomposition.h
-
20src/storage/VectorSet.h
-
1src/storm.cpp
@ -1,57 +1,85 @@ |
|||
#include "src/storage/Decomposition.h"
|
|||
#include "src/storage/MaximalEndComponent.h"
|
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
|
|||
Decomposition::Decomposition() : blocks() { |
|||
template <typename BlockType> |
|||
Decomposition<BlockType>::Decomposition() : blocks() { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Decomposition::Decomposition(Decomposition const& other) : blocks(other.blocks) { |
|||
template <typename BlockType> |
|||
Decomposition<BlockType>::Decomposition(Decomposition const& other) : blocks(other.blocks) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Decomposition& Decomposition::operator=(Decomposition const& other) { |
|||
template <typename BlockType> |
|||
Decomposition<BlockType>& Decomposition<BlockType>::operator=(Decomposition const& other) { |
|||
this->blocks = other.blocks; |
|||
return *this; |
|||
} |
|||
|
|||
Decomposition::Decomposition(Decomposition&& other) : blocks(std::move(other.blocks)) { |
|||
template <typename BlockType> |
|||
Decomposition<BlockType>::Decomposition(Decomposition&& other) : blocks(std::move(other.blocks)) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
Decomposition& Decomposition::operator=(Decomposition&& other) { |
|||
template <typename BlockType> |
|||
Decomposition<BlockType>& Decomposition<BlockType>::operator=(Decomposition&& other) { |
|||
this->blocks = std::move(other.blocks); |
|||
return *this; |
|||
} |
|||
|
|||
size_t Decomposition::size() const { |
|||
template <typename BlockType> |
|||
size_t Decomposition<BlockType>::size() const { |
|||
return blocks.size(); |
|||
} |
|||
|
|||
Decomposition::iterator Decomposition::begin() { |
|||
template <typename BlockType> |
|||
typename Decomposition<BlockType>::iterator Decomposition<BlockType>::begin() { |
|||
return blocks.begin(); |
|||
} |
|||
|
|||
Decomposition::iterator Decomposition::end() { |
|||
template <typename BlockType> |
|||
typename Decomposition<BlockType>::iterator Decomposition<BlockType>::end() { |
|||
return blocks.end(); |
|||
} |
|||
|
|||
Decomposition::const_iterator Decomposition::begin() const { |
|||
template <typename BlockType> |
|||
typename Decomposition<BlockType>::const_iterator Decomposition<BlockType>::begin() const { |
|||
return blocks.begin(); |
|||
} |
|||
|
|||
Decomposition::const_iterator Decomposition::end() const { |
|||
template <typename BlockType> |
|||
typename Decomposition<BlockType>::const_iterator Decomposition<BlockType>::end() const { |
|||
return blocks.end(); |
|||
} |
|||
|
|||
Decomposition::Block const& Decomposition::getBlock(uint_fast64_t index) const { |
|||
template <typename BlockType> |
|||
BlockType const& Decomposition<BlockType>::getBlock(uint_fast64_t index) const { |
|||
return blocks.at(index); |
|||
} |
|||
|
|||
Decomposition::Block const& Decomposition::operator[](uint_fast64_t index) const { |
|||
template <typename BlockType> |
|||
BlockType const& Decomposition<BlockType>::operator[](uint_fast64_t index) const { |
|||
return blocks[index]; |
|||
} |
|||
|
|||
template <typename BlockType> |
|||
std::ostream& operator<<(std::ostream& out, Decomposition<BlockType> const& decomposition) { |
|||
out << "{"; |
|||
if (decomposition.size() > 0) { |
|||
for (uint_fast64_t blockIndex = 0; blockIndex < decomposition.size() - 1; ++blockIndex) { |
|||
out << decomposition.blocks[blockIndex] << ", "; |
|||
} |
|||
out << decomposition.blocks[decomposition.size() - 1]; |
|||
} |
|||
out << "}"; |
|||
return out; |
|||
} |
|||
|
|||
template class Decomposition<StateBlock>; |
|||
template class Decomposition<MaximalEndComponent>; |
|||
} // namespace storage
|
|||
} // namespace storm
|
@ -0,0 +1,52 @@ |
|||
#include "src/storage/MaximalEndComponent.h"
|
|||
#include "src/exceptions/InvalidStateException.h"
|
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
|
|||
MaximalEndComponent::MaximalEndComponent() : stateToChoicesMapping() { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
MaximalEndComponent::MaximalEndComponent(MaximalEndComponent const& other) : stateToChoicesMapping(other.stateToChoicesMapping) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
MaximalEndComponent& MaximalEndComponent::operator=(MaximalEndComponent const& other) { |
|||
stateToChoicesMapping = other.stateToChoicesMapping; |
|||
return *this; |
|||
} |
|||
|
|||
MaximalEndComponent::MaximalEndComponent(MaximalEndComponent&& other) : stateToChoicesMapping(std::move(other.stateToChoicesMapping)) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
MaximalEndComponent& MaximalEndComponent::operator=(MaximalEndComponent&& other) { |
|||
stateToChoicesMapping = std::move(other.stateToChoicesMapping); |
|||
return *this; |
|||
} |
|||
|
|||
void MaximalEndComponent::addState(uint_fast64_t state, std::vector<uint_fast64_t> const& choices) { |
|||
stateToChoicesMapping[state] = choices; |
|||
} |
|||
|
|||
std::vector<uint_fast64_t> const& MaximalEndComponent::getChoicesForState(uint_fast64_t state) const { |
|||
auto stateChoicePair = stateToChoicesMapping.find(state); |
|||
|
|||
if (stateChoicePair == stateToChoicesMapping.end()) { |
|||
throw storm::exceptions::InvalidStateException() << "Cannot retrieve choices for state not contained in MEC."; |
|||
} |
|||
|
|||
return stateChoicePair->second; |
|||
} |
|||
|
|||
bool MaximalEndComponent::containsState(uint_fast64_t state) const { |
|||
auto stateChoicePair = stateToChoicesMapping.find(state); |
|||
|
|||
if (stateChoicePair == stateToChoicesMapping.end()) { |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
#ifndef STORM_STORAGE_MAXIMALENDCOMPONENT_H_ |
|||
#define STORM_STORAGE_MAXIMALENDCOMPONENT_H_ |
|||
|
|||
#include <unordered_map> |
|||
#include <vector> |
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
/*! |
|||
* This class represents a maximal end-component of a nondeterministic model. |
|||
*/ |
|||
class MaximalEndComponent { |
|||
public: |
|||
/*! |
|||
* Creates an empty MEC. |
|||
*/ |
|||
MaximalEndComponent(); |
|||
|
|||
MaximalEndComponent(MaximalEndComponent const& other); |
|||
|
|||
MaximalEndComponent& operator=(MaximalEndComponent const& other); |
|||
|
|||
MaximalEndComponent(MaximalEndComponent&& other); |
|||
|
|||
MaximalEndComponent& operator=(MaximalEndComponent&& other); |
|||
|
|||
/*! |
|||
* Adds the given state and the given choices to the MEC. |
|||
* |
|||
* @param state The state for which to add the choices. |
|||
* @param choices The choices to add for the state. |
|||
*/ |
|||
void addState(uint_fast64_t state, std::vector<uint_fast64_t> const& choices); |
|||
|
|||
/*! |
|||
* Retrieves the choices for the given state that are contained in this MEC under the |
|||
* assumption that the state is in the MEC. |
|||
* |
|||
* @param state The state for which to retrieve the choices. |
|||
* @return A list of choices of the state in the MEC. |
|||
*/ |
|||
std::vector<uint_fast64_t> const& getChoicesForState(uint_fast64_t state) const; |
|||
|
|||
/*! |
|||
* Retrieves whether the given state is contained in this MEC. |
|||
* |
|||
* @param state The state for which to query membership in the MEC. |
|||
* @return True if the given state is contained in the MEC. |
|||
*/ |
|||
bool containsState(uint_fast64_t state) const; |
|||
|
|||
private: |
|||
// This stores the mapping from states contained in the MEC to the choices in this MEC. |
|||
std::unordered_map<uint_fast64_t, std::vector<uint_fast64_t>> stateToChoicesMapping; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_MAXIMALENDCOMPONENT_H_ */ |
@ -0,0 +1,45 @@ |
|||
#include "src/storage/MaximalEndComponentDecomposition.h"
|
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>::MaximalEndComponentDecomposition() : Decomposition() { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>::MaximalEndComponentDecomposition(storm::models::AbstractNondeterministicModel<ValueType> const& model) { |
|||
performMaximalEndComponentDecomposition(model); |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>::MaximalEndComponentDecomposition(MaximalEndComponentDecomposition const& other) : Decomposition(other) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>& MaximalEndComponentDecomposition<ValueType>::operator=(MaximalEndComponentDecomposition const& other) { |
|||
Decomposition::operator=(other); |
|||
return *this; |
|||
} |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>::MaximalEndComponentDecomposition(MaximalEndComponentDecomposition&& other) : Decomposition(std::move(other)) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename ValueType> |
|||
MaximalEndComponentDecomposition<ValueType>& MaximalEndComponentDecomposition<ValueType>::operator=(MaximalEndComponentDecomposition&& other) { |
|||
Decomposition::operator=(std::move(other)); |
|||
return *this; |
|||
} |
|||
|
|||
template <typename ValueType> |
|||
void MaximalEndComponentDecomposition<ValueType>::performMaximalEndComponentDecomposition(storm::models::AbstractNondeterministicModel<ValueType> const& model) { |
|||
// TODO.
|
|||
} |
|||
|
|||
template class MaximalEndComponentDecomposition<double>; |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
#ifndef STORM_STORAGE_MAXIMALENDCOMPONENTDECOMPOSITION_H_ |
|||
#define STORM_STORAGE_MAXIMALENDCOMPONENTDECOMPOSITION_H_ |
|||
|
|||
#include "src/storage/Decomposition.h" |
|||
#include "src/storage/StronglyConnectedComponentDecomposition.h" |
|||
#include "src/storage/MaximalEndComponent.h" |
|||
#include "src/models/AbstractNondeterministicModel.h" |
|||
|
|||
namespace storm { |
|||
namespace storage { |
|||
|
|||
template <typename ValueType> |
|||
class MaximalEndComponentDecomposition : public Decomposition<MaximalEndComponent> { |
|||
public: |
|||
/* |
|||
* Creates an empty MEC decomposition. |
|||
*/ |
|||
MaximalEndComponentDecomposition(); |
|||
|
|||
/* |
|||
* Creates an MEC decomposition of the given model. |
|||
* |
|||
* @param model The model to decompose into MECs. |
|||
*/ |
|||
MaximalEndComponentDecomposition(storm::models::AbstractNondeterministicModel<ValueType> const& model); |
|||
|
|||
MaximalEndComponentDecomposition(MaximalEndComponentDecomposition const& other); |
|||
|
|||
MaximalEndComponentDecomposition& operator=(MaximalEndComponentDecomposition const& other); |
|||
|
|||
MaximalEndComponentDecomposition(MaximalEndComponentDecomposition&& other); |
|||
|
|||
MaximalEndComponentDecomposition& operator=(MaximalEndComponentDecomposition&& other); |
|||
|
|||
private: |
|||
/*! |
|||
* Performs the actual decomposition of the given model into MECs. Stores the MECs found in the current decomposition |
|||
* as a side-effect. |
|||
* |
|||
* @param model The model to decompose. |
|||
*/ |
|||
void performMaximalEndComponentDecomposition(storm::models::AbstractNondeterministicModel<ValueType> const& model); |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_MAXIMALENDCOMPONENTDECOMPOSITION_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue