Graph Indexes

Indexes

General Graphs

In a graph with numbered edges, provide access to neighbors and edge numbers for a specified node.

Note

IncidenceIndex always includes both directions, i.e. for an edge (u, v) with edge index ei, it is (u, ei) ∈ neighbors[v] and (v, ei) ∈ neighbors[u].

source
GraphIdx.num_edgesMethod.
num_edges(::IncidenceIndex)

Actual number of (undirected) edges (not counting both directions).

source

Weights

Often, nodes or edges might have an associated weight. To give the optimizer the possibility to distinguish constant weights (all weights the same) from individual weights we provide the following structs:

Represent weighting that is indexable and callable where each index has the same value.

Usually, weights are assumed to be positive!

Example

julia> w = GraphIdx.ConstantWeights(5.4);

julia> w(3)
5.4

julia> w[3]
5.4
source

Weighting of nodes where every weight can be different. The actual value of a node can be accessed via call - or index syntax.

Example

julia> w = GraphIdx.ArrayWeights([0.1, 0.2, 0.3]);

julia> w(3)
0.3

julia> w[1]
0.1
source

Graph Partition

cluster(x, neigh, eps=1e-5, seed=42)

Find a partition of x such that abs(x[i] - x[j]) < eps for all edges j in neighidx[i] where i and j are in the same partition.

source

Tree Graphs

Provide constant time access to children of a node by index operator.

Example

julia> cidx = GraphIdx.Tree.ChildrenIndex([1, 1, 2, 1]);

julia> GraphIdx.Tree.root_node(cidx)
1

julia> collect(cidx[1])  # root node 1 has children 2 and 4
2-element Array{Int64,1}:
 2
 4

julia> collect(cidx[3])  # node 3 has no children
0-element Array{Int64,1}
source
root_node(::ChildrenIndex)

Return the root node of the underlying tree. This is possible because by convention the root node is stored at ChildrenIndex.idx[1].

source

Once, memory has been allocated we can re-use it to store different tree (of same size!) in it.

reset!(cidx, parent [,root])

Actually compute the index according to parent.

source