Package com.google.ortools.util
Class Domain
- java.lang.Object
-
- com.google.ortools.util.Domain
-
public class Domain extends java.lang.ObjectWe 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanswigCMemOwn
-
Constructor Summary
Constructors Constructor Description Domain()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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DomainadditionWith(Domain domain)Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.static DomainallValues()Returns the full domain Int64.Domaincomplement()Returns the set Int64 ∖ D.booleancontains(long value)Returns true iff value is in Domain.voiddelete()protected voidfinalize()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).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 longgetCPtr(Domain obj)DomainintersectionWith(Domain domain)Returns the intersection of D and domain.booleanisEmpty()Returns true if this is the empty set.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.Domainnegation()Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.
Note in particular that if the negation of Int64 is not Int64 but
Int64 \ {kint64min} !!longsize()Returns the number of elements in the domain.static longswigRelease(Domain obj)java.lang.StringtoString()Returns a compact string of a vector of intervals like "[1,4][6][10,20]".DomainunionWith(Domain domain)Returns the union of D and domain.
-
-
-
Constructor Detail
-
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 Detail
-
getCPtr
public static long getCPtr(Domain obj)
-
swigRelease
public static long swigRelease(Domain obj)
-
finalize
protected void finalize()
- Overrides:
finalizein classjava.lang.Object
-
delete
public void delete()
-
allValues
public static Domain allValues()
Returns the full domain Int64.
-
fromValues
public 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 output
-
fromIntervals
public static Domain fromIntervals(long[][] intervals)
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).
-
fromFlatIntervals
public static Domain fromFlatIntervals(long[] flat_intervals)
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).
-
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
public Domain complement()
Returns the set Int64 ∖ D.
-
negation
public Domain negation()
Returns {x ∈ Int64, ∃ e ∈ D, x = -e}.
Note in particular that if the negation of Int64 is not Int64 but
Int64 \ {kint64min} !!
-
intersectionWith
public Domain intersectionWith(Domain domain)
Returns the intersection of D and domain.
-
additionWith
public Domain additionWith(Domain domain)
Returns {x ∈ Int64, ∃ a ∈ D, ∃ b ∈ domain, x = a + b}.
-
toString
public java.lang.String toString()
Returns a compact string of a vector of intervals like "[1,4][6][10,20]".- Overrides:
toStringin classjava.lang.Object
-
-