44#include <gtest/gtest.h>
61using namespace testing;
136 n0 =
g.insert_node(0);
137 n1 =
g.insert_node(1);
138 n2 =
g.insert_node(2);
139 n3 =
g.insert_node(3);
152 for (
long i = 0; i < n; ++i)
174 return static_cast<long long>(
_getpid());
176 return static_cast<long long>(
getpid());
182 const auto *
test_info = UnitTest::GetInstance()->current_test_info();
183 string base = string(
"floyd_test_latex_") +
test_info->test_suite_name() +
"_" +
186 for (
auto &
ch : base)
190 return (std::filesystem::temp_directory_path() / base).
string();
196 for (
int i = 0; i < 4; ++i)
197 nodes.push_back(
g.insert_node(i));
231 const long n = g.get_num_nodes();
232 for (
long i = 0; i < n; ++i)
244 long idx0 = get_index(dist, n0);
245 long idx1 = get_index(dist, n1);
258 long idx0 = get_index(dist, n0);
259 long idx2 = get_index(dist, n2);
272 long idx0 = get_index(dist, n0);
273 long idx3 = get_index(dist, n3);
286 long idx1 = get_index(dist, n1);
287 long idx0 = get_index(dist, n0);
300 const long n = g.get_num_nodes();
303 for (
long i = 0; i < n; ++i)
304 for (
long j = 0; j < n; ++j)
306 <<
"Distance should be symmetric for i=" << i <<
", j=" << j;
318 const long n = g.get_num_nodes();
319 for (
long i = 0; i < n; ++i) {
320 if (dist(i)->get_info() == 0)
idx0 = i;
321 if (dist(i)->get_info() == 3)
idx3 = i;
340 long idx0 = get_index(dist, n0);
356 long idx0 = get_index(dist, n0);
357 long idx1 = get_index(dist, n1);
373 long idx0 = get_index(dist, n0);
374 long idx2 = get_index(dist, n2);
394 return to_string(mat(
static_cast<long>(i))->get_info());
404 long val = mat(
static_cast<long>(i),
static_cast<long>(j));
415 auto val = mat(
static_cast<long>(i),
static_cast<long>(j));
416 if (
isinf(
static_cast<double>(val)))
428 string filename = latex_temp_filename();
429 ofstream
output(filename);
438 ifstream
input(filename);
441 string content =
ss.str();
443 EXPECT_NE(content.find(
"\\begin{figure}"), string::npos);
444 EXPECT_NE(content.find(
"\\end{figure}"), string::npos);
452 string filename = latex_temp_filename();
453 ofstream
output(filename);
461 ifstream
input(filename);
464 string content =
ss.str();
467 EXPECT_NE(content.find(
"D_0"), string::npos);
468 EXPECT_NE(content.find(
"P_0"), string::npos);
469 EXPECT_NE(content.find(
"D_1"), string::npos);
470 EXPECT_NE(content.find(
"P_1"), string::npos);
478 string filename = latex_temp_filename();
479 ofstream
output(filename);
487 ifstream
input(filename);
490 string content =
ss.str();
494 const long n = g.get_num_nodes();
495 for (
long i = 0; i <= n; ++i) {
537 for (
long i = 0; i < 2; ++i) {
538 if (dist(i)->get_info() == 0)
idx0 = i;
539 if (dist(i)->get_info() == 1)
idx1 = i;
571 for (
long i = 0; i < 4; ++i)
572 idx[dist(i)->get_info()] = i;
612 for (
long i = 0; i < 4; ++i)
613 idx[dist(i)->get_info()] = i;
632 vector<Graph::Node*>
nodes;
634 for (
int i = 0; i <
N; ++i)
638 for (
int i = 0; i <
N; ++i)
639 for (
int j = 0; j <
N; ++j)
649 for (
long i = 0; i <
N; ++i) {
650 for (
long j = 0; j <
N; ++j) {
711 vector<Graph::Node*>
nodes;
713 for (
int i = 0; i <
N; ++i)
717 for (
int i = 0; i <
N - 1; ++i)
721 for (
int i = 0; i <
N - 2; i += 2)
731 for (
long m = 0;
m <
N; ++
m) {
732 int info = dist(
m)->get_info();
737 for (
int i = 0; i <
N; ++i)
738 for (
int j = i; j <
N; ++j)
739 EXPECT_EQ(dist(idx[i], idx[j]), j - i) <<
"Distance from " << i <<
" to " << j;
753 const long n = g.get_num_nodes();
756 for (
long i = 0; i < n; ++i) {
757 for (
long j = 0; j < n; ++j) {
759 EXPECT_EQ(path(i, j), j) <<
"Diagonal should point to self";
761 long next = path(i, j);
776 const long n = g.get_num_nodes();
779 for (
long i = 0; i < n; ++i) {
780 for (
long j = 0; j < n; ++j) {
781 for (
long k = 0;
k < n; ++
k) {
784 <<
"Triangle inequality violated for i=" << i <<
", j=" << j <<
", k=" <<
k;
804 const long n = g.get_num_nodes();
807 for (
long i = 0; i < n; ++i)
812 for (
long i = 0; i < n; ++i)
813 for (
long j = 0; j < n; ++j)
847 for (
long i = 0; i < 3; ++i) {
848 if (dist(i)->get_info() == 0)
idx0 = i;
849 if (dist(i)->get_info() == 2)
idx2 = i;
866 vector<Graph::Node*>
nodes;
868 for (
int i = 0; i <
N; ++i)
872 for (
int i = 0; i <
N; ++i)
873 for (
int j = 0; j <
N; ++j)
883 for (
long i = 0; i <
N; ++i)
887 for (
long i = 0; i <
N; ++i)
888 for (
long j = 0; j <
N; ++j)
890 <<
"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.
string latex_temp_filename() const
static long long process_id() noexcept
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.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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).
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
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Generic graph and digraph implementations.
Adjacency matrix representations for graphs.