[erlang-questions] digraph questions

Bob Ippolito bob@REDACTED
Tue Apr 9 07:59:23 CEST 2019


The data structures here are all opaque, which is why their representations
in the terminal don't see very useful. To get the label, you use the
digraph:vertex/2 or digraph:edge/2 functions. You can discover this by
reading the documentation and search for label, these are the only
functions that have a label anywhere in their return types. You can
traverse the whole graph by using digraph:vertices/1 and then get the label
and edges for each vertex from there (and get the label of each edge along
the way).

Usage of digraph would look something like:

1> Scene10 = digraph:new().
{digraph,#Ref<0.1177877097.1300365313.19691>,
         #Ref<0.1177877097.1300365313.19692>,
         #Ref<0.1177877097.1300365313.19693>,true}
2> digraph:add_vertex(Scene10, "Franco", "Old and fat").
"Franco"
3> digraph:add_vertex(Scene10, "Sophia", "Young and beautiful").
"Sophia"
4> digraph:add_edge(Scene10, "Franco", "Sophia", "loves").
['$e'|0]
5> digraph:add_edge(Scene10, "Sophia", "Franco", "hates").
['$e'|1]
6> digraph:vertex(Scene10, "Franco").
{"Franco","Old and fat"}
7> digraph:edges(Scene10, "Franco").
[['$e'|1],['$e'|0]]
8> [digraph:edge(Scene10, E) || E <- digraph:edges(Scene10, "Franco")].
[{['$e'|1],"Sophia","Franco","hates"},
 {['$e'|0],"Franco","Sophia","loves"}]

Using digraph in the shell is probably not an ideal user experience because
it uses ets tables behind the scene, and they'll be destroyed when your
shell process crashes (e.g. the first time you make a mistake!).

Searching for "erlang digraph graphviz" comes up with a few projects that
seem relevant to your visualization needs.

-bob


On Mon, Apr 8, 2019 at 8:33 PM Lloyd R. Prentice <lloyd@REDACTED>
wrote:

> Many thanks, Richard. I’ll definitively follow up.
>
> Can you tell me how to return the labels?
>
> All the best,
>
> Lloyd
>
> Sent from my iPad
>
> On Apr 8, 2019, at 8:46 PM, Richard O'Keefe <raoknz@REDACTED> wrote:
>
> The obvious way to visualise a graph would be to drive
> something like GraphViz or Gephi or, ideally, UbiGraph
> (https://github.com/alan86alves/ubigraph_server has a
> copy of the Linux x86-64 version; the official source
> is currently unreachable).  There is an erlubi. But
> perhaps the thing you might want to look at first is
> https://github.com/aol/erlgraph
> It will take a bit of patching to get up to date with
> current versions of Erlang and Cowboy.
>
> On Tue, 9 Apr 2019 at 11:29, <lloyd@REDACTED> wrote:
>
>> The Erlang digraph library looks like it may provide an interesting way
>> to diagram scenes in a novel.
>>
>>
>>
>> 1> Scene10 = digraph:new().
>>
>>
>>
>> Imagine:
>>
>>
>>
>> Setting:"park"
>>
>> Character1:"Franco"
>>
>> Character2:"Sophia"
>>
>>
>>
>> 2> digraph:add_vertex(Scene10, "Park", "Night").
>>
>> 3> digraph:add_vertex(Scene10, "Franco", "Old and fat").
>>
>> 4> digraph:add_vertex(Scene10, "Sophia", "Young and beautiful").
>>
>> 5> digraph:add_edge(Scene10, "Franco", "Sophia", "loves").
>>
>>
>>
>> OK to here EXCEPT command 5 returns:
>>
>>
>>
>> ['$e'|0]
>>
>>
>>
>> 6> digraph:add_edge(Scene10, "Sophia", "Franco", "hates").
>>
>>
>>
>> OK to here EXCEPT command 5 returns:
>>
>>
>>
>> ['$e'|0]
>>
>>
>>
>> 6> digraph:add_edge(Scene10, "Sophia", "Franco", "hates").
>>
>> ['$e'|1]
>>
>>
>>
>> Wah!
>>
>>
>>
>> Question 1: How do I see labels?
>>
>>
>>
>> Question 2: Be cool to add a sequence of actions. I can probably figure
>> this out, but is there an elegant solution?
>>
>>
>>
>> Question 3: I'd love to visualize the graph. I see it can be done in
>> Elixir. But I don't know Elixir. Has anyone programmed a way to visualize
>> digraphs in Erlang?
>>
>>
>>
>> Comment: Digraph is crying out for a comprehensive tutorial. I'd love to
>> do it, but just don't know enough yet.
>>
>>
>>
>> Many thanks,
>>
>>
>>
>> LRP
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190408/6cddfbcb/attachment.htm>


More information about the erlang-questions mailing list