Class Domain
java.lang.Object
com.google.ortools.util.Domain
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 that all the functions are safe with respect to integer overflow.
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 that all the functions are safe with respect to integer overflow.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDomain()By default, Domain will be empty.Domain(long value) Constructor for the common case of a singleton domain.Domain(long cPtr, boolean cMemoryOwn) Domain(long left, long right) Constructor for the common case of a single interval [left, right].
If left > right, this will result in the empty domain. -
Method Summary
Modifier and TypeMethodDescriptionadditionWith(Domain domain) Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.static DomainReturns the full domain Int64.Returns the set Int64 ∖ D.booleancontains(long value) Returns true iff value is in Domain.voiddelete()protected voidfinalize()long[]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] (as a C++ std::vector<int64_t>, as a java or C# long[], as
a python list of integers).static DomainfromFlatIntervals(long[] flat_intervals) This method is available in Python, Java and .NET.static DomainfromIntervals(long[][] intervals) This method is available in Python, Java and .NET.static DomainfromValues(long[] values) Creates a domain from the union of an unsorted list of integer values.
Input values may be repeated, with no consequence on the outputstatic longstatic DomaingreaterOrEqual(long value) Returns the domain [value., int_max].intersectionWith(Domain domain) Returns the intersection of D and domain.booleanisEmpty()Returns true if this is the empty set.booleanisIncludedIn(Domain domain) Returns true iff D is included in the given domain.static DomainlowerOrEqual(long value) Returns the domain [int_min, value].longmax()Returns the max value of the domain.
The domain must not be empty.longmin()Returns the min value of the domain.
The domain must not be empty.negation()Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.
Note in particular that if the negation of Int64 is not Int64 but
Int64 \ {kint64min} !!booleanoverlapsWith(Domain domain) Returns true iff D overlaps with the given domain, that is, the
intersection of the two domains is not empty.longsize()Returns the number of elements in the domain.static longswigRelease(Domain obj) toString()Returns a compact string of a vector of intervals like "[1,4][6][10,20]".Returns the union of D and domain.
-
Field Details
-
swigCMemOwn
protected transient boolean swigCMemOwn
-
-
Constructor Details
-
Domain
public Domain(long cPtr, boolean cMemoryOwn) -
Domain
public Domain()By default, Domain will be empty. -
Domain
public Domain(long value) Constructor for the common case of a singleton domain. -
Domain
public Domain(long left, long right) Constructor for the common case of a single interval [left, right].
If left > right, this will result in the empty domain.
-
-
Method Details
-
getCPtr
-
swigRelease
-
finalize
-
delete
public void delete() -
allValues
Returns the full domain Int64. -
lowerOrEqual
Returns the domain [int_min, value]. -
greaterOrEqual
Returns the domain [value., int_max]. -
fromValues
Creates a domain from the union of an unsorted list of integer values.
Input values may be repeated, with no consequence on the output -
fromIntervals
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], [8, 10]] in python).
Note that the intervals can be defined with a single value (i.e. [5]), or
two increasing values (i.e. [8, 10]).
Invalid intervals (start > end) will log a DFATAL error and will be
ignored. -
fromFlatIntervals
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).
Note that invalid intervals (start > end) will log a DFATAL error and will
be ignored. -
flattenedIntervals
public long[] flattenedIntervals()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] (as a C++ std::vector<int64_t>, as a java or C# long[], as
a python list of integers). -
isEmpty
public boolean isEmpty()Returns true if this is the empty set. -
size
public long size()Returns the number of elements in the domain. It is capped at kint64max -
min
public long min()Returns the min value of the domain.
The domain must not be empty. -
max
public long max()Returns the max value of the domain.
The domain must not be empty. -
contains
public boolean contains(long value) Returns true iff value is in Domain. -
isIncludedIn
Returns true iff D is included in the given domain. -
overlapsWith
Returns true iff D overlaps with the given domain, that is, the
intersection of the two domains is not empty. -
complement
Returns the set Int64 ∖ D. -
negation
Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.
Note in particular that if the negation of Int64 is not Int64 but
Int64 \ {kint64min} !! -
intersectionWith
-
unionWith
-
additionWith
-
toString
-