Commit 84eb9c4b authored by Fabian Becker's avatar Fabian Becker

Move all AbstractEAComparators to actually use that as base object

parent 4b0a2ecd
Pipeline #93 passed with stage
......@@ -19,7 +19,7 @@ import java.util.Comparator;
* @see AbstractEAIndividual#isDominatingFitness(double[], double[])
*/
@eva2.util.annotation.Description(value = "A comparator class for general EA individuals. Compares individuals based on their fitness in context of minimization.")
public class EAIndividualComparator implements Comparator<Object>, Serializable {
public class EAIndividualComparator implements Comparator<AbstractEAIndividual>, Serializable {
// flag whether a data field should be used.
private String indyDataKey = "";
private int fitCriterion = -1;
......@@ -122,7 +122,7 @@ public class EAIndividualComparator implements Comparator<Object>, Serializable
* @return -1 if the first is dominant, 1 if the second is dominant, otherwise 0
*/
@Override
public int compare(Object o1, Object o2) {
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
boolean o1domO2, o2domO1;
if (preferFeasible) { // check constraint violation first?
......
......@@ -9,7 +9,7 @@ import java.util.Comparator;
* Compare two AbstractEAIndividuals by their distance to a reference individual.
* Usable to sort by a distance.
*/
public class IndividualDistanceComparator implements Comparator<Object>, Serializable {
public class IndividualDistanceComparator implements Comparator<AbstractEAIndividual>, Serializable {
private AbstractEAIndividual refIndy = null;
private InterfaceDistanceMetric distMetric = null;
......@@ -30,9 +30,9 @@ public class IndividualDistanceComparator implements Comparator<Object>, Seriali
}
@Override
public int compare(Object o1, Object o2) {
double d1 = distMetric.distance((AbstractEAIndividual) o1, refIndy);
double d2 = distMetric.distance((AbstractEAIndividual) o2, refIndy);
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
double d1 = distMetric.distance(o1, refIndy);
double d2 = distMetric.distance(o2, refIndy);
if (d1 == d2) {
return 0;
......
......@@ -10,7 +10,7 @@ import java.util.Comparator;
*
* @author mkron
*/
public class IndividualWeightedFitnessComparator implements Comparator<Object>, Serializable {
public class IndividualWeightedFitnessComparator implements Comparator<AbstractEAIndividual>, Serializable {
/**
* Generated serial version identifier
*/
......@@ -75,9 +75,9 @@ public class IndividualWeightedFitnessComparator implements Comparator<Object>,
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Object o1, Object o2) {
double[] f1 = ((AbstractEAIndividual) o1).getFitness();
double[] f2 = ((AbstractEAIndividual) o2).getFitness();
public int compare(AbstractEAIndividual o1, AbstractEAIndividual o2) {
double[] f1 = o1.getFitness();
double[] f2 = o2.getFitness();
double score1 = calcScore(f1);
double score2 = calcScore(f2);
......
......@@ -52,7 +52,7 @@ public class ArchivingNSGAIISMeasure extends ArchivingNSGAII {
public void calculateCrowdingDistance(Population front) {
Object[] frontArray = front.toArray();
AbstractEAIndividual[] frontArray = front.toArray(new AbstractEAIndividual[front.size()]);
boolean[] assigned = new boolean[frontArray.length];
double[] v = new double[frontArray.length];
......@@ -68,8 +68,8 @@ public class ArchivingNSGAIISMeasure extends ArchivingNSGAII {
Arrays.sort(frontArray, new EAIndividualComparator(0));
((AbstractEAIndividual) frontArray[0]).putData("HyperCube", Double.MAX_VALUE); //die beiden aussen bekommen maximal wert als measure
((AbstractEAIndividual) frontArray[frontArray.length - 1]).putData("HyperCube", Double.MAX_VALUE);
frontArray[0].putData("HyperCube", Double.MAX_VALUE); //die beiden aussen bekommen maximal wert als measure
frontArray[frontArray.length - 1].putData("HyperCube", Double.MAX_VALUE);
v[0] = Double.MAX_VALUE;
v[frontArray.length - 1] = Double.MAX_VALUE;
......
......@@ -1038,7 +1038,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comparator indicate whether constraints should be regarded
* @return The index of the best (worst) individual.
*/
public int getIndexOfBestOrWorstIndividual(boolean bBest, Comparator<Object> comparator) {
public int getIndexOfBestOrWorstIndividual(boolean bBest, Comparator<AbstractEAIndividual> comparator) {
ArrayList<?> sorted = getSorted(comparator);
if (bBest) {
return indexOf(sorted.get(0));
......@@ -1051,7 +1051,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
return getIndexOfBestOrWorstIndividual(true, comparator);
}
public AbstractEAIndividual getBestEAIndividual(Comparator<Object> comparator) {
public AbstractEAIndividual getBestEAIndividual(Comparator<AbstractEAIndividual> comparator) {
int index = getIndexOfBestOrWorstIndividual(true, comparator);
return getEAIndividual(index);
}
......@@ -1199,7 +1199,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* fitness first
* @see #getSortedNIndividuals(int, boolean, Population, Comparator)
*/
public Population getSortedBestFirst(Comparator<Object> comp) {
public Population getSortedBestFirst(Comparator<AbstractEAIndividual> comp) {
Population result = this.cloneWithoutInds();
getSortedNIndividuals(size(), true, result, comp);
result.synchSize();
......@@ -1219,7 +1219,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comp the Comparator to use with individuals
* @param res The m sorted best or worst individuals, where m &lt;= n (will be added to res)
*/
public void getSortedNIndividuals(int n, boolean bBestOrWorst, Population res, Comparator<Object> comp) {
public void getSortedNIndividuals(int n, boolean bBestOrWorst, Population res, Comparator<AbstractEAIndividual> comp) {
if ((n < 0) || (n > super.size())) {
// this may happen, treat it gracefully
//System.err.println("invalid request to getSortedNIndividuals: n="+n + ", size is " + super.size());
......@@ -1291,7 +1291,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* on AbstractEAIndividual instances.
* @return
*/
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<Object> comp) {
protected ArrayList<AbstractEAIndividual> sortBy(Comparator<AbstractEAIndividual> comp) {
if (super.isEmpty()) {
return new ArrayList<>();
}
......@@ -1320,7 +1320,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* @param comp The comparator
* @return
*/
public ArrayList<AbstractEAIndividual> getSorted(Comparator<Object> comp) {
public ArrayList<AbstractEAIndividual> getSorted(Comparator<AbstractEAIndividual> comp) {
if (!comp.equals(lastSortingComparator) || (sortedArr == null) || (super.modCount != lastQModCount)) {
ArrayList<AbstractEAIndividual> sArr = sortBy(comp);
if (sortedArr == null) {
......@@ -1340,7 +1340,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
*
* @see #getSorted(java.util.Comparator)
*/
public Population getSortedPop(Comparator<Object> comp) {
public Population getSortedPop(Comparator<AbstractEAIndividual> comp) {
Population pop = this.cloneWithoutInds();
ArrayList<AbstractEAIndividual> sortedIndies = getSorted(comp);
pop.addAll(sortedIndies);
......
......@@ -44,7 +44,7 @@ import java.util.Vector;
public class ParticleSwarmOptimization extends AbstractOptimizer implements java.io.Serializable, InterfaceAdditionalPopulationInformer {
public enum PSOType { Inertness, Constriction }
Object[] sortedPop = null;
AbstractEAIndividual[] sortedPop = null;
protected AbstractEAIndividual bestIndividual = null;
protected boolean checkRange = true;
protected boolean checkSpeedLimit = false;
......@@ -1299,7 +1299,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java
}
}
if ((topology == PSOTopology.multiSwarm) || (topology == PSOTopology.tree)) {
sortedPop = pop.toArray();
sortedPop = pop.toArray(new AbstractEAIndividual[pop.size()]);
if ((topology == PSOTopology.multiSwarm) || (treeStruct >= 2)) {
Arrays.sort(sortedPop, new EAIndividualComparator());
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment