Graph.hpp
A simple, fast class for managing vertices (nodes) and edges.
Note
Status: BETA
-
class Graph
- #include <Graph.hpp>
A graph class that maintains a set of vertices (nodes) and edges (connecting pairs of nodes)
Subclassed by WeightedGraph
Public Functions
-
inline Graph(size_t num_nodes = 0)
Construct a new graph with the specified number of nodes.
-
inline ~Graph()
-
inline size_t GetSize() const
Get number of vertices in this graph.
-
inline size_t GetEdgeCount() const
Get the total number of edges in this graph.
-
inline Node GetNode(int i)
- Returns:
the
i
th node in the graph
-
inline void Resize(size_t new_size)
Change the number of vertices in this graph.
-
inline const BitVector &GetEdgeSet(size_t id) const
Get the set of nodes that a specified node is connected to.
-
inline size_t GetDegree(size_t id) const
Get the degree of a specified node. For directed graphs, this is the out-degree
-
inline size_t GetInDegree(size_t id) const
Get the in-degree (number of incoming edges) of the node
- Parameters:
id – This should only be used for directed graphs (for undirected graphs, GetDegree() is equivalent and faster)
-
inline size_t GetMaskedDegree(size_t id, const BitVector &mask) const
Get how many of a set of nodes that a specified node is connected to.
-
inline bool HasEdge(size_t from, size_t to) const
Determine if a specific edge is included in this graph.
-
inline void AddEdge(size_t from, size_t to)
Add a specified edge into this graph.
-
inline void RemoveEdge(size_t from, size_t to)
Remove a specified edge from this graph.
-
inline void SetEdge(size_t from, size_t to, bool val)
Set the status of a specified edge as to whether or not it should be in the graph.
-
inline bool HasEdgePair(size_t from, size_t to) const
Determine if edges exist in both directions between a pair of vertices.
-
inline void AddEdgePair(size_t from, size_t to)
Add a pair of edges between two vertices (in both directions)
-
inline void RemoveEdgePair(size_t from, size_t to)
Remove edges in both directions between a pair of vertices.
-
inline void SetEdgePairs(size_t from, size_t to, bool val)
Set the status as to whether a pair of edges (in both direction) exist.
-
inline Graph(size_t num_nodes = 0)
-
class WeightedGraph : public Graph
- #include <Graph.hpp>
A graph class that maintains a set of vertices (nodes), edges (connecting pairs of nodes), and edge weights
Public Functions
-
inline WeightedGraph(size_t num_nodes = 0)
The weight of each edge in the graph.
-
WeightedGraph(const WeightedGraph&) = default
Copy constructor.
-
WeightedGraph(WeightedGraph&&) = default
Move constructor.
-
inline ~WeightedGraph()
-
WeightedGraph &operator=(const WeightedGraph&) = default
Copy operator.
-
WeightedGraph &operator=(WeightedGraph&&) = default
Move operator.
-
inline void Resize(size_t new_size)
-
inline double GetWeight(size_t from, size_t to) const
Determine weight of a specific edge in this graph.
-
inline void AddEdge(size_t from, size_t to, double weight)
When Adding an edge, must also provide a weight.
-
inline void AddEdgePair(size_t from, size_t to, double weight)
When Adding an edge pair, must also provide a weight.
-
inline void Merge(const WeightedGraph &in_graph)
Merge two WeightedGraphs into one.
-
inline void PrintSym(std::ostream &os = std::cout)
Print a symmetric graph to the provided output stream (defaulting to standard out)
-
inline WeightedGraph(size_t num_nodes = 0)