Class GraphBuilder

Nested Relationships

Nested Types

Class Documentation

class GraphBuilder

Public Functions

GraphBuilder(count n = 0, bool weighted = false, bool directed = false, bool autoCompleteEdges = false)

Creates a new GraphBuilder. GraphBuilder supports the basic methods needed to create a new graph (addNode, addEdge, setWeight, increaseWeight). It is designed to be much faster for graph creation, but the speed comes with a restriction: For undirected graphs GraphBuilder will handle u->v and v->u as two different edges. Keep that in mind when using setWeight and increaseWeight. GraphBuilder allows parallelization in a special way. It’s internal data structure saves edges only at the source node. As long as edges from node u are only added/changed by thread t1, every other thread can modifier edges not starting in u. addNode is not threadsafe.

Parameters:
  • n – Number of nodes.

  • weighted – If set to true, the graph has edge weights.

  • directed – If set to true, the graph will be directed.

  • autoCompleteEdges – If set to true, the edges will automatically be added to the adjacency lists of both nodes (decreases the time to build).

void reset(count n = 0)
inline bool isWeighted() const

Returns true if this graph supports edge weights other than 1.0.

Returns:

true if this graph supports edge weights other than 1.0.

inline bool isDirected() const

Return true if this graph supports directed edges.

Returns:

true if this graph supports directed edges.

inline bool isEmpty() const

Return true if graph contains no nodes.

Returns:

true if graph contains no nodes.

inline count numberOfNodes() const

Return the number of nodes in the graph.

Returns:

The number of nodes.

inline index upperNodeIdBound() const

Get an upper bound for the node ids in the graph.

Returns:

An upper bound for the node ids.

node addNode()

Add a new node to the graph and return it.

Returns:

The new node.

void addHalfEdge(node u, node v, edgeweight ew = defaultEdgeWeight)

Insert an edge between the nodes u and v. If the graph is weighted you can optionally set a weight for this edge. The default weight is 1.0. If setUseWholeEdges(true) has been called prior, this sets both half edges, which improves the performance of the graph builder.

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

  • weight – Optional edge weight.

void addHalfOutEdge(node u, node v, edgeweight ew = defaultEdgeWeight)
void addHalfInEdge(node u, node v, edgeweight ew = defaultEdgeWeight)
void swapNeighborhood(node u, std::vector<node> &neighbours, std::vector<edgeweight> &weights, bool selfloop)
inline void setWeight(node u, node v, edgeweight ew)

Set the weight of an edge. If the edge does not exist, it will be inserted.

Parameters:
  • u[in] endpoint of edge

  • v[in] endpoint of edge

  • weight[in] edge weight

void setOutWeight(node u, node v, edgeweight ew)
void setInWeight(node u, node v, edgeweight ew)
inline void increaseWeight(node u, node v, edgeweight ew)

Increase the weight of an edge. If the edge does not exist, it will be inserted.

Parameters:
  • u[in] endpoint of edge

  • v[in] endpoint of edge

  • weight[in] edge weight

void increaseOutWeight(node u, node v, edgeweight ew)
void increaseInWeight(node u, node v, edgeweight ew)
Graph completeGraph()

Generates a Graph instance. The graph builder will be resetted at the end.

inline Graph TLX_DEPRECATED(completeGraph([[maybe_unused]] bool parallel))

DEPRECATED: use completeGraph() instead which uses the parallel mode by default (if possible).

template<typename L>
void forNodes(L handle) const

Iterate over all nodes of the graph and call handle (lambda closure).

Parameters:

handle – Takes parameter (node).

template<typename L>
void parallelForNodes(L handle) const

Iterate randomly over all nodes of the graph and call handle (lambda closure).

Parameters:

handle – Takes parameter (node).

template<typename L>
void forNodePairs(L handle) const

Iterate over all undirected pairs of nodes and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node).

template<typename L>
void parallelForNodePairs(L handle) const

Iterate over all undirected pairs of nodes in parallel and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node).

inline void setAutoCompleteEdges(bool completeEdges = false)