38#include <gtest/gtest.h>
226 auto n1 = g.insert_node(1);
227 auto n2 = g.insert_node(2);
229 g.insert_arc(n1, n2, 10);
239 auto n1 = g.insert_node(1);
240 auto n2 = g.insert_node(2);
242 g.insert_arc(n1, n2, 12);
243 g.insert_arc(n2, n1, 21);
263 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
265 sum += it.get_curr()->get_info();
285 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
287 sum += it.get_curr()->get_info();
309 for (IntGraph::Node_Arc_Iterator it(n1); it.has_curr(); it.next())
311 sum += it.get_curr()->get_info();
326 auto n1 =
g1.insert_node(1);
327 auto n2 =
g1.insert_node(2);
328 g1.insert_arc(n1, n2, 10);
351 auto n1 =
g1.insert_node(1);
352 auto n2 =
g1.insert_node(2);
353 g1.insert_arc(n1, n2, 10);
404 copy.insert_node(999);
417 for (
int i = 0; i < 10; ++i)
418 target.insert_node(i * 100);
442 return a->get_info() < b->get_info();
445 std::vector<int> values;
446 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
447 values.push_back(it.get_curr()->get_info());
449 EXPECT_EQ(values, (std::vector<int>{1, 2, 3}));
463 return a->get_info() < b->get_info();
466 std::vector<int> values;
467 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
468 values.push_back(it.get_curr()->get_info());
470 EXPECT_EQ(values, (std::vector<int>{10, 20, 30}));
480 constexpr int N = 100;
483 std::vector<IntGraph::Node*>
nodes;
484 for (
int i = 0; i <
N; ++i)
490 for (
int i = 0; i <
N; ++i)
491 for (
int j = i + 1; j <
N; ++j)
500 constexpr int N = 50;
502 std::vector<IntDigraph::Node*>
nodes;
503 for (
int i = 0; i <
N; ++i)
504 nodes.push_back(g.insert_node(i));
507 for (
int i = 0; i <
N; ++i)
508 for (
int j = 0; j <
N; ++j)
512 EXPECT_EQ(g.esize(),
static_cast<size_t>(
N * (
N - 1)));
558 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
563 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
607 auto n1 = dg.insert_node(1);
608 auto n2 = dg.insert_node(2);
609 auto arc = dg.insert_arc(n1, n2, 100);
670 "Array_Graph::Node_Iterator must satisfy BasicGraphIterator");
672 "Array_Graph::Arc_Iterator must satisfy BasicGraphIterator");
674 "Array_Graph::Node_Iterator must satisfy GraphNodeIterator");
676 "Array_Graph::Arc_Iterator must satisfy GraphArcIterator");
Generic directed graph (digraph) wrapper template.
Node * get_first_node() const
Return any node in the graph.
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
virtual void remove_node(Node *node) noexcept
Remove a node from the graph and free its memory.
virtual Arc * connect_arc(Arc *arc) noexcept
Connect a previously disconnected arc to the graph.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
virtual void disconnect_arc(Arc *arc) noexcept
Disconnect an arc from graph.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
size_t num_arcs
data associated to the node. Access it with get_info()
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
bool is_digraph() const noexcept
Return true if the graph this is directed.
void sort_arcs(Compare &cmp) noexcept
Sort all the arcs of the graph according to a specific criteria.
constexpr size_t vsize() const noexcept
size_t esize() const noexcept
Return the total of arcs of graph.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
void sort_nodes(Compare &cmp) noexcept
Concept for basic graph iterators.
Concept for graph arc iterators.
Concept for graph node iterators.
Concept for node adjacency iterators.
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Array-based graph implementation.