13#include <gtest/gtest.h>
44 for (
auto it = g.get_arc_it(); it.has_curr(); it.next_ne())
55 for (
auto it = tree.get_arc_it(); it.has_curr(); it.next_ne())
56 total += it.get_current_arc_ne()->get_info();
65 for (
auto it = g.get_arc_it(); it.has_curr(); it.next_ne())
67 auto arc = it.get_current_arc_ne();
69 total += arc->get_info();
78 using Distance_Type =
int;
79 static const Distance_Type Zero_Distance = 0;
80 static const Distance_Type Max_Distance = std::numeric_limits<int>::max();
83 Scaled_Dist() =
default;
84 explicit Scaled_Dist(
int f) : factor(f) {}
86 int operator()(
typename G::Arc *a)
const noexcept
88 return a->get_info() * factor;
100 bool operator()(
typename G::Arc *a)
const noexcept
110 if (tree.get_num_nodes() == 0)
112 if (tree.get_num_nodes() == 1)
116 if (tree.get_num_arcs() != tree.get_num_nodes() - 1)
121 auto first = tree.get_first_node();
133 auto tgt = it.get_tgt_node_ne();
143 return visited == tree.get_num_nodes();
213 std::vector<Node*>
nodes;
266 std::vector<Node*>
leaves;
290 std::vector<std::vector<Node*>>
grid(3, std::vector<Node*>(3));
294 for (
int i = 0; i < 3; ++i)
295 for (
int j = 0; j < 3; ++j)
299 for (
int i = 0; i < 3; ++i)
300 for (
int j = 0; j < 2; ++j)
304 for (
int i = 0; i < 2; ++i)
305 for (
int j = 0; j < 3; ++j)
484 std::vector<Node*>
nodes;
554 std::vector<Node*>
nodes;
592 for (
typename GT::Node_Iterator it(tree); it.has_curr(); it.next_ne())
606 std::vector<Node*>
nodes;
612 std::mt19937
rng(12345);
664 for (
typename GT::Node_Iterator it(tree); it.has_curr(); it.next_ne())
689 for (
typename GT::Arc_Iterator it(tree); it.has_curr(); it.next_ne())
702 auto n0 = dg.insert_node(0);
703 auto n1 = dg.insert_node(1);
704 dg.insert_arc(n0, n1, 1);
771 Node* n0 =
g1.insert_node(0);
772 Node* n1 =
g1.insert_node(1);
773 g1.insert_arc(n0, n1, 5);
798 std::vector<Node*>
nodes;
808 std::mt19937
rng(99999);
810 std::uniform_int_distribution<int>
wdist(1, 1000);
961 ::testing::InitGoogleTest(&
argc,
argv);
Kruskal's minimum spanning tree algorithm.
WeightedDigraph::Node Node
virtual Node * insert_node(Node *p)
Arc * insert_arc(Node *src, Node *tgt, void *a)
Generic directed graph (digraph) wrapper template.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
constexpr bool is_empty() const noexcept
Return true if list is empty.
Computes the minimum spanning tree of a graph using Kruskal's algorithm.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Graph_Node< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
constexpr size_t get_num_arcs() const noexcept
DynArray< Graph::Node * > nodes
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
#define NODE_BITS(p)
Get the control bits of a node.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Arc of graph implemented with double-linked adjacency lists.
Filtered iterator of adjacent arcs of a node.
bool operator()(typename GT::Arc *a) const
Array-based graph implementation.
Generic graph and digraph implementations.
Simple graph implementation with adjacency lists.