Browse Source
shortest paths generator skeleton
shortest paths generator skeleton
Former-commit-id:tempestpy_adaptionsc37fdbbec8
[formerly23dba537c7
] Former-commit-id:6eb54e64ad
tomjanson
9 years ago
committed by
Tom Janson
3 changed files with 189 additions and 14 deletions
@ -1,5 +1,64 @@ |
|||
//
|
|||
// Created by Tom Janson on 15-1025.
|
|||
//
|
|||
|
|||
#include "shortestPaths.h"
|
|||
#include "graph.h"
|
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
namespace shortestPaths { |
|||
template <typename T> |
|||
ShortestPathsGenerator<T>::ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> model) : model(model) { |
|||
// FIXME: does this create a copy? I don't need one, so I should avoid that
|
|||
transitionMatrix = model->getTransitionMatrix(); |
|||
|
|||
// TODO: init various things we'll need later
|
|||
// - predecessors
|
|||
computePredecessors(); |
|||
// - Dijkstra (giving us SP-predecessors, SP-distances)
|
|||
performDijkstra(); |
|||
// - SP-successors
|
|||
computeSPSuccessors(); |
|||
// - shortest paths
|
|||
initializeShortestPaths(); |
|||
} |
|||
|
|||
template <typename T> |
|||
ShortestPathsGenerator<T>::~ShortestPathsGenerator() { |
|||
} |
|||
|
|||
template <typename T> |
|||
void ShortestPathsGenerator<T>::computePredecessors() { |
|||
graphPredecessors.resize(model->getNumberOfStates()); |
|||
|
|||
for (int i = 0; i < transitionMatrix.getRowCount(); i++) { |
|||
// what's the difference? TODO
|
|||
//auto foo = transitionMatrix.getRowGroupEntryCount(i);
|
|||
//auto bar = transitionMatrix.getRowGroupSize(i);
|
|||
|
|||
for (auto transition : transitionMatrix.getRowGroup(i)) { |
|||
graphPredecessors[transition.getColumn()].push_back(i); |
|||
} |
|||
} |
|||
} |
|||
|
|||
template <typename T> |
|||
void ShortestPathsGenerator<T>::performDijkstra() { |
|||
auto result = storm::utility::graph::performDijkstra(*model, transitionMatrix, model->getInitialStates()); |
|||
shortestPathDistances = result.first; |
|||
shortestPathPredecessors = result.second; |
|||
// FIXME: fix bad predecessor result for initial states (either here, or by fixing the Dijkstra)
|
|||
} |
|||
|
|||
template <typename T> |
|||
void ShortestPathsGenerator<T>::computeSPSuccessors() { |
|||
shortestPathSuccessors.resize(model->getNumberOfStates()); |
|||
|
|||
for (int i = 0; i < model->getNumberOfStates(); i++) { |
|||
state_t predecessor = shortestPathPredecessors[i]; |
|||
shortestPathSuccessors[predecessor].push_back(i); |
|||
} |
|||
} |
|||
|
|||
template <typename T> |
|||
void ShortestPathsGenerator<T>::initializeShortestPaths() {} |
|||
} |
|||
} |
|||
} |
@ -1,15 +1,62 @@ |
|||
// |
|||
// Created by Tom Janson on 15-1025. |
|||
// |
|||
|
|||
#ifndef STORM_UTIL_SHORTESTPATHS_H_ |
|||
#define STORM_UTIL_SHORTESTPATHS_H_ |
|||
|
|||
#include <vector> |
|||
#include <boost/optional/optional.hpp> |
|||
#include "src/models/sparse/Model.h" |
|||
#include "src/storage/sparse/StateType.h" |
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
namespace shortestPaths { |
|||
typedef storm::storage::sparse::state_type state_t; |
|||
typedef std::vector<state_t> state_list_t; |
|||
|
|||
template <typename T> |
|||
struct path { |
|||
boost::optional<state_t> tail; |
|||
unsigned int tail_k; |
|||
T distance; |
|||
}; |
|||
|
|||
template <typename T> |
|||
class ShortestPathsGenerator { |
|||
public: |
|||
// FIXME: this shared_ptr-passing business is probably a bad idea |
|||
ShortestPathsGenerator(std::shared_ptr<models::sparse::Model<T>> model); |
|||
~ShortestPathsGenerator(); |
|||
|
|||
private: |
|||
//storm::models::sparse::Model<T>* model; |
|||
std::shared_ptr<storm::models::sparse::Model<T>> model; |
|||
storm::storage::SparseMatrix<T> transitionMatrix; |
|||
|
|||
std::vector<state_list_t> graphPredecessors; |
|||
std::vector<state_t> shortestPathPredecessors; |
|||
std::vector<state_list_t> shortestPathSuccessors; |
|||
std::vector<T> shortestPathDistances; |
|||
|
|||
std::vector<std::vector<path<T>>> shortestPaths; |
|||
std::vector<std::set<path<T>>> shortestPathCandidates; |
|||
|
|||
/*! |
|||
* Computes list of predecessors for all nodes. |
|||
* Reachability is not considered; a predecessor is simply any node that has an edge leading to the |
|||
* node in question. |
|||
* |
|||
* @param model The model whose transitions will be examined |
|||
* @return A vector of predecessors for each node |
|||
*/ |
|||
void computePredecessors(); |
|||
|
|||
class shortestPathsUtil { |
|||
void performDijkstra(); |
|||
void computeSPSuccessors(); |
|||
void initializeShortestPaths(); |
|||
|
|||
}; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif //STORM_UTIL_SHORTESTPATHS_H_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue