|
ADS
Algorithms and Data Structures
|
The cover of a segment by intervals: among \( n \) closed intervals \( [ a_i , b_i ] \), the fewest whose union contains the segment \( [ \mathit{lo} , \mathit{hi} ] \), e.g., the sprinklers at \( D_i \) of radius \( R_i \), of intervals \( [ D_i - R_i , D_i + R_i ] \), that water a lawn \( [ 0 , L ] \). More...
#include "ADS/Contract.h"#include <algorithm>#include <cstddef>#include <numeric>#include <optional>#include <utility>#include <vector>#include "ADS/optimization/impl/IntervalCover.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T> | |
| std::optional< std::vector< std::size_t > > | ADS::minimumIntervalCover (const std::vector< std::pair< T, T > > &I, T lo, T hi) |
| the places of the fewest closed intervals \( I \) whose union contains \( [ \mathit{lo} , \mathit{hi} ] \), by increasing left end; nothing if there is none | |
The cover of a segment by intervals: among \( n \) closed intervals \( [ a_i , b_i ] \), the fewest whose union contains the segment \( [ \mathit{lo} , \mathit{hi} ] \), e.g., the sprinklers at \( D_i \) of radius \( R_i \), of intervals \( [ D_i - R_i , D_i + R_i ] \), that water a lawn \( [ 0 , L ] \).
The greedy choice of chapter 14: with the part \( [ \mathit{lo} , x ] \) already covered, among the intervals that start at \( x \) or before take the one that ends farthest; if none goes past \( x \) the point just after \( x \) stays uncovered and there is no cover. An exchange argument shows that some optimal cover begins with the greedy interval: the interval of an optimal cover that contains \( x \) ends no farther. On the intervals sorted by left end, one scan suffices, \( O( n \log n ) \) time for the sort. The problem is the dual of the independent set of intervals [see Intervals.h], and the one-dimensional case of the set cover, which in general is NP-hard and approximated within \( \ln n \) by the greedy on the most new elements (Chvátal).
The contracts [see Contract.h]: \( \mathit{lo} < \mathit{hi} \) and \( a_i \le b_i \); the intervals chosen cover \( [ \mathit{lo} , \mathit{hi} ] \) (checked at level 3). The functions are defined in IntervalCover.tpp.