|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Graph copy with explicit node mapping. More...
#include <tpl_graph.H>
Public Types | |
| using | Node = typename GT::Node |
| using | Arc = typename GT::Arc |
| using | Node_Type = typename GT::Node_Type |
| using | Arc_Type = typename GT::Arc_Type |
Public Member Functions | |
| GraphCopyWithMapping (const GT &src) | |
| Construct a copy of the given graph with node mapping. | |
| GraphCopyWithMapping ()=default | |
| Default constructor. | |
| GraphCopyWithMapping (GraphCopyWithMapping &&other) noexcept=default | |
| Move constructor. | |
| GraphCopyWithMapping & | operator= (GraphCopyWithMapping &&other) noexcept=default |
| Move assignment operator. | |
| GraphCopyWithMapping (const GraphCopyWithMapping &)=delete | |
| GraphCopyWithMapping & | operator= (const GraphCopyWithMapping &)=delete |
| GT & | get_graph () noexcept |
| Get the copied graph. | |
| const GT & | get_graph () const noexcept |
| Get the copied graph (const version). | |
| Node * | get_copy (Node *orig) const |
| Get the copy of an original node. | |
| Node * | search_copy (Node *orig) const noexcept |
| Search for the copy of an original node (no exception). | |
| bool | has_copy (Node *orig) const noexcept |
| Check if an original node is in the mapping. | |
| size_t | num_nodes () const noexcept |
| Get the number of mapped nodes. | |
| size_t | num_arcs () const noexcept |
| Get the number of arcs in the copied graph. | |
| template<typename Op > | |
| void | for_each_mapping (Op op) const |
| Apply a function to each (original, copy) node pair. | |
| Node * | insert_unmapped_node (const Node_Type &info=Node_Type()) |
| Insert a new node into the copied graph (not mapped). | |
| Node * | insert_unmapped_node (Node_Type &&info) |
| Insert a new node into the copied graph (not mapped, move version). | |
| void | remove_node (Node *node) |
| Remove a node from the copied graph. | |
| Arc * | insert_arc (Node *src, Node *tgt, const Arc_Type &info=Arc_Type()) |
| Insert an arc into the copied graph. | |
| void | remove_arc (Arc *arc) |
| Remove an arc from the copied graph. | |
| void | clear () |
| Clear the copied graph and mapping. | |
Private Member Functions | |
| void | build_copy (const GT &src) |
| Build the copy and mapping. | |
Private Attributes | |
| GT | copied_graph |
| DynMapTree< Node *, Node *, Tree > | node_map |
Graph copy with explicit node mapping.
This class creates a copy of a graph and maintains an explicit mapping from original nodes to their copies using a DynMapTree (not cookies).
This is essential for algorithms like Johnson's that need to:
The mapping is unidirectional: original → copy.
| GT | Graph type (List_Graph, List_Digraph, etc.) |
| Tree | Binary search tree type for the mapping (default Treap) |
Definition at line 3880 of file tpl_graph.H.
Definition at line 3884 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Arc_Type = typename GT::Arc_Type |
Definition at line 3886 of file tpl_graph.H.
Definition at line 3883 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Node_Type = typename GT::Node_Type |
Definition at line 3885 of file tpl_graph.H.
|
inlineexplicit |
Construct a copy of the given graph with node mapping.
Creates a deep copy of the source graph and builds a mapping from source nodes to their corresponding copies.
| [in] | src | The source graph to copy. |
| std::bad_alloc | if there is not enough memory. |
Definition at line 3928 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::build_copy().
|
default |
Default constructor.
Creates an empty graph and an empty mapping.
| none |
|
defaultnoexcept |
Move constructor.
Transfers ownership of the graph and mapping from another instance.
| [in,out] | other | The instance to move from. |
| none |
|
delete |
Build the copy and mapping.
Definition at line 3893 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Dlink::insert(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), Aleph::maps(), and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
Referenced by Aleph::GraphCopyWithMapping< GT, Tree >::GraphCopyWithMapping().
|
inline |
Clear the copied graph and mapping.
Removes all nodes and arcs from the copied graph and clears the mapping.
| none |
Definition at line 4175 of file tpl_graph.H.
References Aleph::clear_graph(), Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
inline |
Apply a function to each (original, copy) node pair.
Iterates over all mappings and applies the given function.
| Op | Function type taking (Node* original, Node* copy). |
| [in] | op | Function to apply. |
| whatever | op throws. |
Definition at line 4070 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
inline |
Get the copy of an original node.
Retrieves the node in the copied graph that corresponds to the given node in the original graph.
| [in] | orig | Pointer to the original node. |
| std::domain_error | if the node is not in the mapping. |
Definition at line 4003 of file tpl_graph.H.
References ah_domain_error_if, Aleph::maps(), and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
inlinenoexcept |
Get the copied graph (const version).
| none |
Definition at line 3990 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph.
|
inlinenoexcept |
Get the copied graph.
| none |
Definition at line 3981 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph.
|
inlinenoexcept |
Check if an original node is in the mapping.
| [in] | orig | Pointer to the original node. |
| none |
Definition at line 4036 of file tpl_graph.H.
References Aleph::maps(), and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
inline |
Insert an arc into the copied graph.
| [in] | src | Source node (in the copy). |
| [in] | tgt | Target node (in the copy). |
| [in] | info | Arc information. |
| std::bad_alloc | if memory allocation fails. |
Definition at line 4150 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), and Aleph::maps().
|
inline |
Insert a new node into the copied graph (not mapped).
Useful for adding auxiliary nodes (like dummy nodes in Johnson's algorithm) that don't correspond to any original node.
| [in] | info | Node information. |
| std::bad_alloc | if memory allocation fails. |
Definition at line 4089 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().
|
inline |
Insert a new node into the copied graph (not mapped, move version).
Useful for adding auxiliary nodes (like dummy nodes in Johnson's algorithm) that don't correspond to any original node.
| [in] | info | Node information (moved). |
| std::bad_alloc | if memory allocation fails. |
Definition at line 4105 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().
|
inlinenoexcept |
Get the number of arcs in the copied graph.
| none |
Definition at line 4057 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and GraphCommon< GT, Node, Arc >::get_num_arcs().
|
inlinenoexcept |
Get the number of mapped nodes.
| none |
Definition at line 4048 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::node_map, and Aleph::HTList::size().
|
delete |
|
defaultnoexcept |
Move assignment operator.
Transfers ownership of the graph and mapping from another instance.
| [in,out] | other | The instance to move from. |
| none |
|
inline |
Remove an arc from the copied graph.
| [in] | arc | Pointer to the arc to remove. |
| none |
Definition at line 4162 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and Aleph::List_Graph< _Graph_Node, _Graph_Arc >::remove_arc().
|
inline |
Remove a node from the copied graph.
If the node was mapped, the mapping entry is removed to keep the mapping consistent.
| [in] | node | Pointer to the node to remove. |
| Any | exception thrown by the underlying mapping or graph removal operations. |
Definition at line 4120 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, FunctionalMethods< Container, T >::for_each(), Aleph::maps(), Aleph::GraphCopyWithMapping< GT, Tree >::node_map, and Aleph::List_Graph< _Graph_Node, _Graph_Arc >::remove_node().
|
inlinenoexcept |
Search for the copy of an original node (no exception).
Retrieves the node in the copied graph that corresponds to the given node in the original graph, or nullptr if not found.
| [in] | orig | Pointer to the original node. |
| none |
Definition at line 4022 of file tpl_graph.H.
References Aleph::maps(), and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
private |
Definition at line 3889 of file tpl_graph.H.
Referenced by Aleph::GraphCopyWithMapping< GT, Tree >::build_copy(), Aleph::GraphCopyWithMapping< GT, Tree >::clear(), Aleph::GraphCopyWithMapping< GT, Tree >::get_graph(), Aleph::GraphCopyWithMapping< GT, Tree >::get_graph(), Aleph::GraphCopyWithMapping< GT, Tree >::insert_arc(), Aleph::GraphCopyWithMapping< GT, Tree >::insert_unmapped_node(), Aleph::GraphCopyWithMapping< GT, Tree >::insert_unmapped_node(), Aleph::GraphCopyWithMapping< GT, Tree >::num_arcs(), Aleph::GraphCopyWithMapping< GT, Tree >::remove_arc(), and Aleph::GraphCopyWithMapping< GT, Tree >::remove_node().
|
private |
Definition at line 3890 of file tpl_graph.H.
Referenced by Aleph::GraphCopyWithMapping< GT, Tree >::build_copy(), Aleph::GraphCopyWithMapping< GT, Tree >::clear(), Aleph::GraphCopyWithMapping< GT, Tree >::for_each_mapping(), Aleph::GraphCopyWithMapping< GT, Tree >::get_copy(), Aleph::GraphCopyWithMapping< GT, Tree >::has_copy(), Aleph::GraphCopyWithMapping< GT, Tree >::num_nodes(), Aleph::GraphCopyWithMapping< GT, Tree >::remove_node(), and Aleph::GraphCopyWithMapping< GT, Tree >::search_copy().