Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DynamicStatePriorityQueue.cpp
Go to the documentation of this file.
2
6
7namespace storm {
8namespace solver {
9namespace stateelimination {
10
11template<typename ValueType>
13 std::vector<std::pair<storm::storage::sparse::state_type, uint_fast64_t>> const& sortedStatePenaltyPairs,
15 std::vector<ValueType> const& oneStepProbabilities, PenaltyFunctionType const& penaltyFunction)
17 transitionMatrix(transitionMatrix),
18 backwardTransitions(backwardTransitions),
19 oneStepProbabilities(oneStepProbabilities),
20 priorityQueue(),
21 stateToPriorityQueueEntry(),
22 penaltyFunction(penaltyFunction) {
23 // Insert all state-penalty pairs into our priority queue.
24 for (auto const& statePenalty : sortedStatePenaltyPairs) {
25 auto it = priorityQueue.insert(priorityQueue.end(), statePenalty);
26 stateToPriorityQueueEntry.emplace(statePenalty.first, it);
27 }
28}
29
30template<typename ValueType>
32 return !priorityQueue.empty();
33}
34
35template<typename ValueType>
37 auto it = priorityQueue.begin();
38 STORM_LOG_TRACE("Popping state " << it->first << " with priority " << it->second << ".");
39 storm::storage::sparse::state_type result = it->first;
40 priorityQueue.erase(priorityQueue.begin());
41 stateToPriorityQueueEntry.erase(result);
42 return result;
43}
44
45template<typename ValueType>
47 // First, we need to find the old priority queue entry for the state.
48 auto priorityQueueEntryIt = stateToPriorityQueueEntry.find(state);
49
50 // If the priority queue does not store the priority of the given state, we must not update it.
51 if (priorityQueueEntryIt == stateToPriorityQueueEntry.end()) {
52 return;
53 }
54
55 // Compute the new priority.
56 uint_fast64_t newPriority = penaltyFunction(state, transitionMatrix, backwardTransitions, oneStepProbabilities);
57
58 if (priorityQueueEntryIt->second->second != newPriority) {
59 // Erase and re-insert the entry into priority queue (with the new priority).
60 priorityQueue.erase(priorityQueueEntryIt->second);
61 stateToPriorityQueueEntry.erase(priorityQueueEntryIt);
62
63 auto newElementIt = priorityQueue.emplace(state, newPriority);
64 stateToPriorityQueueEntry.emplace(state, newElementIt.first);
65 }
66}
67
68template<typename ValueType>
70 return priorityQueue.size();
71}
72
74
77} // namespace stateelimination
78} // namespace solver
79} // namespace storm
DynamicStatePriorityQueue(std::vector< std::pair< storm::storage::sparse::state_type, uint_fast64_t > > const &sortedStatePenaltyPairs, storm::storage::FlexibleSparseMatrix< ValueType > const &transitionMatrix, storm::storage::FlexibleSparseMatrix< ValueType > const &backwardTransitions, std::vector< ValueType > const &oneStepProbabilities, PenaltyFunctionType const &penaltyFunction)
std::function< uint_fast64_t(storm::storage::sparse::state_type const &state, storm::storage::FlexibleSparseMatrix< ValueType > const &transitionMatrix, storm::storage::FlexibleSparseMatrix< ValueType > const &backwardTransitions, std::vector< ValueType > const &oneStepProbabilities)> PenaltyFunctionType
virtual void update(storm::storage::sparse::state_type state) override
virtual storm::storage::sparse::state_type pop() override
The flexible sparse matrix is used during state elimination.
#define STORM_LOG_TRACE(message)
Definition logging.h:12