Package io.jenetics.ext.moea
Interface Vec<T>
- 
- Type Parameters:
 T- the underlying array type, likeint[]ordouble[]
- All Superinterfaces:
 Comparable<Vec<T>>
public interface Vec<T> extends Comparable<Vec<T>>
TheVecinterface represents the fitness result of a multi-objective fitness function. It also defines a set of static factory methods which allows you to createVecinstance from a givenint[],long[]ordouble[]array.The underlying array is just wrapped and not copied. This means you can change the values of thefinal Vec<double[]> point2D = Vec.of(0.1, 5.4); final Vec<int[]> point3D = Vec.of(1, 2, 3);Veconce it is created, Not copying the underlying array is done for performance reason. Changing theVecdata is, of course, never a good idea.- Since:
 - 4.1
 - Version:
 - 4.1
 - See Also:
 VecFactory, Pareto efficiency- Implementation Note:
 - Although the 
Vecinterface extends theComparableinterface, it violates its general contract. It only implements the pareto dominance relation, which defines a partial order. So, trying to sort a list ofVecobjects, might lead to an exception (thrown by the sorting method) at runtime. 
 
- 
- 
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ElementComparator<T>comparator()Return the comparator for comparing the elements of this MO vector.default intcompare(Vec<T> other, int index)Compares thethisvector with theotherat the given componentindex.default intcompareTo(Vec<T> other)The default implementation uses thedominance(Vec)function for defining a partial order of two vectors.Tdata()Return the underlying data structure.ElementDistance<T>distance()Return a function which calculates the element distance of a vector at a given element index.default doubledistance(Vec<T> other, int index)Calculates the distance between two vector elements at the givenindex.Comparator<T>dominance()Return the comparator which defines the (Pareto) dominance measure.static intdominance(double[] u, double[] v)Calculates the Pareto Dominance of the two vectors u and v.static intdominance(int[] u, int[] v)Calculates the Pareto Dominance of the two vectors u and v.static intdominance(long[] u, long[] v)Calculates the Pareto Dominance of the two vectors u and v.static <C extends Comparable<? super C>>
intdominance(C[] u, C[] v)Calculates the Pareto Dominance of the two vectors u and v.default intdominance(Vec<T> other)static <T> intdominance(T[] u, T[] v, Comparator<? super T> comparator)Calculates the Pareto Dominance of the two vectors u and v.intlength()Return the number of vector elements.static Vec<double[]>of(double... array)Wraps the given array into aVecobject.static Vec<int[]>of(int... array)Wraps the given array into aVecobject.static Vec<long[]>of(long... array)Wraps the given array into aVecobject.static <C extends Comparable<? super C>>
Vec<C[]>of(C[] array)Wraps the given array into aVecobject.static <C extends Comparable<? super C>>
Vec<C[]>of(C[] array, ElementDistance<C[]> distance)Wraps the given array into aVecobject.static <T> Vec<T[]>of(T[] array, Comparator<? super T> comparator, ElementDistance<T[]> distance)Wraps the given array into aVecobject. 
 - 
 
- 
- 
Method Detail
- 
length
int length()
Return the number of vector elements.- Returns:
 - the number of vector elements
 
 
- 
comparator
ElementComparator<T> comparator()
Return the comparator for comparing the elements of this MO vector.- Returns:
 - the comparator for comparing the elements of this MO vector
 
 
- 
distance
ElementDistance<T> distance()
Return a function which calculates the element distance of a vector at a given element index.- Returns:
 - a function which calculates the element distance of a vector at a given element index
 
 
- 
dominance
Comparator<T> dominance()
Return the comparator which defines the (Pareto) dominance measure.- Returns:
 - the comparator which defines the (Pareto) dominance measure
 
 
- 
compare
default int compare(Vec<T> other, int index)
Compares thethisvector with theotherat the given componentindex.- Parameters:
 other- the other vectorindex- the component index- Returns:
 - a negative integer, zero, or a positive integer as
        
this[index]is less than, equal to, or greater thanother[index] - Throws:
 NullPointerException- if theotherobject isnullIllegalArgumentException- if theindexis out of the valid range[0, length())
 
- 
distance
default double distance(Vec<T> other, int index)
Calculates the distance between two vector elements at the givenindex.- Parameters:
 other- the second vectorindex- the vector element index- Returns:
 - the distance between two vector elements
 - Throws:
 NullPointerException- if theothervector isnullIllegalArgumentException- if theindexis out of the valid range[0, length())
 
