4#include <boost/optional/optional.hpp>
10#include <unordered_map>
11#include <unordered_set>
20template<
typename ValueType>
30template<
typename ValueType>
33template<
class CValueType,
class CRewardModelType>
66std::ostream&
operator<<(std::ostream& out, Path<T>
const& p);
126 Matrix const& transitionMatrix;
134 std::vector<OrderedStateList> graphPredecessors;
135 std::vector<boost::optional<state_t>> shortestPathPredecessors;
136 std::vector<OrderedStateList> shortestPathSuccessors;
137 std::vector<T> shortestPathDistances;
139 std::vector<std::vector<Path<T>>> kShortestPaths;
140 std::vector<std::set<Path<T>>> candidatePaths;
148 void computePredecessors();
155 void performDijkstra();
162 void computeSPSuccessors();
169 void initializeShortestPaths();
174 void computeNextPath(
state_t node,
unsigned long k);
180 void computeKSP(
unsigned long k);
185 void printKShortestPath(
state_t targetNode,
unsigned long k,
bool head =
true)
const;
194 inline bool isInitialState(
state_t node)
const {
195 return std::find(initialStates.
begin(), initialStates.
end(), node) != initialStates.
end();
198 inline bool isMetaTargetPredecessor(
state_t node)
const {
199 return targetProbMap.count(node) == 1;
203 inline T convertDistance(
state_t tailNode,
state_t headNode, T distance)
const {
207 if (tailNode == headNode) {
209 return one<T>() - distance;
222 for (
state_t node : bitVector) {
223 stateProbMap.emplace(node,
one<T>());
232 inline std::unordered_map<state_t, T> vectorToMap(std::vector<T> probVector)
const {
235 std::unordered_map<state_t, T> stateProbMap;
237 for (
state_t i = 0;
i < probVector.size();
i++) {
238 T probEntry = probVector[
i];
241 if (probEntry != 0) {
244 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
models::sparse::Model< T, models::sparse::StandardRewardModel< T > > Model
ShortestPathsGenerator(Model const &model, BitVector const &targetBV)
Performs precomputations (including meta-target insertion and Dijkstra).
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)
#define STORM_LOG_ASSERT(cond, message)
std::vector< state_t > OrderedStateList
storage::BitVector BitVector
storage::sparse::state_type state_t
std::ostream & operator<<(std::ostream &out, Path< T > const &p)
bool operator==(const Path< T > &rhs) const
unsigned long predecessorK
bool operator<(const Path< T > &rhs) const
boost::optional< state_t > predecessorNode