STAG C++  2.0.0
Spectral Toolkit of Algorithms for Graphs
Loading...
Searching...
No Matches
graph.h File Reference

Description

Core graph class definitions and constructors.

Classes

struct  stag::edge
 A structure representing a weighted edge in a graph. More...
 
class  stag::LocalGraph
 An abstract class which defines methods for exploring the local neighborhood of vertices in a graph. More...
 
class  stag::Graph
 The core object used to represent graphs for use with the library. More...
 
class  stag::AdjacencyListLocalGraph
 A local graph backed by an adjacency list file on disk. More...
 

Functions

stag::Graph stag::cycle_graph (StagInt n)
 
stag::Graph stag::complete_graph (StagInt n)
 
stag::Graph stag::barbell_graph (StagInt n)
 
stag::Graph stag::star_graph (StagInt n)
 
stag::Graph stag::identity_graph (StagInt n)
 
template<typename Scalar >
stag::Graph stag::operator* (Scalar lhs, const stag::Graph &rhs)
 
template<typename Scalar >
stag::Graph stag::operator* (const stag::Graph &lhs, Scalar rhs)
 
stag::Graph stag::operator+ (const stag::Graph &lhs, const stag::Graph &rhs)
 

Function Documentation

◆ cycle_graph()

stag::Graph stag::cycle_graph ( StagInt  n)

Construct a cycle graph on n vertices.

Parameters
nthe number of vertices in the constructed graph
Returns
a stag::Graph object representing a cycle graph

◆ complete_graph()

stag::Graph stag::complete_graph ( StagInt  n)

Construct a complete graph on n vertices.

Parameters
nthe number of vertices in the constructed graph
Returns
a stag::Graph object representing a complete graph

◆ barbell_graph()

stag::Graph stag::barbell_graph ( StagInt  n)

Construct a barbell graph. The barbell graph consists of 2 cliques on n vertices, connected by a single edge.

Parameters
nthe number of vertices in each of the two cliques. The returned graph will have \(2n\) vertices.
Returns
a stag::Graph object representing the barbell graph

◆ star_graph()

stag::Graph stag::star_graph ( StagInt  n)

Construct a star graph. The star graph consists of one central vertex connected by an edge to n-1 outer vertices.

Parameters
nthe number of vertices in the constructed graph
Returns
a stag::Graph object representing the star graph

◆ identity_graph()

stag::Graph stag::identity_graph ( StagInt  n)

Construct the 'identity graph'. The identity graph consists of \(n\) vertices, each with a self-loop of weight 1.

Both the adjacency matrix and Laplacian matrix of the identity graph are equal to the identity matrix.

Parameters
nthe number of vertices in the constructed graph
Returns
a stag::Graph object representing the identity graph

◆ operator*() [1/2]

template<typename Scalar >
stag::Graph stag::operator* ( Scalar  lhs,
const stag::Graph rhs 
)

Multiplying a graph by a scalar is equivalent to multiplying the weight of each edge by the given value.

For example, the following code creates a complete graph with edges of weight 2.

#include <stag/graph.h>
int main() {
stag::Graph myGraph = 2 * stag::complete_graph(10);
return 0;
}
The core object used to represent graphs for use with the library.
Definition: graph.h:139

◆ operator*() [2/2]

template<typename Scalar >
stag::Graph stag::operator* ( const stag::Graph lhs,
Scalar  rhs 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator+()

stag::Graph stag::operator+ ( const stag::Graph lhs,
const stag::Graph rhs 
)

Adding two graphs is equivalent to adding their adjacency matrices.

The graphs must have the same number of vertices. For example, the following code adds a complete graph and a cycle graph on \(5\) vertices.

#include <stag/graph.h>
int main() {
stag::Graph myGraph = stag::complete_graph(5) + stag::cycle_graph(5);
return 0;
}
Exceptions
std::invalud_argumentif the graphs have different sizes.