|
ADS
Algorithms and Data Structures
|
The independent set of weighted intervals of section 13.2: among \( n \) intervals \( [ a_i , b_i ) \), open on the right, of weights \( w_i \), a set of disjoint ones of largest weight. More...
#include "ADS/Contract.h"#include <algorithm>#include <cstddef>#include <numeric>#include <utility>#include <vector>#include "ADS/optimization/impl/WeightedIntervals.tpp"Go to the source code of this file.
Classes | |
| struct | ADS::WeightedInterval< W > |
| an interval \( [ a , b ) \) of weight \( w \) More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class W> | |
| std::pair< std::vector< std::size_t >, W > | ADS::maxinterval (const std::vector< WeightedInterval< W > > &I) |
| the places of the intervals of a largest independent set, in increasing order, and its weight | |
The independent set of weighted intervals of section 13.2: among \( n \) intervals \( [ a_i , b_i ) \), open on the right, of weights \( w_i \), a set of disjoint ones of largest weight.
With the intervals by increasing right end and \( \mathit{pred}[ i ] \) the largest \( j < i \) with \( b_{j-1} \le a_{i-1} \) (0 if none),
\[ \mathit{DP}[ i ] = \max\{ \mathit{DP}[ i - 1 ] , w_{i-1} + \mathit{DP}[ \mathit{pred}[ i ] ] \} , \]
\( \mathit{DP}[ 0 ] = 0 \), and the set is read back from \( \mathit{DP}[ n ] \); the predecessors come from one scan of the \( 2 n \) ends sorted, so that maxinterval() takes \( O( n \log n ) \) time for the sort and \( O( n ) \) for the rest.
The contracts [see Contract.h]: each interval has \( a < b \) and a weight not negative; the intervals chosen are disjoint and weigh the value found (checked at level 3). The operations are defined in WeightedIntervals.tpp.