Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one serialize a digraph in Erlang or Elixir for export purposes

Tags:

erlang

elixir

I am using Erlang's digraph module for storing Directed Acyclic Graphs (DAGs). So for argument's sake here is a super simple graph (using Elixir):

gr = :digraph.new()
:digraph.add_vertex(gr, "A")
:digraph.add_vertex(gr, "B")
:digraph.add_vertex(gr, "C")
:digraph.add_edge(gr, "A", "B")
:digraph.add_edge(gr, "A", "C")

which looks like this:

enter image description here

We can see it's all worked:

iex(7)> :digraph.vertices(gr)
["A", "C", "B"]
iex(8)> :digraph.edges(gr)
[[:"$e" | 0], [:"$e" | 1]]
iex(9)> :digraph.out_neighbours(gr, "A")
["C", "B"]
iex(10)> :digraph.out_neighbours(gr, "B")
[]
iex(11)> :digraph.out_neighbours(gr, "C")
[]
iex(12)> :digraph_utils.is_acyclic(gr)
true

Now I'm going to be adding and removing more vertices and edges, but I would like to transmit these graphs to applications outside of the Elixir/Erlang ecosystem such as Cytoscape.js. Is there a standardized way to serialize digraphs into some industry standard readable format (json or xml for example), such as JGF, Netlix's Falcor JSON Graph format, or other?

I could write my own serializer but I'd prefer something pre-existing. I can't find anything that does this in digraph or digraph_utils.

like image 499
Thomas Browne Avatar asked Dec 16 '18 01:12

Thomas Browne


1 Answers

Searching there are various solutions for exporting digraph data to various popular formats, but nothing canonical Two of the most popular of these formats are DOT and GraphML.

Some Elixir and Erlang libraries for exporting digraphs to various formats:

  • https://github.com/mikowitz/graphvix
  • https://github.com/jabarszcz/digraph_viz
  • https://github.com/fenollp/erlang-dot

Some Elixir and Erlang examples of updating the front-end in soft realtime using js libs such as vis.js and web sockets:

  • http://blog.songsaboutsnow.com/elixir/graphviz/2018/06/26/graphvix-part1.html
  • https://github.com/swelham/digraph_viewer
  • https://rshestakov.wordpress.com/2013/03/17/extended-example-with-graphviz-updates-via-websockets/
like image 141
starbelly Avatar answered Sep 29 '22 12:09

starbelly