Browse Source

rm model as member; extracting all needed stuff in ctor

# Conflicts:
#	src/utility/shortestPaths.cpp
tempestpy_adaptions
tomjanson 9 years ago
committed by Tom Janson
parent
commit
e883c60519
  1. 15
      src/utility/shortestPaths.cpp
  2. 14
      src/utility/shortestPaths.h

15
src/utility/shortestPaths.cpp

@ -8,12 +8,11 @@ namespace storm {
namespace ksp {
template <typename T>
ShortestPathsGenerator<T>::ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> 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<state_t>(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::pair<T, state_t>, std::greater<std::pair<T, state_t>>> 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<state_t> bfsQueue;
for (state_t initialState : model->getInitialStates()) {
for (state_t initialState : initialStates) {
bfsQueue.push(initialState);
}

14
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<models::sparse::Model<T>> model, state_t singleTarget);
ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> model, storage::BitVector const& targetBV);
ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> model, std::string const& targetLabel);
ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> 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<T> maybeTransitionMatrix, std::vector<T> targetProbVector);
inline ~ShortestPathsGenerator(){}
@ -91,13 +97,12 @@ namespace storm {
private:
std::shared_ptr<models::sparse::Model<T>> model;
storage::SparseMatrix<T> transitionMatrix;
state_t numStates; // includes meta-target, i.e. states in model + 1
state_list_t targets;
std::unordered_set<state_t> targetSet;
state_t metaTarget;
storage::BitVector initialStates;
state_list_t targets;
std::vector<state_list_t> graphPredecessors;
std::vector<boost::optional<state_t>> 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();
}

Loading…
Cancel
Save