diff --git a/src/utility/shortestPaths.cpp b/src/utility/shortestPaths.cpp index ffd3730f1..f70799d15 100644 --- a/src/utility/shortestPaths.cpp +++ b/src/utility/shortestPaths.cpp @@ -27,7 +27,9 @@ namespace storm { candidatePaths.resize(numStates); } - // TODO: probTargetVector [!] to probTargetMap ctor + template + ShortestPathsGenerator::ShortestPathsGenerator(storage::SparseMatrix transitionMatrix, std::vector targetProbVector, BitVector initialStates) + : ShortestPathsGenerator(transitionMatrix, vectorToMap(targetProbVector), initialStates) {} // extracts the relevant info from the model and delegates to ctor above template diff --git a/src/utility/shortestPaths.h b/src/utility/shortestPaths.h index 400485997..b78a0758a 100644 --- a/src/utility/shortestPaths.h +++ b/src/utility/shortestPaths.h @@ -65,11 +65,11 @@ namespace storm { ShortestPathsGenerator(std::shared_ptr> model, std::string const& targetLabel = "target"); // a further alternative: use transition matrix of maybe-states - // combined with target vector (e.g., the instantiated matrix/ - // vector from SamplingModel); + // combined with target vector (e.g., the instantiated matrix/vector from SamplingModel); // in this case separately specifying a target makes no sense - //ShortestPathsGenerator(storm::storage::SparseMatrix maybeTransitionMatrix, std::vector targetProbVector); - ShortestPathsGenerator(storm::storage::SparseMatrix maybeTransitionMatrix, std::unordered_map targetProbMap, BitVector initialStates); + ShortestPathsGenerator(storage::SparseMatrix transitionMatrix, std::vector targetProbVector, BitVector initialStates); + ShortestPathsGenerator(storage::SparseMatrix maybeTransitionMatrix, std::unordered_map targetProbMap, BitVector initialStates); + inline ~ShortestPathsGenerator(){} @@ -174,13 +174,30 @@ namespace storm { /** * Returns a map where each state of the input BitVector is mapped to 1 (`one`). */ - inline std::unordered_map allProbOneMap(BitVector bitVector) const& { + inline std::unordered_map allProbOneMap(BitVector bitVector) const { std::unordered_map stateProbMap; for (state_t node : bitVector) { - stateProbMap.emplace(node, one()); + stateProbMap.emplace(node, one()); // FIXME check rvalue warning (here and below) } return stateProbMap; } + + inline std::unordered_map vectorToMap(std::vector probVector) const { + assert(probVector.size() == numStates); + + std::unordered_map stateProbMap; + + // non-zero entries (i.e. true transitions) are added to the map + for (state_t i = 0; i < probVector.size(); i++) { + T probEntry = probVector[i]; + if (probEntry != 0) { + assert(0 < probEntry <= 1); + stateProbMap.emplace(i, probEntry); + } + } + + return stateProbMap; + } // ----------------------- }; }