Moving IndividualInterface to eva2.optimization.individuals. package

This commit is contained in:
Fabian Becker 2013-10-11 16:31:28 +02:00
parent 2c82732428
commit ac220652c1
19 changed files with 88 additions and 179 deletions

View File

@ -25,7 +25,7 @@ import eva2.optimization.strategies.SimulatedAnnealing;
import eva2.optimization.strategies.ClusteringHillClimbing;
import eva2.optimization.strategies.ClusterBasedNichingEA;
import eva2.optimization.strategies.MonteCarloSearch;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.go.InterfaceTerminator;
import eva2.optimization.enums.DETypeEnum;

View File

@ -8,7 +8,7 @@ import eva2.optimization.stat.AbstractStatistics;
import eva2.optimization.stat.StatisticsStandalone;
import eva2.optimization.stat.InterfaceTextListener;
import eva2.optimization.OptimizationStateListener;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.go.InterfaceTerminator;
import eva2.optimization.individuals.InterfaceDataTypeBinary;
import eva2.optimization.individuals.InterfaceDataTypeDouble;

View File

@ -1,9 +1,4 @@
package eva2.gui.editor;
/*
* Title: EvA2 Description: Copyright: Copyright (c) 2012 Company: University of Tuebingen, Computer
* Architecture @author Holger Ulmer, Felix Streichert, Hannes Planatscher, Fabian Becker @version:
* $Revision: 266 $ $Date: 2007-11-20 14:33:48 +0100 (Tue, 20 Nov 2007) $ $Author: mkron $
*/
import eva2.EvAInfo;
import eva2.gui.OptimizationEditorPanel;

View File

@ -34,14 +34,6 @@ import java.util.ArrayList;
import java.util.Date;
import javax.swing.*;
/**
* Created by IntelliJ IDEA. User: streiche Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
*
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 306 $ $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec
* 2007) $ $Author: mkron $
*/
public class GOStandaloneVersion implements InterfaceGOStandalone, InterfacePopulationChangedEventListener, java.io.Serializable {
// Interface GUI Stuff

View File

@ -1,7 +1,6 @@
package eva2.optimization.individuals;
import eva2.gui.BeanInspector;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.codings.gp.InterfaceProgram;
import eva2.optimization.operator.constraint.InterfaceConstraint;
import eva2.optimization.operator.crossover.InterfaceCrossover;
@ -26,15 +25,8 @@ import java.util.*;
* (Genotype)Individual(Phenotype)
* Thus a binary individual coding double values is named GAIndividualDoubleData and a
* real-valued individual coding binary values is named ESIndividualBinaryData.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 11.05.2003
* Time: 14:36:09
* To change this template use Options | File Templates.
*/
public abstract class AbstractEAIndividual implements IndividualInterface, java.io.Serializable {
public int functionCalls = 0; // TODO ist irgendwie eine Kruecke
protected int age = 0;
private long id = 0;
private static long idCounter = 0;
@ -61,7 +53,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
public AbstractEAIndividual() {
idCounter++;
id = idCounter;
// System.out.println("my id is " + id);
}
public long getIndyID() {
@ -155,10 +146,8 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* @param individual The individual to clone.
*/
public void cloneAEAObjects(AbstractEAIndividual individual) {
// m_Name = new String(individual.m_Name);
dataHash = (HashMap<String, Object>) (individual.dataHash.clone());
constraintViolation = individual.constraintViolation;
// areaConst4ParallelViolated = individual.areaConst4ParallelViolated;
isMarked = individual.isMarked;
isPenalized = individual.isPenalized;
individualIndex = individual.individualIndex;
@ -373,23 +362,9 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
}
}
}
// for (int i = 0; i < result.length; i++) {
// result[i].giveNewName();
// }
return result;
}
// /**
// * Toggle the parent logging mechanism. It keeps track of the ancestor IDs of an individual
// * if mutation/crossover are used. Set the desired length of logging history (generations) or
// * set it to 0 to deactivate heritage logging.
// *
// * @param logPs
// */
// public void setLogHeritagetLen(int logLen) {
// logParentLen = logLen;
// }
/**
* Add an ancestor generation with multiple parents.
*
@ -407,8 +382,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
parentTree[i + 1] = (AbstractEAIndividual) parents.getEAIndividual(i).clone();
}
}
// addHeritage(parentIDs);
}
/**
@ -447,11 +420,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return sb.toString();
}
// private void addHeritage(Long[] parentIDs) {
// heritage.add(parentIDs);
//// if (heritage.size() > logParentLen) heritage.remove(0);
// }
/**
* Add an ancestor generation with only one parent.
*
@ -465,16 +433,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return parentIDs;
}
// /**
// * Returns the last set of parental IDs or null if none are available.
// *
// * @return the last set of parental IDs or null if none are available
// */
// public Long[] getHeritage() {
// if (heritage != null) return heritage.getLast();
// else return null;
// }
/**
* This method will allow you to get the current age of an individual Zero
* means it has not even been evaluated.
@ -1284,16 +1242,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
return (IndividualInterface) this.clone();
}
// /** This method is used to get the basic data type of an individual double[].
// * @deprecated Since not all EAIndividuals provide double as basic data type
// * the fitness can be is returned as default value.
// * @see #getFitness()
// * @return double[]
// */
// public double[] getDoubleArray() {
// if (this instanceof InterfaceDataTypeDouble) return ((InterfaceDataTypeDouble)this).getDoubleData();
// else return this.getFitness();
// }
public boolean isDominantNotEqual(double[] otherFitness) {
return isDominatingFitnessNotEqual(fitness, otherFitness);
}

