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 Domain
Returns the full domain Int64.Returns the set Int64 ∖ D.boolean
contains
(long value) Returns true iff value is in Domain.void
delete()
protected void
finalize()
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 Domain
fromFlatIntervals
(long[] flat_intervals) This method is available in Python, Java and .NET.static Domain
fromIntervals
(long[][] intervals) This method is available in Python, Java and .NET.static Domain
fromValues
(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 long
intersectionWith
(Domain domain) Returns the intersection of D and domain.boolean
isEmpty()
Returns true if this is the empty set.long
max()
Returns the max value of the domain.
The domain must not be empty.long
min()
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} !!long
size()
Returns the number of elements in the domain.static long
swigRelease
(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. -
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. -
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
-