C++ Reference
C++ Reference: CP-SAT
sorted_interval_list.h
Go to the documentation of this file.
Allows to iterate over all values of a domain in order with for (const int64_t v : domain....
Definition: sorted_interval_list.h:171
void operator++()
Definition: sorted_interval_list.h:181
bool operator!=(absl::InlinedVector< ClosedInterval, 1 >::const_iterator end) const
Definition: sorted_interval_list.h:190
int64_t operator*() const
Definition: sorted_interval_list.h:179
DomainIterator(const absl::InlinedVector< ClosedInterval, 1 > &intervals)
Definition: sorted_interval_list.h:173
We call domain any subset of Int64 = [kint64min, kint64max].
Definition: sorted_interval_list.h:82
static Domain FromValues(std::vector< int64_t > values)
Creates a domain from the union of an unsorted list of integer values.
Domain InverseMultiplicationBy(const int64_t coeff) const
Returns {x ∈ Int64, ∃ e ∈ D, x * coeff = e}.
std::string ToString() const
Returns a compact string of a vector of intervals like "[1,4][6][10,20]".
bool IsIncludedIn(const Domain &domain) const
Returns true iff D is included in the given domain.
bool Contains(int64_t value) const
Returns true iff value is in Domain.
Domain ContinuousMultiplicationBy(int64_t coeff) const
Returns a superset of MultiplicationBy() to avoid the explosion in the representation size.
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
Definition: sorted_interval_list.h:440
static Domain FromFlatIntervals(const std::vector< int64_t > &flat_intervals)
This method is available in Python, Java and .NET.
std::vector< int64_t > FlattenedIntervals() const
This method returns the flattened list of interval bounds of the domain.
DomainIteratorBeginEndWithOwnership Values() const &&
Definition: sorted_interval_list.h:215
int NumIntervals() const
Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.
Definition: sorted_interval_list.h:433
int64_t FixedValue() const
Returns the value of a fixed domain.
Domain ContinuousMultiplicationBy(const Domain &domain) const
Returns a superset of MultiplicationBy() to avoid the explosion in the representation size.
bool operator<(const Domain &other) const
Lexicographic order on the intervals() representation.
Domain AdditionWith(const Domain &domain) const
Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.
static Domain FromIntervals(absl::Span< const ClosedInterval > intervals)
Creates a domain from the union of an unsorted list of intervals.
ClosedInterval front() const
Definition: sorted_interval_list.h:434
bool operator!=(const Domain &other) const
Definition: sorted_interval_list.h:424
Domain UnionWith(const Domain &domain) const
Returns the union of D and domain.
ClosedInterval operator[](int i) const
Definition: sorted_interval_list.h:436
Domain MultiplicationBy(int64_t coeff, bool *exact=nullptr) const
Returns {x ∈ Int64, ∃ e ∈ D, x = e * coeff}.
bool IsFixed() const
Returns true iff the domain is reduced to a single value.
Domain IntersectionWith(const Domain &domain) const
Returns the intersection of D and domain.
Domain PositiveDivisionBySuperset(const Domain &divisor) const
Returns a superset of {x ∈ Int64, ∃ e ∈ D, ∃ d ∈ divisor, x = e / d }.
std::vector< ClosedInterval > intervals() const
Definition: sorted_interval_list.h:448
bool operator==(const Domain &other) const
Definition: sorted_interval_list.h:420
int64_t SmallestValue() const
Returns the value closest to zero.
Domain(const Domain &other)
Copy constructor (mandatory as we define the move constructor).
Definition: sorted_interval_list.h:89
Domain RelaxIfTooComplex() const
If NumIntervals() is too large, this return a superset of the domain.
static Domain FromFlatSpanOfIntervals(absl::Span< const int64_t > flat_intervals)
Same as FromIntervals() for a flattened representation (start, end, start, end, .....
Domain(int64_t value)
Constructor for the common case of a singleton domain.
Domain SquareSuperset() const
Returns a superset of {x ∈ Int64, ∃ y ∈ D, x = y * y }.
absl::InlinedVector< ClosedInterval, 1 >::const_iterator begin() const
Definition: sorted_interval_list.h:437
Domain & operator=(const Domain &other)
Copy operator (mandatory as we define the move operator).
Definition: sorted_interval_list.h:92
Domain DivisionBy(int64_t coeff) const
Returns {x ∈ Int64, ∃ e ∈ D, x = e / coeff}.
static Domain FromVectorIntervals(const std::vector< std::vector< int64_t > > &intervals)
This method is available in Python, Java and .NET.
Domain(int64_t left, int64_t right)
Constructor for the common case of a single interval [left, right].
DomainIteratorBeginEnd Values() const &
Definition: sorted_interval_list.h:214
int64_t ValueAtOrAfter(int64_t input) const
Domain PositiveModuloBySuperset(const Domain &modulo) const
Returns a superset of {x ∈ Int64, ∃ e ∈ D, ∃ m ∈ modulo, x = e % m }.
Domain SimplifyUsingImpliedDomain(const Domain &implied_domain) const
Advanced usage.
int64_t ValueAtOrBefore(int64_t input) const
Returns the closest value in the domain that is <= (resp.
This class represents a sorted list of disjoint, closed intervals.
Definition: sorted_interval_list.h:484
SortedDisjointIntervalList(const std::vector< int64_t > &starts, const std::vector< int64_t > &ends)
Creates a SortedDisjointIntervalList and fills it with intervals [starts[i]..ends[i]].
const ClosedInterval & last() const
Returns a const& to the last interval.
Definition: sorted_interval_list.h:584
void InsertIntervals(const std::vector< int64_t > &starts, const std::vector< int64_t > &ends)
Adds all intervals [starts[i]..ends[i]].
int NumIntervals() const
Returns the number of disjoint intervals in the list.
Definition: sorted_interval_list.h:553
IntervalSet::const_iterator ConstIterator
Definition: sorted_interval_list.h:493
ConstIterator end() const
Definition: sorted_interval_list.h:579
void swap(SortedDisjointIntervalList &other)
Definition: sorted_interval_list.h:587
std::string DebugString() const
IntervalSet::iterator Iterator
Definition: sorted_interval_list.h:492
SortedDisjointIntervalList(const std::vector< int > &starts, const std::vector< int > &ends)
Iterator InsertInterval(int64_t start, int64_t end)
Adds the interval [start..end] to the list, and merges overlapping or immediately adjacent intervals ...
std::set< ClosedInterval, IntervalComparator > IntervalSet
Definition: sorted_interval_list.h:491
void clear()
Definition: sorted_interval_list.h:586
ConstIterator begin() const
Const iterators for SortedDisjoinIntervalList.
Definition: sorted_interval_list.h:578
SortedDisjointIntervalList BuildComplementOnInterval(int64_t start, int64_t end)
Builds the complement of the interval list on the interval [start, end].
Iterator LastIntervalLessOrEqual(int64_t value) const
Iterator FirstIntervalGreaterOrEqual(int64_t value) const
Returns an iterator to either:
SortedDisjointIntervalList()
SortedDisjointIntervalList(const std::vector< ClosedInterval > &intervals)
Iterator GrowRightByOne(int64_t value, int64_t *newly_covered)
If value is in an interval, increase its end by one, otherwise insert the interval [value,...
void InsertIntervals(const std::vector< int > &starts, const std::vector< int > &ends)
Definition: cp_model.h:59
std::ostream & operator<<(std::ostream &out, const ClosedInterval &interval)
int64_t SumOfKMinValueInDomain(const Domain &domain, int k)
bool IntervalsAreSortedAndNonAdjacent(absl::Span< const ClosedInterval > intervals)
Returns true iff we have:
int64_t SumOfKMaxValueInDomain(const Domain &domain, int k)
Represents a closed interval [start, end].
Definition: sorted_interval_list.h:34
bool operator==(const ClosedInterval &other) const
Definition: sorted_interval_list.h:42
std::string DebugString() const
ClosedInterval()
Definition: sorted_interval_list.h:35
bool operator<(const ClosedInterval &other) const
Definition: sorted_interval_list.h:49
ClosedInterval(int64_t s, int64_t e)
Definition: sorted_interval_list.h:36
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
Definition: sorted_interval_list.h:202
const absl::InlinedVector< ClosedInterval, 1 > & intervals
Definition: sorted_interval_list.h:205
DomainIterator begin() const
Definition: sorted_interval_list.h:201
Definition: sorted_interval_list.h:207
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end() const
Definition: sorted_interval_list.h:209
absl::InlinedVector< ClosedInterval, 1 > intervals
Definition: sorted_interval_list.h:212
DomainIterator begin() const
Definition: sorted_interval_list.h:208
Definition: sorted_interval_list.h:486
bool operator()(const ClosedInterval &a, const ClosedInterval &b) const
Definition: sorted_interval_list.h:487