operations_research::Domain Class Reference

Detailed Description

We call "domain" any subset of Int64 = [kint64min, kint64max].

This class can be used to represent such set efficiently as a sorted and non-adjacent list of intervals. This is efficient as long as the size of such list stays reasonable.In the comments below, the domain of *this will always be written 'D'.

Note
all the functions are safe with respect to integer overflow.

Definition at line 70 of file sorted_interval_list.h.

Public Member Functions

 Domain ()
 By default, Domain will be empty. More...
 
 Domain (int64 value)
 Constructor for the common case of a singleton domain. More...
 
 Domain (int64 left, int64 right)
 Constructor for the common case of a single interval [left, right]. More...
 
std::vector< int64 > FlattenedIntervals () const
 This method returns the flattened list of interval bounds of the domain. More...
 
bool IsEmpty () const
 Returns true if this is the empty set. More...
 
int64 Size () const
 Returns the number of elements in the domain. It is capped at kint64max. More...
 
int64 Min () const
 Returns the domain min value. More...
 
int64 Max () const
 Returns the domain max value. More...
 
bool Contains (int64 value) const
 Returns true iff value is in Domain. More...
 
bool IsIncludedIn (const Domain &domain) const
 Returns true iff D is included in the given domain. More...
 
Domain Complement () const
 Returns the set Int64 ∖ D. More...
 
Domain Negation () const
 Returns {x ∈ Int64, ∃ e ∈ D, x = -e}. More...
 
Domain IntersectionWith (const Domain &domain) const
 Returns the set D ∩ domain. More...
 
Domain UnionWith (const Domain &domain) const
 Returns the set D ∪ domain. More...
 
Domain AdditionWith (const Domain &domain) const
 Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}. More...
 
Domain MultiplicationBy (int64 coeff, bool *exact=nullptr) const
 Returns {x ∈ Int64, ∃ e ∈ D, x = e * coeff}. More...
 
Domain RelaxIfTooComplex () const
 If NumIntervals() is too large, this return a superset of the domain. More...
 
Domain ContinuousMultiplicationBy (int64 coeff) const
 Returns a super-set of MultiplicationBy() to avoid the explosion in the representation size. More...
 
Domain ContinuousMultiplicationBy (const Domain &domain) const
 Returns a super-set of MultiplicationBy() to avoid the explosion in the representation size. More...
 
Domain DivisionBy (int64 coeff) const
 Returns {x ∈ Int64, ∃ e ∈ D, x = e / coeff}. More...
 
Domain InverseMultiplicationBy (const int64 coeff) const
 Returns {x ∈ Int64, ∃ e ∈ D, x * coeff = e}. More...
 
Domain SimplifyUsingImpliedDomain (const Domain &implied_domain) const
 Advanced usage. More...
 
std::string ToString () const
 Returns a compact std::string of a vector of intervals like "[1,4][6][10,20]". More...
 
bool operator< (const Domain &other) const
 Lexicographic order on the intervals() representation. More...
 
bool operator== (const Domain &other) const
 
bool operator!= (const Domain &other) const
 
int NumIntervals () const
 Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals. More...
 
ClosedInterval front () const
 
ClosedInterval back () const
 
ClosedInterval operator[] (int i) const
 
absl::InlinedVector< ClosedInterval, 1 >::const_iterator begin () const
 
absl::InlinedVector< ClosedInterval, 1 >::const_iterator end () const
 
std::vector< ClosedIntervalintervals () const
 

Static Public Member Functions

static Domain AllValues ()
 Returns the full domain Int64. More...
 
static Domain FromValues (std::vector< int64 > values)
 Creates a domain from the union of an unsorted list of integer values. More...
 
static Domain FromIntervals (absl::Span< const ClosedInterval > intervals)
 Creates a domain from the union of an unsorted list of intervals. More...
 
static Domain FromVectorIntervals (const std::vector< std::vector< int64 > > &intervals)
 This method is available in Python, Java and .NET. More...
 
static Domain FromFlatIntervals (const std::vector< int64 > &flat_intervals)
 This method is available in Python, Java and .NET. More...
 

Constructor & Destructor Documentation

◆ Domain() [1/3]

operations_research::Domain::Domain ( )
inline

By default, Domain will be empty.

Definition at line 73 of file sorted_interval_list.h.

◆ Domain() [2/3]