View File

@ -21,33 +21,33 @@ import eva2.tools.math.RNG;
*/
public class ESIndividualDoubleData extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypeDouble, java.io.Serializable {
private double[] m_Genotype;
private double[] m_Phenotype;
private double[][] m_Range;
private double[] genotype;
private double[] phenotype;
private double[][] range;
public ESIndividualDoubleData() {
this.mutationProbability = 1.0;
this.mutationOperator = new MutateESGlobal(0.2, MutateESCrossoverTypeEnum.intermediate);
this.crossoverProbability = 0.5;
this.crossoverOperator = new CrossoverESDefault();
this.m_Genotype = new double[1];
this.m_Phenotype = null;
this.m_Range = new double[1][2];
this.m_Range[0][0] = -10;
this.m_Range[0][1] = 10;
this.genotype = new double[1];
this.phenotype = null;
this.range = new double[1][2];
this.range[0][0] = -10;
this.range[0][1] = 10;
}
public ESIndividualDoubleData(ESIndividualDoubleData individual) {
if (individual.m_Phenotype != null) {
this.m_Phenotype = new double[individual.m_Phenotype.length];
System.arraycopy(individual.m_Phenotype, 0, this.m_Phenotype, 0, this.m_Phenotype.length);
if (individual.phenotype != null) {
this.phenotype = new double[individual.phenotype.length];
System.arraycopy(individual.phenotype, 0, this.phenotype, 0, this.phenotype.length);
}
this.m_Genotype = new double[individual.m_Genotype.length];
this.m_Range = new double[individual.m_Range.length][2];
for (int i = 0; i < this.m_Genotype.length; i++) {
this.m_Genotype[i] = individual.m_Genotype[i];
this.m_Range[i][0] = individual.m_Range[i][0];
this.m_Range[i][1] = individual.m_Range[i][1];
this.genotype = new double[individual.genotype.length];
this.range = new double[individual.range.length][2];
for (int i = 0; i < this.genotype.length; i++) {
this.genotype[i] = individual.genotype[i];
this.range[i][0] = individual.range[i][0];
this.range[i][1] = individual.range[i][1];
}
// cloning the members of AbstractEAIndividual
@ -82,26 +82,26 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
public boolean equalGenotypes(AbstractEAIndividual individual) {
if (individual instanceof ESIndividualDoubleData) {
ESIndividualDoubleData indy = (ESIndividualDoubleData) individual;
if ((this.m_Genotype == null) || (indy.m_Genotype == null)) {
if ((this.genotype == null) || (indy.genotype == null)) {
return false;
}
if ((this.m_Range == null) || (indy.m_Range == null)) {
if ((this.range == null) || (indy.range == null)) {
return false;
}
if (this.m_Genotype.length != indy.m_Genotype.length) {
if (this.genotype.length != indy.genotype.length) {
return false;
}
if (this.m_Range.length != indy.m_Range.length) {
if (this.range.length != indy.range.length) {
return false;
}
for (int i = 0; i < this.m_Genotype.length; i++) {
if (this.m_Genotype[i] != indy.m_Genotype[i]) {
for (int i = 0; i < this.genotype.length; i++) {
if (this.genotype[i] != indy.genotype[i]) {
return false;
}
if (this.m_Range[i][0] != indy.m_Range[i][0]) {
if (this.range[i][0] != indy.range[i][0]) {
return false;
}
if (this.m_Range[i][1] != indy.m_Range[i][1]) {
if (this.range[i][1] != indy.range[i][1]) {
return false;
}
}
@ -125,28 +125,28 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
double[][] newRange = new double[length][2];
// copy the old values for the decision parameters and the range
for (int i = 0; ((i < newDesPa.length) && (i < this.m_Genotype.length)); i++) {
newDesPa[i] = this.m_Genotype[i];
newRange[i][0] = this.m_Range[i][0];
newRange[i][1] = this.m_Range[i][1];
for (int i = 0; ((i < newDesPa.length) && (i < this.genotype.length)); i++) {
newDesPa[i] = this.genotype[i];
newRange[i][0] = this.range[i][0];
newRange[i][1] = this.range[i][1];
}
// if the new length is bigger than the last value fills the extra elements
for (int i = this.m_Genotype.length; (i < newDesPa.length); i++) {
newDesPa[i] = this.m_Genotype[this.m_Genotype.length - 1];
newRange[i][0] = this.m_Range[this.m_Genotype.length - 1][0];
newRange[i][1] = this.m_Range[this.m_Genotype.length - 1][1];
for (int i = this.genotype.length; (i < newDesPa.length); i++) {
newDesPa[i] = this.genotype[this.genotype.length - 1];
newRange[i][0] = this.range[this.genotype.length - 1][0];
newRange[i][1] = this.range[this.genotype.length - 1][1];
}
this.m_Genotype = newDesPa;
this.m_Range = newRange;
this.m_Phenotype = null; // mark as invalid
this.genotype = newDesPa;
this.range = newRange;
this.phenotype = null; // mark as invalid
// changed 28.08.03 by request of Spieth
// this.m_DecisionParameters = new double[length];
// this.m_Range = new double[length][2];
// for (int i = 0; i < this.m_Range.length; i++) {
// this.m_Range[i][0] = -10;
// this.m_Range[i][1] = 10;
// this.range = new double[length][2];
// for (int i = 0; i < this.range.length; i++) {
// this.range[i][0] = -10;
// this.range[i][1] = 10;
// }
}
@ -157,7 +157,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public int size() {
return this.m_Genotype.length;
return this.genotype.length;
}
/**
@ -169,13 +169,13 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public void setDoubleRange(double[][] range) {
if (range.length != this.m_Range.length) {
if (range.length != this.range.length) {
System.out.println("Warning: Trying to set a range of length " + range.length + " to a vector of length "
+ this.m_Range.length + "!\n Use method setDoubleDataLength first! (ESIndividualDoubleData:setDoubleRange)");
+ this.range.length + "!\n Use method setDoubleDataLength first! (ESIndividualDoubleData:setDoubleRange)");
}
for (int i = 0; ((i < this.m_Range.length) && (i < range.length)); i++) {
this.m_Range[i][0] = range[i][0];
this.m_Range[i][1] = range[i][1];
for (int i = 0; ((i < this.range.length) && (i < range.length)); i++) {
this.range[i][0] = range[i][0];
this.range[i][1] = range[i][1];
}
}
@ -186,7 +186,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public double[][] getDoubleRange() {
return this.m_Range;
return this.range;
}
/**
@ -199,12 +199,12 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
public double[] getDoubleData() {
// since the phenotype is set to null if the genotype is changed,
// it should now be save to only perform the copy if the phenotype is null
if (this.m_Phenotype != null) {
return m_Phenotype;
if (this.phenotype != null) {
return phenotype;
} else {
this.m_Phenotype = new double[this.m_Genotype.length];
System.arraycopy(this.m_Genotype, 0, this.m_Phenotype, 0, this.m_Genotype.length);
return this.m_Phenotype;
this.phenotype = new double[this.genotype.length];
System.arraycopy(this.genotype, 0, this.phenotype, 0, this.genotype.length);
return this.phenotype;
}
}
@ -216,10 +216,10 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public double[] getDoubleDataWithoutUpdate() {
if (m_Phenotype == null) {
if (phenotype == null) {
return getDoubleData();
} else {
return this.m_Phenotype;
return this.phenotype;
}
}
@ -231,7 +231,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public void setDoublePhenotype(double[] doubleData) {
this.m_Phenotype = doubleData;
this.phenotype = doubleData;
}
/**
@ -244,8 +244,8 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
public void setDoubleGenotype(double[] doubleData) {
// this.setDoublePhenotype(doubleData);
this.setDoublePhenotype(null); // tag it as invalid
this.m_Genotype = new double[doubleData.length];
System.arraycopy(doubleData, 0, this.m_Genotype, 0, doubleData.length);
this.genotype = new double[doubleData.length];
System.arraycopy(doubleData, 0, this.genotype, 0, doubleData.length);
}
/************************************************************************************
@ -260,7 +260,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
public void init(InterfaceOptimizationProblem opt) {
super.init(opt);
// evil operators may not respect the range, so at least give some hint
if (!Mathematics.isInRange(m_Genotype, m_Range)) {
if (!Mathematics.isInRange(genotype, range)) {
EVAERROR.errorMsgOnce("Warning: Individual out of range after initialization (and potential initial crossover/mutation)!");
}
}
@ -276,7 +276,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
public void initByValue(Object obj, InterfaceOptimizationProblem opt) {
if (obj instanceof double[]) {
double[] bs = (double[]) obj;
if (bs.length != this.m_Genotype.length) {
if (bs.length != this.genotype.length) {
System.out.println("Init value and requested length doesn't match!");
}
this.setDoubleGenotype(bs);
@ -309,8 +309,8 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
strB.append(";");
}
strB.append("}) Value: [");
for (int i = 0; i < this.m_Genotype.length; i++) {
strB.append(this.m_Genotype[i]);
for (int i = 0; i < this.genotype.length; i++) {
strB.append(this.genotype[i]);
strB.append("; ");
}
strB.append("]");
@ -327,7 +327,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public double[] getDGenotype() {
return this.m_Genotype;
return this.genotype;
}
/**
@ -337,14 +337,14 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public void setDGenotype(double[] b) {
this.m_Genotype = b;
this.m_Phenotype = null; // mark it as invalid
for (int i = 0; i < this.m_Genotype.length; i++) {
if (this.m_Genotype[i] < this.m_Range[i][0]) {
this.m_Genotype[i] = this.m_Range[i][0];
this.genotype = b;
this.phenotype = null; // mark it as invalid
for (int i = 0; i < this.genotype.length; i++) {
if (this.genotype[i] < this.range[i][0]) {
this.genotype[i] = this.range[i][0];
}
if (this.m_Genotype[i] > this.m_Range[i][1]) {
this.m_Genotype[i] = this.m_Range[i][1];
if (this.genotype[i] > this.range[i][1]) {
this.genotype[i] = this.range[i][1];
}
}
}
@ -355,8 +355,8 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
* @param b The new genotype of the Individual
*/
public void setDGenotypeNocheck(double[] b) {
this.m_Phenotype = null; // mark it as invalid
this.m_Genotype = b;
this.phenotype = null; // mark it as invalid
this.genotype = b;
}
/**
@ -364,8 +364,8 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public void defaultMutate() {
ESIndividualDoubleData.defaultMutate(this.m_Genotype, this.m_Range);
m_Phenotype = null; // mark it as invalid
ESIndividualDoubleData.defaultMutate(this.genotype, this.range);
phenotype = null; // mark it as invalid
}
/**
@ -390,11 +390,11 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
@Override
public void defaultInit(InterfaceOptimizationProblem prob) {
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange) prob).getInitRange() != null)) {
ESIndividualDoubleData.defaultInit(m_Genotype, (double[][]) ((InterfaceHasInitRange) prob).getInitRange());
ESIndividualDoubleData.defaultInit(genotype, (double[][]) ((InterfaceHasInitRange) prob).getInitRange());
} else {
ESIndividualDoubleData.defaultInit(m_Genotype, m_Range);
ESIndividualDoubleData.defaultInit(genotype, range);
}
m_Phenotype = null; // mark as invalid
phenotype = null; // mark as invalid
}
/**

View File

@ -1,18 +1,7 @@
package eva2.optimization.go;
package eva2.optimization.individuals;
import eva2.optimization.problems.InterfaceOptimizationProblem;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 306 $
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
*/
/**
* Minimal interface for an EA individual.
*/

View File

@ -4,11 +4,6 @@ package eva2.optimization.individuals;
* This interface gives access to a real-valued genotype and should
* only be used by mutation and crossover operators. Onyl exception are
* data type specific optimization strategies like PSO or DE.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 24.03.2003
* Time: 15:59:45
* To change this template use Options | File Templates.
*/
public interface InterfaceESIndividual {

View File

@ -6,11 +6,6 @@ import java.util.BitSet;
* This interface gives access to a binary genotype and should
* only be used by mutation and crossover operators. Exceptions are
* data type specific optimization strategies like CHC or PBIL.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 24.03.2003
* Time: 14:25:24
* To change this template use Options | File Templates.
*/
public interface InterfaceGAIndividual {

View File

@ -4,11 +4,6 @@ package eva2.optimization.individuals;
/**
* This interface gives access to a integer genotype and should
* only be used by mutation and crossover operators.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 18.05.2005
* Time: 16:54:03
* To change this template use File | Settings | File Templates.
*/
public interface InterfaceGIIndividual {

View File

@ -1,6 +1,6 @@
package eva2.optimization.operator.mutation;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.population.Population;
import eva2.optimization.problems.InterfaceOptimizationProblem;

View File

@ -1,7 +1,7 @@
package eva2.optimization.operator.mutation;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.InterfaceGPIndividual;
import eva2.optimization.population.Population;

View File

@ -12,7 +12,7 @@ import eva2.OptimizerRunnable;
import eva2.gui.BeanInspector;
import eva2.gui.plot.Plot;
import eva2.gui.plot.TopoPlot;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.go.InterfaceTerminator;
import eva2.optimization.enums.ESMutationInitialSigma;
import eva2.optimization.enums.PostProcessMethod;

View File

@ -6,7 +6,7 @@ import eva2.optimization.individuals.InterfaceESIndividual;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.InterfaceGAIndividual;
import eva2.gui.editor.GenericObjectEditor;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.go.InterfacePopulationChangedEventListener;
import eva2.optimization.operator.distancemetric.EuclideanMetric;
import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;

View File

@ -10,7 +10,7 @@ package eva2.optimization.population;
* $Author: mkron $
*/
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
/**
*

View File

@ -1,7 +1,7 @@
package eva2.optimization.stat;
import eva2.gui.BeanInspector;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.population.PopulationInterface;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.operator.distancemetric.InterfaceDistanceMetric;

View File

@ -1,6 +1,6 @@
package eva2.optimization.stat;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.population.PopulationInterface;
import eva2.optimization.population.Population;
import eva2.optimization.problems.InterfaceAdditionalPopulationInformer;

View File

@ -1,6 +1,6 @@
package eva2.optimization.stat;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.population.PopulationInterface;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.population.Population;

View File

@ -1,6 +1,6 @@
package eva2.optimization.strategies;
import eva2.optimization.go.IndividualInterface;
import eva2.optimization.individuals.IndividualInterface;
import eva2.optimization.individuals.AbstractEAIndividual;
import eva2.optimization.individuals.ESIndividualDoubleData;
import eva2.optimization.individuals.InterfaceDataTypeDouble;