Merge branch 'master' of gitlab.cs.uni-tuebingen.de:eva2/eva2

This commit is contained in:
Fabian Becker 2014-10-23 11:52:08 +02:00
commit c7bf4dd7e2
5 changed files with 26 additions and 73 deletions

View File

@ -185,9 +185,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return false;
}
// Age will not be used
//if (this.age != indy.age) return false;
// checking on mutation/crossover probabilities
if (this.mutationProbability != indy.mutationProbability) {
return false;
@ -203,7 +200,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
if (!this.crossoverOperator.equals(indy.crossoverOperator)) {
return false;
}
// System.err.println("Check whether this is semantically meant by equality!!! (AbstractEAIndividual.equals())");
return true;
} else {
return false;
@ -235,10 +231,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return "AbstractEAIndividual";
}
// public String getIndividualName() {
// return this.name;
// }
/**
* This method is used when a new offspring is created the increment the
* name.
@ -276,28 +268,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
*/
public abstract boolean equalGenotypes(AbstractEAIndividual individual);
// /** Every object should have it's equals method, but who to programm it.
// * Currently i will limit myself to check the class and the fitness
// * values.
// * @param obj
// * @return True if the objects are equal.
// */
// public boolean equals(Object obj) {
// if (obj instanceof AbstractEAIndividual) {
// AbstractEAIndividual indy = (AbstractEAIndividual)obj;
// if (this.fitness.length != indy.fitness.length) return false;
//// for (int i = 0; i < this.fitness.length; i++) if (this.fitness[i] != indy.fitness[i]) return false;
//// for (int i = 0; i < this.fitness.length; i++)
//// if (new Double(this.fitness[i]).compareTo(new Double(indy.fitness[i])) != 0) return false;
// for (int i = 0; i < this.fitness.length; i++) {
// if (Math.abs(this.fitness[i]- indy.fitness[i]) > 0.00000001) return false;
// }
// return true;
// } else {
// return false;
// }
// }
/**
* This method will allow a default initialisation of the individual
*
@ -305,7 +275,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
*/
public void init(InterfaceOptimizationProblem opt) {
initializationOperator.initialize(this, opt);
// this.defaultInit(opt);
this.mutationOperator.init(this, opt);
this.crossoverOperator.init(this, opt);
}
@ -411,7 +380,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
sb.append("[ ");
for (int i = 0; i < parentTree.length; i++) {
sb.append(parentTree[i].getHeritageTree(depth - 1));
// if ((i+1) < parentTree.length) sb.append(", ");
}
sb.append("] ");
}
@ -779,7 +747,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
} else {
return (constrViolComp > 0);
}
// return isDominatingFitnessNotEqual(getFitness(), indy.getFitness());
}
/**
@ -1087,8 +1054,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
} else if (individual instanceof InterfaceDataTypeDouble) {
double[] d = ((InterfaceDataTypeDouble) individual).getDoubleData();
for (int i = 0; i < d.length; i++) {
// sb.append(d[i]);
// if ((i+1) < d.length) sb.append(separator);
fm.format("% .3f", d[i]);
if ((i + 1) < d.length) {
sb.append(separator);

View File

@ -4,11 +4,6 @@ package eva2.optimization.individuals;
* This interface gives access to a double phenotype and except
* for problemspecific operators should only be used by the
* optimization problem.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 24.03.2003
* Time: 10:57:39
* To change this template use Options | File Templates.
*/
public interface InterfaceDataTypeDouble {

View File

@ -90,10 +90,6 @@ public class OBGAIndividualPermutationData extends AbstractEAIndividual implemen
}
}
/************************************************************************************
* AbstractEAIndividual methods
*/
/**
* This method will initialize the individual with a given value for the
* phenotype.
@ -203,11 +199,11 @@ public class OBGAIndividualPermutationData extends AbstractEAIndividual implemen
perm[p] = new int[this.genotype[p].length];
ArrayList pot = new ArrayList();
for (int i = 0; i < this.sizePermutation()[p]; i++) {
pot.add(new Integer(firstindex[p] + i));
pot.add(firstindex[p] + i);
}
int i = 0;
while (!pot.isEmpty()) {
perm[p][i] = ((Integer) (pot.remove(RNG.randomInt(0, pot.size() - 1)))).intValue();
perm[p][i] = (Integer) (pot.remove(RNG.randomInt(0, pot.size() - 1)));
i++;
}
}

View File

@ -296,10 +296,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
/**
* This method will generate one new individual from the given population
*
* @param pop The current population
* @param population The current population
* @param parentIndex
* @return AbstractEAIndividual
*/
public AbstractEAIndividual generateNewIndividual(Population pop, int parentIndex) {
public AbstractEAIndividual generateNewIndividual(Population population, int parentIndex) {
AbstractEAIndividual indy;
InterfaceDataTypeDouble esIndy;
@ -309,11 +310,11 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
parents = null;
}
try {
// select one random indy as starting individual. its a parent in any case.
// select one random indy as starting individual. It's a parent in any case.
if (parentIndex < 0) {
parentIndex = RNG.randomInt(0, pop.size() - 1);
parentIndex = RNG.randomInt(0, population.size() - 1);
}
indy = (AbstractEAIndividual) (pop.getEAIndividual(parentIndex)).getClone();
indy = (AbstractEAIndividual) (population.getEAIndividual(parentIndex)).getClone();
esIndy = (InterfaceDataTypeDouble) indy;
} catch (java.lang.ClassCastException e) {
throw new RuntimeException("Differential Evolution currently requires InterfaceESIndividual as basic data type!");
@ -325,9 +326,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
switch (this.DEType) {
case DE1_Rand_1: {
// this is DE1 or DE/rand/1
double[] delta = this.fetchDeltaRandom(pop);
double[] delta = this.fetchDeltaRandom(population);
if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex));
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentF() * delta[i];
@ -336,10 +337,10 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
case DE_CurrentToRand: {
// this is DE/current-to-rand/1
double[] rndDelta = this.fetchDeltaRandom(pop);
double[] bestDelta = this.fetchDeltaCurrentRandom(pop, esIndy);
double[] rndDelta = this.fetchDeltaRandom(population);
double[] bestDelta = this.fetchDeltaCurrentRandom(population, esIndy);
if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex));
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentLambda() * bestDelta[i] + this.getCurrentF() * rndDelta[i];
@ -348,10 +349,10 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
case DE2_CurrentToBest: {
// this is DE2 or DE/current-to-best/1
double[] rndDelta = this.fetchDeltaRandom(pop);
double[] bestDelta = this.fetchDeltaBest(pop, esIndy);
double[] rndDelta = this.fetchDeltaRandom(population);
double[] bestDelta = this.fetchDeltaBest(population, esIndy);
if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex));
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentLambda() * bestDelta[i] + this.getCurrentF() * rndDelta[i];
@ -360,12 +361,12 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
case DE_Best_1: {
// DE/best/1
AbstractEAIndividual bestIndy = getBestIndy(pop);
AbstractEAIndividual bestIndy = getBestIndy(population);
oX = getGenotype(bestIndy);
if (parents != null) {
parents.add(bestIndy);
} // Add best instead of preselected
double[] delta1 = this.fetchDeltaRandom(pop);
double[] delta1 = this.fetchDeltaRandom(population);
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentF() * delta1[i];
}
@ -373,13 +374,13 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
case DE_Best_2: {
// DE/best/2
AbstractEAIndividual bestIndy = getBestIndy(pop);
AbstractEAIndividual bestIndy = getBestIndy(population);
oX = getGenotype(bestIndy);
if (parents != null) {
parents.add(bestIndy);
} // Add best instead of preselected
double[] delta1 = this.fetchDeltaRandom(pop);
double[] delta2 = this.fetchDeltaRandom(pop);
double[] delta1 = this.fetchDeltaRandom(population);
double[] delta2 = this.fetchDeltaRandom(population);
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentF() * delta1[i] + this.getCurrentF() * delta2[i];
}
@ -388,7 +389,7 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
case TrigonometricDE: {
// this is trigonometric mutation
if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex));
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
if (RNG.flipCoin(this.mt)) {
double[] xk, xl;
@ -396,8 +397,8 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
InterfaceDataTypeDouble indy1 = null, indy2 = null;
try {
// and i got indy!
indy1 = (InterfaceDataTypeDouble) pop.get(RNG.randomInt(0, pop.size() - 1));
indy2 = (InterfaceDataTypeDouble) pop.get(RNG.randomInt(0, pop.size() - 1));
indy1 = (InterfaceDataTypeDouble) population.get(RNG.randomInt(0, population.size() - 1));
indy2 = (InterfaceDataTypeDouble) population.get(RNG.randomInt(0, population.size() - 1));
if (parents != null) {
parents.add((AbstractEAIndividual) indy1);
parents.add((AbstractEAIndividual) indy2);
@ -416,9 +417,9 @@ public class DifferentialEvolution implements InterfaceOptimizer, java.io.Serial
}
} else {
// this is DE1
double[] delta = this.fetchDeltaRandom(pop);
double[] delta = this.fetchDeltaRandom(population);
if (parents != null) {
parents.add(pop.getEAIndividual(parentIndex));
parents.add(population.getEAIndividual(parentIndex));
} // Add wherever oX is used directly
for (int i = 0; i < oX.length; i++) {
vX[i] = oX[i] + this.getCurrentF() * delta[i];

View File

@ -48,10 +48,6 @@ public class Serializer {
objectStream.writeObject(objToStore);
objectStream.flush();
objectStream.close();
String output;
Gson gson = new Gson();
output = gson.toJson(objToStore);
System.out.println(output);
} catch (java.io.NotSerializableException ex) {
LOGGER.log(Level.SEVERE, "Object is not serializable!", ex);
}