Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DynamicStatePriorityQueue.cpp
Go to the documentation of this file.
2
4
7
8namespace storm {
9namespace solver {
10namespace stateelimination {
11
12template<typename ValueType>
14 std::vector<std::pair<storm::storage::sparse::state_type, uint_fast64_t>> const& sortedStatePenaltyPairs,
16 std::vector<ValueType> const& oneStepProbabilities, PenaltyFunctionType const& penaltyFunction)
18 transitionMatrix(transitionMatrix),
19 backwardTransitions(backwardTransitions),
20 oneStepProbabilities(oneStepProbabilities),
21 priorityQueue(),
22 stateToPriorityQueueEntry(),
23 penaltyFunction(penaltyFunction) {
24 // Insert all state-penalty pairs into our priority queue.
25 for (auto const& statePenalty : sortedStatePenaltyPairs) {
26 auto it = priorityQueue.insert(priorityQueue.end(), statePenalty);
27 stateToPriorityQueueEntry.emplace(statePenalty.first, it);
28 }
29}
30
31template<typename ValueType>
33 return !priorityQueue.empty();
34}
35
36template<typename ValueType>
38 auto it = priorityQueue.begin();
39 STORM_LOG_TRACE("Popping state " << it->first << " with priority " << it->second << ".");
40 storm::storage::sparse::state_type result = it->first;
41 priorityQueue.erase(priorityQueue.begin());
42 stateToPriorityQueueEntry.erase(result);
43 return result;
44}
45
46template<typename ValueType>
48 // First, we need to find the old priority queue entry for the state.
49 auto priorityQueueEntryIt = stateToPriorityQueueEntry.find(state);
50
51 // If the priority queue does not store the priority of the given state, we must not update it.
52 if (priorityQueueEntryIt == stateToPriorityQueueEntry.end()) {
53 return;
54 }
55
56 // Compute the new priority.
57 uint_fast64_t newPriority = penaltyFunction(state, transitionMatrix, backwardTransitions, oneStepProbabilities);
58
59 if (priorityQueueEntryIt->second->second != newPriority) {
60 // Erase and re-insert the entry into priority queue (with the new priority).
61 priorityQueue.erase(priorityQueueEntryIt->second);
62 stateToPriorityQueueEntry.erase(priorityQueueEntryIt);
63
64 auto newElementIt = priorityQueue.emplace(state, newPriority);
65 stateToPriorityQueueEntry.emplace(state, newElementIt.first);
66 }
67}
68
69template<typename ValueType>
71 return priorityQueue.size();
72}
73
75
76#ifdef STORM_HAVE_CARL
79#endif
80} // namespace stateelimination
81} // namespace solver
82} // 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:17
LabParser.cpp.
Definition cli.cpp:18