1#ifndef STORM_UTIL_SHORTESTPATHS_H_
2#define STORM_UTIL_SHORTESTPATHS_H_
4#include <boost/optional/optional.hpp>
5#include <unordered_set>
13template<
typename ValueType>
23template<
typename ValueType>
24class StandardRewardModel;
26template<
class CValueType,
class CRewardModelType>
59std::ostream&
operator<<(std::ostream& out, Path<T>
const& p);
119 Matrix const& transitionMatrix;
127 std::vector<OrderedStateList> graphPredecessors;
128 std::vector<boost::optional<state_t>> shortestPathPredecessors;
129 std::vector<OrderedStateList> shortestPathSuccessors;
130 std::vector<T> shortestPathDistances;
132 std::vector<std::vector<Path<T>>> kShortestPaths;
133 std::vector<std::set<Path<T>>> candidatePaths;
141 void computePredecessors();
148 void performDijkstra();
155 void computeSPSuccessors();
162 void initializeShortestPaths();
167 void computeNextPath(
state_t node,
unsigned long k);
173 void computeKSP(
unsigned long k);
178 void printKShortestPath(
state_t targetNode,
unsigned long k,
bool head =
true)
const;
187 inline bool isInitialState(
state_t node)
const {
188 return std::find(initialStates.
begin(), initialStates.
end(), node) != initialStates.
end();
191 inline bool isMetaTargetPredecessor(
state_t node)
const {
192 return targetProbMap.count(node) == 1;
196 inline T convertDistance(
state_t tailNode,
state_t headNode, T distance)
const {
200 if (tailNode == headNode) {
202 return one<T>() - distance;
205 return zero<T>() - distance;
215 for (
state_t node : bitVector) {
216 stateProbMap.emplace(node, one<T>());
225 inline std::unordered_map<state_t, T> vectorToMap(std::vector<T> probVector)
const {
228 std::unordered_map<state_t, T> stateProbMap;
230 for (
state_t i = 0;
i < probVector.size();
i++) {
231 T probEntry = probVector[
i];
234 if (probEntry != 0) {
235 assert(0 < probEntry);
236 assert(probEntry <= 1);
237 stateProbMap.emplace(i, probEntry);
Base class for all sparse models.
A bit vector that is internally represented as a vector of 64-bit values.
const_iterator end() const
Returns an iterator pointing at the element past the back of the bit vector.
const_iterator begin() const
Returns an iterator to the indices of the set bits in the bit vector.
A class that holds a possibly non-square matrix in the compressed row storage format.
storage::SparseMatrix< T > Matrix
std::unordered_map< state_t, T > StateProbMap
storage::BitVector getStates(unsigned long k)
Returns the states that occur in the KSP.
T getDistance(unsigned long k)
Returns distance (i.e., probability) of the KSP.
~ShortestPathsGenerator()
OrderedStateList getPathAsList(unsigned long k)
Returns the states of the KSP as back-to-front traversal.
ShortestPathsGenerator(Matrix const &maybeTransitionMatrix, StateProbMap const &targetProbMap, BitVector const &initialStates, MatrixFormat matrixFormat)
std::vector< state_t > OrderedStateList
storage::BitVector BitVector
std::ostream & operator<<(std::ostream &out, Path< T > const &p)
storage::sparse::state_type state_t
bool operator==(const Path< T > &rhs) const
unsigned long predecessorK
bool operator<(const Path< T > &rhs) const
boost::optional< state_t > predecessorNode