ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ShortestJobFirst.h File Reference

Shortest Job First (exercise 14.5): \( n \) programs of durations \( t_i \), run one after the other, in the order that minimizes the average time of completion: by increasing duration, since moving the shortest program to the front of any order does not increase any time of completion; \( O( n \log n ) \). More...

#include "ADS/Contract.h"
#include <algorithm>
#include <cstddef>
#include <numeric>
#include <vector>
#include "ADS/optimization/impl/ShortestJobFirst.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

template<class T>
std::vector< std::size_t > ADS::shortestJobFirst (const std::vector< T > &t)
 the order of the programs, by increasing duration
template<class T>
T ADS::totalCompletion (const std::vector< T > &t, const std::vector< std::size_t > &A)
 the sum of the times of completion of the programs in the order \( A \), \( \sum_k ( t_{A[ 0 ]} + \cdots + t_{A[ k ]} ) \)
template<class T, class W>
std::vector< std::size_t > ADS::smithOrder (const std::vector< T > &t, const std::vector< W > &w)
 the order of the programs of times \( t \) and weights \( w \) of least weighted sum of the times of completion, by increasing \( t / w \) (Smith's rule)
template<class T, class W>
auto ADS::weightedCompletion (const std::vector< T > &t, const std::vector< W > &w, const std::vector< std::size_t > &A)
 the sum of \( w_i C_i \) in the order \( A \), \( C_i \) the time of completion of \( i \)

Detailed description

Shortest Job First (exercise 14.5): \( n \) programs of durations \( t_i \), run one after the other, in the order that minimizes the average time of completion: by increasing duration, since moving the shortest program to the front of any order does not increase any time of completion; \( O( n \log n ) \).

With the weights \( w_i \) of the programs (the probabilities of the files on a tape, read at the times of completion), the order of least weighted sum \( \sum_i w_i C_i \) of the times of completion \( C_i \) is Smith's rule, by increasing \( t_i / w_i \), compared as \( t_a w_b < t_b w_a \) (no division, and a program of weight 0 goes last): the exchange of two adjacent programs \( a \), \( b \) changes the sum by \( t_a w_b - t_b w_a \); \( O( n \log n ) \). With precedence constraints the problem is NP-hard in general, and solved by Lawler's merging of chains on series-parallel orders.

The contracts [see Contract.h]: the times are not negative, the order is by increasing time, and the order given to totalCompletion() has places of \( t \); the weights are not negative and no program has both time and weight 0, and the order of smithOrder() is by increasing \( t / w \). The operations are defined in ShortestJobFirst.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, exercise 14.5, https://algoritmicamente.it/materiali/libro/capitoli/cap14.pdf
W. E. Smith, Various optimizers for single-stage production, Naval Research Logistics Quarterly 3(1-2), 59-66, 1956, doi:10.1002/nav.3800030106
E. L. Lawler, Sequencing jobs to minimize total weighted completion time subject to precedence constraints, Annals of Discrete Mathematics 2, 75-90, 1978, doi:10.1016/S0167-5060(08)70323-6
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa