|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
#include <tpl_graph.H>
Classes | |
| class | Iterator |
| Iterator on nodes and arcs of a path. More... | |
| struct | Path_Desc |
Public Types | |
| using | Node_Type = typename GT::Node_Type |
| The type of data stored in the nodes. | |
| using | Arc_Type = typename GT::Arc_Type |
| The type of data stored in the arc. | |
Public Member Functions | |
| bool | check () const |
Return true if the path is consistent. | |
| bool | check_directed () const |
Return true if the directed path is consistent. | |
| const GT & | get_graph () const noexcept |
| Get a constant reference to the graph. | |
| bool | inside_graph (const GT &gr) const noexcept |
Return true if this is on graph gr | |
| Path (const GT &__g) noexcept | |
Construct a empty path on graph __g | |
| Path () noexcept | |
| void | init (Node *start_node) |
| Set the first node of a path. | |
| Path (const GT &_g, Node *start_node) | |
| Construct a path starting from a given node. | |
| void | set_graph (const GT &__g, Node *start_node=nullptr) |
| Set the graph of the path. | |
| size_t | size () const noexcept |
| Return the path length in nodes. | |
| bool | is_empty () const noexcept |
Return true if the path is empty. | |
| void | empty () |
| Clean the path: all the nodes and arc are removed. | |
| Path (const Path &path) | |
| Copy constructor. | |
| Path (Path &&path) noexcept | |
| Move constructor. | |
| Path & | operator= (const Path &path) |
| Copy assignment. | |
| Path & | operator= (Path &&path) noexcept |
| Move assignment. | |
| void | append (Arc *arc) |
| Append an arc to the path. | |
| void | append (Node *node) |
| Append a node to the path. | |
| void | append_directed (Node *p) |
| Append a node to a directed path. | |
| void | append_directed (Arc *arc) |
| Append an arc to a directed path. | |
| void | insert (Arc *arc) |
| Insert an arc as the first of a path. | |
| void | insert (Node *node) |
| Insert a node to the path. | |
| void | insert_directed (Node *p) |
| Append a node to a directed path. | |
| void | insert_directed (Arc *arc) |
| Append an arc to a directed path. | |
| Node * | get_first_node () const |
Return the first node of path; throws overflow_error if path is empty. | |
| Node * | get_last_node () const |
Return the last node of path; throws overflow_error if path is empty. | |
| Arc * | get_first_arc () const |
Return the first arc of path; throws overflow_error if path is empty. | |
| Arc * | get_last_arc () const |
Return the last arc of a path; throws overflow_error if the path is empty. | |
| bool | is_cycle () const |
Return true if this is a cycle; throws if path is empty. | |
| Node * | remove_last_node () |
| Remove the last node of path. | |
| Node * | remove_first_node () |
| Remove the first node of a path. | |
| void | swap (Path &path) noexcept |
| Fast swap between two paths (constant time) | |
| Iterator | get_it () const |
| Returns an iterator on the path. | |
| template<class Operation > | |
| void | for_each_node (Operation op=Operation()) const |
| Execute an operation on each node of path. | |
| template<class Operation > | |
| void | for_each_arc (Operation op=Operation()) const |
| Execute an operation on each arc of path. | |
| bool | contains_node (Node *node) const noexcept |
Return true if node belongs to the path. | |
| bool | contains_arc (Arc *arc) const noexcept |
Return true if arc belongs to the path. | |
| DynList< Node * > | nodes () const |
| Return a list with the nodes of path (order according to the path) | |
| DynList< Arc * > | arcs () const |
| Return a list with the arcs of a path (order, according to the path) | |
| 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,. | |
Private Types | |
| using | Node = typename GT::Node |
| using | Arc = typename GT::Arc |
Private Member Functions | |
| void | check_graph () |
Private Attributes | |
| const GT * | g = nullptr |
| DynDlist< Path_Desc > | list |
Path on a graph.
Many problems on graphs require dynamic building of partial or complete paths. This class models a path on a graph and it is designed for dynamically and sequentially building the path during graph's traversal.
The paths are built by their ends; that is by inserting or appending. A path is a deque.
Path<GT> operates on both directed and non-directed graphs. However, it is necessary to take some previsions.
If the graph is directed (ListDigraph,List_SGraph or Array_Graph), then the class operates transparently and equivalently than on non-directed graphs.
If for practice circumstances you are treating a non-directed graph as a directed one, for example, because you need to know the incoming arcs, you must advertise to Path class about this fact.
The way that we are designed consists in separating the path construction through specific methods; concretely, the methods insert_directed() and append_directed(). You could observe very extraneous behaviors if you forget this separation.
Definition at line 2668 of file tpl_graph.H.
Definition at line 2681 of file tpl_graph.H.
| using Aleph::Path< GT >::Arc_Type = typename GT::Arc_Type |
The type of data stored in the arc.
Definition at line 2675 of file tpl_graph.H.
Definition at line 2680 of file tpl_graph.H.
| using Aleph::Path< GT >::Node_Type = typename GT::Node_Type |
The type of data stored in the nodes.
Definition at line 2672 of file tpl_graph.H.
Construct a empty path on graph __g
Definition at line 2753 of file tpl_graph.H.
|
inlinenoexcept |
Definition at line 2756 of file tpl_graph.H.
Construct a path starting from a given node.
| [in] | _g | the graph |
| [in] | start_node | pointer to start node of a path |
| bad_alloc | if there is no enough memory |
Definition at line 2779 of file tpl_graph.H.
References Aleph::init, and Aleph::maps().
Copy constructor.
Definition at line 2827 of file tpl_graph.H.
Move constructor.
Definition at line 2830 of file tpl_graph.H.
Append an arc to the path.
This method searches the last node of path and appends it an arc.
The arc must be connected to the last node.
| [in] | arc | pointer to arc |
| bad_alloc | if there is no enough memory |
| invalid_argument | if arc is not linked to the last node of path |
| domain_error | if the graph has not been specified |
| domain_error | if the path is empty |
Definition at line 2865 of file tpl_graph.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::DynList< T >::append(), Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, GraphCommon< GT, Node, Arc >::get_connected_node(), Aleph::DynList< T >::get_last(), Aleph::Path< GT >::list, and Aleph::maps().
Referenced by Aleph::__find_path_depth_first(), Aleph::Path< GT >::append(), Aleph::find_min_path(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::get_min_path(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Append a node to the path.
This method appends node at the end of path. For this, the adjacent arcs of the last node are examined until finding an arc linking node.
If the path is empty, the node becomes its first node.
If the operation is successful, then node becomes the last node of the path.
| [in] | node | pointer to the node to append in the path |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 2898 of file tpl_graph.H.
References ah_invalid_argument_if, Aleph::Path< GT >::append(), Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, Aleph::Path< GT >::get_last_node(), Aleph::init, Aleph::Path< GT >::list, Aleph::maps(), and Aleph::search_arc().
Append an arc to a directed path.
This method appends arc at the end of a directed path. For this, the source node of arc must match the current last node of a directed path.
If the operation is successful, then node becomes the last node of the path.
| [in] | arc | pointer |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 2977 of file tpl_graph.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::DynList< T >::append(), Aleph::Path< GT >::check_graph(), Aleph::DynList< T >::get_last(), Aleph::Path< GT >::list, and Aleph::maps().
Append a node to a directed path.
This method inserts node at the end of a directed path. For this, the outcoming arcs of the last node of path are examined until finding an arc linking node.
If the path is empty, the node becomes its first node.
If the operation is successful, then node becomes the last node of the path.
| [in] | p | node pointer to the node to append in the path |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 2937 of file tpl_graph.H.
References ah_invalid_argument_if, Aleph::DynList< T >::append(), Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, Aleph::DynList< T >::get_last(), Aleph::init, Aleph::Path< GT >::list, Aleph::maps(), and Aleph::search_directed_arc().
Referenced by Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::get_min_path(), TEST_F(), and TEST_F().
Return a list with the arcs of a path (order, according to the path)
Definition at line 3378 of file tpl_graph.H.
References Aleph::DynList< T >::append(), Aleph::Path< GT >::for_each_arc(), and Aleph::maps().
Referenced by TEST_F().
|
inline |
Return true if the path is consistent.
Definition at line 2716 of file tpl_graph.H.
References Aleph::Path< GT >::g, GraphCommon< GT, Node, Arc >::get_connected_node(), Aleph::DynList< T >::get_first(), Aleph::HTList::is_unitarian_or_empty(), l, Aleph::Path< GT >::list, Aleph::maps(), and Aleph::DynList< T >::remove_first().
|
inline |
Return true if the directed path is consistent.
Definition at line 2731 of file tpl_graph.H.
References Aleph::Path< GT >::g, Aleph::DynList< T >::get_last(), GraphCommon< GT, Node, Arc >::get_src_node(), Aleph::Path< GT >::list, and Aleph::maps().
|
inlineprivate |
Definition at line 2709 of file tpl_graph.H.
References ah_domain_error_if, and Aleph::Path< GT >::g.
Referenced by Aleph::Path< GT >::append(), Aleph::Path< GT >::append(), Aleph::Path< GT >::append_directed(), Aleph::Path< GT >::append_directed(), Aleph::Path< GT >::empty(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert_directed(), and Aleph::Path< GT >::insert_directed().
Return true if arc belongs to the path.
Definition at line 3358 of file tpl_graph.H.
References Aleph::Path< GT >::Iterator::has_current_arc().
Referenced by TEST_F().
Return true if node belongs to the path.
Definition at line 3349 of file tpl_graph.H.
References Aleph::Path< GT >::Iterator::has_current_node().
Referenced by TEST_F().
|
inline |
Clean the path: all the nodes and arc are removed.
Definition at line 2819 of file tpl_graph.H.
References Aleph::Path< GT >::check_graph(), Aleph::HTList::is_empty(), Aleph::Path< GT >::list, and Aleph::maps().
Referenced by Aleph::Tarjan_Connected_Components< GT, Itor, SA >::compute_cycle(), Aleph::Find_Path_Breadth_First< GT, Itor, SA >::find_path(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_path(), Aleph::find_path_depth_first(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::get_min_path(), Aleph::Path< GT >::operator=(), and Aleph::Path< GT >::set_graph().
|
inline |
Execute an operation on each arc of path.
| [in] | op | operation |
Definition at line 3342 of file tpl_graph.H.
References Aleph::Path< GT >::Iterator::has_current_arc().
Referenced by Aleph::Path< GT >::arcs(), Aleph::cancel_cycle(), print_path(), and print_path_detailed().
|
inline |
Execute an operation on each node of path.
| [in] | op | operation |
Definition at line 3331 of file tpl_graph.H.
References Aleph::Path< GT >::Iterator::has_current_node().
Referenced by Aleph::Path< GT >::nodes(), print_path(), and print_path_detailed().
|
inline |
Return the first arc of path; throws overflow_error if path is empty.
Definition at line 3141 of file tpl_graph.H.
References Aleph::Path< GT >::list.
|
inline |
Return the first node of path; throws overflow_error if path is empty.
Definition at line 3125 of file tpl_graph.H.
References Aleph::Path< GT >::list.
Referenced by Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert_directed(), Aleph::Path< GT >::is_cycle(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Get a constant reference to the graph.
Definition at line 2741 of file tpl_graph.H.
References Aleph::Path< GT >::g.
Referenced by Aleph::get_min_path().
|
inline |
Returns an iterator on the path.
Definition at line 3321 of file tpl_graph.H.
Referenced by demo_any_path(), and demo_degrees_of_separation().
|
inline |
Return the last arc of a path; throws overflow_error if the path is empty.
Definition at line 3148 of file tpl_graph.H.
References ah_domain_error_if, Aleph::DynDlist< T >::Iterator::get_curr(), Aleph::Path< GT >::list, Aleph::DynDlist< T >::Iterator::prev(), and Aleph::DynDlist< T >::Iterator::reset_last().
|
inline |
Return the last node of path; throws overflow_error if path is empty.
Definition at line 3132 of file tpl_graph.H.
References Aleph::DynList< T >::get_last(), Aleph::Path< GT >::list, and Aleph::maps().
Referenced by Aleph::__find_path_depth_first(), Aleph::Path< GT >::append(), Aleph::Path< GT >::is_cycle(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Set the first node of a path.
| start_node | pointer to start node of a path |
| bad_alloc | if there is no enough memory |
start_node (of course) must belong to the graph. This is not verified Definition at line 2767 of file tpl_graph.H.
References Aleph::Path< GT >::list, and Aleph::maps().
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), and Aleph::get_min_path().
Insert an arc as the first of a path.
This method inserts arc at the beginning of a path. For this, the adjacent arcs of the current first node of the path are examined until find an arc linking node.
If the operation is successful, then node becomes the first node of the path.
| [in] | arc | pointer |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the first node of the path |
| domain_error | if the graph has not been specified |
Definition at line 3008 of file tpl_graph.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, GraphCommon< GT, Node, Arc >::get_connected_node(), Aleph::DynList< T >::get_first(), Aleph::Path< GT >::list, and Aleph::maps().
Referenced by Aleph::Find_Path_Breadth_First< GT, Itor, SA >::find_path(), Aleph::find_path_breadth_first(), TEST_F(), TEST_F(), and TEST_F().
Insert a node to the path.
This method inserts node at the beginning of the path. For this, the adjacent arcs of the last node are examined until finding an arc linking node.
If the operation is successful, then node becomes the first node of the path.
| [in] | node | pointer to the node to insert in the path |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 3039 of file tpl_graph.H.
References ah_domain_error_if, Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, Aleph::Path< GT >::get_first_node(), Aleph::init, Aleph::Path< GT >::list, Aleph::maps(), and Aleph::search_arc().
Append an arc to a directed path.
This method appends arc at the beginning of a directed path. For this, the target node of arc must be the current first node of a directed path.
| [in] | arc | pointer |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 3108 of file tpl_graph.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::Path< GT >::check_graph(), Aleph::DynList< T >::get_first(), Aleph::DynList< T >::insert(), Aleph::Path< GT >::list, and Aleph::maps().
Append a node to a directed path.
This method inserts node at the end of a directed path. For this, the outcoming arcs of the last node of the path are examined until finding an arc linking node.
If the operation is successful, then node becomes the last node of the path.
| [in] | p | node pointer to the node to insert in the path |
| bad_alloc | if there is no enough memory |
| invalid_argument | if node is not reachable from the last node of the path |
| domain_error | if the graph has not been specified |
Definition at line 3075 of file tpl_graph.H.
References ah_domain_error_if, Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::g, Aleph::Path< GT >::get_first_node(), Aleph::init, Aleph::Path< GT >::list, Aleph::maps(), and Aleph::search_directed_arc().
Return true if this is on graph gr
Definition at line 2747 of file tpl_graph.H.
References Aleph::Path< GT >::g, and Aleph::maps().
Referenced by Aleph::Find_Path_Breadth_First< GT, Itor, SA >::find_path(), and TEST().
|
inline |
Return true if this is a cycle; throws if path is empty.
Definition at line 3160 of file tpl_graph.H.
References Aleph::Path< GT >::get_first_node(), and Aleph::Path< GT >::get_last_node().
Referenced by Aleph::cancel_cycle(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Return true if the path is empty.
Definition at line 2813 of file tpl_graph.H.
References Aleph::HTList::is_empty(), and Aleph::Path< GT >::list.
Referenced by Aleph::cancel_cycle(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), and TYPED_TEST().
Return a list with the nodes of path (order according to the path)
Definition at line 3367 of file tpl_graph.H.
References Aleph::DynList< T >::append(), Aleph::Path< GT >::for_each_node(), and Aleph::maps().
Referenced by TEST_F().
|
inlinenoexcept |
Return true if this is not equal to p,.
Definition at line 3404 of file tpl_graph.H.
References Aleph::eq(), and Aleph::maps().
|
inline |
Copy assignment.
Definition at line 2833 of file tpl_graph.H.
References Aleph::Path< GT >::empty(), Aleph::Path< GT >::g, and Aleph::Path< GT >::list.
|
inlinenoexcept |
Move assignment.
Definition at line 2845 of file tpl_graph.H.
References Aleph::Path< GT >::g, and Aleph::Path< GT >::list.
|
inlinenoexcept |
Return true if this is equal to p,.
== must be defined for the data types stored in the nodes and arcs respectively.| [in] | p | path to compare with this |
true if node to node and arc to arc the paths are equal; false otherwise. Definition at line 3398 of file tpl_graph.H.
References Aleph::eq().
|
inline |
Remove the first node of a path.
| overflow_error | if the path is empty |
Definition at line 3182 of file tpl_graph.H.
References Aleph::Path< GT >::list.
Referenced by TEST_F().
|
inline |
Remove the last node of path.
| overflow_error | if path is empty |
Definition at line 3170 of file tpl_graph.H.
References Aleph::Path< GT >::list.
Referenced by Aleph::__find_path_depth_first(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find_path(), and TEST_F().
Set the graph of the path.
Sometimes, by example, if you manage a path attribute inside a class, you do not use the graph, but you need to declare the path. This method is intended to set the graph of a path.
Eventually, if a path is already built, then this one is erased before to set the graph.
| [in] | __g | the graph |
| [in] | start_node | pointer to start node of path |
| bad_alloc | if there is no enough memory |
Definition at line 2797 of file tpl_graph.H.
References Aleph::Path< GT >::empty(), Aleph::Path< GT >::g, Aleph::init, and Aleph::maps().
Referenced by Aleph::Tarjan_Connected_Components< GT, Itor, SA >::compute_cycle(), Aleph::Tarjan_Connected_Components< GT, Itor, SA >::compute_cycle(), Aleph::Find_Path_Depth_First< GT, Itor, SA >::find(), and Aleph::find_min_path().
|
inlinenoexcept |
Return the path length in nodes.
Definition at line 2807 of file tpl_graph.H.
References Aleph::Path< GT >::list, and Aleph::HTList::size().
Referenced by demo_any_path(), demo_degrees_of_separation(), main(), print_path(), print_path_detailed(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TYPED_TEST().
Fast swap between two paths (constant time)
Definition at line 3189 of file tpl_graph.H.
References Aleph::Path< GT >::g, and Aleph::Path< GT >::list.
Definition at line 2678 of file tpl_graph.H.
Referenced by Aleph::Path< GT >::append(), Aleph::Path< GT >::append(), Aleph::Path< GT >::append_directed(), Aleph::Path< GT >::check(), Aleph::Path< GT >::check_directed(), Aleph::Path< GT >::check_graph(), Aleph::Path< GT >::get_graph(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert_directed(), Aleph::Path< GT >::inside_graph(), Aleph::Path< GT >::operator=(), Aleph::Path< GT >::operator=(), Aleph::Path< GT >::set_graph(), and Aleph::Path< GT >::swap().
Definition at line 2707 of file tpl_graph.H.
Referenced by Aleph::Path< GT >::append(), Aleph::Path< GT >::append(), Aleph::Path< GT >::append_directed(), Aleph::Path< GT >::append_directed(), Aleph::Path< GT >::check(), Aleph::Path< GT >::check_directed(), Aleph::Path< GT >::empty(), Aleph::Path< GT >::get_first_arc(), Aleph::Path< GT >::get_first_node(), Aleph::Path< GT >::get_last_arc(), Aleph::Path< GT >::get_last_node(), Aleph::Path< GT >::init(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert(), Aleph::Path< GT >::insert_directed(), Aleph::Path< GT >::insert_directed(), Aleph::Path< GT >::is_empty(), Aleph::Path< GT >::operator=(), Aleph::Path< GT >::operator=(), Aleph::Path< GT >::remove_first_node(), Aleph::Path< GT >::remove_last_node(), Aleph::Path< GT >::size(), and Aleph::Path< GT >::swap().