Data type for general directed graphs (adjacency list representation). More...
#include <ogdf/basic/Graph_d.h>
Classes | |
class | CCsInfo |
Info structure for maintaining connected components. More... | |
class | HiddenEdgeSet |
Functionality for temporarily hiding edges in constant time. More... | |
Public Types | |
Enumerations | |
These enumerations are mainly meant for advanced or internal usage scenarios. | |
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... | |
Iterators | |
These types are used for graph object iterators, which are returned by graph object containers like nodes and edges. | |
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. | |
Public Member Functions | |
Graph () | |
Constructs an empty graph. | |
Graph (const Graph &G) | |
Constructs a graph that is a copy of G . | |
virtual | ~Graph () |
Destructor. | |
Access methods | |
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. | |
int | nodeArrayTableSize () const |
Returns the table size of node arrays associated with this graph. | |
int | edgeArrayTableSize () const |
Returns the table size of edge arrays associated with this graph. | |
int | adjEntryArrayTableSize () const |
Returns the table size of adjEntry arrays associated with this graph. | |
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. | |
Creation of new nodes and edges | |
node | newNode () |
Creates a new node and returns it. | |
node | newNode (int index) |
Creates a new node with predefined index and returns it. | |
edge | newEdge (node v, node w) |
Creates a new edge (v ,w ) and returns it. | |
edge | newEdge (node v, node w, int index) |
Creates a new edge (v ,w ) with predefined index and returns it. | |
edge | newEdge (adjEntry adjSrc, adjEntry adjTgt, Direction dir=Direction::after) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (node v, adjEntry adjTgt) |
Creates a new edge at predefined positions in the adjacency lists. | |
edge | newEdge (adjEntry adjSrc, node w) |
Creates a new edge at predefined positions in the adjacency lists. | |
Removing nodes and edges | |
virtual void | delNode (node v) |
Removes node v and all incident edges from the graph. | |
virtual void | delEdge (edge e) |
Removes edge e from the graph. | |
virtual void | clear () |
Removes all nodes and all edges from the graph. | |
Advanced modification methods | |
void | insert (const Graph &G, NodeArray< node > &nodeMap) |
Inserts Graph G as a subgraph into this Graph. | |
void | insert (const Graph &G) |
Inserts Graph G as a subgraph into this Graph. | |
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 . | |
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. | |
Miscellaneous | |
int | genus () const |
Returns the genus of the graph's embedding. | |
bool | representsCombEmbedding () const |
Returns true iff the graph represents a combinatorial embedding. | |
Registering arrays and observers | |
ListIterator< NodeArrayBase * > | registerArray (NodeArrayBase *pNodeArray) const |
Registers a node array. | |
ListIterator< EdgeArrayBase * > | registerArray (EdgeArrayBase *pEdgeArray) const |
Registers an edge array. | |
ListIterator< AdjEntryArrayBase * > | registerArray (AdjEntryArrayBase *pAdjArray) const |
Registers an adjEntry array. | |
ListIterator< GraphObserver * > | registerStructure (GraphObserver *pStructure) const |
Registers a graph observer (e.g. a ClusterGraph). | |
void | unregisterArray (ListIterator< NodeArrayBase * > it) const |
Unregisters a node array. | |
void | unregisterArray (ListIterator< EdgeArrayBase * > it) const |
Unregisters an edge array. | |
void | unregisterArray (ListIterator< AdjEntryArrayBase * > it) const |
Unregisters an adjEntry array. | |
void | unregisterStructure (ListIterator< GraphObserver * > it) const |
Unregisters a graph observer. | |
template<class ArrayBase > | |
void | moveRegisterArray (ListIterator< ArrayBase * > it, ArrayBase *pArray) const |
Move the registration it of an graph element array to pArray (used with move semantics for graph element arrays). | |
void | resetEdgeIdCount (int maxId) |
Resets the edge id count to maxId . | |
Operators | |
Graph & | operator= (const Graph &G) |
Assignment operator. | |
Public Attributes | |
Graph object containers | |
These containers maintain the nodes and edges of the graph, and provide node and edge iterators. | |
internal::GraphObjectContainer< NodeElement > | nodes |
The container containing all node objects. | |
internal::GraphObjectContainer< EdgeElement > | edges |
The container containing all edge objects. | |
Protected Member Functions | |
void | assign (const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
void | construct (const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
void | constructInitByActiveNodes (const List< node > &nodeList, const NodeArray< bool > &activeNodes, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
void | constructInitByCC (const CCsInfo &info, int cc, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
Constructs a copy of connected component cc in info . | |
void | constructInitByNodes (const Graph &G, const List< node > &nodeList, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
Constructs a copy of the subgraph of G induced by nodeList . | |
Private Member Functions | |
void | copy (const Graph &G) |
void | copy (const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge) |
edge | createEdgeElement (node v, node w, adjEntry adjSrc, adjEntry adjTgt) |
void | moveAdj (adjEntry adj, node w) |
node | pureNewNode () |
void | reinitArrays (bool doResetTableSizes=true) |
Re-initializes registed arrays with respect to the current sizes. Calls resetTableSizes() if doResetTableSizes is true (default). | |
void | resetAdjEntryIndex (int newIndex, int oldIndex) |
void | resetTableSizes () |
Sets the sizes of registered node and edge arrays to the next power of two that is no less than the current id counts. Respects the minimum table size constants. | |
void | restoreAllEdges () |
Used to restore all hidden edges upon deleting the graph. | |
Private Attributes | |
int | m_edgeArrayTableSize |
The current table size of edge arrays associated with this graph. | |
int | m_edgeIdCount |
The Index that will be assigned to the next created edge. | |
List< HiddenEdgeSet * > | m_hiddenEdgeSets |
The list of hidden edges. | |
std::mutex | m_mutexRegArrays |
The critical section for protecting shared acces to register/unregister methods. | |
int | m_nodeArrayTableSize |
The current table size of node arrays associated with this graph. | |
int | m_nodeIdCount |
The Index that will be assigned to the next created node. | |
ListPure< AdjEntryArrayBase * > | m_regAdjArrays |
The registered adjEntry arrays. | |
ListPure< EdgeArrayBase * > | m_regEdgeArrays |
The registered edge arrays. | |
ListPure< NodeArrayBase * > | m_regNodeArrays |
The registered node arrays. | |
ListPure< GraphObserver * > | m_regStructures |
The registered graph structures. | |
Data type for general directed graphs (adjacency list representation).
The class Graph allows shared access of threads to const methods only. If one thread executes a non-const method, shared access is no longer thread-safe.
You may iterate over the nodes and edges of a graph using C++11 range-based for loops. Find some examples below.
Iterate over all nodes v of graph G using c++11 syntax :
Iterate over all nodes v of graph G :
Iterate over all edges e of graph G using c++11 syntax :
|
strong |
|
strong |
ogdf::Graph::Graph | ( | ) |
Constructs an empty graph.
Constructs a graph that is a copy of G
.
The constructor assures that the adjacency lists of nodes in the constructed graph are in the same order as the adjacency lists in G
. This is in particular important when dealing with embedded graphs.
G | is the graph that will be copied. |
|
virtual |
Destructor.
|
inline |
|
protected |
Removes all nodes and all edges from the graph.
Reimplemented in ogdf::GraphCopy.
Collapses all nodes in the list nodesToCollapse
to the first node in the list.
Parallel edges are removed.
NODELIST | is the type of input node list. |
nodesToCollapse | is the list of nodes that will be collapsed. This list will be empty after the call. |
|
protected |
|
protected |
|
protected |
Constructs a copy of connected component cc
in info
.
|
protected |
Constructs a copy of the subgraph of G
induced by nodeList
.
This method preserves the order in the adjacency lists, i.e., if G
is embedded, its embedding induces the embedding of the copy.
Contracts edge e
while preserving the order of adjacency entries.
e | is the edge to be contracted. |
keepSelfLoops | determines whether edges parallel to e will result in self-loops or not (in the latter case, they will also be contracted). |
e
to which all edges have been moved. The implementation ensures this to be the source of the former edge e
.
|
private |
Removes edge e
from the graph.
Reimplemented in ogdf::GraphCopySimple, ogdf::GraphCopy, and ogdf::PlanRepExpansion.
Removes node v
and all incident edges from the graph.
Reimplemented in ogdf::GraphCopySimple, and ogdf::GraphCopy.
|
inline |
|
inline |
|
inline |
|
inline |
int ogdf::Graph::genus | ( | ) | const |
Returns the genus of the graph's embedding.
The genus of a graph is defined as follows. Let G be a graph with m edges, n nodes, nz isolated vertices, fc face cycles, and c connected components. Then,
\[ genus(G) = (m - n - nz - fc + 2c)/2 \]
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void ogdf::Graph::move | ( | edge | e, |
adjEntry | adjSrc, | ||
Direction | dirSrc, | ||
adjEntry | adjTgt, | ||
Direction | dirTgt | ||
) |
Moves edge e
to a different adjacency list.
The source adjacency entry of e
is moved to the adjacency list containing adjSrc
and is inserted before or after adjSrc
, and its target adjacency entry to the adjacency list containing adjTgt
and is inserted before or after adjTgt
; e
is afterwards an edge from owner(adjSrc
) to owner(adjTgt
).
e | is the edge to be moved. |
adjSrc | is the adjaceny entry before or after which the source adjacency entry of e will be inserted. |
dirSrc | specifies if the source adjacency entry of e will be inserted before or after adjSrc . |
adjTgt | is the adjaceny entry before or after which the target adjacency entry of e will be inserted. |
dirTgt | specifies if the target adjacency entry of e will be inserted before or after adjTgt . |
Moves adjacency entry adjMove
before or after adjPos
.
adjMove
and adjAfter are distinct entries in the same adjacency list.adjMove | is an entry in the adjacency list of a node in this graph. |
adjPos | is an entry in the same adjacency list as adjMove . |
dir | specifies if adjMove is moved before or after adjPos . |
Moves adjacency entry adjMove
after adjAfter
.
adjMove
and adjAfter
are distinct entries in the same adjacency list.adjMove | is an entry in the adjacency list of a node in this graph. |
adjAfter | is an entry in the same adjacency list as adjMove . |
Moves adjacency entry adjMove
before adjBefore
.
adjMove
and adjBefore
are distinct entries in the same adjacency list.adjMove | is an entry in the adjacency list of a node in this graph. |
adjBefore | is an entry in the same adjacency list as adjMove . |
|
inline |
Moves the source node of edge e
to a specific position in an adjacency list.
Let w be the node containing adjSrc
. If e=
(v,u) before, then e=(w,u) afterwards. Inserts the adjacency entry before or after adjSrc
according to dir
.
e | is the edge whose source node is moved. |
adjSrc | is the adjacency entry before or after which the source adjacency entry of e is inserted. |
dir | specifies if the source adjacency entry of e is inserted before or after adjSrc . |
Moves the source node of edge e
to node w
.
If e=
(v,u) before, then e=
(w
,u) afterwards.
e | is the edge whose source node is moved. |
w | is the new source node of e . |
Moves the target node of edge e
to a specific position in an adjacency list.
Let w be the node containing adjTgt
. If e=
(v,u) before, then e=(v,w) afterwards. Inserts the adjacency entry before or after adjTgt
according to dir
.
e | is the edge whose target node is moved. |
adjTgt | is the adjacency entry before or after which the target adjacency entry of e is inserted. |
dir | specifies if the target adjacency entry of e is inserted before or after adjTgt . |
Moves the target node of edge e
to node w
.
If e=
(v,u) before, then e=
(v,w
) afterwards.
e | is the edge whose target node is moved. |
w | is the new target node of e . |
edge ogdf::Graph::newEdge | ( | adjEntry | adjSrc, |
adjEntry | adjTgt, | ||
Direction | dir = Direction::after |
||
) |
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 after which the new edge is inserted in the adjacency list of v. |
adjTgt | is the adjacency entry 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. |
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 source node of the new edge; the edge is added at the end of the adjacency list of w . |
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. |
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. |
Creates a new edge (v
,w
) with predefined index and returns it.
index
is currently not the index of any other edge in the graph.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. |
node ogdf::Graph::newNode | ( | ) |
Creates a new node and returns it.
Creates a new node with predefined index and returns it.
index
is currently not the index of any other node in the graph.index | is the index that will be assigned to the newly created node. |
|
inline |
|
inline |
|
inline |
Assignment operator.
The assignment operature assures that the adjacency lists of nodes in the constructed graph are in the same order as the adjacency lists in G
. This is in particular important when dealing with embedded graphs.
G | is the graph to be copied. |
|
private |
ListIterator< AdjEntryArrayBase * > ogdf::Graph::registerArray | ( | AdjEntryArrayBase * | pAdjArray | ) | const |
Registers an adjEntry array.
pAdjArray | is a pointer to the adjacency entry array's base; this adjacency entry array must be associated with this graph. |
ListIterator< EdgeArrayBase * > ogdf::Graph::registerArray | ( | EdgeArrayBase * | pEdgeArray | ) | const |
Registers an edge array.
pEdgeArray | is a pointer to the edge array's base; this edge array must be associated with this graph. |
ListIterator< NodeArrayBase * > ogdf::Graph::registerArray | ( | NodeArrayBase * | pNodeArray | ) | const |
Registers a node array.
pNodeArray | is a pointer to the node array's base; this node array must be associated with this graph. |
ListIterator< GraphObserver * > ogdf::Graph::registerStructure | ( | GraphObserver * | pStructure | ) | const |
Registers a graph observer (e.g. a ClusterGraph).
pStructure | is a pointer to the graph observer that shall be registered; this graph observer must be associated with this graph. |
Re-initializes registed arrays with respect to the current sizes. Calls resetTableSizes() if doResetTableSizes
is true
(default).
|
inline |
Resets the edge id count to maxId
.
The next edge will get edge id maxId
+1. Use this function with caution! It is provided as an efficient way to reduce the edge id count. The Graph class increments the edge id count whenever an edge is created; free edge ids resulting from removing edges are not reused (there is not something like a freelist).
This function is , e.g., useful, when a lot of edges has been added and all these edges are removed again (without creating other new edges meanwile). Then, it is safe to reduce the edge id count to the value it had before, cf. the following code snippet:
Reducing the edge id count will reduce the memory consumption of edge arrays associated with the graph.
maxId
<= maximal edge id in the graph.maxId | is an upper bound of the edge ids in the graph. |
|
private |
Sets the sizes of registered node and edge arrays to the next power of two that is no less than the current id counts. Respects the minimum table size constants.
|
private |
Used to restore all hidden edges upon deleting the graph.
void ogdf::Graph::reverseAdjEdges | ( | ) |
Reverses all adjacency lists.
void ogdf::Graph::reverseAllEdges | ( | ) |
Reverses all edges in the graph.
Reverses the edge e
, i.e., exchanges source and target node.
Searches and returns an edge connecting nodes v
and w
in time O( min(deg(v
), deg(w
))).
v | is the first endpoint of the edge to be searched. |
w | is the second endpoint of the edge to be searched. |
directed | iff set to true, enforces that v must be the source node and w the target node of the edge. |
v
,w
) (or (w
,v
) for !directed
) if such an edge exists, nullptr otherwise.
|
inline |
Sorts the adjacency list of node v
according to newOrder
.
newOrder
contains exactly the adjacency entries of v!
ADJ_ENTRY_LIST | is the type of the input adjacency entry list. |
v | is the node whose adjacency list will be sorted. |
newOrder | is the list of adjacency entries of v in the new order. |
Splits edge e
into two edges introducing a new node.
Let e=
(v,w). Then, the resulting two edges are e=(v,u) and e'=(u,w), where u is a new node.
e
is modified by this operation.e | is the edge to be split. |
Reimplemented in ogdf::GraphCopy, ogdf::ClusterPlanRep, ogdf::PlanRep, ogdf::PlanRepExpansion, ogdf::PlanRepInc, and ogdf::PlanRepUML.
Splits a node while preserving the order of adjacency entries.
This method splits a node v into two nodes vl and vr. Node vl receives all adjacent edges of v from adjStartLeft
until the edge preceding adjStartRight
, and vr the remaining nodes (thus adjStartRight
is the first edge that goes to vr). The order of adjacency entries is preserved. Additionally, a new edge (vl,vr) is created, such that this edge is inserted before adjStartLeft
and adjStartRight
in the adjacency lists of vl and vr.
When adjStartLeft
and adjStartRight
are the same, vl receives all edges and the edge (vl, vr) is inserted before adjStartLeft
in the adjacency list of vl.
Node v is modified to become node vl, and node vr is returned. This method is useful when modifying combinatorial embeddings.
adjStartLeft | is the first entry that goes to the left node. |
adjStartRight | is the first entry that goes to the right node. |
void ogdf::Graph::unregisterArray | ( | ListIterator< AdjEntryArrayBase * > | it | ) | const |
Unregisters an adjEntry array.
it | is an iterator pointing to the entry in the list of registered adjacency entry arrays for the adjacency entry array to be unregistered. |
void ogdf::Graph::unregisterArray | ( | ListIterator< EdgeArrayBase * > | it | ) | const |
Unregisters an edge array.
it | is an iterator pointing to the entry in the list of registered edge arrays for the edge array to be unregistered. |
void ogdf::Graph::unregisterArray | ( | ListIterator< NodeArrayBase * > | it | ) | const |
Unregisters a node array.
it | is an iterator pointing to the entry in the list of registered node arrays for the node array to be unregistered. |
void ogdf::Graph::unregisterStructure | ( | ListIterator< GraphObserver * > | it | ) | const |
Unregisters a graph observer.
it | is an iterator pointing to the entry in the list of registered graph observers for the graph observer to be unregistered. |
Undoes a split operation.
For two edges eIn
= (x,u) and eOut
= (u,y), removes node u by joining eIn
and eOut
. Edge eOut
is removed and eIn
is reused.
eIn
and eOut
are the only edges incident with u and none of them is a self-loop.eIn | is the (only) incoming edge of u. |
eOut | is the (only) outgoing edge of u. |
Reimplemented in ogdf::GraphCopy, and ogdf::PlanRepExpansion.
Undoes a split operation.
Removes node u
by joining the two edges adjacent to u
. The outgoing edge of u
is removed and the incoming edge is reused
u
has exactly one incoming and one outgoing edge, and none of them is a self-loop.u | is the node to be unsplit. |
internal::GraphObjectContainer<EdgeElement> ogdf::Graph::edges |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
internal::GraphObjectContainer<NodeElement> ogdf::Graph::nodes |