Topological ordering to schedule tasks (digraph)

Frank Muller frank.muller.erl@REDACTED
Tue Nov 23 20:41:24 CET 2021


Hi everyone,

I’m trying to use “digraph” and related modules to find dependencies
between tasks.

Here’s an example:
https://dreampuf.github.io/GraphvizOnline/#digraph%20G%20%7B%0A%20%20a%20-%3E%20b%3B%0A%20%20a%20-%3E%20c%3B%0A%20%20a%20-%3E%20d%3B%0A%20%20c%20-%3E%20d%3B%0A%7D

Using digraph:

G = digraph:new(),
digraph:add_vertex(G, a),
digraph:add_vertex(G, b),
digraph:add_vertex(G, c),
digraph:add_vertex(G, d),

digraph:add_edge(G, a, b),
digraph:add_edge(G, a, c),
digraph:add_edge(G, a, d),
digraph:add_edge(G, c, d),

digraph_utils:topsort(G).
[a,b,c,d]


Would it be possible to get the following "topological ordering” instead?

[{a, [b, c]}, {b, []}, {c, [d]}, {d, []}]


This way, I can easily schedule and order my tasks:
1. task “a" has to be performed after “c" and “d” are completed
2. similarly, “c" has to be done after “d”
3. finally, “b" and “d" can be run first, in parallel and without any
constraint

Thanks
/F.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20211123/60ac595b/attachment.htm>


More information about the erlang-questions mailing list