All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
NetworKit::GraphBuilder Class Reference

#include <GraphBuilder.h>

Public Member Functions

 GraphBuilder (count n=0, bool weighted=false, bool directed=false)
 Creates a new GraphBuilder. More...
 
void reset (count n=0)
 
void setName (std::string name)
 Set name of graph to name. More...
 
bool isWeighted () const
 Returns true if this graph supports edge weights other than 1.0. More...
 
bool isDirected () const
 Return true if this graph supports directed edges. More...
 
bool isEmpty () const
 Return true if graph contains no nodes. More...
 
count numberOfNodes () const
 Return the number of nodes in the graph. More...
 
index upperNodeIdBound () const
 Get an upper bound for the node ids in the graph. More...
 
node addNode ()
 Add a new node to the graph and return it. More...
 
void addHalfEdge (node u, node v, edgeweight ew=defaultEdgeWeight)
 Insert an edge between the nodes u and v. More...
 
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)
 
void setWeight (node u, node v, edgeweight ew)
 Set the weight of an edge. More...
 
void setOutWeight (node u, node v, edgeweight ew)
 
void setInWeight (node u, node v, edgeweight ew)
 
void increaseWeight (node u, node v, edgeweight ew)
 Increase the weight of an edge. More...
 
void increaseOutWeight (node u, node v, edgeweight ew)
 
void increaseInWeight (node u, node v, edgeweight ew)
 
Graph toGraph (bool autoCompleteEdges, bool parallel=false)
 Generates a Graph instance. More...
 
template<typename L >
void forNodes (L handle) const
 Iterate over all nodes of the graph and call handle (lambda closure). More...
 
template<typename L >
void parallelForNodes (L handle) const
 Iterate randomly over all nodes of the graph and call handle (lambda closure). More...
 
template<typename L >
void forNodePairs (L handle) const
 Iterate over all undirected pairs of nodes and call handle (lambda closure). More...
 
template<typename L >
void parallelForNodePairs (L handle) const
 Iterate over all undirected pairs of nodes in parallel and call handle (lambda closure). More...
 

Constructor & Destructor Documentation

NetworKit::GraphBuilder::GraphBuilder ( count  n = 0,
bool  weighted = false,
bool  directed = 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
nNumber of nodes.
weightedIf set to true, the graph has edge weights.
directedIf set to true, the graph will be directed.

Member Function Documentation

void NetworKit::GraphBuilder::addHalfEdge ( node  u,
node  v,
edgeweight  ew = defaultEdgeWeight 
)
inline

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.

Parameters
uEndpoint of edge.
vEndpoint of edge.
weightOptional edge weight.
void NetworKit::GraphBuilder::addHalfInEdge ( node  u,
node  v,
edgeweight  ew = defaultEdgeWeight 
)
void NetworKit::GraphBuilder::addHalfOutEdge ( node  u,
node  v,
edgeweight  ew = defaultEdgeWeight 
)
node NetworKit::GraphBuilder::addNode ( )

Add a new node to the graph and return it.

Returns
The new node.
template<typename L >
void NetworKit::GraphBuilder::forNodePairs ( handle) const

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

Parameters
handleTakes parameters (node, node).
template<typename L >
void NetworKit::GraphBuilder::forNodes ( handle) const

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

Parameters
handleTakes parameter (node).
void NetworKit::GraphBuilder::increaseInWeight ( node  u,
node  v,
edgeweight  ew 
)
void NetworKit::GraphBuilder::increaseOutWeight ( node  u,
node  v,
edgeweight  ew 
)
void NetworKit::GraphBuilder::increaseWeight ( node  u,
node  v,
edgeweight  ew 
)
inline

Increase the weight of an edge.

If the edge does not exist, it will be inserted.

Parameters
[in]uendpoint of edge
[in]vendpoint of edge
[in]weightedge weight
bool NetworKit::GraphBuilder::isDirected ( ) const
inline

Return true if this graph supports directed edges.

Returns
true if this graph supports directed edges.
bool NetworKit::GraphBuilder::isEmpty ( ) const
inline

Return true if graph contains no nodes.

Returns
true if graph contains no nodes.
bool NetworKit::GraphBuilder::isWeighted ( ) const
inline

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

Returns
true if this graph supports edge weights other than 1.0.
count NetworKit::GraphBuilder::numberOfNodes ( ) const
inline

Return the number of nodes in the graph.

Returns
The number of nodes.
template<typename L >
void NetworKit::GraphBuilder::parallelForNodePairs ( handle) const

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

Parameters
handleTakes parameters (node, node).
template<typename L >
void NetworKit::GraphBuilder::parallelForNodes ( handle) const

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

Parameters
handleTakes parameter (node).
void NetworKit::GraphBuilder::reset ( count  n = 0)
void NetworKit::GraphBuilder::setInWeight ( node  u,
node  v,
edgeweight  ew 
)
void NetworKit::GraphBuilder::setName ( std::string  name)
inline

Set name of graph to name.

Parameters
nameThe name.
void NetworKit::GraphBuilder::setOutWeight ( node  u,
node  v,
edgeweight  ew 
)
void NetworKit::GraphBuilder::setWeight ( node  u,
node  v,
edgeweight  ew 
)
inline

Set the weight of an edge.

If the edge does not exist, it will be inserted.

Parameters
[in]uendpoint of edge
[in]vendpoint of edge
[in]weightedge weight
void NetworKit::GraphBuilder::swapNeighborhood ( node  u,
std::vector< node > &  neighbours,
std::vector< edgeweight > &  weights,
bool  selfloop 
)
Graph NetworKit::GraphBuilder::toGraph ( bool  autoCompleteEdges,
bool  parallel = false 
)

Generates a Graph instance.

The graph builder will be reseted at the end.

index NetworKit::GraphBuilder::upperNodeIdBound ( ) const
inline

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

Returns
An upper bound for the node ids.

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