24namespace shortest_path {
46 typename F = std::function<void(
const TNode &,
47 const typename TGraph::edge_type::weight_type &)> >
52 F f_user = [](
const TNode &,
53 const typename TGraph::edge_type::weight_type &) ->
void {});
73 template<
typename TGraph,
typename TNode,
typename F = std::function<void(
const TNode &,
74 const typename TGraph::edge_type::weight_type &)>>
80 F f_user = [](
const TNode &,
81 const typename TGraph::edge_type::weight_type &) {});
83 template<
typename TGraph,
typename TNode>
95 template<
typename TNode,
typename TWeight>
105 template<
typename TGraph,
typename TNode,
typename F>
107 Data<TNode, typename TGraph::edge_type::weight_type>
108 impl(
const TGraph &
graph,
114 template<
typename TNode,
typename TWeight>
115 inline static void init(SPFA::Data<TNode, TWeight> &data,
const TNode &
start);
123template<
typename TGraph,
typename TNode,
typename F>
130template<
typename TGraph,
typename TNode,
typename F>
135 using weight_type =
typename TGraph::edge_type::weight_type;
137 Data<TNode, weight_type> data = impl(
graph,
start, f_user);
143template<
typename TGraph,
typename TNode,
typename F>
144SPFA::Data<TNode, typename TGraph::edge_type::weight_type>
145SPFA::impl(
const TGraph &
graph,
const TNode &
start, F f_user) {
146 using weight_type =
typename TGraph::edge_type::weight_type;
148 Data<TNode, weight_type> data;
150 auto nodes =
graph.getNodes();
151 size_t nodes_cnt = nodes.size();
156 while (!data.q.empty()) {
157 TNode n = data.q.front();
163 f_user(n, data.g[n]);
165 if (data.v[n] >= nodes_cnt) {
166 throw std::out_of_range(
"SPFA: Detect negative cycle in graph.");
169 for (
const auto &s_edge:
graph.successorEdges(n)) {
173 weight_type gscore = data.g.at(n) + s_edge.weight();
176 auto search_d = data.g.find(s);
179 if (search_d == data.g.end() || search_d->second > gscore) {
182 data.p.insert_or_assign(s, n);
200template<
typename TNode,
typename TWeight>
201void SPFA::init(SPFA::Data<TNode, TWeight> &data,
const TNode &
start) {
202 data.q.push_back(
start);
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
static ext::pair< ext::vector< TNode >, TWeight > reconstructWeightedPath(const ext::map< TNode, TNode > &p, const ext::map< TNode, TWeight > &g, const TNode &start, const TNode &goal)
Definition: ReconstructPath.hpp:132
static TNode const & other(const TEdge &e, const TNode &n)
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPathRegistration(const TGraph &graph, const TNode &start, const TNode &goal)
Definition: SPFA.hpp:86
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPath(const TGraph &graph, const TNode &start, const TNode &goal, F f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) {})
Definition: SPFA.hpp:131
static void run(const TGraph &graph, const TNode &start, F f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) -> void {})
Definition: SPFA.hpp:124
q
Definition: SingleInitialStateEpsilonTransition.h:85
Definition: ReconstructPath.hpp:14
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14