(…or, Christmas in July)
I’m very excited to announce MetaGraphs.jl, the latest product of our LightGraphs.jl abstraction efforts.
From day 1, associating metadata with vertices and edges has been the #1 request of LightGraphs users. Until recently, we didn’t have a really good way of doing this while keeping the performance of the underlying graph analytic functions intact.
This changes today.
Information about graphs, vertices, and edges can now be stored in (and retrieved from) MetaGraph
s or MetaDiGraph
s, and can even be used to filter the underlying graph. Here are some quick examples:
using MetaGraphs, LightGraphs
# create a MetaGraph from a LightGraph
mg = MetaGraph(CompleteGraph(3))
# Let's add some metadata to the graph itself
set_prop!(mg, :name, "This is a MetaCompleteGraph")
# Let's get it
get_prop(mg, :name)
# Now add some vertex labels (keys are symbols, values can be anything.)
set_prop!(mg, 1, :color, "blue")
set_prop!(mg, 1, :id, 0x4)
set_prop!(mg, 2, :color, "red")
set_prop!(mg, 2, :id, 62)
set_prop!(mg, 3, :color, "blue")
# We'll skip :id data for vertex 3
# Now let's add some edge labels. We choose :weight deliberately.
set_prop!(mg, 1, 2, :weight, 0.2)
set_prop!(mg, 2, 3, :weight, 0.4)
# Filter all the vertices that have an :id property (of any value) set
vertices_with_id = filter_vertices(mg, :id)
# How about blue ones?
blue_vertices = filter_vertices(mg, :color, "blue")
# How about edges with custom weights?
weighted_edges = filter_edges(mg, :weight)
# What about all edges with a weight > 0.3? Use an arbitrary function!
heavy_edges = filter_edges(mg, (g, e) -> weights(mg)[src(e), dst(e)] > 0.3)
# These are filters. What can we do with them? We can list the results...
v1 = collect(vertices_with_id)
# ...or we can create a subgraph based on the filter.
# This contains vertices and any connecting edges.
bluemg = mg[blue_vertices]
# PS: because MetaGraphs are edge-weight aware (default property :weight),
# graph functions that require weights just work:
enumerate_paths(dijkstra_shortest_paths(mg, 1), 3) # 1, 2, 3
As always, please feel free to raise issues / ask questions via
Gitter or GitHub issues.
Thanks to all the contributors and users of JuliaGraphs packages. Your continuing support means a great deal.