31 # include <ahFunction.H> 33 # include <tpl_indexArc.H> 34 # include <tpl_dynMat.H> 98 typedef typename GT::Node Node;
99 typedef typename GT::Arc Arc;
100 typedef typename Distance::Distance_Type Distance_Type;
105 const Distance_Type Inf;
106 bool negative_cycle =
false;
113 bool has_negative_cycle()
const noexcept {
return negative_cycle; }
115 const DynMatrix<long> & get_path_mat()
const noexcept {
return path_mat; }
132 auto i = binary_search(nodes, p);
133 if (i < 0 or i > nodes.
size() or nodes(i) != p)
134 throw domain_error(
"Floyd_All_Shortest_Paths::index_node() not found");
141 : g(const_cast<GT&>(__g)), n(g.get_num_nodes()),
142 Inf(std::numeric_limits<Distance_Type>::max()),
143 path_mat(n, n), dist(n, n), sa(__sa)
146 nodes.
reserve(g.get_num_nodes());
147 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
148 nodes.
access(i++) = it.get_curr_ne();
149 in_place_sort(nodes);
157 for (
long i = 0; i < n; ++i)
159 Node * src = nodes(i);
160 for (
long j = 0; j < n; ++j)
168 Node * tgt = nodes(j);
176 dist(i, j) = Distance () (arc);
182 for (
long k = 0; k < n; ++k)
183 for (
long i = 0; i < n; ++i)
185 const Distance_Type & dik = dist(i, k);
186 for (
long j = 0; j < n; ++j)
188 const Distance_Type & dij = dist(i, j);
192 const Distance_Type & dkj = dist(k, j);
197 Distance_Type new_dist = dik + dkj;
200 dist(i, j) = new_dist;
201 path_mat(i, j) = path_mat(i, k);
206 for (i = 0; i < n; ++i)
209 negative_cycle =
true;
217 string entry(
const Distance_Type & e)
222 std::stringstream ss;
229 Distance_Type Inf = std::numeric_limits<Distance_Type>::max();
230 const int n = dist.
rows();
231 for (
int i = 0; i < n; ++i)
233 for (
int j = 0; j < n; ++j)
234 if (dist.
access(i,j) == Inf)
237 cout << dist.
access(i,j) <<
" ";
243 Path<GT> get_min_path(
const long src_idx,
const long tgt_idx)
const 245 auto src = nodes(src_idx);
249 if (src_idx == tgt_idx)
255 const auto & k = path_mat(i, tgt_idx);
267 Path<GT> get_min_path(
typename GT::Node * src,
typename GT::Node * tgt)
const GT_Arc * search_directed(void *src, void *tgt)
Definition: tpl_indexArc.H:139
void reserve(const size_t l, const size_t r)
Definition: tpl_dynArray.H:998
const size_t & rows() const noexcept
Return the number of rows.
Definition: tpl_dynMat.H:180
T & access(const size_t i) const noexcept
Definition: tpl_dynArray.H:874
T & access(const size_t i, const size_t j) const
Fast access to i-th row j-th column.
Definition: tpl_dynMat.H:209
Definition: tpl_graph.H:53
DynList< typename GT::Arc * > arcs(typename GT::Node *p, SA sa=SA())
Definition: tpl_graph.H:1893
Node * select_node(long i) const noexcept
Definition: Floyd.H:126
Definition: tpl_graph.H:1063
void append_directed(Node *p)
Definition: tpl_graph.H:2880
Definition: tpl_indexArc.H:67
Definition: tpl_graph_utils.H:1753
size_t size() const noexcept
Definition: tpl_dynArray.H:641
Definition: tpl_dynArray.H:159
long index_node(Node *p) const noexcept
Definition: Floyd.H:130
void allocate()
Definition: tpl_dynMat.H:111