#include "src/solver/stateelimination/DynamicStatePriorityQueue.h" #include "src/adapters/CarlAdapter.h" #include "src/utility/macros.h" #include "src/utility/constants.h" namespace storm { namespace solver { namespace stateelimination { template DynamicStatePriorityQueue::DynamicStatePriorityQueue(std::vector> const& sortedStatePenaltyPairs, storm::storage::FlexibleSparseMatrix const& transitionMatrix, storm::storage::FlexibleSparseMatrix const& backwardTransitions, std::vector const& oneStepProbabilities, PenaltyFunctionType const& penaltyFunction) : StatePriorityQueue(), transitionMatrix(transitionMatrix), backwardTransitions(backwardTransitions), oneStepProbabilities(oneStepProbabilities), priorityQueue(), stateToPriorityQueueEntry(), penaltyFunction(penaltyFunction) { // Insert all state-penalty pairs into our priority queue. for (auto const& statePenalty : sortedStatePenaltyPairs) { auto it = priorityQueue.insert(priorityQueue.end(), statePenalty); stateToPriorityQueueEntry.emplace(statePenalty.first, it); } } template bool DynamicStatePriorityQueue::hasNext() const { return !priorityQueue.empty(); } template storm::storage::sparse::state_type DynamicStatePriorityQueue::pop() { auto it = priorityQueue.begin(); STORM_LOG_TRACE("Popping state " << it->first << " with priority " << it->second << "."); storm::storage::sparse::state_type result = it->first; priorityQueue.erase(priorityQueue.begin()); stateToPriorityQueueEntry.erase(result); return result; } template void DynamicStatePriorityQueue::update(storm::storage::sparse::state_type state) { // First, we need to find the old priority queue entry for the state. auto priorityQueueEntryIt = stateToPriorityQueueEntry.find(state); // If the priority queue does not store the priority of the given state, we must not update it. if (priorityQueueEntryIt == stateToPriorityQueueEntry.end()) { return; } // Compute the new priority. uint_fast64_t newPriority = penaltyFunction(state, transitionMatrix, backwardTransitions, oneStepProbabilities); if (priorityQueueEntryIt->second->second != newPriority) { // Erase and re-insert the entry into priority queue (with the new priority). priorityQueue.erase(priorityQueueEntryIt->second); stateToPriorityQueueEntry.erase(priorityQueueEntryIt); auto newElementIt = priorityQueue.emplace(state, newPriority); stateToPriorityQueueEntry.emplace(state, newElementIt.first); } } template std::size_t DynamicStatePriorityQueue::size() const { return priorityQueue.size(); } template class DynamicStatePriorityQueue; #ifdef STORM_HAVE_CARL template class DynamicStatePriorityQueue; template class DynamicStatePriorityQueue; #endif } } }