operations_research::Domain::Domain ( int64  value)
explicit

Constructor for the common case of a singleton domain.

◆ Domain() [3/3]

operations_research::Domain::Domain ( int64  left,
int64  right 
)

Constructor for the common case of a single interval [left, right].

If left > right, this will result in the empty domain.

Member Function Documentation

◆ AdditionWith()

Domain operations_research::Domain::AdditionWith ( const Domain domain) const

Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.

◆ AllValues()

static Domain operations_research::Domain::AllValues ( )
static

Returns the full domain Int64.

◆ back()

ClosedInterval operations_research::Domain::back ( ) const
inline

Definition at line 244 of file sorted_interval_list.h.

◆ begin()

absl::InlinedVector<ClosedInterval, 1>::const_iterator operations_research::Domain::begin ( ) const
inline

Definition at line 246 of file sorted_interval_list.h.

◆ Complement()

Domain operations_research::Domain::Complement ( ) const

Returns the set Int64 ∖ D.

◆ Contains()

bool operations_research::Domain::Contains ( int64  value) const

Returns true iff value is in Domain.

◆ ContinuousMultiplicationBy() [1/2]

Domain operations_research::Domain::ContinuousMultiplicationBy ( int64  coeff) const

Returns a super-set of MultiplicationBy() to avoid the explosion in the representation size.

This behaves as if we replace the set D of non-adjacent integer intervals by the set of floating-point element in the same intervals.For instance, [1, 100] * 2 will be transformed in [2, 200] and not in [2][4][6]...[200] like in MultiplicationBy(). Note that this would be similar to a InverseDivisionBy(), but not quite the same because if we look for {x ∈ Int64, ∃ e ∈ D, x / coeff = e}, then we will get [2, 201] in the case above.

◆ ContinuousMultiplicationBy() [2/2]

Domain operations_research::Domain::ContinuousMultiplicationBy ( const Domain domain) const

Returns a super-set of MultiplicationBy() to avoid the explosion in the representation size.

This behaves as if we replace the set D of non-adjacent integer intervals by the set of floating-point element in the same intervals.For instance, [1, 100] * 2 will be transformed in [2, 200] and not in [2][4][6]...[200] like in MultiplicationBy(). Note that this would be similar to a InverseDivisionBy(), but not quite the same because if we look for {x ∈ Int64, ∃ e ∈ D, x / coeff = e}, then we will get [2, 201] in the case above.

◆ DivisionBy()

Domain operations_research::Domain::DivisionBy ( int64  coeff) const

Returns {x ∈ Int64, ∃ e ∈ D, x = e / coeff}.

For instance Domain(1, 7).DivisionBy(2) == Domain(0, 3).

◆ end()

absl::InlinedVector<ClosedInterval, 1>::const_iterator operations_research::Domain::end ( ) const
inline

Definition at line 249 of file sorted_interval_list.h.

◆ FlattenedIntervals()

std::vector<int64> operations_research::Domain::FlattenedIntervals ( ) const

This method returns the flattened list of interval bounds of the domain.

Thus the domain {0, 1, 2, 5, 8, 9, 10} will return 0, 2, 5, 5, 8, 10.

◆ FromFlatIntervals()

static Domain operations_research::Domain::FromFlatIntervals ( const std::vector< int64 > &  flat_intervals)
static

This method is available in Python, Java and .NET.

It allows building a Domain object from a flattened list of intervals (long[] in Java and .NET, [0, 2, 5, 5, 8, 10] in python).

◆ FromIntervals()

static Domain operations_research::Domain::FromIntervals ( absl::Span< const ClosedInterval intervals)
static

Creates a domain from the union of an unsorted list of intervals.

◆ FromValues()

static Domain operations_research::Domain::FromValues ( std::vector< int64 >  values)
static

Creates a domain from the union of an unsorted list of integer values.

Input values may be repeated, with no consequence on the output

◆ FromVectorIntervals()

static Domain operations_research::Domain::FromVectorIntervals ( const std::vector< std::vector< int64 > > &  intervals)
static

This method is available in Python, Java and .NET.

It allows building a Domain object from a list of intervals (long[][] in Java and .NET, [[0, 2], [5, 5], [8, 10]] in python).

◆ front()

ClosedInterval operations_research::Domain::front ( ) const
inline

Definition at line 243 of file sorted_interval_list.h.

