12template<
typename ValueType,
typename RewardModelType>
15 bool onlyInitialStatesRelevant)
17 transitions(numberOfMemoryStates,
std::vector<
boost::optional<
storm::storage::
BitVector>>(numberOfMemoryStates)),
18 stateLabeling(numberOfMemoryStates),
19 initialMemoryStates(onlyInitialStatesRelevant ? model.getInitialStates().getNumberOfSetBits() : model.getNumberOfStates(), 0),
20 onlyInitialStatesRelevant(onlyInitialStatesRelevant) {
24template<
typename ValueType,
typename RewardModelType>
28 transitions(memoryStructure.getTransitionMatrix()),
29 stateLabeling(memoryStructure.getStateLabeling()),
30 initialMemoryStates(memoryStructure.getInitialMemoryStates()),
31 onlyInitialStatesRelevant(memoryStructure.isOnlyInitialStatesRelevantSet()) {
35template<
typename ValueType,
typename RewardModelType>
37 STORM_LOG_THROW(!onlyInitialStatesRelevant || model.getInitialStates().get(initialModelState), storm::exceptions::InvalidOperationException,
38 "Invalid index of initial model state: " << initialMemoryState <<
". This is not an initial state of the model.");
40 initialMemoryState < transitions.size(), storm::exceptions::InvalidOperationException,
41 "Invalid index of initial memory state: " << initialMemoryState <<
". There are only " << transitions.size() <<
" states in this memory structure.");
43 auto initMemStateIt = initialMemoryStates.begin();
45 if (onlyInitialStatesRelevant) {
46 for (
auto initState : model.getInitialStates()) {
47 if (initState == initialModelState) {
48 *initMemStateIt = initialMemoryState;
55 for (uint_fast64_t state = 0; state < model.getNumberOfStates(); ++state) {
56 if (state == initialModelState) {
57 *initMemStateIt = initialMemoryState;
64 assert(initMemStateIt != initialMemoryStates.end());
67template<
typename ValueType,
typename RewardModelType>
70 boost::optional<storm::storage::BitVector>
const& modelChoices) {
71 auto const& modelTransitions = model.getTransitionMatrix();
73 STORM_LOG_THROW(startState < transitions.size(), storm::exceptions::InvalidOperationException,
74 "Invalid index of start state: " << startState <<
". There are only " << transitions.size() <<
" states in this memory structure.");
75 STORM_LOG_THROW(goalState < transitions.size(), storm::exceptions::InvalidOperationException,
76 "Invalid index of goal state: " << startState <<
". There are only " << transitions.size() <<
" states in this memory structure.");
77 STORM_LOG_THROW(modelStates.
size() == modelTransitions.getRowGroupCount(), storm::exceptions::InvalidOperationException,
78 "The modelStates have invalid size.");
79 STORM_LOG_THROW(!modelChoices || modelChoices->size() == modelTransitions.getRowGroupCount(), storm::exceptions::InvalidOperationException,
80 "The modelChoices have invalid size.");
86 for (
auto choice : modelChoices.get()) {
87 for (
auto entryIt = modelTransitions.getRow(choice).begin(); entryIt < modelTransitions.getRow(choice).end(); ++entryIt) {
88 if (modelStates.
get(entryIt->getColumn())) {
89 transitionVector.
set(entryIt - modelTransitions.begin());
94 for (uint_fast64_t choice = 0; choice < modelTransitions.getRowCount(); ++choice) {
95 for (
auto entryIt = modelTransitions.getRow(choice).begin(); entryIt < modelTransitions.getRow(choice).end(); ++entryIt) {
96 if (modelStates.
get(entryIt->getColumn())) {
97 transitionVector.
set(entryIt - modelTransitions.begin());
104 if (transitionVector.
empty()) {
105 transitions[startState][goalState] = boost::none;
107 transitions[startState][goalState] = std::move(transitionVector);
111template<
typename ValueType,
typename RewardModelType>
113 STORM_LOG_THROW(state < transitions.size(), storm::exceptions::InvalidOperationException,
114 "Can not add label to state with index " << state <<
". There are only " << transitions.size() <<
" states in this memory structure.");
115 if (!stateLabeling.containsLabel(label)) {
116 stateLabeling.addLabel(label);
118 stateLabeling.addLabelToState(label, state);
121template<
typename ValueType,
typename RewardModelType>
123 return MemoryStructure(std::move(transitions), std::move(stateLabeling), std::move(initialMemoryStates), onlyInitialStatesRelevant);
126template<
typename ValueType,
typename RewardModelType>
131 return memoryBuilder.
build();
Base class for all sparse models.
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
A bit vector that is internally represented as a vector of 64-bit values.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
void setInitialMemoryState(uint_fast64_t initialModelState, uint_fast64_t initialMemoryState)
Specifies for the given state of the model the corresponding initial memory state.
MemoryStructureBuilder(uint_fast64_t numberOfMemoryStates, storm::models::sparse::Model< ValueType, RewardModelType > const &model, bool onlyInitialStatesRelevant=true)
Initializes a new builder with the data from the provided memory structure.
MemoryStructure build()
Builds the memory structure.
static MemoryStructure buildTrivialMemoryStructure(storm::models::sparse::Model< ValueType, RewardModelType > const &model)
Builds a trivial memory structure for the given model (consisting of a single memory state)
void setTransition(uint_fast64_t const &startState, uint_fast64_t const &goalState, storm::storage::BitVector const &modelStates, boost::optional< storm::storage::BitVector > const &modelChoices=boost::none)
Specifies a transition of the memory structure.
void setLabel(uint_fast64_t const &state, std::string const &label)
Sets a label to the given memory state.
This class represents a (deterministic) memory structure that can be used to encode certain events (s...
#define STORM_LOG_THROW(cond, exception, message)