Namespace graph#

namespace graph
template<typename T>
class unaryint
#include <graph.hpp>
template<>
class unaryint<bool>
#include <graph.hpp>
template<> vector< int > >
#include <graph.hpp>
template<>
class unaryint<void*>
#include <graph.hpp>

this one is a little weird &#8212; construct a unaryint(nullptr) and get back the identity function f(x) -> x

template<>
class unaryint<int>
#include <graph.hpp>
class input_graph
#include <graph.hpp>

Represents an undirected graph as a list of edges.

Provides methods to extract those edges into neighbor lists (with options to relabel and produce directed graphs).

As an input to the library this may be a disconnected graph, but when returned from components it is a connected sub graph.

Public Functions

inline input_graph()

Constructs an empty graph.

inline input_graph(int n_v, const std::vector<int> &aside, const std::vector<int> &bside)

Constructs a graph from the provided edges.

The ends of edge ii are aside[ii] and bside[ii].

Parameters:
  • n_v – Number of nodes in the graph.

  • aside – List of nodes describing edges.

  • bside – List of nodes describing edges.

inline void clear()

Remove all edges and nodes from a graph.

inline int a(const int i) const

Return the nodes on either end of edge i

inline int b(const int i) const

Return the nodes on either end of edge i

inline size_t num_nodes() const

Return the size of the graph in nodes.

inline size_t num_edges() const

Return the size of the graph in edges.

inline void push_back(int ai, int bi)

Add an edge to the graph.

template<typename T1, typename ...Args>
inline std::vector<std::vector<int>> get_neighbors_sources(const T1 &sources, Args... args) const

produce a std::vector<std::vector<int>> of neigborhoods, with certain nodes marked as sources (inbound edges are omitted) sources is either a std::vector<int> (where non-sources x have sources[x] = 0), or another type for which we have a unaryint specialization optional arguments: relabel, mask (any type with a unaryint specialization) relabel is applied to the nodes as they are placed into the neighborhood list (and not used for checking sources / mask) mask is used to filter down to the induced graph on nodes x with mask[x] = 1

template<typename T2, typename ...Args>
inline std::vector<std::vector<int>> get_neighbors_sinks(const T2 &sinks, Args... args) const

produce a std::vector<std::vector<int>> of neigborhoods, with certain nodes marked as sinks (outbound edges are omitted) sinks is either a std::vector<int> (where non-sinks x have sinks[x] = 0), or another type for which we have a unaryint specialization optional arguments: relabel, mask (any type with a unaryint specialization) relabel is applied to the nodes as they are placed into the neighborhood list (and not used for checking sinks / mask) mask is used to filter down to the induced graph on nodes x with mask[x] = 1

template<typename ...Args>
inline std::vector<std::vector<int>> get_neighbors(Args... args) const

produce a std::vector<std::vector<int>> of neigborhoods optional arguments: relabel, mask (any type with a unaryint specialization) relabel is applied to the nodes as they are placed into the neighborhood list (and not used for checking mask) mask is used to filter down to the induced graph on nodes x with mask[x] = 1

class components
#include <graph.hpp>

Represents a graph as a series of connected components.

The input graph may consist of many components, they will be separated in the construction.

Public Functions

inline const std::vector<int> &nodes(int c) const

Get the set of nodes in a component.

inline size_t size() const

Get the number of connected components in the graph.

inline size_t num_reserved(int c) const

returns the number of reserved nodes in a component

inline size_t size(int c) const

Get the size (in nodes) of a component.

inline const input_graph &component_graph(int c) const

Get a const reference to the graph object of a component.

inline std::vector<std::vector<int>> component_neighbors(int c) const

Construct a neighborhood list for component c, with reserved nodes as sources.

template<typename T>
inline bool into_component(const int c, T &nodes_in, std::vector<int> &nodes_out) const

translate nodes from the input graph, to their labels in component c

template<typename T>
inline void from_component(const int c, T &nodes_in, std::vector<int> &nodes_out) const

translate nodes from labels in component c, back to their original input labels