diff --git a/src/utility/shortestPaths.cpp b/src/utility/shortestPaths.cpp index ac868070d..409030c32 100644 --- a/src/utility/shortestPaths.cpp +++ b/src/utility/shortestPaths.cpp @@ -8,12 +8,11 @@ namespace storm { namespace ksp { template ShortestPathsGenerator::ShortestPathsGenerator(std::shared_ptr> model, - state_list_t const& targets) : model(model), targets(targets) { - // FIXME: does this create a copy? I don't need one, so I should avoid that - transitionMatrix = model->getTransitionMatrix(); - numStates = model->getNumberOfStates() + 1; // one more for meta-target - - metaTarget = numStates - 1; // first unused state number + state_list_t const& targets) : transitionMatrix(model->getTransitionMatrix()), + numStates(model->getNumberOfStates() + 1), // one more for meta-target + metaTarget(model->getNumberOfStates()), // first unused state number + initialStates(model->getInitialStates()), + targets(targets) { targetSet = std::unordered_set(targets.begin(), targets.end()); computePredecessors(); @@ -126,7 +125,7 @@ namespace storm { // default comparison on pair actually works fine if distance is the first entry std::set, std::greater>> dijkstraQueue; - for (state_t initialState : model->getInitialStates()) { + for (state_t initialState : initialStates) { shortestPathDistances[initialState] = zeroDistance; dijkstraQueue.emplace(zeroDistance, initialState); } @@ -179,7 +178,7 @@ namespace storm { // BFS in Dijkstra-SP order std::queue bfsQueue; - for (state_t initialState : model->getInitialStates()) { + for (state_t initialState : initialStates) { bfsQueue.push(initialState); } diff --git a/src/utility/shortestPaths.h b/src/utility/shortestPaths.h index 8139f1c91..64fa16ca6 100644 --- a/src/utility/shortestPaths.h +++ b/src/utility/shortestPaths.h @@ -63,7 +63,13 @@ namespace storm { // all of which will be converted to list and delegated to constructor above ShortestPathsGenerator(std::shared_ptr> model, state_t singleTarget); ShortestPathsGenerator(std::shared_ptr> model, storage::BitVector const& targetBV); - ShortestPathsGenerator(std::shared_ptr> model, std::string const& targetLabel); + 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); + // in this case separately specifying a target makes no sense + //ShortestPathsGenerator(storm::storage::SparseMatrix maybeTransitionMatrix, std::vector targetProbVector); inline ~ShortestPathsGenerator(){} @@ -91,13 +97,12 @@ namespace storm { private: - std::shared_ptr> model; storage::SparseMatrix transitionMatrix; state_t numStates; // includes meta-target, i.e. states in model + 1 - - state_list_t targets; std::unordered_set targetSet; state_t metaTarget; + storage::BitVector initialStates; + state_list_t targets; std::vector graphPredecessors; std::vector> shortestPathPredecessors; @@ -160,7 +165,6 @@ namespace storm { // --- tiny helper fcts --- inline bool isInitialState(state_t node) const { - auto initialStates = model->getInitialStates(); return find(initialStates.begin(), initialStates.end(), node) != initialStates.end(); }