Let's say I have a set of Tasks that they have dependencies. These tasks are not in order, but the execution of tasks should be in the proper order. Each task has two properties: Before and After.
Before contains list of tasks that are dependending to the result of this task -- so it should be run before them; After contains list of tasks that this specific tasks depends on them. So there are two ways to say B depends on the result of A:
a) Add A to the B's After list
b) Add B to the A's Befor list
Either way should work. Also there can be gap between tasks and it should be filled-up automatically on the execution time. For example imagine we have the following tasks:
Task1
|____ Before: Task3, Task4
|____ After: NA
Task4
|____ Before: Task8
|____ After: Task3
Task2
|____ Before: NA
|____ After: Task1
Task3
|____ Before: Task5
|____ After: Task2
Task5
|____ Before: Task7
|____ After: Task3
So here there is a little bit ambiguity about which task should run first: Task4 or Task5? But it is not important as long as they get executed after Task3 and before Task7 and Task8. This is up to the algorithm to put them in the right place.
The only way that I can think of doing this is to scan all of the tasks first and basically register the dependencies and then start over and execute each task now in their proper order.
The complexity/efficiency of the algorithm is not very important as I have less than 500 Tasks to order before executing them, but I prefer to use a well-known algorithm or method to solve this, rather putting things together just to get it done.
Update: The main reason I need both Before and After properties is to reduce human error while creating tasks. e.g. It is more semantic to say CreateDirectory
is After LoadConfiguration
and Before CopyFiles
. Of course you can say CopyFiles
is after CreateDirectory
, and CreateDirectory
is after LoadConfiguration
.
But in the end all of these will be converted only to After properties.