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

Shortest Job First (exercise 14.5). More...

Files

file  ADS/optimization/ShortestJobFirst.h
 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 ) \).

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).

The definitions, the invariants and the costs of the area are in Theory of optimization.

Function documentation

◆ shortestJobFirst()

template<class T>
std::vector< std::size_t > ADS::shortestJobFirst ( const std::vector< T > & t)

the order of the programs, by increasing duration

In pseudocode (exercise 14.5):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{shortestJobFirst}( t )\quad \triangleright \ \text{an exchange of two jobs out of order lowers the total} \cr 2 & \quad \textbf{return}\ ( 0 , \ldots , n - 1 ) \text{ stably sorted by } t_i \end{array}} \]

Precondition
no time negative
Postcondition
the places by increasing time

◆ smithOrder()

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)

In pseudocode (Smith's rule, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{smithOrder}( t , w ) \cr 2 & \quad \textbf{return}\ \text{the places sorted stably, } a \text{ } \text{before } b \text{ when } t_a w_b < t_b w_a \end{array}} \]

Precondition
\( |t| = |w| \), \( t \) and \( w \) not negative, \( t_i + w_i > 0 \)
Postcondition
the places by increasing \( t / w \)

◆ totalCompletion()

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 ]} ) \)

Precondition
the places of \( A \) are places of \( t \)

◆ weightedCompletion()

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 \)

Precondition
\( |t| = |w| \) and the places of \( A \) are places of \( t \)