IGraphs.jl is a low-level wrapper for igraph in Julia. It provides access to igraph on arm/amd64 windows/mac/linux. It now wraps igraph 1.0.0
Here is a quick example of IGraphs.jl used together with the julia Graphs.jl ecosystem:
using Graphs
using Graphs.Experimental
using IGraphs
using Random
# make a random graph from Graphs.jl
g = random_regular_graph(10, 8)
# make a random isomorph to it
m = adjacency_matrix(g)
p = randperm(nv(g))
m = m[p,p]
gp = Graph(m)
# dispatching on default Graphs.jl functions and on IGraphs.jl implementations for the same functions
# We use algorithm=IGraphAlg() to specify that we want the IGraphs.jl algoritm
@assert has_isomorph(g, gp) == has_isomorph(g, gp, IGraphAlg()) == true
@assert diameter(g) == diameter(gp, IGraphAlg())
@assert radius(g) == radius(gp, IGraphAlg())
Here is a much lower-level example of directly calling the igraph C functions (all of them provided in LibIGraph
):
import Graphs
using Graphs: ne, nv
using IGraphs
# color an empty graph
g = IGraph(5)
v = IGVectorInt()
LibIGraph.vertex_coloring_greedy(g,v,LibIGraph.IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS)
@assert collect(v) == [0,0,0,0,0]
# color a ring graph
g = IGraph(5)
LibIGraph.ring(g, 5, false, false, true);
v = IGVectorInt() LibIGraph.vertex_coloring_greedy(g,v,LibIGraph.IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS)
@assert collect(v) == [0,2,1,0,1]
# run the Leiden community algorithm
# get a named graph from Graphs.jl and convert it to an igraph data structure
g = Graphs.smallgraph(:karate)
ig = IGraph(g)
# prepare some constant igraph vectors
membership = IGVectorInt(zeros(nv(ig)))
membership_null = IGVectorInt(zeros(nv(ig)))
edge_weights = IGVectorFloat(ones(ne(ig)))
node_weights = IGVectorFloat(ones(nv(ig)))
# run community_leiden with and without weights
res = LibIGraph.community_leiden(ig, edge_weights, node_weights, IGNull(), 0.05, 0.01, 0, 1, membership)
res_null = LibIGraph.community_leiden(ig, IGNull(), IGNull(), IGNull(), 0.05, 0.01, 0, 1, membership_null)
@assert membership == membership_null
@assert res == res_null