◆ IntersectionWith()

Domain operations_research::Domain::IntersectionWith ( const Domain domain) const

Returns the set D ∩ domain.

◆ intervals()

std::vector<ClosedInterval> operations_research::Domain::intervals ( ) const
inline
Deprecated:
Todo:
(user): remove, this makes a copy and is of a different type that our internal InlinedVector() anyway.

Definition at line 258 of file sorted_interval_list.h.

◆ InverseMultiplicationBy()

Domain operations_research::Domain::InverseMultiplicationBy ( const int64  coeff) const

Returns {x ∈ Int64, ∃ e ∈ D, x * coeff = e}.

For instance Domain(1, 7).InverseMultiplicationBy(2) == Domain(1, 3).

◆ IsEmpty()

bool operations_research::Domain::IsEmpty ( ) const

Returns true if this is the empty set.

◆ IsIncludedIn()

bool operations_research::Domain::IsIncludedIn ( const Domain domain) const

Returns true iff D is included in the given domain.

◆ Max()

int64 operations_research::Domain::Max ( ) const

Returns the domain max value.

It checks that the domain is not empty.

◆ Min()

int64 operations_research::Domain::Min ( ) const

Returns the domain min value.

It checks that the domain is not empty.

◆ MultiplicationBy()

Domain operations_research::Domain::MultiplicationBy ( int64  coeff,
bool *  exact = nullptr 
) const

Returns {x ∈ Int64, ∃ e ∈ D, x = e * coeff}.

Note
because the resulting domain will only contains multiple of coeff, the size of intervals.size() can become really large. If it is larger than a fixed constant, exact will be set to false and the result will be set to ContinuousMultiplicationBy(coeff).

◆ Negation()

Domain operations_research::Domain::Negation ( ) const

Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.

Note in particular that if the negation of Int64 is not Int64 but Int64 \ {kint64min} !!

◆ NumIntervals()

int operations_research::Domain::NumIntervals ( ) const
inline

Basic read-only std::vector<> wrapping to view a Domain as a sorted list of non-adjacent intervals.

Note that we don't expose size() which might be confused with the number of values in the domain.

Definition at line 241 of file sorted_interval_list.h.

◆ operator!=()

bool operations_research::Domain::operator!= ( const Domain other) const
inline

Definition at line 233 of file sorted_interval_list.h.

◆ operator<()

bool operations_research::Domain::operator< ( const Domain other) const

Lexicographic order on the intervals() representation.

◆ operator==()

bool operations_research::Domain::operator== ( const Domain other) const
inline

Definition at line 229 of file sorted_interval_list.h.

◆ operator[]()

ClosedInterval operations_research::Domain::operator[] ( int  i) const
inline

Definition at line 245 of file sorted_interval_list.h.

◆ RelaxIfTooComplex()

Domain operations_research::Domain::RelaxIfTooComplex ( ) const

If NumIntervals() is too large, this return a superset of the domain.

◆ SimplifyUsingImpliedDomain()

Domain operations_research::Domain::SimplifyUsingImpliedDomain ( const Domain implied_domain) const

Advanced usage.

Given some "implied" information on this domain that is assumed to be always true (i.e. only values in the intersection with implied domain matter), this function will simplify the current domain without changing the set of "possible values".More precisely, this will:

  • Take the intersection with implied_domain.
  • Minimize the number of intervals. That is, if the domain is like [1,2][4] and implied is [1][4], then the domain can be relaxed to [1, 4] to simplify its complexity without changing the set of admissible value assuming only implied values can be seen.
  • Restrict as much as possible the bounds of the remaining intervals. I.e if the input is [1,2] and implied is [0,4], then the domain will not be changed.
    Note
    domain.SimplifyUsingImpliedDomain(domain) will just return [domain.Min(), domain.Max()]. This is meant to be applied to the rhs of a constraint to make its propagation more efficient.

◆ Size()

int64 operations_research::Domain::Size ( ) const

Returns the number of elements in the domain. It is capped at kint64max.

◆ ToString()

std::string operations_research::Domain::ToString ( ) const

Returns a compact std::string of a vector of intervals like "[1,4][6][10,20]".

◆ UnionWith()

Domain operations_research::Domain::UnionWith ( const Domain domain) const

Returns the set D ∪ domain.


The documentation for this class was generated from the following file: