44#include <gtest/gtest.h>
55using namespace testing;
130 n0 =
g.insert_node(0);
131 n1 =
g.insert_node(1);
132 n2 =
g.insert_node(2);
133 n3 =
g.insert_node(3);
146 for (
long i = 0; i < n; ++i)
168 for (
int i = 0; i < 4; ++i)
169 nodes.push_back(
g.insert_node(i));
203 const long n = g.get_num_nodes();
204 for (
long i = 0; i < n; ++i)
216 long idx0 = get_index(dist, n0);
217 long idx1 = get_index(dist, n1);
230 long idx0 = get_index(dist, n0);
231 long idx2 = get_index(dist, n2);
244 long idx0 = get_index(dist, n0);
245 long idx3 = get_index(dist, n3);
258 long idx1 = get_index(dist, n1);
259 long idx0 = get_index(dist, n0);
272 const long n = g.get_num_nodes();
275 for (
long i = 0; i < n; ++i)
276 for (
long j = 0; j < n; ++j)
278 <<
"Distance should be symmetric for i=" << i <<
", j=" << j;
290 const long n = g.get_num_nodes();
291 for (
long i = 0; i < n; ++i) {
292 if (dist(i)->get_info() == 0)
idx0 = i;
293 if (dist(i)->get_info() == 3)
idx3 = i;
312 long idx0 = get_index(dist, n0);
328 long idx0 = get_index(dist, n0);
329 long idx1 = get_index(dist, n1);
345 long idx0 = get_index(dist, n0);
346 long idx2 = get_index(dist, n2);
366 return to_string(mat(
static_cast<long>(i))->get_info());
376 long val = mat(
static_cast<long>(i),
static_cast<long>(j));
387 auto val = mat(
static_cast<long>(i),
static_cast<long>(j));
388 if (
isinf(
static_cast<double>(val)))
400 string filename =
"/tmp/floyd_test_latex.tex";
401 ofstream
output(filename);
410 ifstream
input(filename);
424 string filename =
"/tmp/floyd_test_latex2.tex";
425 ofstream
output(filename);
433 ifstream
input(filename);
450 string filename =
"/tmp/floyd_test_latex3.tex";
451 ofstream
output(filename);
459 ifstream
input(filename);
466 const long n = g.get_num_nodes();
467 for (
long i = 0; i <= n; ++i) {
509 for (
long i = 0; i < 2; ++i) {
510 if (dist(i)->get_info() == 0)
idx0 = i;
511 if (dist(i)->get_info() == 1)
idx1 = i;
543 for (
long i = 0; i < 4; ++i)
544 idx[dist(i)->get_info()] = i;
584 for (
long i = 0; i < 4; ++i)
585 idx[dist(i)->get_info()] = i;
604 vector<Graph::Node*>
nodes;
606 for (
int i = 0; i <
N; ++i)
610 for (
int i = 0; i <
N; ++i)
611 for (
int j = 0; j <
N; ++j)
621 for (
long i = 0; i <
N; ++i) {
622 for (
long j = 0; j <
N; ++j) {
683 vector<Graph::Node*>
nodes;
685 for (
int i = 0; i <
N; ++i)
689 for (
int i = 0; i <
N - 1; ++i)
693 for (
int i = 0; i <
N - 2; i += 2)
703 for (
long m = 0; m <
N; ++m) {
704 int info = dist(m)->get_info();
709 for (
int i = 0; i <
N; ++i)
710 for (
int j = i; j <
N; ++j)
711 EXPECT_EQ(dist(idx[i], idx[j]), j - i) <<
"Distance from " << i <<
" to " << j;
725 const long n = g.get_num_nodes();
728 for (
long i = 0; i < n; ++i) {
729 for (
long j = 0; j < n; ++j) {
731 EXPECT_EQ(path(i, j), j) <<
"Diagonal should point to self";
733 long next = path(i, j);
748 const long n = g.get_num_nodes();
751 for (
long i = 0; i < n; ++i) {
752 for (
long j = 0; j < n; ++j) {
753 for (
long k = 0;
k < n; ++
k) {
756 <<
"Triangle inequality violated for i=" << i <<
", j=" << j <<
", k=" <<
k;
776 const long n = g.get_num_nodes();
779 for (
long i = 0; i < n; ++i)
784 for (
long i = 0; i < n; ++i)
785 for (
long j = 0; j < n; ++j)
819 for (
long i = 0; i < 3; ++i) {
820 if (dist(i)->get_info() == 0)
idx0 = i;
821 if (dist(i)->get_info() == 2)
idx2 = i;
838 vector<Graph::Node*>
nodes;
840 for (
int i = 0; i <
N; ++i)
844 for (
int i = 0; i <
N; ++i)
845 for (
int j = 0; j <
N; ++j)
855 for (
long i = 0; i <
N; ++i)
859 for (
long i = 0; i <
N; ++i)
860 for (
long j = 0; j <
N; ++j)
862 <<
"Should be reachable from " << i <<
" to " << j;
List_Graph< Node, Arc > Graph
Auxiliary adjacency matrix with custom entry type.
size_t get_num_nodes() const noexcept
Get number of nodes (matrix dimension)
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
size_t size() const noexcept
Return the path length in nodes.
Test fixture with integer weights.
IntDistanceArc::Distance_Type Dist
Test fixture with a simple weighted graph.
long get_index(Ady_Mat< Graph, Dist > &mat, Node *node) const
DistanceArc::Distance_Type Dist
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
DynArray< Graph::Node * > nodes
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 find_min_path(Mat &p, const long src_index, const long tgt_index, Path< typename Mat::Graph_Type > &path)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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.
Floyd-Warshall algorithm with LaTeX output generation.
TEST_F(FloydSimpleGraphTest, DiagonalIsZero)
Main namespace for Aleph-w library functions.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
void next()
Advance all underlying iterators (bounds-checked).
DynList< T > maps(const C &c, Op op)
Classic map operation.
Arc of graph implemented with double-linked adjacency lists.
Arc info type with required Distance_Type and constants.
Distance_Type get_distance() const
static constexpr Distance_Type Zero_Distance
DistanceArc(Distance_Type d)
static constexpr Distance_Type Max_Distance
Integer distance arc type.
Distance_Type get_distance() const
IntDistanceArc(Distance_Type d)
static constexpr Distance_Type Zero_Distance
static constexpr Distance_Type Max_Distance
bool operator()(int a, int b) const
int operator()(int a, int b) const
Generic graph and digraph implementations.
Adjacency matrix representations for graphs.