# YDS algorithm

YDS is a scheduling algorithm for dynamic speed scaling processors which minimizes the total energy consumption. It was named after and developed by Yao et al. There is both an online and an offline version of the algorithm.

## Offline Algorithm

Definitions:
* There is a set of n Jobs $J:=J_{1},...,J_{n}$, where each job $J_{i}$ has a release time $r_{i}$, deadline $d_{i}$ and a processing volume $w_{i}$.
* $I$ is a certain time interval.
* Also we have $\Delta _{I}={\frac {1}{|I|}}\sum _{J_{i}\in S_{I}}w_{i}$, the work density in $I$.
* And finally $S_{I}\in J$ is the set of Jobs that must be processed in $I$, that means Jobs with $[r_{i},d_{i}]\in I$.
The algorithm then works as follows:
In other terms it's a recursive algorithm that will follow these steps until all jobs are scheduled:
* Calculate all intensities for all possible combinations of intervals. This means that for every start time and end time combination the intensity of work is calculated. For this the times of all jobs whose arrival time and deadline lie inside the interval are added and divided by the interval length. To speed up the process, only combinations of arrival times and later deadlines need to be considered, as times without arrival of a process or deadline can be shrunk to a smaller interval with the same processes, thus increasing intensity, and negative intervals are invalid. Then the maximum intensity interval is selected. In case of multiple equally intense intervals, one can be chosen at will, as intensities of non-overlapping intervals do not influence each other, and removing a part of an interval will not change the intensity of the rest, as processes are removed proportionally.
* The processes inside this interval are scheduled using Earliest Deadline First, meaning that the job inside this interval whose deadline will arrive soonest is scheduled first, and so on. The jobs are executed at the above calculated intensity to fit all jobs inside the interval.
* The interval is removed from the timeline, as no more calculations can be scheduled here. To simplify further calculations, all arrival times and deadlines of remaining jobs are recalculated to omit already occupied times. For example, assume a job $A$ with arrival time $a_{A}=0$, deadline $d_{A}=10$ and a workload $w_{A}=5$, and a job $B$ with $a_{B}=5$, $d_{B}=10$ and $w_{B}=4$. Assume the previous interval was from time $3$ to $8$. To omit this interval the times of $A$ and $B$ need to be adjusted; workloads are unaffected, as no work has been done for either $A$ or $B$. $a_{A}$ stays the same, as it's unaffected by later omissions. $d_{A}$, however, needs to be changed to $5$, as $10-(8-3)=5$. This is the time job $A$ has left before its deadline. The arrival time $a_{B}$ becomes $3$, as it would have been inside the removed interval. $d_{B}$ also becomes $5$, as the time left after the removed interval is $2$. It is important, however, to remember the actual arrival and deadline times for later assembly of the scheduling.
* Repeat steps 1-3 until all jobs have been scheduled.
* Assemble jobs into final scheduling according to their allotted time intervals. Remember, though, that an interval may be split in two by another interval calculated earlier.
For any Job instance, the algorithm computes an optimal schedule minimizing the total energy consumption.