129 typedef typename AM::Graph_Type::Arc_Type
Arc_Type;
131 typedef typename AM::Graph_Type
GT;
152 entry = AM::Graph_Type::Arc_Type::Zero_Distance;
165 Arc * lightest =
nullptr;
166 for (
typename GT::Node_Arc_Iterator it(src); it.has_curr(); it.next_ne())
167 if (it.get_tgt_node_ne() == tgt
and
168 (lightest ==
nullptr or
169 Compare () (it.get_current_arc_ne()->get_info().get_distance(),
170 lightest->
get_info().get_distance())))
171 lightest = it.get_current_arc_ne();
173 if (lightest ==
nullptr)
175 entry = AM::Graph_Type::Arc_Type::Max_Distance;
179 entry = lightest->
get_info().get_distance();
185namespace latex_floyd_detail
192 template <AlephGraph GT,
class Compare>
197 using Dist_Type =
typename GT::Arc_Type::Distance_Type;
202 for (
long i = 0; i < n; ++i)
204 for (
long j = 0; j < n; ++j)
205 dist(i, j) = i == j ? GT::Arc_Type::Zero_Distance
206 : GT::Arc_Type::Max_Distance;
209 Node * src = dist(i);
210 for (
typename GT::Node_Arc_Iterator it(src); it.has_curr(); it.next_ne())
212 Node * tgt = it.get_tgt_node_ne();
216 const long j = dist(tgt);
217 const Dist_Type
w = it.get_current_arc_ne()->get_info().get_distance();
224 else if (Compare () (
w, dist(i, j)))
255template <AlephGraph GT,
class Compare,
class Plus>
261 typedef typename GT::Arc_Type::Distance_Type Dist_Type;
263 latex_floyd_detail::initialize_matrices<GT, Compare>(dist, path);
265 const Dist_Type &
max = GT::Arc_Type::Max_Distance;
269 for (
int i = 0; i < n; ++i)
270 for (
int s = 0; s < n; ++s)
271 if (dist(s, i) <
max)
272 for (
int t = 0; t < n; ++t)
274 if (!(dist(i, t) <
max))
277 Dist_Type new_dist =
Plus () (dist(s, i), dist(i, t));
279 if (Compare () (new_dist, dist(s, t)))
281 path(s, t) = path(s, i);
282 dist(s, t) = new_dist;
289template <AlephGraph GT>
295 using Dist_T =
typename GT::Arc_Type::Distance_Type;
333template <AlephGraph
GT,
class Compare,
class Plus,
334 template <
class>
class P_i,
335 template <
class>
class P_ij,
336 template <
class>
class D_ij>
346 typedef typename GT::Arc_Type::Distance_Type Dist_Type;
348 latex_floyd_detail::initialize_matrices<GT, Compare>(dist, path);
350 const Dist_Type &
max = GT::Arc_Type::Max_Distance;
354 output <<
"\\begin{figure}[H]{\\tiny " << std::endl
355 <<
"\\begin{tabular}{ll}" << std::endl
356 <<
"\\begin{tabular}{ll}" << std::endl;
357 mat_to_latex <Dist_Mat, P_i<Dist_Mat>, P_i<Dist_Mat>, D_ij<Dist_Mat> >
358 (dist, n, n,
output,
"\\hskip -5mm $D_0=$",
"\\\\ ");
359 output <<
"\\end{tabular}" << std::endl
360 <<
" & \\begin{tabular}{ll}" << std::endl;
361 mat_to_latex <Path_Mat, P_i<Path_Mat>, P_i<Path_Mat>, P_ij<Path_Mat> >
362 (path, n, n,
output,
"\\hskip -7mm $P_0=$",
"\\\\ ");
363 output <<
"\\end{tabular}" << std::endl
364 <<
"\\end{tabular}" << std::endl
365 <<
"}\\end{figure}" << std::endl;
367 for (
int i = 0; i < n; ++i)
369 for (
int s = 0; s < n; ++s)
370 if (dist(s, i) <
max)
371 for (
int t = 0; t < n; ++t)
373 if (!(dist(i, t) <
max))
376 Dist_Type new_dist =
Plus() (dist(s, i), dist(i, t));
378 if (Compare () (new_dist, dist(s, t)))
380 path(s, t) = path(s, i);
381 dist(s, t) = new_dist;
386 snprintf(buf, 256,
"\\hskip -5mm $D_%d=$ ", i + 1);
388 output <<
"\\begin{figure}[H]{\\tiny " << std::endl
389 <<
"\\begin{tabular}{ll}" << std::endl
390 <<
"\\begin{tabular}{ll}" << std::endl;
391 mat_to_latex <Dist_Mat, P_i<Dist_Mat>, P_i<Dist_Mat>, D_ij<Dist_Mat> >
392 (dist, n, n,
output, buf,
"\\\\ ");
393 output <<
"\\end{tabular}" << std::endl
394 <<
" & \\begin{tabular}{ll}" << std::endl;
396 snprintf(buf, 256,
"\\hskip -7mm $P_%d=$ ", i + 1);
398 mat_to_latex <Path_Mat, P_i<Path_Mat>, P_i<Path_Mat>, P_ij<Path_Mat> >
399 (path, n, n,
output, buf,
"\\\\");
400 output <<
"\\end{tabular}" << std::endl
401 <<
"\\end{tabular}" << std::endl
402 <<
"}\\end{figure}" << std::endl;
409template <AlephGraph
GT,
410 template <
class>
class P_i,
411 template <
class>
class P_ij,
412 template <
class>
class D_ij>
419 using Dist_T =
typename GT::Arc_Type::Distance_Type;
421 P_i, P_ij, D_ij>(g, dist, path,
output);
C++20 concepts for the protocol shared by graph algorithms.
Standard functor implementations and comparison objects.
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Auxiliary adjacency matrix with custom entry type.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
GT & get_list_graph() noexcept
Get reference to underlying graph.
Simple dynamic array with automatic resizing and functional operations.
Graph_Node< Node_Info > Node
The graph type.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
size_t num_arcs
data associated to the node. Access it with get_info()
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
void floyd_all_shortest_paths_latex(GT &g, Ady_Mat< GT, typename GT::Arc_Type::Distance_Type > &dist, Ady_Mat< GT, long > &path, std::ofstream &output)
Floyd-Warshall algorithm with LaTeX step-by-step output.
void floyd_all_shortest_paths(GT &g, Ady_Mat< GT, typename GT::Arc_Type::Distance_Type > &dist, Ady_Mat< GT, long > &path)
Compute all-pairs shortest paths using Floyd-Warshall algorithm.
Matrix to LaTeX table conversion utilities.
Path reconstruction from Floyd-Warshall path matrices.
void initialize_matrices(Ady_Mat< GT, typename GT::Arc_Type::Distance_Type > &dist, Ady_Mat< GT, long > &path)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Matrix initialization functor for Floyd-Warshall.
AM::Graph_Type::Arc_Type Arc_Type
AM::Arc_Type::Distance_Type Distance_Type
void operator()(AM &mat, Node *src, Node *tgt, const long &i, const long &j, Distance_Type &entry, void *p)
Dynamic array container with automatic resizing.
Adjacency matrix representations for graphs.