AvogadroLibs 1.97.0
Public Member Functions | List of all members
Graph Class Reference

The Graph class represents a graph data structure. More...

#include <avogadro/core/graph.h>

Public Member Functions

 Graph ()
 
 Graph (size_t n)
 
 ~Graph ()
 
void setSize (size_t n)
 
size_t size () const
 
bool isEmpty () const
 
void clear ()
 
size_t addVertex ()
 
void removeVertex (size_t index)
 
void swapVertexIndices (size_t a, size_t b)
 
size_t vertexCount () const
 
size_t addEdge (size_t a, size_t b)
 
void removeEdge (size_t a, size_t b)
 
void removeEdge (size_t edgeIndex)
 
void removeEdges ()
 
void removeEdges (size_t index)
 
void editEdgeInPlace (size_t edgeIndex, size_t a, size_t b)
 
void swapEdgeIndices (size_t edgeIndex1, size_t edgeIndex2)
 
size_t edgeCount () const
 
std::vector< size_t > neighbors (size_t index) const
 
std::vector< size_t > edges (size_t index) const
 
std::pair< size_t, size_t > endpoints (size_t edgeIndex) const
 
size_t degree (size_t index) const
 
bool containsEdge (size_t a, size_t b) const
 
const Array< std::pair< size_t, size_t > > & edgePairs () const
 
std::vector< std::set< size_t > > connectedComponents () const
 
std::set< size_t > connectedComponent (size_t index) const
 
size_t subgraphsCount () const
 
size_t subgraph (size_t index) const
 
size_t subgraphCount (size_t index) const
 
size_t getConnectedID (size_t index) const
 

Detailed Description

A graph consists of vertices and edges, wherein every edge connects two vertices. Each vertex is assigned an index, starting from 0 up to size() - 1. Each edge is also assigned an index, from 0 to edgeCount() - 1.

Constructor & Destructor Documentation

◆ Graph() [1/2]

Graph ( )

Creates a new, empty graph.

◆ Graph() [2/2]

Graph ( size_t  n)
explicit

Creates a new graph containing size n vertices.

◆ ~Graph()

~Graph ( )

Destroys the graph.

Member Function Documentation

◆ setSize()

void setSize ( size_t  n)

Sets the number of vertices in the graph to size n.

If n is smaller than size(), this removes all vertices with index n or higher, as well as any edges connected to them, while preserving all other vertices and edges. These vertices keep their existing indices, while no guarantee is made regarding preserved edge indices.

If n is larger than size(), a number of unconnected vertices are added, up to the requested size. All existing vertices and edges are preserved in their current form.

◆ size()

size_t size ( ) const
Returns
the number of vertices in the graph.

◆ isEmpty()

bool isEmpty ( ) const
Returns
true if the graph is empty (i.e. size() == 0).

◆ clear()

void clear ( )

Removes all vertices and edges from the graph.

◆ addVertex()

size_t addVertex ( )

Adds a vertex to the graph and returns its index. The new vertex is initially not connected. All existing vertices and edges are preserved and their indices unchanged.

◆ removeVertex()

void removeVertex ( size_t  index)

Removes the vertex at index from the graph, as well as all edges to it. If index is not the highest vertex index in the graph, the vertex with highest index will be assigned the index of the removed vertex. All other vertices will keep their indices. No guarantees are made regarding edge indices.

◆ swapVertexIndices()

void swapVertexIndices ( size_t  a,
size_t  b 
)

Swaps two vertices' indices, without affecting connectivity. All other vertices and all edges keep their existing indices.

◆ vertexCount()

size_t vertexCount ( ) const
Returns
the number of vertices in the graph.

◆ addEdge()

size_t addEdge ( size_t  a,
size_t  b 
)

Adds an edge between vertices a and b and returns its index. All existing vertices and edges are preserved unchanged.

◆ removeEdge() [1/2]

void removeEdge ( size_t  a,
size_t  b 
)

Removes the edge between vertices a and b. All vertices keep their indices. If the removed edge has an index lower than the highest edge index in the graph, the edge with the highest index is given the index of the removed edge. All other edges remain unchanged.

◆ removeEdge() [2/2]

void removeEdge ( size_t  edgeIndex)

Removes edge with index edgeIndex. All vertices keep their indices. If edgeIndex is lower than the highest edge index in the graph, the edge with the highest index is given the index of the removed edge. All other edges remain unchanged.

◆ removeEdges() [1/2]

void removeEdges ( )

Removes all of the edges from the graph, without affecting vertices.

◆ removeEdges() [2/2]

void removeEdges ( size_t  index)

Removes all of the edges that contain the vertex at index from the graph.

◆ editEdgeInPlace()

void editEdgeInPlace ( size_t  edgeIndex,
size_t  a,
size_t  b 
)

Removes the edge at edgeIndex, and creates a new one between vertices a and b, with the same index as the removed edge. All other edges and vertices keep their current indices.

◆ swapEdgeIndices()

void swapEdgeIndices ( size_t  edgeIndex1,
size_t  edgeIndex2 
)

Swaps two edges' indices, without affecting connectivity. All other edges and all vertices keep their current indices.

◆ edgeCount()

size_t edgeCount ( ) const
Returns
the number of edges in the graph.

◆ neighbors()

std::vector< size_t > neighbors ( size_t  index) const
Returns
a vector containing the indices of each vertex that the vertex at index shares an edge with.

◆ edges()

std::vector< size_t > edges ( size_t  index) const
Returns
a vector containing the indices of each edge that the vertex at index is an endpoint of; that is, the edges incident at it.

◆ endpoints()

std::pair< size_t, size_t > endpoints ( size_t  edgeIndex) const
Returns
the indices of the two vertices that the edge at index connects; that is, its endpoints.

◆ degree()

size_t degree ( size_t  index) const
Returns
the degree of the vertex at index.

◆ containsEdge()

bool containsEdge ( size_t  a,
size_t  b 
) const
Returns
true if the graph contains an edge between vertices a and b.

◆ edgePairs()

const Array< std::pair< size_t, size_t > > & edgePairs ( ) const
Returns
an array with all edges, where every element contains the indices of both endpoints of the edge with index equal to the element's array index.

◆ connectedComponents()

std::vector< std::set< size_t > > connectedComponents ( ) const
Returns
a vector of vector containing the indices of each vertex in each connected component in the graph.

◆ connectedComponent()

std::set< size_t > connectedComponent ( size_t  index) const
Returns
a set containing the indices of each vertex connected with index.

◆ subgraphsCount()

size_t subgraphsCount ( ) const
Returns
the number of connected subgraphs.

◆ subgraph()

size_t subgraph ( size_t  index) const
Returns
the subgraph ID of the connected subgraph index lies in.

◆ subgraphCount()

size_t subgraphCount ( size_t  index) const
Returns
the size of the connected subgraph that includes index, that is, the number of connected vertices in it.

◆ getConnectedID()

size_t getConnectedID ( size_t  index) const
Returns
the subgraph ID of the connected subgraph index lies in.

The documentation for this class was generated from the following file: