38#include <gtest/gtest.h>
272 auto n1 = g.insert_node(1);
273 auto n2 = g.insert_node(2);
275 g.insert_arc(n1, n2, 10);
285 auto n1 = g.insert_node(1);
286 auto n2 = g.insert_node(2);
288 g.insert_arc(n1, n2, 12);
289 g.insert_arc(n2, n1, 21);
309 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
311 sum += it.get_curr()->get_info();
331 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
333 sum += it.get_curr()->get_info();
355 for (IntGraph::Node_Arc_Iterator it(n1); it.has_curr(); it.next())
357 sum += it.get_curr()->get_info();
376 for (IntGraph::Node_Arc_Iterator it(n1); it.has_curr(); it.next())
378 targets.push_back(it.get_tgt_node()->get_info());
390 auto n1 = g.insert_node(1);
391 auto n2 = g.insert_node(2);
393 g.insert_arc(n1, n2, 12);
395 IntDigraph::Arc_Iterator it(g);
397 EXPECT_EQ(it.get_src_node()->get_info(), 1);
398 EXPECT_EQ(it.get_tgt_node()->get_info(), 2);
408 auto n1 =
g1.insert_node(1);
409 auto n2 =
g1.insert_node(2);
410 g1.insert_arc(n1, n2, 10);
433 auto n1 =
g1.insert_node(1);
434 auto n2 =
g1.insert_node(2);
435 g1.insert_arc(n1, n2, 10);
471 auto n1 =
g1.insert_node(1);
472 auto n2 =
g1.insert_node(2);
473 g1.insert_arc(n1, n2, 10);
497 auto n1 =
g1.insert_node(1);
498 auto n2 =
g1.insert_node(2);
499 g1.insert_arc(n1, n2, 10);
529 constexpr int N = 100;
532 std::vector<IntGraph::Node*>
nodes;
533 for (
int i = 0; i <
N; ++i)
539 for (
int i = 0; i <
N; ++i)
540 for (
int j = i + 1; j <
N; ++j)
549 constexpr int N = 50;
551 std::vector<IntDigraph::Node*>
nodes;
552 for (
int i = 0; i <
N; ++i)
553 nodes.push_back(g.insert_node(i));
556 for (
int i = 0; i <
N; ++i)
557 for (
int j = 0; j <
N; ++j)
561 EXPECT_EQ(g.esize(),
static_cast<size_t>(
N * (
N - 1)));
584 auto n1 = g.insert_node(1);
586 auto arc = g.insert_arc(n1, n1, 11);
599 for (IntGraph::Node_Iterator it(g); it.has_curr(); it.next())
604 for (IntGraph::Arc_Iterator it(g); it.has_curr(); it.next())
683 IntGraph::Node_Iterator it(g);
685 EXPECT_EQ(it.get_current_node()->get_info(), 42);
686 EXPECT_EQ(it.get_current_node_ne()->get_info(), 42);
696 IntGraph::Node_Arc_Iterator it(n1);
698 EXPECT_EQ(it.get_current_arc()->get_info(), 100);
699 EXPECT_EQ(it.get_current_arc_ne()->get_info(), 100);
709 IntGraph::Arc_Iterator it(g);
711 EXPECT_EQ(it.get_current_arc()->get_info(), 100);
712 EXPECT_EQ(it.get_current_arc_ne()->get_info(), 100);
765 auto n1 = dg.insert_node(1);
766 auto n2 = dg.insert_node(2);
767 auto arc = dg.insert_arc(n1, n2, 100);
830 auto n1 = dg.insert_node(1);
831 auto n2 = dg.insert_node(2);
832 dg.insert_arc(n1, n2, 100);
844 auto n1 = dg.insert_node(1);
845 auto n2 = dg.insert_node(2);
846 dg.insert_arc(n1, n2, 100);
859 "List_SGraph::Node_Iterator must satisfy BasicGraphIterator");
861 "List_SGraph::Arc_Iterator must satisfy BasicGraphIterator");
863 "List_SGraph::Node_Iterator must satisfy GraphNodeIterator");
865 "List_SGraph::Arc_Iterator must satisfy GraphArcIterator");
Generic directed graph (digraph) wrapper template.
DynList & swap(DynList &l) noexcept
Swap this with l.
Arc for graphs implemented with simple adjacency lists.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
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 void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Graph class implemented with singly-linked adjacency lists.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
void * tgt_node
Please don't use.
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.
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)
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
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.
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.
Node for graphs implemented with simple adjacency lists.
DynList< void * > arc_list
Adjacency list of arcs incident to this node.
Simple graph implementation with adjacency lists.