ntbea.IntArrayPattern Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of NTBEA Show documentation
Show all versions of NTBEA Show documentation
Parameter optimisation with the N-Tuple Bandit Evolutionary Algorithm
package ntbea;
import java.util.Arrays;
import java.util.HashMap;
/**
* This class provides a hashable and comparable wrapper around an array of int.
*
* It provides equals, compareTo, and hashCode methods
*/
public class IntArrayPattern implements Comparable {
public static void main(String[] args) {
int[] x = {0, 1, 2, 3, 3};
int[] ix1 = {0, 3};
int[] ix2 = {0, 4};
int[] ix3 = {0, 1};
IntArrayPattern p1 = new IntArrayPattern().setPattern(x, ix1);
IntArrayPattern p2 = new IntArrayPattern().setPattern(x, ix2);
IntArrayPattern p3 = new IntArrayPattern().setPattern(x, ix3);
HashMap test = new HashMap<>();
test.put(p1, 1);
test.put(p2, 2);
test.put(p3, 3);
System.out.println(test);
}
public int[] v;
public IntArrayPattern setPattern(int[] v) {
this.v = v;
return this;
}
public IntArrayPattern setPattern(int[] x, int[] ix) {
v = new int[ix.length];
for (int i=0; i p.v[i]) {
return 1;
}
if (v[i] < p.v[i]) {
return -1;
}
}
return 0;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
public String toString() {
return Arrays.toString(v);
}
}