There are tasks that read from a file, do some processing and write to a file. These tasks are to be scheduled based on the dependency. Also tasks can be run in parallel, so the
Your tasks are an oriented graph with (hopefully) no cycles.
I contains sources
and wells
(sources being tasks that don't depends (have no inbound edge), wells being tasks that unlock no task (no outbound edge)).
A simple solution would be to give priority to your tasks based on their usefulness (lets call that U
.
Typically, starting by the wells, they have a usefulness U = 1
, because we want them to finish.
Put all the wells' predecessors in a list L
of currently being assessed node.
Then, taking each node in L
, it's U
value is the sum of the U
values of the nodes that depends on him + 1. Put all parents of the current node in the L
list.
Loop until all nodes have been treated.
Then, start the task that can be started and have the biggest U
value, because it is the one that will unlock the largest number of tasks.
In your example,
U(C) = U(D) = U(F) = 1
U(B) = U(E) = 2
U(A) = 4
Meaning you'll start A first with E if possible, then B and C (if possible), then D and F