68 template <
typename Node_Info>
71 template <
typename Arc_Info>
79 template <
typename __Graph_Node,
typename __Graph_Arc>
88 template <
typename MT,
typename Entry_Info,
typename Copy>
118 template <
typename __Node_Info = Empty_Class>
219 template <
typename _Arc_Info = Empty_Class>
424 template <
typename _Graph_Node = Graph_Node<
unsigned long>,
425 typename _Graph_Arc = Graph_Arc<
unsigned long>>
427 :
public GraphCommon<List_Graph<_Graph_Node, _Graph_Arc>,
428 _Graph_Node, _Graph_Arc>
457 return static_cast<Node *
>(p);
462 return static_cast<Arc *
>(p);
548 while (
not node->arc_list.is_empty())
601 return reinterpret_cast<Arc *
>(arc);
607 assert(src_node !=
nullptr and tgt_node !=
nullptr and a !=
nullptr);
608 Arc *arc =
static_cast<Arc *
>(a);
609 arc->src_node = src_node;
610 arc->tgt_node = tgt_node;
613 std::unique_ptr<Arc_Node> src_arc_node = std::make_unique<Arc_Node>(arc);
618 if (src_node == tgt_node)
619 arc->tgt_arc_node = src_arc_node.get();
622 std::unique_ptr<Arc_Node> tgt_arc_node = std::make_unique<Arc_Node>(arc);
625 arc->tgt_arc_node = tgt_arc_node.get();
626 tgt_node->arc_list.append(tgt_arc_node.get());
627 ++tgt_node->num_arcs;
628 tgt_arc_node.release();
633 arc->src_arc_node = src_arc_node.get();
634 src_node->arc_list.append(src_arc_node.get());
635 ++src_node->num_arcs;
639 src_arc_node.release();
655 Arc_Node *src_arc_node = arc->src_arc_node;
658 --src_node->num_arcs;
664 if (src_node != tgt_node)
666 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
668 --tgt_node->num_arcs;
704 Arc_Node *src_arc_node = arc->src_arc_node;
706 --src_node->num_arcs;
711 if (src_node != tgt_node)
713 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
715 --tgt_node->num_arcs;
739 Arc_Node *src_arc_node = arc->src_arc_node;
740 Arc_Node *tgt_arc_node = arc->tgt_arc_node;
744 if (src_node != tgt_node)
746 tgt_node->arc_list.
append(tgt_arc_node);
747 ++tgt_node->num_arcs;
751 src_node->arc_list.append(src_arc_node);
752 ++src_node->num_arcs;
1115 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1118 typename GT::Node_Arc_Iterator,
1122 typename GT::Node_Arc_Iterator,
1126 typename GT::Node_Arc_Iterator,
1162 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1204 template <
class GT,
class Show_Node = Dft_Show_Node<GT>>
1238 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1239 requires std::is_invocable_r_v<void, Op &, typename GT::Node *>
1257 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1258 requires std::is_invocable_r_v<void, Op &, typename GT::Arc *>
1277 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1278 requires std::is_invocable_r_v<void, Op &, typename GT::Arc *>
1299 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1300 requires std::is_invocable_r_v<bool, Op &, typename GT::Node *>
1321 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1322 requires std::is_invocable_r_v<bool, Op &, typename GT::Arc *>
1343 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1344 requires std::is_invocable_r_v<bool, Op &, typename GT::Arc *>
1369 template <AlephGraph
GT,
typename T,
1372 requires std::is_invocable_r_v<T, Op &, typename GT::Node *>
1395 template <AlephGraph
GT,
typename T,
1423 template <AlephGraph
GT,
typename T,
1426 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
1447 template <AlephGraph
GT,
typename T,
1480 template <AlephGraph
GT,
typename T,
1483 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
1505 template <AlephGraph
GT,
typename T,
1529 template <AlephGraph GT,
typename T, NodeFilter<GT> SN = Dft_Show_Node<GT>,
class Op>
1530 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Node *>
1552 template <AlephGraph GT,
typename T, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1553 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
1576 template <AlephGraph GT,
typename T, ArcFilter<GT> SA = Dft_Show_Arc<GT>,
class Op>
1577 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
1611 template <
typename __Graph_Node = Graph_Node<
int>,
1612 typename __Graph_Arc = Graph_Arc<
int>>
1622 using ArcPair = std::tuple<typename GT::Arc *, typename GT::Node *>;
1644 return a->src_node ==
src;
1674 return a->tgt_node ==
tgt;
1688 template <
class GT,
class Filter>
1692 typename GT::Node_Arc_Iterator,
Filter>;
1728 return it.has_curr();
1735 return it.get_curr();
1742 return it.get_curr_ne();
1756 return filt.get_node(a);
1829 template <
class GT,
class Show_Arc = Dft_Show_Arc<GT>>
1874 template <
class GT,
class SA = Dft_Show_Arc<GT>>
1919 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1936 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1952 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1968 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1983 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1998 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2004 typename GT::Arc *a = it.get_curr();
2017 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2023 typename GT::Arc *a = it.get_curr();
2039 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2059 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2090 template <AlephGraph GT,
class Itor,
class Operation>
2094 for (Itor it(p); it.has_curr(); it.next_ne())
2095 if (
not op(it.get_curr()))
2117 template <AlephGraph GT,
class Itor,
class Operation>
2121 for (Itor it(p); it.has_curr(); it.next_ne())
2137 template <AlephGraph GT,
class Op>
2150 template <AlephGraph GT,
class Op>
2167 template <AlephGraph GT,
class Op>
2187 template <AlephGraph GT,
class Op>
2208 template <AlephGraph GT,
class Op>
2238 template <AlephGraph GT,
typename T,
class Op>
2239 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
2259 template <AlephGraph GT,
typename T>
2284 template <AlephGraph GT,
typename T,
class Op>
2285 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
2304 template <AlephGraph GT,
class Op>
2329 template <AlephGraph GT,
class Op>
2342 template <AlephGraph GT,
class Op>
2359 template <AlephGraph GT,
class Op>
2379 template <AlephGraph GT,
class Op>
2400 template <AlephGraph GT,
class Op>
2430 template <AlephGraph GT,
typename T,
class Op>
2431 requires std::is_invocable_r_v<T, Op &, typename GT::Arc *>
2451 template <AlephGraph GT,
typename T>
2476 template <AlephGraph GT,
typename T,
class Op>
2477 requires std::is_invocable_r_v<T, Op &, const T &, typename GT::Arc *>
2496 template <AlephGraph GT,
class Op>
2522 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2528 assert(src !=
nullptr and tgt !=
nullptr);
2531 std::swap(tgt, src);
2534 if (
itor.get_tgt_node_ne() == tgt)
2535 return itor.get_current_arc_ne();
2550 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2557 assert(src !=
nullptr and tgt !=
nullptr);
2560 if (
typename GT::Arc *a = it.get_curr(); a->src_node == src
and a->tgt_node == tgt)
2570 template <AlephGraph GT>
2577 template <AlephGraph GT>
2584 template <AlephGraph GTSRC, AlephGraph GTTGT>
2591 template <AlephGraph GTSRC, AlephGraph GTTGT>
2592 typename GTTGT::Arc *
mapped_arc(
typename GTSRC::Arc *a)
noexcept
2614 template <AlephGraph GT>
2623 template <AlephGraph GT>
2636 template <AlephGraph GT,
class Operation, NodeFilter<GT> SN = Dft_Show_Node<GT>>
2656 op(g, it.get_curr());
2667 op(g, it.get_curr());
2681 template <AlephGraph GT,
class Operation, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2701 op(g, it.get_curr());
2707 op(g, it.get_curr());
2720 op(g, it.get_current_arc_ne());
2727 op(g, it.get_current_arc_ne());
2797 if (
not (
node->get_info() ==
r.node->get_info()))
2801 return r.arc ==
nullptr;
2803 if (
r.arc ==
nullptr)
2806 return arc->get_info() ==
r.arc->get_info();
2836 return list.all([
this](
auto d)
2840 and list.get_last().arc ==
nullptr;
2918 return list.is_empty();
2926 list.remove_first();
2957 std::swap(
g, path.g);
2958 list.swap(path.list);
2985 <<
"arc has not link to last node of path";
3012 if (
list.is_empty())
3022 <<
"There is no an arc connecting to the node";
3051 if (
list.is_empty())
3097 <<
"The arc does not connect the last node";
3128 <<
"arc has not link to first node of path";
3153 if (
list.is_empty())
3190 if (
list.is_empty())
3228 <<
"The arc does not connect the first node";
3237 return list.get_first().node;
3253 return list.get_first().arc;
3261 <<
"Path with only a node (without any arc)";
3282 auto d =
list.remove_last();
3283 list.get_last().arc =
nullptr;
3294 auto d =
list.remove_first();
3301 std::swap(
g, path.g);
3302 list.swap(path.list);
3440 template <
class Operation>
3444 op(it.get_current_node_ne());
3451 template <
class Operation>
3455 op(it.get_current_arc_ne());
3462 if (it.get_current_node_ne() == node)
3471 if (it.get_current_arc_ne() == arc)
3510 return eq(this->list, p.list);
3516 return not eq(this->list, p.list);
3520 template <AlephGraph GT>
3576 template <AlephGraph GT>
3589 auto arc = it.get_current_arc_ne();
3613 template <AlephGraph GTS, AlephGraph GTT>
3614 void map_nodes(
typename GTS::Node *p,
typename GTT::Node *q)
noexcept
3641 template <AlephGraph GTS, AlephGraph GTT>
3642 void map_arcs(
typename GTS::Arc *p,
typename GTT::Arc *q)
noexcept
3658 template <AlephGraph GT>
3661 for (
typename GT::Arc_Iterator it(g); it.has_curr();)
3663 typename GT::Arc *arc = it.get_curr_ne();
3668 for (
typename GT::Node_Iterator it(g); it.has_curr();)
3670 typename GT::Node *p = it.get_curr_ne();
3676 template <AlephGraph GT>
3685 for (
typename GT::Node_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3687 typename GT::Node *src_node = it.get_current_node_ne();
3688 std::unique_ptr<typename GT::Node>
3690 map.
insert(src_node, tgt_node.get());
3692 typename GT::Node *tgt = tgt_node.release();
3694 gtgt.insert_node(tgt);
3704 for (
typename GT::Arc_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3731 template <
class GTT,
class GTS>
3734 void operator()(
typename GTT::Node *tgt,
typename GTS::Node *src)
noexcept
3744 template <
class GTT,
class GTS>
3749 tgt->get_info() = src->get_info();
3761 template <AlephGraph
GTT, AlephGraph
GTS,
3772 for (
typename GTS::Node_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3774 typename GTS::Node *src_node = it.get_current_node_ne();
3775 std::unique_ptr<typename GTT::Node> tgt_node(
new typename GTT::Node);
3777 map.
insert(src_node, tgt_node.get());
3779 typename GTT::Node *tgt = tgt_node.release();
3780 gtgt.insert_node(tgt);
3790 for (
typename GTS::Arc_Iterator it(
gsrc); it.has_curr(); it.next_ne())
3792 typename GTS::Arc *
src_arc = it.get_current_arc_ne();
3795 typename GTT::Node *src_node = map[
gsrc.get_src_node(
src_arc)];
3796 typename GTT::Node *tgt_node = map[
gsrc.get_tgt_node(
src_arc)];
3797 typename GTT::Arc *
tgt_arc =
gtgt.insert_arc(src_node, tgt_node);
3824 template <AlephGraph GT, NodeFilter<GT> SN = Dft_Show_Node<GT>, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
3852 typename GT::Node *src_node = it.get_curr();
3853 std::unique_ptr<typename GT::Node>
3854 tgt_node(
new typename GT::Node(src_node));
3855 map.
insert(src_node, tgt_node.get());
3857 typename GT::Node *tgt = tgt_node.release();
3858 gtgt.insert_node(tgt);
3911 template <AlephGraph GT,
class Distance>
3951 template <AlephGraph GT>
3989 template <
class,
class>
class Tree =
Treap>
4006 for (
typename GT::Node_Iterator it(src); it.has_curr(); it.next_ne())
4008 Node *src_node = it.get_curr();
4014 for (
typename GT::Arc_Iterator it(src); it.has_curr(); it.next_ne())
4117 <<
"Node not found in mapping (not from original graph?)";
4135 return ptr ? ptr->second :
nullptr;
4179 template <
typename Op>
4238 if (
pair.second == node)
4240 original_node = pair.first;
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
Simplified graph interface for common use cases.
void put_itor_at_the_end(Itor &it) noexcept
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Space-efficient bit array implementation.
Arc_Node(void *__arc) noexcept
Copy_Graph(SA __sa=SA(), SN __sn=SN())
Constructor.
void copy(GT >gt, const GT &gsrc, const bool cookie_map)
void operator()(GT >gt, GT &gsrc, const bool cookie_map=true)
Perform the copy from gsrc to gtgt.
Filtered iterator on directed graphs.
GT::Arc * get_curr_ne() const noexcept
Return the current arc.
void reset_last() noexcept
Reset the iterator to the last arc.
void reset_first() noexcept
Reset the iterator to the first arc.
GT::Node * get_node_ne() const noexcept
Return the connected node to current arc.
GT::Node * get_node() const
Return the connected node to current arc.
GT::Arc * get_curr() const
Return the current arc.
Digraph_Iterator(typename GT::Node *p)
Iterator type.
Filter_Iterator< typename GT::Node *, typename GT::Node_Arc_Iterator, Filter > Itor
auto get_tgt_node_ne() const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
void end() noexcept
Put the iterator in end state.
auto get_tgt_node() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool has_curr() const noexcept
Return true the iterator has an current arc.
auto get_current_arc() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
GT::Node * get_node(typename GT::Arc *a) const noexcept
Return the connected node to arc.
void prev()
Move the iterator one position backward.
typename Itor::Item_Type Item_Type
void next()
Move the iterator one position forward.
Generic directed graph (digraph) wrapper template.
bool is_in_last() const noexcept
Return true if the iterator is positiones on the last item.
bool has_curr() const noexcept
Return true if the iterator has current item.
Dlink * get_curr() const
Return the current node of iterator.
Dlink * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Doubly linked circular list node.
void append(Dlink *node) noexcept
Insert node before this.
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
void insert(Dlink *node) noexcept
Insert node after this.
T & get_curr() const
Return the current item; throw overflow_error if there is no current item.
void reset_last() noexcept
Reset the iterator to the last item.
void prev()
Move the iterator one item backward.
T & get_curr_ne() const noexcept
Dynamic doubly linked list with O(1) size and bidirectional access.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
T & get_first() const
Return the first item of the list.
Dynamic map implemented with an AVL tree.
Generic key-value map implemented on top of a binary search tree.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Generic filter iterator wrapper.
void next()
Advances the iterator to the next filtered element.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
void reset_last()
Resets the iterator to the last filtered element.
void prev()
Moves the iterator backward to the previous filtered element.
typename It::Item_Type Item_Type
The type of element returned by get_curr()
void reset_first()
Resets the iterator to the first filtered element.
Graph copy with explicit node mapping.
Node * search_copy(Node *orig) const noexcept
Search for the copy of an original node (no exception).
typename GT::Arc_Type Arc_Type
bool has_copy(Node *orig) const noexcept
Check if an original node is in the mapping.
GraphCopyWithMapping & operator=(const GraphCopyWithMapping &)=delete
Node * insert_unmapped_node(Node_Type &&info)
Insert a new node into the copied graph (not mapped, move version).
void build_copy(const GT &src)
Build the copy and mapping.
GraphCopyWithMapping()=default
Default constructor.
const GT & get_graph() const noexcept
Get the copied graph (const version).
DynMapTree< Node *, Node *, Tree > node_map
void remove_node(Node *node)
Remove a node from the copied graph.
Node * get_copy(Node *orig) const
Get the copy of an original node.
void clear()
Clear the copied graph and mapping.
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &info=Arc_Type())
Insert an arc into the copied graph.
GraphCopyWithMapping(const GT &src)
Construct a copy of the given graph with node mapping.
void remove_arc(Arc *arc)
Remove an arc from the copied graph.
void for_each_mapping(Op op) const
Apply a function to each (original, copy) node pair.
size_t num_arcs() const noexcept
Get the number of arcs in the copied graph.
Node * insert_unmapped_node(const Node_Type &info=Node_Type())
Insert a new node into the copied graph (not mapped).
typename GT::Node_Type Node_Type
GraphCopyWithMapping(GraphCopyWithMapping &&other) noexcept=default
Move constructor.
size_t num_nodes() const noexcept
Get the number of mapped nodes.
GT & get_graph() noexcept
Get the copied graph.
GraphCopyWithMapping(const GraphCopyWithMapping &)=delete
GraphCopyWithMapping & operator=(GraphCopyWithMapping &&other) noexcept=default
Move assignment operator.
bool is_unitarian_or_empty() const noexcept
Return true if list contains one element or is empty.
Filtered iterator for incoming arcs of a node.
typename GT::Arc * Item_Type
In_Iterator(typename GT::Node *p, SA sa=SA())
Iterator on the arcs of a graph.
Node_Arc_Iterator(Node *src) noexcept
Constructs an iterator on the node src.
Node * get_node_ne() const noexcept
Node * get_tgt_node_ne() const noexcept
Arc_Node * get_current_arc_node() const
Arc * get_current_arc() const
Return the current arc.
Arc * get_curr_ne() const noexcept
Node_Arc_Iterator()=default
The container type (a node)
Arc_Node * get_current_arc_node_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Node * Set_Type
The type of data of set.
Node * get_tgt_node() const
Return the connected node to source node (src passed in construction time) through the current arc.
Graph implemented with double-linked adjacency lists.
Dlink & get_node_dlink() noexcept
Return a reference to the internal node Dlink for sorting.
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.
Dlink & get_arc_dlink() noexcept
Return a reference to the internal arc Dlink for sorting.
void swap(List_Graph &g) noexcept
Swap in constant time this with g
Arc * get_first_arc() const
Return any arc in the graph.
static Arc * dlink_to_arc(Dlink *p) noexcept
static Arc_Node * dlink_to_arc_node(Dlink *p) noexcept
virtual void remove_node(Node *node) noexcept
Remove a node from the graph and free its memory.
static Node * dlink_to_node(Dlink *p) noexcept
virtual Arc * connect_arc(Arc *arc) noexcept
Connect a previously disconnected arc to the graph.
typename Node::Node_Type Node_Type
The arc class type.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
static Arc * void_to_arc(Arc_Node *arc_node) noexcept
_Graph_Node Node
The graph type.
virtual void disconnect_arc(Arc *arc) noexcept
Disconnect an arc from graph.
_Graph_Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
List_Graph()=default
Construct an empty graph.
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Filtered iterator on the nodes of a graph.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
The element type: Node*.
Node_Iterator()=default
The set: the arcs of a graph.
Node_Iterator(const GT &g, Show_Node sn=Show_Node())
Construct a iterator with filter sn
Functor that traverses the arcs of a graph and performs an operation.
void operator()(const GT &g, typename GT::Node *p, Operation op=Operation()) const
Call to `op on each arc of a node.
void operator()(GT &g, Operation op=Operation()) const
void operator()(const GT &g, Operation op=Operation()) const
Call to `op on each arc.
Operate_On_Arcs(SA __sa=SA())
Initialize the functor with the filter sa
void operator()(GT &g, typename GT::Node *p, Operation op=Operation()) const
Functor that traverses the nodes of a graph and performs an operation.
Operate_On_Nodes(SN __sn=SN())
Initialize the functor with the filter sa
void operator()(const GT &g, Operation op=Operation())
Call to operation on each node.
void operator()(GT &g, Operation op=Operation())
Call to operation on each node.
Filtered iterator for outcoming arcs of a node.
Out_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
typename GT::Arc * Item_Type
Iterator on nodes and arcs of a path.
Node * get_current_node_ne() const noexcept
std::tuple< Node *, Arc * > get_tuple() const
Return a tuple with the current node and arc.
Node * get_current_node() const
Return the current node of a path.
std::tuple< Node *, Arc * > get_tuple_ne() const noexcept
Node * get_curr_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Arc * get_current_arc() const
Return the current arc of a path.
Iterator(const Path &path) noexcept
Create an iterator on the first node of path
Path_Desc & get_curr_path_desc() const
bool has_current_node() const noexcept
Return true if the iterator has a current node.
Path_Desc & get_curr_path_desc_ne() const noexcept
std::pair< Node *, Arc * > get_pair() const
Return a pair with the current node and arc.
bool has_current_arc() const noexcept
Return true if iterator has current arc.
bool is_cycle() const
Return true if this is a cycle; throws if path is empty.
void insert(Arc *arc)
Insert an arc as the first of a path.
void for_each_node(Operation op=Operation()) const
Execute an operation on each node of path.
void empty()
Clean the path: all the nodes and arc are removed.
Path & operator=(const Path &path)
Copy assignment.
DynList< Arc * > arcs() const
Return a list with the arcs of a path (order, according to the path)
typename GT::Arc_Type Arc_Type
The type of data stored in the arc.
void init(Node *start_node)
Set the first node of a path.
void append(Node *node)
Append a node to the path.
Path & operator=(Path &&path) noexcept
Move assignment.
size_t size() const noexcept
Return the path length in nodes.
bool check_directed() const
Return true if the directed path is consistent.
bool contains_node(Node *node) const noexcept
Return true if node belongs to the path.
void insert_directed(Node *p)
Append a node to a directed path.
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
bool operator==(const Path &p) const noexcept
Return true if this is equal to p,.
bool operator!=(const Path &p) const noexcept
Return true if this is not equal to p,.
Iterator get_it() const
Returns an iterator on the path.
Path(Path &&path) noexcept
Move constructor.
bool is_empty() const noexcept
Return true if the path is empty.
typename GT::Node_Type Node_Type
The type of data stored in the nodes.
bool check() const
Return true if the path is consistent.
bool inside_graph(const GT &gr) const noexcept
Return true if this is on graph gr
Arc * get_last_arc() const
Return the last arc of a path; throws overflow_error if the path is empty.
Path(const GT &__g) noexcept
Construct a empty path on graph __g
bool contains_arc(Arc *arc) const noexcept
Return true if arc belongs to the path.
void swap(Path &path) noexcept
Fast swap between two paths (constant time)
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
Node * remove_first_node()
Remove the first node of a path.
Arc * get_first_arc() const
Return the first arc of path; throws overflow_error if path is empty.
void clear()
Empties the container.
DynDlist< Path_Desc > list
void append(Arc *arc)
Append an arc to the path.
void append_directed(Node *p)
Append a node to a directed path.
void insert_directed(Arc *arc)
Append an arc to a directed path.
Path(const GT &_g, Node *start_node)
Construct a path starting from a given node.
DynList< Node * > nodes() const
Return a list with the nodes of path (order according to the path)
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Path(const Path &path)
Copy constructor.
Node * remove_last_node()
Remove the last node of path.
void insert(Node *node)
Insert a node to the path.
const GT & get_graph() const noexcept
Get a constant reference to the graph.
void for_each_arc(Operation op=Operation()) const
Execute an operation on each arc of path.
void append_directed(Arc *arc)
Append an arc to a directed path.
Filter the incoming arcs.
bool operator()(typename GT::Arc *a) const noexcept
GT::Node * get_node(typename GT::Arc *a) const noexcept
__In_Filt(typename GT::Node *__tgt) noexcept
Filter the outcoming arcs.
bool operator()(typename GT::Arc *a) const noexcept
GT::Node * get_node(typename GT::Arc *a) const noexcept
__Out_Filt(typename GT::Node *__src) noexcept
Common methods for the arc of a graph.
void * get_connected_node(void *node) noexcept
Common attributes and methods for nodes (vertexes) belonging to graphs.
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()
Common methods to the Aleph-w ( ) graph classes.
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Node * insert_node(const Node_Type &node_info)
Allocate a new node, set by copy its data content and insert it into the 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.
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
void common_swap(GT &g) noexcept
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Create and insert a new arc linking two nodes and copying data.
constexpr size_t get_num_arcs() const noexcept
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
QuadTree - Hierarchical spatial index for 2D points.
A graph usable by the graph algorithms.
Generic filter iterator wrapper for Aleph containers.
Graph base classes and common utilities via CRTP.
DynArray< Graph::Arc * > arcs
DynList< typename GT::Node * > in_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered incoming arcs to p.
void for_each_out_arc(typename GT::Node *p, Op op=Op())
Traverse the outcoming arcs of a node and executes an operation.
void for_each_node(const GT &g, Op operation, SN sn=SN())
Traverse all the nodes of graph filtering some ones according to a condition and executing an operati...
#define ARC_COOKIE(p)
Return the arc cookie
void map_arcs(typename GTS::Arc *p, typename GTT::Arc *q) noexcept
Map two arcs of different types of graphs through their cookies.
bool traverse_in_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of incoming arcs of a node.
DynList< ArcPair< GT > > out_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered outcoming pairs of (arc,node) related to node p
Container< T > arcs_map(GT &g, Op transformation, SA sa=SA())
Map the filtered arcs of a graph to a transformed type.
bool traverse_arcs(typename GT::Node *p, Operation op=Operation())
Generic arcs traverse of a node.
bool traverse_out_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of outcoming arcs of a node.
#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass)
Macro to generate copy/move constructors and assignment operators.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
void inter_copy_graph(GTT >gt, const GTS &gsrc, const bool cookie_map=false)
Copy between different types of graphs.
bool forall_node(const GT &g, Op cond, SN sn=SN())
Return true if condition cond is met on every filtered node of the graph.
Container< T > nodes_map(GT &g, Op transformation, SN sn=SN())
Map the filtered nodes of a graph to a transformed type.
#define ARC_BITS(p)
Return the control bits of arc p.
size_t out_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered out degree of node p
#define NODE_COOKIE(p)
Return the node cookie
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
DynList< typename GT::Node * > out_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered outcoming arcs of p.
size_t in_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered in degree of node p.
GT::Node * mapped_node(typename GT::Node *p) noexcept
Return the mapped node through the cookie of p
std::tuple< typename GT::Arc *, typename GT::Node * > ArcPair
Alias used for encapsulating a pair of arc and node (related between them).
T foldl_nodes(GT &g, const T &init, Op operation, SN sn=SN())
Fold the filtered nodes of a graph.
void for_each_arc(const GT &g, Op operation, SA sa=SA())
Traverse all the arcs of graph filtering some ones according to a condition and executing an operatio...
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
DynList< typename GT::Arc * > in_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
GT::Arc * search_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Arc filtered searching given two nodes.
T foldl_arcs(GT &g, const T &init, Op operation, SA sa=SA())
Fold the filtered arcs of a graph.
GT::Arc * search_directed_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept
Searching of directed arc linking two nodes.
#define NODE_BITS(p)
Get the control bits of a node.
bool forall_arc(const GT &g, Op cond, SA sa=SA())
Return true if condition cond is met on every filtered arc of the graph.
void for_each_in_arc(typename GT::Node *p, Op op=Op())
Traverse the incoming arcs of a node and executes an operation.
void copy_graph(GT >gt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
void map_nodes(typename GTS::Node *p, typename GTT::Node *q) noexcept
Map two nodes of different types of graphs through their cookies.
DynList< ArcPair< GT > > in_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming pairs of (arc,node) related to node p
Path< GT > find_path_depth_first(const GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Depth-first search of a path between two nodes.
DynList< typename GT::Arc * > out_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
Main namespace for Aleph-w library functions.
auto search_in_arc(typename GT::Node *p, Op op=Op())
Search an incoming arc to a node satisfying a condition op.
DynList< typename GT::Arc * > filter_in_arcs(typename GT::Node *p, Op cond)
Filter the incoming arcs meeting an condition.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
auto map_in_arcs(typename GT::Node *p, Op op)
Map the incoming arcs to a transformation,.
bool all_out_arc(typename GT::Node *p, Op op=Op())
Test if the outcoming arcs meet a condition.
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
T foldl_in_arcs(typename GT::Node *p, const T &init, Op op)
Fold the incoming arcs of a node.
auto map_out_arcs(typename GT::Node *p, Op op)
Map the outcoming arcs to a transformation,.
DynList< typename GT::Arc * > filter_out_arcs(typename GT::Node *p, Op cond)
Filter the outcoming arcs meeting an condition.
auto search_out_arc(typename GT::Node *p, Op op=Op())
Search an outcoming arc to a node satisfying a condition op.
static bool __find_path_depth_first(const GT &g, typename GT::Node *curr_node, typename GT::Arc *curr_arc, typename GT::Node *end_node, Path< GT > &path)
T foldl_out_arcs(typename GT::Node *p, const T &init, Op op)
Fold the outcoming arcs of a node.
bool all_in_arc(typename GT::Node *p, Op op=Op())
Test if the incoming arcs meet a condition.
GT::Arc * mapped_arc(typename GT::Arc *a) noexcept
Return the mapped arc through the cookie of p
bool exists_in_arc(typename GT::Node *p, Op op=Op())
Test if it exists an incoming arc satisfying an operation.
bool exists_out_arc(typename GT::Node *p, Op op=Op())
Test if it exists an outcoming arc satisfying an operation.
bool are_equal(const GT &g1, const GT &g2)
Fast graph comparison.
static std::atomic< bool > init
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Filtered iterator on all the arcs of a graph.
Arc_Iterator()=default
Type of set all the arcs.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
Type of element: Arc*.
Arc_Iterator(const GT &g, Show_Arc sa=Show_Arc())
Constructor,.
Default copy arc functor.
void operator()(typename GTT::Arc *tgt, typename GTS::Arc *src)
Default copy node functor.
void operator()(typename GTT::Node *tgt, typename GTS::Node *src) noexcept
Default filter for filtered iterators on arcs.
void set_cookie(void *) noexcept
bool operator()(typename GT::Arc *) const noexcept
Default filter for the graph nodes.
bool operator()(typename GT::Node *) const noexcept
Arc of graph implemented with double-linked adjacency lists.
Arc_Node * src_arc_node
The type of data stored in the arc.
Graph_Arc(const Graph_Arc &arc)
Graph_Arc(const Arc_Info &info) noexcept
Copy constructor.
Graph_Arc(Arc_Info &&info=Arc_Info()) noexcept
Move or rvalue constructor.
GTArcCommon< _Arc_Info > Base
Graph_Arc & operator=(const Graph_Arc &arc)
Node belonging to a graph implemented with a double linked adjacency list.
GTNodeCommon< __Node_Info > Base
Graph_Node(const Graph_Node &node) noexcept
Graph_Node(Graph_Node *node)
Copy constructor from a node pointer.
Graph_Node(Node_Info &&info=Node_Info()) noexcept
Move or rvalue constructor.
Graph_Node(const Node_Info &info) noexcept
The type of data stored in the node.
Graph_Node & operator=(const Graph_Node &node)
Iterator on all arcs of a graph.
Arc_Iterator()=default
The type of set.
Node * get_tgt_node() const
Return the target node of current arc.
Arc_Iterator(const List_Graph &g) noexcept
Initialize an iterator for all the arc of g
Arc * get_curr_ne() const noexcept
Arc * get_current_arc_ne() const noexcept
Return the current arc. Throw overflow_error if there is no one.
Node * get_src_node_ne() const
Node * get_src_node() const
Return the source node of the current arc.
Node * get_tgt_node_ne() const
Arc * get_current_arc() const
Node_Iterator(const List_Graph &g)
Construct an iterator on the nodes of g
Filtered iterator of adjacent arcs of a node.
Node_Arc_Iterator(typename GT::Node *p, Show_Arc sa=Show_Arc())
Construct and filtered iterator according to condition sa.
Node_Arc_Iterator()=default
Type of set: p's arcs.
typename Itor::Item_Type Item_Type
typename Itor::Set_Type Set_Type
type of element: Arc*
Filter of painter arcs with that are set the Spanning_Tree control bit.
Painted_Min_Spanning_Tree() noexcept
bool operator()(typename GT::Arc *a) noexcept
Distance::Distance_Type dist
Accumulative distance from the first seen arc until the last seen.
Path_Desc(Node *_node=nullptr, Arc *_arc=nullptr) noexcept
bool operator==(const Path_Desc &r) const noexcept
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Common node iterator for graph having its node derived from Dlink class.
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic key-value map based on balanced binary search trees.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Treap with rank (order statistics).
Treap< int >::Node * last_node