Repository navigation
Algorithm
We decided to use the A* algorithm to produce optimal solutions for task graphs up to 20 nodes. It is a best first state space search algorithm that reduces the state space search by our implemented cost function and clipping techniques.
Description and details of the algorithm used and its implementation.
The A* algorithm relies on priority queues to determine which partial solutions to visit next in the total state space of partial solutions. In determining the priority for each partial solution, heuristics are used. Heuristics are essentially underestimates of the current partial solution - that is, given the current partial solution, all partial or full solutions that can be generated from that current partial solution is guaranteed to have a total cost that is greater than or equal to that underestimate.
There are several cost functions the algorithm uses to determine a partial solution's underestimate: idle time, bottom level, data ready time, and parent's underestimate. Each heuristic has the potential to outperform its peers based on the type of the input graph, thus the algorithm incorporates all heuristics in an attempt to get the best of all worlds. Naturally, the best underestimate is the highest underestimate - if one cost function guarantees the cost function to be at least 5 seconds, and another cost function guarantees 8 seconds, then the second cost function implies the first, making the first redundant. Thus, the algorithm's candidate heuristic is Max(all heuristics).
The bottom level heuristic of each node calculates the longest path from the selected node. This helps provide an underestimate for the length of the schedule. Thus, all full schedules that can be generated from a partial schedule must be at least as great as the maximum time to get to a leaf. The calculation only takes into consideration all the weights of the nodes in the path, ignoring the edge weights.
The bottom level is calculated once and once only, prior to the generation of the partial solutions. This is because the bottom level for each node is specific to that node, and remains static throughout the generation of partial solutions. Thus, after calculation, it is cached in a hashmap and is referenced throughout the partial schedule generation in O(1) time.
Implementation
The bottom level cache is generated by using a queue, with the leaves of the graph being queued first. The bottom level for a node is calculated by SUM(MAX(Bottom level of all children)+self.weight). Because the leaves have no children, their bottom level weights are their weights themselves. Every time a node's bottom level is added to the cache, it checks that node's parents and sees if all of that parent's children's bottom level is already in the cache. If it is true, then it adds the parent to the queue. In this way, the queue moves up the tree towards the root/s.
The idle time heuristic takes into account the amount of time being wasted by a processor in a partial solution, and uses this to calculate an underestimate. In an ideal scenario, with no idle time, each task is distributed equally across each processor. That is, the total schedule cost in this ideal scenario is the sum of all the weights of the tasks divided by the number of processors available. However, the idle time represents time that can never be gained back, thus it adds to the total cost required for an ideal scenario. The idle time heuristic assumes this total idle time can be distributed equally across the processors, thus it is also divided by the total number of processors,
Implementation
The idle time heuristic has two components: the total current idle time, and the total weight. The total weight is a constant: the sum of all weights in the graph divided by the number of processors available. Thus, this is calculated prior to the generation of partial solutions and stored as a field. The total current idle time, however, changes based on the current partial solution. Luckily, since idle time is lost time that never can be gained back, it will never decrease when more nodes are added to a partial solution. Thus, idle time can be updated incrementally with each addition of a node, using the idle time of its parent partial solution, in O(1) time. The idle time is stored as a protected field of a partial solution, and is referenced by child partial solutions to generate their own idle times.
During incremental idle time updates, our solution is to find the start time of the node we are about to add to our new partial solution, and note the processor in which we are adding the node to. Using this processor, we find the latest finish time for that processor prior to adding our new node, and then use this value to subtract from our new node's start time. If the new node we are about to add is the first node for that processor, then the incremental idle time is just the start time of that new node.
The parent's underestimate acts as a guarding heuristic against the other heuristics. This guarding property is arises as the parent's underestimate guarantees the children's underestimates to be at least as large as the parent's underestimate.