Indexes
General Graphs
GraphIdx.IncidenceIndex
— Type.In a graph with numbered edges, provide access to neighbors and edge numbers for a specified node.
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]
.
GraphIdx.num_edges
— Method.num_edges(::IncidenceIndex)
Actual number of (undirected) edges (not counting both directions).
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:
GraphIdx.ConstantWeights
— Type.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
GraphIdx.ArrayWeights
— Type.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
Graph Partition
GraphIdx.Cluster.cluster
— Method.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.
Tree Graphs
GraphIdx.Tree.ChildrenIndex
— Type.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}
GraphIdx.Tree.root_node
— Method.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]
.
Once, memory has been allocated we can re-use it to store different tree (of same size!) in it.
GraphIdx.Tree.reset!
— Method.reset!(cidx, parent [,root])
Actually compute the index according to parent
.