- 
dominance
default int dominance(Vec<T> other)
- Parameters:
 other- the other vector- Returns:
 1if value() ≻ other,-1if other ≻ value() and0otherwise- Throws:
 NullPointerException- if theothervector isnull
 
- 
compareTo
default int compareTo(Vec<T> other)
The default implementation uses thedominance(Vec)function for defining a partial order of two vectors.- Specified by:
 compareToin interfaceComparable<T>- Parameters:
 other- the other vector- Returns:
 1if value() ≻ other,-1if other ≻ value() and0otherwise- Throws:
 NullPointerException- if theothervector isnull
 
- 
dominance
static <C extends Comparable<? super C>> int dominance(C[] u, C[] v)
Calculates the Pareto Dominance of the two vectors u and v.- Type Parameters:
 C- the element type of vector u and v- Parameters:
 u- the first vectorv- the second vector- Returns:
 1if u ≻ v,-1if v ≻ u and0otherwise- Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- ifu.length != v.length- See Also:
 Pareto.dominance(Comparable[], Comparable[])
 
- 
dominance
static <T> int dominance(T[] u, T[] v, Comparator<? super T> comparator)
Calculates the Pareto Dominance of the two vectors u and v.- Type Parameters:
 T- the element type of vector u and v- Parameters:
 u- the first vectorv- the second vectorcomparator- the element comparator which is used for calculating the dominance- Returns:
 1if u ≻ v,-1if v ≻ u and0otherwise- Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- ifu.length != v.length- See Also:
 Pareto.dominance(Object[], Object[], Comparator)
 
- 
dominance
static int dominance(int[] u, int[] v)
Calculates the Pareto Dominance of the two vectors u and v.- Parameters:
 u- the first vectorv- the second vector- Returns:
 1if u ≻ v,-1if v ≻ u and0otherwise- Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- ifu.length != v.length- See Also:
 Pareto.dominance(int[], int[])
 
- 
dominance
static int dominance(long[] u, long[] v)
Calculates the Pareto Dominance of the two vectors u and v.- Parameters:
 u- the first vectorv- the second vector- Returns:
 1if u ≻ v,-1if v ≻ u and0otherwise- Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- ifu.length != v.length- See Also:
 Pareto.dominance(long[], long[])
 
- 
dominance
static int dominance(double[] u, double[] v)
Calculates the Pareto Dominance of the two vectors u and v.- Parameters:
 u- the first vectorv- the second vector- Returns:
 1if u ≻ v,-1if v ≻ u and0otherwise- Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- ifu.length != v.length- See Also:
 Pareto.dominance(double[], double[])
 
- 
of
static <C extends Comparable<? super C>> Vec<C[]> of(C[] array)
Wraps the given array into aVecobject.- Type Parameters:
 C- the array element type- Parameters:
 array- the wrapped array- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- if thearraylength is zero
 
- 
of
static <C extends Comparable<? super C>> Vec<C[]> of(C[] array, ElementDistance<C[]> distance)
Wraps the given array into aVecobject.- Type Parameters:
 C- the array element type- Parameters:
 array- the wrapped arraydistance- the array element distance measure- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- if thearraylength is zero
 
- 
of
static <T> Vec<T[]> of(T[] array, Comparator<? super T> comparator, ElementDistance<T[]> distance)
Wraps the given array into aVecobject.- Type Parameters:
 T- the array element type- Parameters:
 array- the wrapped arraycomparator- the (natural order) comparator of the array elementsdistance- the distance function between two vector elements- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if one of the arguments isnullIllegalArgumentException- if thearraylength is zero
 
- 
of
static Vec<int[]> of(int... array)
Wraps the given array into aVecobject.- Parameters:
 array- the wrapped array- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if the givenarrayisnullIllegalArgumentException- if thearraylength is zero
 
- 
of
static Vec<long[]> of(long... array)
Wraps the given array into aVecobject.- Parameters:
 array- the wrapped array- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if the givenarrayisnullIllegalArgumentException- if thearraylength is zero
 
- 
of
static Vec<double[]> of(double... array)
Wraps the given array into aVecobject.- Parameters:
 array- the wrapped array- Returns:
 - the given array wrapped into a 
Vecobject. - Throws:
 NullPointerException- if the givenarrayisnullIllegalArgumentException- if thearraylength is zero
 
 - 
 
 -