Topological ordering to schedule tasks (digraph)
Frank Muller <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAFA6GnCLFkQMV1Wo_pzwzEcKmBctjPzVx4bh4LVA2Ske2sfPeA@mail.gmail.com> |
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.