Copies of graphs with mapping between nodes and edges. More...
#include <ogdf/basic/GraphCopy.h>
Public Member Functions | |
GraphCopySimple () | |
GraphCopySimple (const Graph &G) | |
GraphCopySimple (const Graph *G) | |
GraphCopySimple (const GraphCopySimple &other) | |
void | clear () override |
Removes all nodes and edges from this copy but does not break the link with the original graph. | |
adjEntry | copy (adjEntry adj) const override |
Returns the adjacency entry in the graph copy corresponding to adj . | |
virtual adjEntry | copy (adjEntry adj) const=0 |
Returns the adjacency entry in the graph copy corresponding to adj . | |
edge | copy (edge e) const override |
Returns the edge in the graph copy corresponding to e . | |
virtual edge | copy (edge e) const=0 |
Returns the edge in the graph copy corresponding to e . | |
node | copy (node v) const |
Returns the node in the graph copy corresponding to v . | |
void | copyEmbeddingToOriginal (Graph &orig) const |
Copies the current embedding back to (a non-const version of) the original graph. | |
void | delEdge (edge e) override |
Removes edge e . | |
edge | newEdge (adjEntry adjSrc, adjEntry adjTgt, Direction dir=Direction::after, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (adjEntry adjSrc, node w, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (edge eOrig) |
Creates a new edge in the graph copy with original edge eOrig . | |
edge | newEdge (node v, adjEntry adjTgt, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (node v, node w, int index=-1) |
Creates a new edge (v ,w ) and returns it. | |
template<typename S , typename T > | |
edge | newEdge (S src, Direction dirSrc, T tgt, Direction dirTgt, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
GraphCopySimple & | operator= (const GraphCopySimple &other) |
void | setOriginalEmbedding () override |
Sets the embedding of the graph copy to the embedding of the original graph. | |
void | setOriginalGraph (const Graph &G) |
Re-initializes the copy using G , but does not create any nodes or edges. | |
void | setOriginalGraph (const Graph *G) override |
Re-initializes the copy using G (which might be null), but does not create any nodes or edges. | |
virtual void | setOriginalGraph (const Graph *G)=0 |
Re-initializes the copy using G (which might be null), but does not create any nodes or edges. | |
![]() | |
GraphCopyBase ()=default | |
Constructs a GraphCopyBase associated with no graph. | |
GraphCopyBase (const GraphCopyBase &other)=delete | |
GraphCopyBase (GraphCopyBase &&other) noexcept=delete | |
node | copy (node v) const |
Returns the node in the graph copy corresponding to v . | |
void | createEmpty (const Graph &G) |
Re-initializes the copy using G , but does not create any nodes or edges. | |
void | delNode (node v) override |
Removes node v . | |
bool | getLinkCopiesOnInsert () const |
const Graph * | getOriginalGraph () const |
void | init (const Graph &G) |
Re-initializes the copy using G , creating copies for all nodes and edges in G . | |
void | init (const Graph *G) |
Re-initializes the copy using G (which might be null), creating copies for all nodes and edges in G . | |
bool | isDummy (adjEntry adj) const |
Returns true iff adj->theEdge() has no corresponding edge in the original graph. | |
bool | isDummy (edge e) const |
Returns true iff e has no corresponding edge in the original graph. | |
bool | isDummy (node v) const |
Returns true iff v has no corresponding node in the original graph. | |
node | newNode (int index=-1) |
Creates a new node and returns it. | |
node | newNode (node vOrig) |
Creates a new node in the graph copy with original node vOrig . | |
GraphCopyBase & | operator= (const GraphCopyBase &other)=delete |
GraphCopyBase & | operator= (GraphCopyBase &&other) noexcept=delete |
const Graph & | original () const |
Returns a reference to the original graph. | |
adjEntry | original (adjEntry adj) const |
Returns the adjacency entry in the original graph corresponding to adj . | |
edge | original (edge e) const |
Returns the edge in the original graph corresponding to e . | |
node | original (node v) const |
Returns the node in the original graph corresponding to v . | |
void | setLinkCopiesOnInsert (bool linkCopiesOnInsert) |
Whether insert(getOriginalGraph()) will automatically set copy and original . | |
void | setOriginalGraph (const Graph &G) |
Re-initializes the copy using G , but does not create any nodes or edges. | |
![]() | |
Graph () | |
Constructs an empty graph. | |
Graph (const Graph ©) | |
Constructs a graph that is a copy of G . | |
Graph (Graph &&move)=delete | |
virtual | ~Graph () |
Destructor. | |
Graph & | operator= (const Graph ©) |
Overwrites this graph to be a copy of G . | |
Graph & | operator= (Graph &&move)=delete |
bool | empty () const |
Returns true iff the graph is empty, i.e., contains no nodes. | |
int | numberOfNodes () const |
Returns the number of nodes in the graph. | |
int | numberOfEdges () const |
Returns the number of edges in the graph. | |
int | maxNodeIndex () const |
Returns the largest used node index. | |
int | maxEdgeIndex () const |
Returns the largest used edge index. | |
int | maxAdjEntryIndex () const |
Returns the largest used adjEntry index. | |
node | firstNode () const |
Returns the first node in the list of all nodes. | |
node | lastNode () const |
Returns the last node in the list of all nodes. | |
edge | firstEdge () const |
Returns the first edge in the list of all edges. | |
edge | lastEdge () const |
Returns the last edge in the list of all edges. | |
node | chooseNode (std::function< bool(node)> includeNode=[](node) { return true;}, bool isFastTest=true) const |
Returns a random node. | |
edge | chooseEdge (std::function< bool(edge)> includeEdge=[](edge) { return true;}, bool isFastTest=true) const |
Returns a random edge. | |
template<class CONTAINER > | |
void | allNodes (CONTAINER &nodeContainer) const |
Returns a container with all nodes of the graph. | |
template<class CONTAINER > | |
void | allEdges (CONTAINER &edgeContainer) const |
Returns a container with all edges of the graph. | |
node | newNode (int index=-1) |
Creates a new node and returns it. | |
edge | newEdge (node v, node w, int index=-1) |
Creates a new edge (v ,w ) and returns it. | |
edge | newEdge (node v, adjEntry adjTgt, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (adjEntry adjSrc, node w, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (adjEntry adjSrc, adjEntry adjTgt, Direction dir=Direction::after, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
template<typename S , typename T > | |
edge | newEdge (S src, Direction dirSrc, T tgt, Direction dirTgt, int index=-1) |
Creates a new edge at predefined positions in the adjacency lists. | |
void | restoreAllEdges () |
Restore all hidden edges and invalidate all HiddenEdgeSets. | |
virtual edge | split (edge e) |
Splits edge e into two edges introducing a new node. | |
void | unsplit (node u) |
Undoes a split operation. | |
virtual void | unsplit (edge eIn, edge eOut) |
Undoes a split operation. | |
node | splitNode (adjEntry adjStartLeft, adjEntry adjStartRight) |
Splits a node while preserving the order of adjacency entries. | |
node | contract (edge e, bool keepSelfLoops=false) |
Contracts edge e while preserving the order of adjacency entries. | |
void | move (edge e, adjEntry adjSrc, Direction dirSrc, adjEntry adjTgt, Direction dirTgt) |
Moves edge e to a different adjacency list. | |
void | moveTarget (edge e, node w) |
Moves the target node of edge e to node w . | |
void | moveTarget (edge e, adjEntry adjTgt, Direction dir) |
Moves the target node of edge e to a specific position in an adjacency list. | |
void | moveSource (edge e, node w) |
Moves the source node of edge e to node w . | |
void | moveSource (edge e, adjEntry adjSrc, Direction dir) |
Moves the source node of edge e to a specific position in an adjacency list. | |
edge | searchEdge (node v, node w, bool directed=false) const |
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w ))). | |
void | reverseEdge (edge e) |
Reverses the edge e , i.e., exchanges source and target node. | |
void | reverseAllEdges () |
Reverses all edges in the graph. | |
template<class NODELIST > | |
void | collapse (NODELIST &nodesToCollapse) |
Collapses all nodes in the list nodesToCollapse to the first node in the list. | |
template<class ADJ_ENTRY_LIST > | |
void | sort (node v, const ADJ_ENTRY_LIST &newOrder) |
Sorts the adjacency list of node v according to newOrder . | |
template<class IT > | |
void | sort (node v, IT begin, IT end) |
Sorts the adjacency list of node v according to the range denoted by two iterators. | |
void | reverseAdjEdges (node v) |
Reverses the adjacency list of v . | |
void | moveAdj (adjEntry adjMove, Direction dir, adjEntry adjPos) |
Moves adjacency entry adjMove before or after adjPos . | |
void | moveAdjAfter (adjEntry adjMove, adjEntry adjAfter) |
Moves adjacency entry adjMove after adjAfter . | |
void | moveAdjBefore (adjEntry adjMove, adjEntry adjBefore) |
Moves adjacency entry adjMove before adjBefore . | |
void | reverseAdjEdges () |
Reverses all adjacency lists. | |
void | swapAdjEdges (adjEntry adj1, adjEntry adj2) |
Exchanges two entries in an adjacency list. | |
int | genus () const |
Returns the genus of the graph's embedding. | |
bool | representsCombEmbedding () const |
Returns true iff the graph represents a combinatorial embedding. | |
void | consistencyCheck () const |
Asserts that this graph is consistent. | |
internal::GraphNodeRegistry & | nodeRegistry () |
Returns a reference to the registry of node arrays associated with this graph. | |
const internal::GraphNodeRegistry & | nodeRegistry () const |
Returns a const reference to the registry of node arrays associated with this graph. | |
operator const internal::GraphNodeRegistry & () const | |
internal::GraphEdgeRegistry & | edgeRegistry () |
Returns a reference to the registry of edge arrays associated with this graph. | |
const internal::GraphEdgeRegistry & | edgeRegistry () const |
Returns a const reference to the registry of edge arrays associated with this graph. | |
operator const internal::GraphEdgeRegistry & () const | |
internal::GraphAdjRegistry & | adjEntryRegistry () |
Returns a reference to the registry of adjEntry arrays associated with this graph. | |
const internal::GraphAdjRegistry & | adjEntryRegistry () const |
Returns a const reference to the registry of adjEntry arrays associated with this graph. | |
operator const internal::GraphAdjRegistry & () const | |
void | resetEdgeIdCount (int maxId) |
Resets the edge id count to maxId . | |
void | resetNodeIdCount (int maxId) |
template<OGDF_NODE_ITER NI, OGDF_EDGE_ITER EI, bool copyEmbedding = true, bool copyIDs = false, bool notifyObservers = true> | |
std::pair< int, int > | insert (const NI &nodesBegin, const NI &nodesEnd, const EI &edgesBegin, const EI &edgesEnd, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given subgraph into this graph. | |
template<OGDF_NODE_ITER NI, OGDF_EDGE_FILTER EF, bool copyIDs = false, bool notifyObservers = true> | |
std::pair< int, int > | insert (const NI &nodesBegin, const NI &nodesEnd, const EF &edgeFilter, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given subgraph into this graph. | |
template<OGDF_NODE_LIST NL> | |
std::pair< int, int > | insert (const NL &nodeList, const EdgeSet &edgeSet, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given subgraph into this graph. | |
template<OGDF_NODE_LIST NL, OGDF_EDGE_LIST EL> | |
std::pair< int, int > | insert (const NL &nodeList, const EL &edgeList, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given subgraph into this graph. | |
std::pair< int, int > | insert (const CCsInfo &info, int cc, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given connected component cc into this graph. | |
std::pair< int, int > | insert (const Graph &G, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap) |
Inserts a copy of a given Graph G into this graph. | |
std::pair< int, int > | insert (const Graph &G) |
Inserts a copy of a given Graph G into this graph. | |
![]() | |
Observable ()=default | |
Observable (const Observable ©)=delete | |
If you want to copy a subclass of Observable, call the default Observable() constructor. | |
Observable (Observable &&move)=delete | |
If you want to move a subclass of Observable, call the default Observable() constructor. | |
virtual | ~Observable () |
Note that all Observers must already be removed once the destructor of this base class is invoked (e.g. | |
Observable & | operator= (const Observable ©)=delete |
Observable & | operator= (Observable &&move)=delete |
Public Attributes | |
EdgeArray< edge > | m_eCopy |
The corresponding edge in the graph copy. | |
![]() | |
internal::GraphObjectContainer< NodeElement > | nodes |
The container containing all node objects. | |
internal::GraphObjectContainer< EdgeElement > | edges |
The container containing all edge objects. | |
Protected Member Functions | |
void | edgeInserted (void *userData, edge original, edge copy) override |
Callback notifying subclasses that insert() copied an edge. | |
![]() | |
void | nodeInserted (void *userData, node original, node copy) override |
Callback notifying subclasses that insert() copied a node. | |
void * | preInsert (bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap, int *newNodes, int *newEdges) override |
Callback notifying subclasses that some graph is about to be insert() -ed. | |
![]() | |
virtual void | postInsert (void *userData, int newNodes, int newEdges) |
Callback notifying subclasses that an insert() call has finished. | |
![]() | |
void | clearObservers () |
const ListPure< GraphObserver * > & | getObservers () const |
ListPure< GraphObserver * >::iterator | registerObserver (GraphObserver *obs) const |
Registers an observer. | |
void | unregisterObserver (typename ListPure< GraphObserver * >::iterator it) const |
Unregisters an observer. | |
Additional Inherited Members | |
![]() | |
enum class | EdgeType { association = 0 , generalization = 1 , dependency = 2 } |
The type of edges (only used in derived classes). More... | |
enum class | NodeType { vertex = 0 , dummy = 1 , generalizationMerger = 2 , generalizationExpander = 3 , highDegreeExpander = 4 , lowDegreeExpander = 5 , associationClass = 6 } |
The type of nodes. More... | |
using | node_iterator = internal::GraphIterator< node > |
Provides a bidirectional iterator to a node in a graph. | |
using | edge_iterator = internal::GraphIterator< edge > |
Provides a bidirectional iterator to an edge in a graph. | |
using | adjEntry_iterator = internal::GraphIterator< adjEntry > |
Provides a bidirectional iterator to an entry in an adjacency list. | |
![]() | |
EdgeArray< edge > | m_eOrig |
The corresponding edge in the original graph. | |
bool | m_linkCopiesOnInsert |
Whether insert(getOriginalGraph()) will set copy and original . | |
const Graph * | m_pGraph = nullptr |
The original graph. | |
NodeArray< node > | m_vCopy |
The corresponding node in the graph copy. | |
NodeArray< node > | m_vOrig |
The corresponding node in the original graph. | |
Copies of graphs with mapping between nodes and edges.
The class GraphCopySimple represents a copy of a graph and maintains a mapping between the nodes and edges of the original graph to the copy and vice versa.
New nodes and edges can be added to the copy; the counterpart of those nodes and edges is 0 indicating that there is no counterpart. This class does not support splitting of edges in such a way that both edges resulting from the split are mapped to the same original edge; this feature is provided by GraphCopy.
Definition at line 260 of file GraphCopy.h.
|
inlineexplicit |
Definition at line 264 of file GraphCopy.h.
|
inlineexplicit |
Definition at line 266 of file GraphCopy.h.
|
inlineexplicit |
Definition at line 268 of file GraphCopy.h.
|
inline |
Definition at line 274 of file GraphCopy.h.
|
overridevirtual |
Removes all nodes and edges from this copy but does not break the link with the original graph.
Implements ogdf::GraphCopyBase.
Returns the adjacency entry in the graph copy corresponding to adj
.
Note that this method does not pay attention to reversed edges. Given a source (target) adjacency entry, the source (target) adjacency entry of the copy edge is returned.
adj | is an adjacency entry in the original graph. |
nullptr
if it doesn't exist. Implements ogdf::GraphCopyBase.
Definition at line 307 of file GraphCopy.h.
Returns the adjacency entry in the graph copy corresponding to adj
.
Has to be defined by the implemented GraphCopyBase subclass.
adj | is an adjacency entry in the original graph. |
nullptr
if it doesn't exist. Implements ogdf::GraphCopyBase.
Returns the edge in the graph copy corresponding to e
.
e | is an edge in the original graph. |
nullptr
if it doesn't exist. Implements ogdf::GraphCopyBase.
Definition at line 294 of file GraphCopy.h.
Returns the edge in the graph copy corresponding to e
.
Has to be defined by the implemented GraphCopyBase subclass.
e | is an edge in the original graph. |
nullptr
if it doesn't exist. Implements ogdf::GraphCopyBase.
Returns the node in the graph copy corresponding to v
.
v | is a node in the original graph. |
nullptr
if it doesn't exist. Definition at line 146 of file GraphCopy.h.
void ogdf::GraphCopySimple::copyEmbeddingToOriginal | ( | Graph & | orig | ) | const |
Copies the current embedding back to (a non-const version of) the original graph.
Currently, this only works correctly if both graphs are still the same.
orig | identical to getOriginalGraph(), but not const |
|
overridevirtual |
|
overrideprotectedvirtual |
Callback notifying subclasses that insert() copied an edge.
userData | value returned from the initial preInsert() call |
original | the original edge |
copy | the created copy |
Reimplemented from ogdf::Graph.
|
inline |
Creates a new edge at predefined positions in the adjacency lists.
Let v be the node whose adjacency list contains adjSrc
, and w the node whose adjacency list contains adjTgt
. Then, the created edge is (v,w).
adjSrc | is the adjacency entry before / after which the new edge is inserted in the adjacency list of v. |
adjTgt | is the adjacency entry before / after which the new edge is inserted in the adjacency list of w. |
dir | specifies if the edge is inserted before or after the given adjacency entries. |
index | is the index that will be assigned to the newly created edge. If negative or not given will use the next free index maxEdgeIndex() . Passing an edge index that is already in use results in an inconsistent data structure. Only specify this parameter if you know what you're doing! |
Creates a new edge at predefined positions in the adjacency lists.
Let v be the node whose adjacency list contains adjSrc
. Then, the created edge is (v,w
).
adjSrc | is the adjacency entry after which the new edge is inserted in the adjacency list of v. |
w | is the target node of the new edge; the edge is added at the end of the adjacency list of w . |
index | is the index that will be assigned to the newly created edge. If negative or not given will use the next free index maxEdgeIndex() . Passing an edge index that is already in use results in an inconsistent data structure. Only specify this parameter if you know what you're doing! |
Creates a new edge in the graph copy with original edge eOrig
.
eOrig
is not the original edge of another edge in the copy. Definition at line 320 of file GraphCopy.h.
Creates a new edge at predefined positions in the adjacency lists.
Let w be the node whose adjacency list contains adjTgt
. Then, the created edge is (v
,w).
v | is the source node of the new edge; the edge is added at the end of the adjacency list of v . |
adjTgt | is the adjacency entry after which the new edge is inserted in the adjacency list of w. |
index | is the index that will be assigned to the newly created edge. If negative or not given will use the next free index maxEdgeIndex() . Passing an edge index that is already in use results in an inconsistent data structure. Only specify this parameter if you know what you're doing! |
Creates a new edge (v
,w
) and returns it.
v | is the source node of the newly created edge. |
w | is the target node of the newly created edge. |
index | is the index that will be assigned to the newly created edge. If negative or not given will use the next free index maxEdgeIndex() . Passing an edge index that is already in use results in an inconsistent data structure. Only specify this parameter if you know what you're doing! |
|
inline |
Creates a new edge at predefined positions in the adjacency lists.
Let v either be the node src
or the node whose adjacency list contains the adjEntry src
, and w either the node tgt
or the node whose adjacency list contains the adjEntry tgt
. Then, the created edge is (v,w).
src | is v or the adjacency entry before / after which the new edge is inserted in the adjacency list of v. |
dirSrc | specifies if the edge is inserted before or after adjSrc . |
tgt | is w or the adjacency entry before / after which the new edge is inserted in the adjacency list of w. |
dirTgt | specifies if the edge is inserted before or after adjTgt . |
index | is the index that will be assigned to the newly created edge. If negative or not given will use the next free index maxEdgeIndex() . Passing an edge index that is already in use results in an inconsistent data structure. Only specify this parameter if you know what you're doing! |
GraphCopySimple & ogdf::GraphCopySimple::operator= | ( | const GraphCopySimple & | other | ) |
|
overridevirtual |
Sets the embedding of the graph copy to the embedding of the original graph.
Edges that have no copy in this graph will be left out, while dummy edges that are not present in the original graph will be moved to the end of their nodes' adjacency lists.
Implements ogdf::GraphCopyBase.
|
inline |
Re-initializes the copy using G
, but does not create any nodes or edges.
Definition at line 96 of file GraphCopy.h.
|
overridevirtual |
Re-initializes the copy using G
(which might be null), but does not create any nodes or edges.
Implements ogdf::GraphCopyBase.
|
virtual |
Re-initializes the copy using G
(which might be null), but does not create any nodes or edges.
Implements ogdf::GraphCopyBase.
The corresponding edge in the graph copy.
Definition at line 262 of file GraphCopy.h.