|
Aleph-w 7.10.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 5145 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Arc = typename GT::Arc |
Definition at line 5149 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Arc_Type = typename GT::Arc_Type |
Definition at line 5151 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Node = typename GT::Node |
Definition at line 5148 of file tpl_graph.H.
| using Aleph::GraphCopyWithMapping< GT, Tree >::Node_Type = typename GT::Node_Type |
Definition at line 5150 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 5193 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 |
|
inlineprivate |
Build the copy and mapping.
Definition at line 5158 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::Filter_Iterator< Container, It, Show_Item >::next_ne(), 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 5440 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 5335 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 5268 of file tpl_graph.H.
References ah_domain_error_if, and Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
inlinenoexcept |
Get the copied graph (const version).
| none |
Definition at line 5255 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph.
|
inlinenoexcept |
Get the copied graph.
| none |
Definition at line 5246 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 5301 of file tpl_graph.H.
References 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 5415 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc().
|
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 5354 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node().
|
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 5370 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, and Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node().
|
inlinenoexcept |
Get the number of arcs in the copied graph.
| none |
Definition at line 5322 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 5313 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
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 5427 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 5385 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::copied_graph, 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 5287 of file tpl_graph.H.
References Aleph::GraphCopyWithMapping< GT, Tree >::node_map.
|
private |
Definition at line 5154 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 5155 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().