Remove m_ from all operator classes

This commit is contained in:
Fabian Becker 2014-02-05 16:41:39 +01:00
parent 7223d27a08
commit 85fa426e30
37 changed files with 635 additions and 726 deletions

View File

@ -12,20 +12,15 @@ import java.util.ArrayList;
/** /**
* The DBSCAN method. As far as I recall this is an hierachical * The DBSCAN method. As far as I recall this is an hierachical
* clustering method like the single-link method. * clustering method like the single-link method.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 24.04.2003
* Time: 15:17:53
* To change this template use Options | File Templates.
*/ */
public class ClusteringDensityBased implements InterfaceClusteringDistanceParam, InterfaceClusteringMetricBased, java.io.Serializable { public class ClusteringDensityBased implements InterfaceClusteringDistanceParam, InterfaceClusteringMetricBased, java.io.Serializable {
private InterfaceDistanceMetric m_Metric = new PhenotypeMetric(); private InterfaceDistanceMetric metric = new PhenotypeMetric();
private double m_ClusterDistance = 0.1; private double clusterDistance = 0.1;
private int m_MinimumGroupSize = 3; private int minimumGroupSize = 3;
private boolean[][] ConnectionMatrix; private boolean[][] connectionMatrix;
private boolean[] Clustered; private boolean[] clustered;
private boolean m_TestConvergingSpeciesOnBestOnly = true; private boolean testConvergingSpeciesOnBestOnly = true;
public ClusteringDensityBased() { public ClusteringDensityBased() {
} }
@ -36,7 +31,7 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
* @param sigma the minimum cluster distance * @param sigma the minimum cluster distance
*/ */
public ClusteringDensityBased(double sigma) { public ClusteringDensityBased(double sigma) {
m_ClusterDistance = sigma; clusterDistance = sigma;
} }
/** /**
@ -45,8 +40,8 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
* @param sigma the minimum cluster distance * @param sigma the minimum cluster distance
*/ */
public ClusteringDensityBased(double sigma, int minGSize) { public ClusteringDensityBased(double sigma, int minGSize) {
m_ClusterDistance = sigma; clusterDistance = sigma;
m_MinimumGroupSize = minGSize; minimumGroupSize = minGSize;
} }
/** /**
@ -55,36 +50,36 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
* @param sigma the minimum cluster distance * @param sigma the minimum cluster distance
*/ */
public ClusteringDensityBased(double sigma, int minGSize, InterfaceDistanceMetric metric) { public ClusteringDensityBased(double sigma, int minGSize, InterfaceDistanceMetric metric) {
m_ClusterDistance = sigma; clusterDistance = sigma;
m_MinimumGroupSize = minGSize; minimumGroupSize = minGSize;
m_Metric = metric; this.metric = metric;
} }
public ClusteringDensityBased(ClusteringDensityBased a) { public ClusteringDensityBased(ClusteringDensityBased a) {
if (a.m_Metric != null) { if (a.metric != null) {
this.m_Metric = (InterfaceDistanceMetric) a.m_Metric.clone(); this.metric = (InterfaceDistanceMetric) a.metric.clone();
} }
this.m_TestConvergingSpeciesOnBestOnly = a.m_TestConvergingSpeciesOnBestOnly; this.testConvergingSpeciesOnBestOnly = a.testConvergingSpeciesOnBestOnly;
this.m_ClusterDistance = a.m_ClusterDistance; this.clusterDistance = a.clusterDistance;
this.m_MinimumGroupSize = a.m_MinimumGroupSize; this.minimumGroupSize = a.minimumGroupSize;
if (a.Clustered != null) { if (a.clustered != null) {
this.Clustered = new boolean[a.Clustered.length]; this.clustered = new boolean[a.clustered.length];
for (int i = 0; i < this.Clustered.length; i++) { for (int i = 0; i < this.clustered.length; i++) {
if (a.Clustered[i]) { if (a.clustered[i]) {
this.Clustered[i] = true; this.clustered[i] = true;
} else { } else {
this.Clustered[i] = false; this.clustered[i] = false;
} }
} }
} }
if (a.ConnectionMatrix != null) { if (a.connectionMatrix != null) {
this.ConnectionMatrix = new boolean[a.ConnectionMatrix.length][a.ConnectionMatrix[0].length]; this.connectionMatrix = new boolean[a.connectionMatrix.length][a.connectionMatrix[0].length];
for (int i = 0; i < this.ConnectionMatrix.length; i++) { for (int i = 0; i < this.connectionMatrix.length; i++) {
for (int j = 0; j < this.ConnectionMatrix[i].length; j++) { for (int j = 0; j < this.connectionMatrix[i].length; j++) {
if (a.ConnectionMatrix[i][j]) { if (a.connectionMatrix[i][j]) {
this.ConnectionMatrix[i][j] = true; this.connectionMatrix[i][j] = true;
} else { } else {
this.ConnectionMatrix[i][j] = false; this.connectionMatrix[i][j] = false;
} }
} }
} }
@ -104,8 +99,8 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
@Override @Override
public Population[] cluster(Population pop, Population referencePop) { public Population[] cluster(Population pop, Population referencePop) {
ConnectionMatrix = new boolean[pop.size()][pop.size()]; connectionMatrix = new boolean[pop.size()][pop.size()];
Clustered = new boolean[pop.size()]; clustered = new boolean[pop.size()];
AbstractEAIndividual tmpIndy1, tmpIndy2; AbstractEAIndividual tmpIndy1, tmpIndy2;
Population PopulationOfUnclustered, Cluster, template; Population PopulationOfUnclustered, Cluster, template;
ArrayList<Population> ClusteredPopulations = new ArrayList<Population>(); ArrayList<Population> ClusteredPopulations = new ArrayList<Population>();
@ -118,32 +113,32 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
// Build the connection Matrix // Build the connection Matrix
for (int i = 0; i < pop.size(); i++) { for (int i = 0; i < pop.size(); i++) {
tmpIndy1 = (AbstractEAIndividual) pop.get(i); tmpIndy1 = (AbstractEAIndividual) pop.get(i);
ConnectionMatrix[i][i] = true; connectionMatrix[i][i] = true;
for (int j = i + 1; j < pop.size(); j++) { for (int j = i + 1; j < pop.size(); j++) {
tmpIndy2 = (AbstractEAIndividual) pop.get(j); tmpIndy2 = (AbstractEAIndividual) pop.get(j);
if (tmpIndy1 == null || (tmpIndy2 == null)) { if (tmpIndy1 == null || (tmpIndy2 == null)) {
System.err.println("Warning: Individual should not be null (ClusteringDensityBased)!"); System.err.println("Warning: Individual should not be null (ClusteringDensityBased)!");
} }
if ((tmpIndy1 != null) && (tmpIndy2 != null) && (this.m_Metric.distance(tmpIndy1, tmpIndy2) < this.m_ClusterDistance)) { if ((tmpIndy1 != null) && (tmpIndy2 != null) && (this.metric.distance(tmpIndy1, tmpIndy2) < this.clusterDistance)) {
ConnectionMatrix[i][j] = true; connectionMatrix[i][j] = true;
ConnectionMatrix[j][i] = true; connectionMatrix[j][i] = true;
} else { } else {
ConnectionMatrix[i][j] = false; connectionMatrix[i][j] = false;
ConnectionMatrix[j][i] = false; connectionMatrix[j][i] = false;
} }
} }
} }
for (int i = 0; i < Clustered.length; i++) { for (int i = 0; i < clustered.length; i++) {
Clustered[i] = false; clustered[i] = false;
} }
// Now identify clusters within pop and add them to the result // Now identify clusters within pop and add them to the result
for (int i = 0; i < ConnectionMatrix.length; i++) { for (int i = 0; i < connectionMatrix.length; i++) {
if (!Clustered[i]) { if (!clustered[i]) {
Cluster = (Population) template.clone(); Cluster = (Population) template.clone();
this.addRowToPopulation(i, Cluster, pop); this.addRowToPopulation(i, Cluster, pop);
if (Cluster.size() >= this.m_MinimumGroupSize) { if (Cluster.size() >= this.minimumGroupSize) {
ClusteredPopulations.add(Cluster); ClusteredPopulations.add(Cluster);
} else { } else {
PopulationOfUnclustered.addPopulation(Cluster); PopulationOfUnclustered.addPopulation(Cluster);
@ -159,7 +154,7 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
} }
/** /**
* This method adds all Connected and !Clustered Individuals form row index * This method adds all Connected and !clustered Individuals form row index
* to pop * to pop
* *
* @param index The index of the row that is to be computed. * @param index The index of the row that is to be computed.
@ -167,11 +162,11 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
* @param source The source which is to be clustered. * @param source The source which is to be clustered.
*/ */
private void addRowToPopulation(int index, Population cluster, Population source) { private void addRowToPopulation(int index, Population cluster, Population source) {
for (int i = 0; i < ConnectionMatrix[index].length; i++) { for (int i = 0; i < connectionMatrix[index].length; i++) {
if ((!Clustered[i]) && (ConnectionMatrix[index][i])) { if ((!clustered[i]) && (connectionMatrix[index][i])) {
Clustered[i] = true; clustered[i] = true;
ConnectionMatrix[index][i] = false; connectionMatrix[index][i] = false;
ConnectionMatrix[i][index] = false; connectionMatrix[i][index] = false;
cluster.add(source.get(i)); cluster.add(source.get(i));
this.addRowToPopulation(i, cluster, source); this.addRowToPopulation(i, cluster, source);
} }
@ -187,10 +182,10 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
*/ */
@Override @Override
public boolean mergingSpecies(Population species1, Population species2, Population referencePop) { public boolean mergingSpecies(Population species1, Population species2, Population referencePop) {
if (m_TestConvergingSpeciesOnBestOnly) { if (testConvergingSpeciesOnBestOnly) {
double specDist = this.m_Metric.distance(species1.getBestEAIndividual(), species2.getBestEAIndividual()); double specDist = this.metric.distance(species1.getBestEAIndividual(), species2.getBestEAIndividual());
// System.out.println("Dist between species is " + specDist); // System.out.println("Dist between species is " + specDist);
return (specDist < this.m_ClusterDistance); return (specDist < this.clusterDistance);
} else { } else {
Population tmpPop = new Population(species1.size() + species2.size()); Population tmpPop = new Population(species1.size() + species2.size());
tmpPop.addPopulation(species1); tmpPop.addPopulation(species1);
@ -209,8 +204,8 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
// * @return True or False. // * @return True or False.
// */ // */
// public boolean belongsToSpecies(AbstractEAIndividual indy, Population species, Population pop) { // public boolean belongsToSpecies(AbstractEAIndividual indy, Population species, Population pop) {
// if (this.m_TestConvergingSpeciesOnBestOnly) { // if (this.testConvergingSpeciesOnBestOnly) {
// if (this.distanceMetric.distance(indy, species.getBestEAIndividual()) < this.m_ClusterDistance) return true; // if (this.distanceMetric.distance(indy, species.getBestEAIndividual()) < this.clusterDistance) return true;
// else return false; // else return false;
// } else { // } else {
// Population tmpPop = (Population)species.clone(); // Population tmpPop = (Population)species.clone();
@ -238,8 +233,8 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
double minDist = -1; double minDist = -1;
res[l] = -1; res[l] = -1;
for (int spI = 0; spI < species.length; spI++) { // O(species.length^2) for (int spI = 0; spI < species.length; spI++) { // O(species.length^2)
Pair<Integer, Double> iDist = Population.getClosestFarthestIndy(loners.getEAIndividual(l), species[spI], m_Metric, true); Pair<Integer, Double> iDist = Population.getClosestFarthestIndy(loners.getEAIndividual(l), species[spI], metric, true);
if (iDist.tail() < m_ClusterDistance) { // its close enough to be added if (iDist.tail() < clusterDistance) { // its close enough to be added
// set SP ID only if its the closest species which is still below cluster distance // set SP ID only if its the closest species which is still below cluster distance
if (minDist < 0 || (iDist.tail() < minDist)) { if (minDist < 0 || (iDist.tail() < minDist)) {
res[l] = spI; res[l] = spI;
@ -278,12 +273,12 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
*/ */
@Override @Override
public InterfaceDistanceMetric getMetric() { public InterfaceDistanceMetric getMetric() {
return this.m_Metric; return this.metric;
} }
@Override @Override
public void setMetric(InterfaceDistanceMetric m) { public void setMetric(InterfaceDistanceMetric m) {
this.m_Metric = m; this.metric = m;
} }
public String metricTipText() { public String metricTipText() {
@ -296,14 +291,14 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
* @return The currently used minimal group size. * @return The currently used minimal group size.
*/ */
public int getMinimumGroupSize() { public int getMinimumGroupSize() {
return this.m_MinimumGroupSize; return this.minimumGroupSize;
} }
public void setMinimumGroupSize(int m) { public void setMinimumGroupSize(int m) {
if (m < 1) { if (m < 1) {
m = 1; m = 1;
} }
this.m_MinimumGroupSize = m; this.minimumGroupSize = m;
} }
public String minimumGroupSizeTipText() { public String minimumGroupSizeTipText() {
@ -317,7 +312,7 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
@Override @Override
public double getClustDistParam() { public double getClustDistParam() {
return this.m_ClusterDistance; return this.clusterDistance;
} }
@Override @Override
@ -325,7 +320,7 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
if (m < 0) { if (m < 0) {
m = 0; m = 0;
} }
this.m_ClusterDistance = m; this.clusterDistance = m;
} }
public String clustDistTipText() { public String clustDistTipText() {
@ -348,7 +343,7 @@ public class ClusteringDensityBased implements InterfaceClusteringDistanceParam,
// plot.plotArea.addDElement(popRep); // plot.plotArea.addDElement(popRep);
// //System.out.println("Adding" + i + " : ("+tmpIndy1.getDoubleData()[0]+"/"+tmpIndy1.getDoubleData()[1]+")"); // //System.out.println("Adding" + i + " : ("+tmpIndy1.getDoubleData()[0]+"/"+tmpIndy1.getDoubleData()[1]+")");
// for (int j = i; j < pop.size(); j++) { // for (int j = i; j < pop.size(); j++) {
// if (ConnectionMatrix[i][j]) { // if (connectionMatrix[i][j]) {
// popRep = new DPointSet(); // popRep = new DPointSet();
// popRep.setConnected(true); // popRep.setConnected(true);
// tmpIndy1 = (InterfaceDataTypeDouble)pop.get(i); // tmpIndy1 = (InterfaceDataTypeDouble)pop.get(i);

View File

@ -18,20 +18,15 @@ import java.util.Arrays;
/** /**
* The k-mean clustering algorithms. I guess it is not a hierachical * The k-mean clustering algorithms. I guess it is not a hierachical
* clustering method. * clustering method.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 27.09.2004
* Time: 13:49:44
* To change this template use File | Settings | File Templates.
*/ */
public class ClusteringKMeans implements InterfaceClustering, java.io.Serializable { public class ClusteringKMeans implements InterfaceClustering, java.io.Serializable {
private int m_K = 5; private int k = 5;
private double[][] m_C = null; private double[][] c = null;
private double mergeDist = 0.001; private double mergeDist = 0.001;
private boolean m_UseSearchSpace = true; private boolean useSearchSpace = true;
private boolean m_ReuseC = false; private boolean reuseC = false;
private boolean m_Debug = false; private boolean debug = false;
private int minClustSize = 1; private int minClustSize = 1;
InterfaceDistanceMetric metric = new EuclideanMetric(); InterfaceDistanceMetric metric = new EuclideanMetric();
AbstractEAIndividual tmpIndy = null; AbstractEAIndividual tmpIndy = null;
@ -41,16 +36,16 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
} }
public ClusteringKMeans(ClusteringKMeans a) { public ClusteringKMeans(ClusteringKMeans a) {
this.m_Debug = a.m_Debug; this.debug = a.debug;
this.m_K = a.m_K; this.k = a.k;
this.m_UseSearchSpace = a.m_UseSearchSpace; this.useSearchSpace = a.useSearchSpace;
this.metric = a.metric; this.metric = a.metric;
this.minClustSize = a.minClustSize; this.minClustSize = a.minClustSize;
this.mergeDist = a.mergeDist; this.mergeDist = a.mergeDist;
if (a.m_C != null) { if (a.c != null) {
this.m_C = new double[a.m_C.length][a.m_C[0].length]; this.c = new double[a.c.length][a.c[0].length];
for (int i = 0; i < this.m_C.length; i++) { for (int i = 0; i < this.c.length; i++) {
System.arraycopy(a.m_C[i], 0, this.m_C[i], 0, this.m_C[i].length); System.arraycopy(a.c[i], 0, this.c[i], 0, this.c[i].length);
} }
} }
} }
@ -77,7 +72,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
*/ */
@Override @Override
public Population[] cluster(Population pop, Population referencePop) { public Population[] cluster(Population pop, Population referencePop) {
if (pop.size() < m_K) { if (pop.size() < k) {
// in this case, there arent enough indies to do anything, so we just return them as "unclustered" // in this case, there arent enough indies to do anything, so we just return them as "unclustered"
Population[] res = new Population[1]; Population[] res = new Population[1];
res[0] = pop.cloneShallowInds(); res[0] = pop.cloneShallowInds();
@ -85,15 +80,15 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
} }
tmpIndy = (AbstractEAIndividual) pop.getEAIndividual(0).clone(); tmpIndy = (AbstractEAIndividual) pop.getEAIndividual(0).clone();
// double[][] data = this.extractClusterDataFrom(pop); // double[][] data = this.extractClusterDataFrom(pop);
if (!(this.m_ReuseC) || (this.m_C == null)) { if (!(this.reuseC) || (this.c == null)) {
this.m_C = new double[this.m_K][]; this.c = new double[this.k][];
// now choose random initial Cs // now choose random initial Cs
Population initialSeeds = pop.getRandNIndividuals(this.m_K); Population initialSeeds = pop.getRandNIndividuals(this.k);
for (int i = 0; i < this.m_K; i++) { for (int i = 0; i < this.k; i++) {
if (m_UseSearchSpace) { if (useSearchSpace) {
this.m_C[i] = initialSeeds.getEAIndividual(i).getDoublePosition().clone(); this.c[i] = initialSeeds.getEAIndividual(i).getDoublePosition().clone();
} else { } else {
this.m_C[i] = initialSeeds.getEAIndividual(i).getFitness().clone(); this.c[i] = initialSeeds.getEAIndividual(i).getFitness().clone();
} }
// this.c[i] = data[RNG.randomInt(0, data.length-1)]; // this.c[i] = data[RNG.randomInt(0, data.length-1)];
@ -115,8 +110,8 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
for (int i = 0; i < pop.size(); i++) { for (int i = 0; i < pop.size(); i++) {
// check which C is closest // check which C is closest
assign = 0; assign = 0;
for (int j = 1; j < this.m_C.length; j++) { for (int j = 1; j < this.c.length; j++) {
if (this.distance(pop.getEAIndividual(i), this.m_C[assign]) > this.distance(pop.getEAIndividual(i), this.m_C[j])) { if (this.distance(pop.getEAIndividual(i), this.c[assign]) > this.distance(pop.getEAIndividual(i), this.c[j])) {
assign = j; assign = j;
} }
} }
@ -124,18 +119,18 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
} }
// now calcuate the mean of each cluster and calculate new C // now calcuate the mean of each cluster and calculate new C
newC = new double[this.m_K][m_C[0].length]; newC = new double[this.k][c[0].length];
numbOfAssigned = new int[this.m_K]; numbOfAssigned = new int[this.k];
for (int i = 0; i < newC.length; i++) { for (int i = 0; i < newC.length; i++) {
numbOfAssigned[i] = 1; numbOfAssigned[i] = 1;
for (int j = 0; j < newC[i].length; j++) { for (int j = 0; j < newC[i].length; j++) {
newC[i][j] = this.m_C[i][j]; newC[i][j] = this.c[i][j];
} }
} }
for (int i = 0; i < assignment.length; i++) { for (int i = 0; i < assignment.length; i++) {
numbOfAssigned[assignment[i]]++; numbOfAssigned[assignment[i]]++;
for (int j = 0; j < newC[assignment[i]].length; j++) { for (int j = 0; j < newC[assignment[i]].length; j++) {
if (m_UseSearchSpace) { if (useSearchSpace) {
newC[assignment[i]][j] += pop.getEAIndividual(i).getDoublePosition()[j]; newC[assignment[i]][j] += pop.getEAIndividual(i).getDoublePosition()[j];
} else { } else {
newC[assignment[i]][j] += pop.getEAIndividual(i).getFitness(j); newC[assignment[i]][j] += pop.getEAIndividual(i).getFitness(j);
@ -150,7 +145,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
//else System.out.println("Someone was not assigned any data!? "+ i +" "+numbOfAssigned[i] + ": Data.size()="+data.length); //else System.out.println("Someone was not assigned any data!? "+ i +" "+numbOfAssigned[i] + ": Data.size()="+data.length);
} }
} }
if (this.m_Debug) { if (this.debug) {
// let's see how they arrive here // let's see how they arrive here
Plot plot; Plot plot;
double[] tmpD = new double[2]; double[] tmpD = new double[2];
@ -166,10 +161,10 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
GraphPointSet mySet; GraphPointSet mySet;
DPoint myPoint; DPoint myPoint;
Chart2DDPointIconText tmp; Chart2DDPointIconText tmp;
for (int i = 0; i < this.m_C.length; i++) { for (int i = 0; i < this.c.length; i++) {
mySet = new GraphPointSet(10 + i, plot.getFunctionArea()); mySet = new GraphPointSet(10 + i, plot.getFunctionArea());
mySet.setConnectedMode(true); mySet.setConnectedMode(true);
myPoint = new DPoint(this.m_C[i][0], this.m_C[i][1]); myPoint = new DPoint(this.c[i][0], this.c[i][1]);
tmp = new Chart2DDPointIconText("Old: " + i); tmp = new Chart2DDPointIconText("Old: " + i);
tmp.setIcon(new Chart2DDPointIconCircle()); tmp.setIcon(new Chart2DDPointIconCircle());
myPoint.setIcon(tmp); myPoint.setIcon(tmp);
@ -181,7 +176,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
mySet.addDPoint(myPoint); mySet.addDPoint(myPoint);
} }
} }
if (this.m_Debug) { if (this.debug) {
// let's see how they arrive here // let's see how they arrive here
Plot plot; Plot plot;
double[] tmpD = new double[2]; double[] tmpD = new double[2];
@ -206,20 +201,20 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
} }
// finally let's check whether or not the C changed and if i can terminate k_Means // finally let's check whether or not the C changed and if i can terminate k_Means
finished = true; finished = true;
for (int i = 0; i < this.m_C.length; i++) { for (int i = 0; i < this.c.length; i++) {
if (EuclideanMetric.euclideanDistance(this.m_C[i], newC[i]) > 0.0001) { if (EuclideanMetric.euclideanDistance(this.c[i], newC[i]) > 0.0001) {
finished = false; finished = false;
} }
this.m_C[i] = newC[i]; this.c[i] = newC[i];
} }
} // gosh now i'm done } // gosh now i'm done
// finally lets build the new populations // finally lets build the new populations
Population[] result = this.cluster(pop, this.m_C); Population[] result = this.cluster(pop, this.c);
// Population[] result = new Population[this.m_K]; // Population[] result = new Population[this.k];
// for (int i = 0; i < assignment.length; i++) // for (int i = 0; i < assignment.length; i++)
// result[assignment[i]].add(pop.get(i)); // result[assignment[i]].add(pop.get(i));
if (this.m_Debug) { if (this.debug) {
// let's see how they arrive here // let's see how they arrive here
Plot plot; Plot plot;
double[] tmpD = new double[2]; double[] tmpD = new double[2];
@ -315,7 +310,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
* @return The scalar distances between d1 and d2 * @return The scalar distances between d1 and d2
*/ */
private double distance(AbstractEAIndividual indy, double[] p) { private double distance(AbstractEAIndividual indy, double[] p) {
if (m_UseSearchSpace) { if (useSearchSpace) {
((InterfaceDataTypeDouble) tmpIndy).setDoubleGenotype(p); ((InterfaceDataTypeDouble) tmpIndy).setDoubleGenotype(p);
} else { } else {
tmpIndy.setFitness(p); tmpIndy.setFitness(p);
@ -337,7 +332,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
// let's fetch the raw data either the double // let's fetch the raw data either the double
// phenotype or the coordinates in objective space // phenotype or the coordinates in objective space
// @todo: i case of repair i would need to set the phenotype! // @todo: i case of repair i would need to set the phenotype!
if (this.m_UseSearchSpace && (pop.get(0) instanceof InterfaceDataTypeDouble)) { if (this.useSearchSpace && (pop.get(0) instanceof InterfaceDataTypeDouble)) {
for (int i = 0; i < pop.size(); i++) { for (int i = 0; i < pop.size(); i++) {
data[i] = ((InterfaceDataTypeDouble) pop.get(i)).getDoubleData(); data[i] = ((InterfaceDataTypeDouble) pop.get(i)).getDoubleData();
} }
@ -391,17 +386,17 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
* @return The centroids * @return The centroids
*/ */
public double[][] getC() { public double[][] getC() {
return this.m_C; return this.c;
} }
public void resetC() { public void resetC() {
this.m_C = null; this.c = null;
} }
public static void main(String[] args) { public static void main(String[] args) {
ClusteringKMeans ckm = new ClusteringKMeans(); ClusteringKMeans ckm = new ClusteringKMeans();
ckm.setUseSearchSpace(true); ckm.setUseSearchSpace(true);
ckm.m_Debug = true; ckm.debug = true;
Population pop = new Population(); Population pop = new Population();
F1Problem f1 = new F1Problem(); F1Problem f1 = new F1Problem();
f1.setProblemDimension(2); f1.setProblemDimension(2);
@ -439,14 +434,14 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
* @return The current number of clusters to find. * @return The current number of clusters to find.
*/ */
public int getK() { public int getK() {
return this.m_K; return this.k;
} }
public void setK(int m) { public void setK(int m) {
if (m < 1) { if (m < 1) {
m = 1; m = 1;
} }
this.m_K = m; this.k = m;
} }
public String kTipText() { public String kTipText() {
@ -460,11 +455,11 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
* @return The distance type to use. * @return The distance type to use.
*/ */
public boolean getUseSearchSpace() { public boolean getUseSearchSpace() {
return this.m_UseSearchSpace; return this.useSearchSpace;
} }
public void setUseSearchSpace(boolean m) { public void setUseSearchSpace(boolean m) {
this.m_UseSearchSpace = m; this.useSearchSpace = m;
} }
public String useSearchSpaceTipText() { public String useSearchSpaceTipText() {
@ -477,11 +472,11 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
* @return The distance type to use. * @return The distance type to use.
*/ */
public boolean getReuseC() { public boolean getReuseC() {
return this.m_ReuseC; return this.reuseC;
} }
public void setReuseC(boolean m) { public void setReuseC(boolean m) {
this.m_ReuseC = m; this.reuseC = m;
} }
public String reuseCTipText() { public String reuseCTipText() {

View File

@ -6,38 +6,33 @@ import eva2.optimization.individuals.InterfaceDataTypeDouble;
/** /**
* This area constraint for parallelization is based on * This area constraint for parallelization is based on
* the class type an individual belongs to. * the class type an individual belongs to.
* Created by IntelliJ IDEA.
* User: streiche
* Date: 03.10.2004
* Time: 15:07:36
* To change this template use File | Settings | File Templates.
*/ */
public class ConstBelongsToDifferentClass implements InterfaceConstraint, java.io.Serializable { public class ConstBelongsToDifferentClass implements InterfaceConstraint, java.io.Serializable {
private double[] m_Class; private double[] classes;
private double[][] m_OtherClasses; private double[][] otherClasses;
private boolean m_UsePhenotype = false; private boolean usePhenotype = false;
public ConstBelongsToDifferentClass() { public ConstBelongsToDifferentClass() {
} }
public ConstBelongsToDifferentClass(double[] m, double[][] b, boolean p) { public ConstBelongsToDifferentClass(double[] m, double[][] b, boolean p) {
this.m_Class = m; this.classes = m;
this.m_OtherClasses = b; this.otherClasses = b;
this.m_UsePhenotype = p; this.usePhenotype = p;
} }
public ConstBelongsToDifferentClass(ConstBelongsToDifferentClass a) { public ConstBelongsToDifferentClass(ConstBelongsToDifferentClass a) {
this.m_UsePhenotype = a.m_UsePhenotype; this.usePhenotype = a.usePhenotype;
if (a.m_Class != null) { if (a.classes != null) {
this.m_Class = new double[a.m_Class.length]; this.classes = new double[a.classes.length];
System.arraycopy(a.m_Class, 0, this.m_Class, 0, a.m_Class.length); System.arraycopy(a.classes, 0, this.classes, 0, a.classes.length);
} }
if (a.m_OtherClasses != null) { if (a.otherClasses != null) {
this.m_OtherClasses = new double[a.m_OtherClasses.length][]; this.otherClasses = new double[a.otherClasses.length][];
for (int i = 0; i < a.m_OtherClasses.length; i++) { for (int i = 0; i < a.otherClasses.length; i++) {
this.m_OtherClasses[i] = new double[a.m_OtherClasses[i].length]; this.otherClasses[i] = new double[a.otherClasses[i].length];
System.arraycopy(a.m_OtherClasses[i], 0, this.m_OtherClasses[i], 0, a.m_OtherClasses[i].length); System.arraycopy(a.otherClasses[i], 0, this.otherClasses[i], 0, a.otherClasses[i].length);
} }
} }
} }
@ -57,14 +52,14 @@ public class ConstBelongsToDifferentClass implements InterfaceConstraint, java.i
@Override @Override
public boolean isValid(AbstractEAIndividual indy) { public boolean isValid(AbstractEAIndividual indy) {
double[] data; double[] data;
if (this.m_UsePhenotype && (indy instanceof InterfaceDataTypeDouble)) { if (this.usePhenotype && (indy instanceof InterfaceDataTypeDouble)) {
data = ((InterfaceDataTypeDouble) indy).getDoubleData(); data = ((InterfaceDataTypeDouble) indy).getDoubleData();
} else { } else {
data = ((AbstractEAIndividual) indy).getFitness(); data = ((AbstractEAIndividual) indy).getFitness();
} }
double distanceToMyClass = this.distance(data, this.m_Class); double distanceToMyClass = this.distance(data, this.classes);
for (int i = 0; i < this.m_OtherClasses.length; i++) { for (int i = 0; i < this.otherClasses.length; i++) {
if (distanceToMyClass > this.distance(data, this.m_OtherClasses[i])) { if (distanceToMyClass > this.distance(data, this.otherClasses[i])) {
return false; return false;
} }
} }

View File

@ -37,8 +37,8 @@ public class AdaptiveCrossoverEAMixer extends CrossoverEAMixer implements Interf
* @param mutators * @param mutators
*/ */
public AdaptiveCrossoverEAMixer(InterfaceCrossover... crossovers) { public AdaptiveCrossoverEAMixer(InterfaceCrossover... crossovers) {
this.m_Crossers = new PropertyCrossoverMixer(crossovers); this.crossoverMixer = new PropertyCrossoverMixer(crossovers);
this.m_Crossers.m_SelectedTargets = m_Crossers.m_AvailableTargets.clone(); this.crossoverMixer.selectedTargets = crossoverMixer.availableTargets.clone();
} }
@Override @Override
@ -66,7 +66,7 @@ public class AdaptiveCrossoverEAMixer extends CrossoverEAMixer implements Interf
} }
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt, Population pop, double fit) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt, Population pop, double fit) {
InterfaceCrossover[] mutators = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] mutators = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < mutators.length; i++) { for (int i = 0; i < mutators.length; i++) {
mutators[i].init(individual, opt); mutators[i].init(individual, opt);
} }
@ -81,7 +81,7 @@ public class AdaptiveCrossoverEAMixer extends CrossoverEAMixer implements Interf
} }
public void update(AbstractEAIndividual individual, InterfaceOptimizationProblem opt, Population pop, double fit) { public void update(AbstractEAIndividual individual, InterfaceOptimizationProblem opt, Population pop, double fit) {
InterfaceCrossover[] mutators = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] mutators = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < mutators.length; i++) { for (int i = 0; i < mutators.length; i++) {
mutators[i].init(individual, opt); mutators[i].init(individual, opt);
} }

View File

@ -16,13 +16,13 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM1 implements InterfaceCrossover, java.io.Serializable { public class CM1 implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CM1() { public CM1() {
} }
public CM1(CM1 c) { public CM1(CM1 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
@Override @Override
@ -58,7 +58,7 @@ public class CM1 implements InterfaceCrossover, java.io.Serializable {
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -15,14 +15,14 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM3 implements InterfaceCrossover, java.io.Serializable { public class CM3 implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CM3() { public CM3() {
} }
public CM3(CM3 c) { public CM3(CM3 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
@Override @Override
@ -69,7 +69,7 @@ public class CM3 implements InterfaceCrossover, java.io.Serializable {
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -15,14 +15,14 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM4 implements InterfaceCrossover, java.io.Serializable { public class CM4 implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CM4() { public CM4() {
} }
public CM4(CM4 c) { public CM4(CM4 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
@Override @Override
@ -71,7 +71,7 @@ public class CM4 implements InterfaceCrossover, java.io.Serializable {
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -15,14 +15,14 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM5 implements InterfaceCrossover, java.io.Serializable { public class CM5 implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CM5() { public CM5() {
} }
public CM5(CM5 c) { public CM5(CM5 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
@Override @Override
@ -54,7 +54,7 @@ public class CM5 implements InterfaceCrossover, java.io.Serializable {
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -17,14 +17,14 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM6 implements InterfaceCrossover, java.io.Serializable { public class CM6 implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CM6() { public CM6() {
} }
public CM6(CM6 c) { public CM6(CM6 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
@Override @Override
@ -60,7 +60,7 @@ public class CM6 implements InterfaceCrossover, java.io.Serializable {
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -14,7 +14,7 @@ import java.util.BitSet;
* @author Alex * @author Alex
*/ */
public class CM7 implements InterfaceCrossover, java.io.Serializable, InterfaceEvaluatingCrossoverOperator { public class CM7 implements InterfaceCrossover, java.io.Serializable, InterfaceEvaluatingCrossoverOperator {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private int evaluations = 0; private int evaluations = 0;
public CM7() { public CM7() {
@ -22,7 +22,7 @@ public class CM7 implements InterfaceCrossover, java.io.Serializable, InterfaceE
} }
public CM7(CM7 c) { public CM7(CM7 c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.evaluations = c.evaluations; this.evaluations = c.evaluations;
} }
@ -51,7 +51,7 @@ public class CM7 implements InterfaceCrossover, java.io.Serializable, InterfaceE
different++; different++;
data.flip(i); data.flip(i);
((InterfaceDataTypeBinary) indy1).setBinaryGenotype(data); ((InterfaceDataTypeBinary) indy1).setBinaryGenotype(data);
this.m_OptimizationProblem.evaluate(indy1); this.optimizationProblem.evaluate(indy1);
this.evaluations++; this.evaluations++;
if (indy1.getFitness(0) < min) { if (indy1.getFitness(0) < min) {
foundBetter = true; foundBetter = true;
@ -75,7 +75,7 @@ public class CM7 implements InterfaceCrossover, java.io.Serializable, InterfaceE
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -17,7 +17,7 @@ import java.util.ArrayList;
public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluatingCrossoverOperator, java.io.Serializable { public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluatingCrossoverOperator, java.io.Serializable {
public static final String CROSSOVER_EA_MIXER_OPERATOR_KEY = "CrossoverEAMixerOperatorKey"; public static final String CROSSOVER_EA_MIXER_OPERATOR_KEY = "CrossoverEAMixerOperatorKey";
protected PropertyCrossoverMixer m_Crossers; protected PropertyCrossoverMixer crossoverMixer;
protected boolean useSelfAdaption = false; protected boolean useSelfAdaption = false;
protected double tau1 = 0.15; protected double tau1 = 0.15;
protected double lowerLimitChance = 0.05; protected double lowerLimitChance = 0.05;
@ -51,18 +51,18 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
System.out.println("Illegal access exception for " + (String) crossers.get(i)); System.out.println("Illegal access exception for " + (String) crossers.get(i));
} }
} }
this.m_Crossers = new PropertyCrossoverMixer(tmpList); this.crossoverMixer = new PropertyCrossoverMixer(tmpList);
tmpList = new InterfaceCrossover[2]; tmpList = new InterfaceCrossover[2];
tmpList[0] = new CrossoverESArithmetical(); tmpList[0] = new CrossoverESArithmetical();
tmpList[1] = new CrossoverESSBX(); tmpList[1] = new CrossoverESSBX();
this.m_Crossers.setSelectedCrossers(tmpList); this.crossoverMixer.setSelectedCrossers(tmpList);
this.m_Crossers.normalizeWeights(); this.crossoverMixer.normalizeWeights();
this.m_Crossers.setDescriptiveString("Combining alternative mutation operators, please norm the weights!"); this.crossoverMixer.setDescriptiveString("Combining alternative mutation operators, please norm the weights!");
this.m_Crossers.setWeightsLabel("Weights"); this.crossoverMixer.setWeightsLabel("Weights");
} }
public CrossoverEAMixer(CrossoverEAMixer mutator) { public CrossoverEAMixer(CrossoverEAMixer mutator) {
this.m_Crossers = (PropertyCrossoverMixer) mutator.m_Crossers.clone(); this.crossoverMixer = (PropertyCrossoverMixer) mutator.crossoverMixer.clone();
this.useSelfAdaption = mutator.useSelfAdaption; this.useSelfAdaption = mutator.useSelfAdaption;
this.tau1 = mutator.tau1; this.tau1 = mutator.tau1;
this.lowerLimitChance = mutator.lowerLimitChance; this.lowerLimitChance = mutator.lowerLimitChance;
@ -103,7 +103,7 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
InterfaceCrossover[] crossers = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] crossers = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < crossers.length; i++) { for (int i = 0; i < crossers.length; i++) {
crossers[i].init(individual, opt); crossers[i].init(individual, opt);
} }
@ -118,8 +118,8 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
*/ */
@Override @Override
public AbstractEAIndividual[] mate(AbstractEAIndividual indy1, Population partners) { public AbstractEAIndividual[] mate(AbstractEAIndividual indy1, Population partners) {
this.m_Crossers.normalizeWeights(); this.crossoverMixer.normalizeWeights();
double[] probs = this.m_Crossers.getWeights(); double[] probs = this.crossoverMixer.getWeights();
if (this.useSelfAdaption) { if (this.useSelfAdaption) {
for (int i = 0; i < probs.length; i++) { for (int i = 0; i < probs.length; i++) {
probs[i] *= Math.exp(this.tau1 * RNG.gaussianDouble(1)); probs[i] *= Math.exp(this.tau1 * RNG.gaussianDouble(1));
@ -130,10 +130,10 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
probs[i] = 1; probs[i] = 1;
} }
} }
this.m_Crossers.normalizeWeights(); this.crossoverMixer.normalizeWeights();
} }
InterfaceCrossover[] crossover = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] crossover = this.crossoverMixer.getSelectedCrossers();
double pointer = RNG.randomFloat(0, 1); double pointer = RNG.randomFloat(0, 1);
double dum = probs[0]; double dum = probs[0];
lastOperatorIndex = 0; lastOperatorIndex = 0;
@ -197,11 +197,11 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
* @param d The crossover operators. * @param d The crossover operators.
*/ */
public void setCrossovers(PropertyCrossoverMixer d) { public void setCrossovers(PropertyCrossoverMixer d) {
this.m_Crossers = d; this.crossoverMixer = d;
} }
public PropertyCrossoverMixer getCrossovers() { public PropertyCrossoverMixer getCrossovers() {
return this.m_Crossers; return this.crossoverMixer;
} }
public String CrossoversTipText() { public String CrossoversTipText() {
@ -268,7 +268,7 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
@Override @Override
public int getEvaluations() { public int getEvaluations() {
int numEvals = 0; int numEvals = 0;
InterfaceCrossover[] crossers = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] crossers = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < crossers.length; i++) { for (int i = 0; i < crossers.length; i++) {
if (crossers[i] instanceof InterfaceEvaluatingCrossoverOperator) { if (crossers[i] instanceof InterfaceEvaluatingCrossoverOperator) {
numEvals += ((InterfaceEvaluatingCrossoverOperator) crossers[i]).getEvaluations(); numEvals += ((InterfaceEvaluatingCrossoverOperator) crossers[i]).getEvaluations();
@ -279,7 +279,7 @@ public class CrossoverEAMixer implements InterfaceCrossover, InterfaceEvaluating
@Override @Override
public void resetEvaluations() { public void resetEvaluations() {
InterfaceCrossover[] crossers = this.m_Crossers.getSelectedCrossers(); InterfaceCrossover[] crossers = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < crossers.length; i++) { for (int i = 0; i < crossers.length; i++) {
if (crossers[i] instanceof InterfaceEvaluatingCrossoverOperator) { if (crossers[i] instanceof InterfaceEvaluatingCrossoverOperator) {
((InterfaceEvaluatingCrossoverOperator) crossers[i]).resetEvaluations(); ((InterfaceEvaluatingCrossoverOperator) crossers[i]).resetEvaluations();

View File

@ -11,22 +11,16 @@ import eva2.tools.math.RNG;
* namely c[i]=Sum_j (r_i * p_ji) * namely c[i]=Sum_j (r_i * p_ji)
* where r_i are uniform random numbers normed to the sum of one and * where r_i are uniform random numbers normed to the sum of one and
* p_ji is the i-th component of parent j. * p_ji is the i-th component of parent j.
* <p/>
* Created by IntelliJ IDEA.
* User: streiche
* Date: 25.07.2003
* Time: 16:14:54
* To change this template use Options | File Templates.
*/ */
public class CrossoverESArithmetical implements InterfaceCrossover, java.io.Serializable { public class CrossoverESArithmetical implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverESArithmetical() { public CrossoverESArithmetical() {
} }
public CrossoverESArithmetical(CrossoverESArithmetical c) { public CrossoverESArithmetical(CrossoverESArithmetical c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -126,7 +120,7 @@ public class CrossoverESArithmetical implements InterfaceCrossover, java.io.Seri
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -15,16 +15,16 @@ import eva2.tools.math.RNG;
*/ */
public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializable { public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private double m_Alpha = 0.5; private double alpha = 0.5;
public CrossoverESBLXAlpha() { public CrossoverESBLXAlpha() {
} }
public CrossoverESBLXAlpha(CrossoverESBLXAlpha c) { public CrossoverESBLXAlpha(CrossoverESBLXAlpha c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.m_Alpha = c.m_Alpha; this.alpha = c.alpha;
} }
/** /**
@ -78,7 +78,7 @@ public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializ
double I = 0; double I = 0;
for (int i = 0; i < children.length; i++) { for (int i = 0; i < children.length; i++) {
for (int j = 0; j < children[i].length; j++) { for (int j = 0; j < children[i].length; j++) {
I = (extremeValues[j][1] - extremeValues[j][0]) * this.m_Alpha; I = (extremeValues[j][1] - extremeValues[j][0]) * this.alpha;
children[i][j] = RNG.randomDouble(extremeValues[j][0] - I, extremeValues[j][1] + I); children[i][j] = RNG.randomDouble(extremeValues[j][0] - I, extremeValues[j][1] + I);
} }
} }
@ -105,7 +105,7 @@ public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializ
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverESBLXAlpha) { if (crossover instanceof CrossoverESBLXAlpha) {
CrossoverESBLXAlpha cross = (CrossoverESBLXAlpha) crossover; CrossoverESBLXAlpha cross = (CrossoverESBLXAlpha) crossover;
if (this.m_Alpha != cross.m_Alpha) { if (this.alpha != cross.alpha) {
return false; return false;
} }
return true; return true;
@ -125,7 +125,7 @@ public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializ
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override
@ -165,11 +165,11 @@ public class CrossoverESBLXAlpha implements InterfaceCrossover, java.io.Serializ
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Alpha = a; this.alpha = a;
} }
public double getAlpha() { public double getAlpha() {
return this.m_Alpha; return this.alpha;
} }
public String alphaTipText() { public String alphaTipText() {

View File

@ -14,22 +14,16 @@ import eva2.tools.math.RNG;
* <p/> * <p/>
* where c[i] is the i-th child component and p_ij is the i-th component * where c[i] is the i-th child component and p_ij is the i-th component
* of parent j. * of parent j.
* <p/>
* Created by IntelliJ IDEA.
* User: streiche
* Date: 02.12.2003
* Time: 14:01:31
* To change this template use Options | File Templates.
*/ */
public class CrossoverESFlat implements InterfaceCrossover, java.io.Serializable { public class CrossoverESFlat implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverESFlat() { public CrossoverESFlat() {
} }
public CrossoverESFlat(CrossoverESFlat c) { public CrossoverESFlat(CrossoverESFlat c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -125,7 +119,7 @@ public class CrossoverESFlat implements InterfaceCrossover, java.io.Serializable
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -13,14 +13,14 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class CrossoverESIntermediate implements InterfaceCrossover, java.io.Serializable { public class CrossoverESIntermediate implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverESIntermediate() { public CrossoverESIntermediate() {
} }
public CrossoverESIntermediate(CrossoverESIntermediate c) { public CrossoverESIntermediate(CrossoverESIntermediate c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -112,7 +112,7 @@ public class CrossoverESIntermediate implements InterfaceCrossover, java.io.Seri
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -7,23 +7,19 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 25.07.2003
* Time: 15:32:33
* To change this template use Options | File Templates.
*/ */
public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Serializable { public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private int m_NumberOfCrossovers = 3; private int numberOfCrossovers = 3;
public CrossoverESNPointDiscrete() { public CrossoverESNPointDiscrete() {
} }
public CrossoverESNPointDiscrete(CrossoverESNPointDiscrete mutator) { public CrossoverESNPointDiscrete(CrossoverESNPointDiscrete mutator) {
this.m_OptimizationProblem = mutator.m_OptimizationProblem; this.optimizationProblem = mutator.optimizationProblem;
this.m_NumberOfCrossovers = mutator.m_NumberOfCrossovers; this.numberOfCrossovers = mutator.numberOfCrossovers;
} }
/** /**
@ -59,7 +55,7 @@ public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Se
if ((indy1 instanceof InterfaceESIndividual) && (partners.get(0) instanceof InterfaceESIndividual)) { if ((indy1 instanceof InterfaceESIndividual) && (partners.get(0) instanceof InterfaceESIndividual)) {
int length = ((InterfaceESIndividual) result[0]).getDGenotype().length; int length = ((InterfaceESIndividual) result[0]).getDGenotype().length;
int mixer = RNG.randomInt(0, partners.size()); int mixer = RNG.randomInt(0, partners.size());
int[] crossoverPoints = new int[this.m_NumberOfCrossovers]; int[] crossoverPoints = new int[this.numberOfCrossovers];
parents = new double[partners.size() + 1][]; parents = new double[partners.size() + 1][];
children = new double[partners.size() + 1][]; children = new double[partners.size() + 1][];
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
@ -68,11 +64,11 @@ public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Se
System.arraycopy(((InterfaceESIndividual) result[i]).getDGenotype(), 0, parents[i], 0, parents[i].length); System.arraycopy(((InterfaceESIndividual) result[i]).getDGenotype(), 0, parents[i], 0, parents[i].length);
System.arraycopy(((InterfaceESIndividual) result[i]).getDGenotype(), 0, children[i], 0, parents[i].length); System.arraycopy(((InterfaceESIndividual) result[i]).getDGenotype(), 0, children[i], 0, parents[i].length);
} }
for (int i = 0; i < this.m_NumberOfCrossovers; i++) { for (int i = 0; i < this.numberOfCrossovers; i++) {
crossoverPoints[i] = RNG.randomInt(0, length - 1); crossoverPoints[i] = RNG.randomInt(0, length - 1);
} }
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
if (i == crossoverPoints[j]) { if (i == crossoverPoints[j]) {
mixer++; mixer++;
} }
@ -105,7 +101,7 @@ public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Se
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverESNPointDiscrete) { if (crossover instanceof CrossoverESNPointDiscrete) {
CrossoverESNPointDiscrete cross = (CrossoverESNPointDiscrete) crossover; CrossoverESNPointDiscrete cross = (CrossoverESNPointDiscrete) crossover;
if (this.m_NumberOfCrossovers != cross.m_NumberOfCrossovers) { if (this.numberOfCrossovers != cross.numberOfCrossovers) {
return false; return false;
} }
return true; return true;
@ -125,7 +121,7 @@ public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Se
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override
@ -165,11 +161,11 @@ public class CrossoverESNPointDiscrete implements InterfaceCrossover, java.io.Se
if (crossovers < 0) { if (crossovers < 0) {
crossovers = 0; crossovers = 0;
} }
this.m_NumberOfCrossovers = crossovers; this.numberOfCrossovers = crossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {

View File

@ -7,23 +7,19 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 14.04.2004
* Time: 16:23:27
* To change this template use File | Settings | File Templates.
*/ */
public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover, java.io.Serializable { public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private int m_NumberOfCrossovers = 3; private int numberOfCrossovers = 3;
public CrossoverESNPointDiscreteDislocation() { public CrossoverESNPointDiscreteDislocation() {
} }
public CrossoverESNPointDiscreteDislocation(CrossoverESNPointDiscreteDislocation mutator) { public CrossoverESNPointDiscreteDislocation(CrossoverESNPointDiscreteDislocation mutator) {
this.m_OptimizationProblem = mutator.m_OptimizationProblem; this.optimizationProblem = mutator.optimizationProblem;
this.m_NumberOfCrossovers = mutator.m_NumberOfCrossovers; this.numberOfCrossovers = mutator.numberOfCrossovers;
} }
/** /**
@ -59,7 +55,7 @@ public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover,
if ((indy1 instanceof InterfaceESIndividual) && (partners.get(0) instanceof InterfaceESIndividual)) { if ((indy1 instanceof InterfaceESIndividual) && (partners.get(0) instanceof InterfaceESIndividual)) {
int length = ((InterfaceESIndividual) result[0]).getDGenotype().length; int length = ((InterfaceESIndividual) result[0]).getDGenotype().length;
int mixer = RNG.randomInt(0, partners.size()); int mixer = RNG.randomInt(0, partners.size());
int[] crossoverPoints = new int[this.m_NumberOfCrossovers + 1]; int[] crossoverPoints = new int[this.numberOfCrossovers + 1];
parents = new double[partners.size() + 1][]; parents = new double[partners.size() + 1][];
children = new double[partners.size() + 1][]; children = new double[partners.size() + 1][];
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
@ -71,7 +67,7 @@ public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover,
for (int i = 0; i < crossoverPoints.length; i++) { for (int i = 0; i < crossoverPoints.length; i++) {
crossoverPoints[i] = RNG.randomInt(0, length - 1); crossoverPoints[i] = RNG.randomInt(0, length - 1);
} }
crossoverPoints[RNG.randomInt(0, this.m_NumberOfCrossovers)] = 0; crossoverPoints[RNG.randomInt(0, this.numberOfCrossovers)] = 0;
int parIndex = 0; int parIndex = 0;
int chiIndex = 0; int chiIndex = 0;
boolean bol; boolean bol;
@ -120,7 +116,7 @@ public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover,
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverESNPointDiscreteDislocation) { if (crossover instanceof CrossoverESNPointDiscreteDislocation) {
CrossoverESNPointDiscreteDislocation cross = (CrossoverESNPointDiscreteDislocation) crossover; CrossoverESNPointDiscreteDislocation cross = (CrossoverESNPointDiscreteDislocation) crossover;
if (this.m_NumberOfCrossovers != cross.m_NumberOfCrossovers) { if (this.numberOfCrossovers != cross.numberOfCrossovers) {
return false; return false;
} }
return true; return true;
@ -140,7 +136,7 @@ public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover,
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override
@ -180,11 +176,11 @@ public class CrossoverESNPointDiscreteDislocation implements InterfaceCrossover,
if (crossovers < 0) { if (crossovers < 0) {
crossovers = 0; crossovers = 0;
} }
this.m_NumberOfCrossovers = crossovers; this.numberOfCrossovers = crossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {

View File

@ -14,26 +14,22 @@ import eva2.tools.math.RNG;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 09.02.2005
* Time: 11:17:17
* To change this template use File | Settings | File Templates.
*/ */
public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable { public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private double m_Eta = 0.2; private double eta = 0.2;
private double m_Zeta = 0.2; private double zeta = 0.2;
public CrossoverESPCX() { public CrossoverESPCX() {
} }
public CrossoverESPCX(CrossoverESPCX c) { public CrossoverESPCX(CrossoverESPCX c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.m_Eta = c.m_Eta; this.eta = c.eta;
this.m_Zeta = c.m_Zeta; this.zeta = c.zeta;
} }
/** /**
@ -106,12 +102,12 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
// first the parent and the d // first the parent and the d
for (int j = 0; j < parents[i].length; j++) { for (int j = 0; j < parents[i].length; j++) {
children[i][j] = parents[i][j]; children[i][j] = parents[i][j];
children[i][j] += RNG.gaussianDouble(this.m_Zeta) * tmpD[j]; children[i][j] += RNG.gaussianDouble(this.zeta) * tmpD[j];
} }
// then the other parents // then the other parents
for (int j = 1; j < subSpace.size(); j++) { for (int j = 1; j < subSpace.size(); j++) {
tmpD = (double[]) subSpace.get(j); tmpD = (double[]) subSpace.get(j);
w = RNG.gaussianDouble(this.m_Zeta); w = RNG.gaussianDouble(this.zeta);
children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD)); children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD));
} }
} }
@ -217,7 +213,7 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -286,8 +282,8 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
} }
CrossoverESPCX cross = new CrossoverESPCX(); CrossoverESPCX cross = new CrossoverESPCX();
cross.m_Eta = 0.2; cross.eta = 0.2;
cross.m_Zeta = 0.2; cross.zeta = 0.2;
AbstractEAIndividual[] offsprings; AbstractEAIndividual[] offsprings;
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
offsprings = cross.mate(indy1, pop); offsprings = cross.mate(indy1, pop);
@ -333,11 +329,11 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Eta = a; this.eta = a;
} }
public double getEta() { public double getEta() {
return this.m_Eta; return this.eta;
} }
public String etaTipText() { public String etaTipText() {
@ -348,11 +344,11 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Zeta = a; this.zeta = a;
} }
public double getZeta() { public double getZeta() {
return this.m_Zeta; return this.zeta;
} }
public String zetaTipText() { public String zetaTipText() {

View File

@ -10,28 +10,24 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 27.02.2004
* Time: 17:49:16
* To change this template use File | Settings | File Templates.
*/ */
public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable { public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private double m_Eta = 0.2; private double eta = 0.2;
public CrossoverESSBX() { public CrossoverESSBX() {
} }
public CrossoverESSBX(double eta) { public CrossoverESSBX(double eta) {
m_Eta = eta; this.eta = eta;
} }
public CrossoverESSBX(CrossoverESSBX c) { public CrossoverESSBX(CrossoverESSBX c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.m_Eta = c.m_Eta; this.eta = c.eta;
} }
/** /**
@ -77,9 +73,9 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
for (int i = 0; i < children[0].length; i++) { for (int i = 0; i < children[0].length; i++) {
u = RNG.randomDouble(0, 1); u = RNG.randomDouble(0, 1);
if (u <= 0.5) { if (u <= 0.5) {
beta = Math.pow((2 * u), 1 / (this.m_Eta + 1)); beta = Math.pow((2 * u), 1 / (this.eta + 1));
} else { } else {
beta = Math.pow((0.5 / (1 - u)), 1 / (this.m_Eta + 1)); beta = Math.pow((0.5 / (1 - u)), 1 / (this.eta + 1));
} }
children[0][i] = 0.5 * ((1 + beta) * parents[0][i] + (1 - beta) * parents[1][i]); children[0][i] = 0.5 * ((1 + beta) * parents[0][i] + (1 - beta) * parents[1][i]);
children[1][i] = 0.5 * ((1 - beta) * parents[0][i] + (1 + beta) * parents[1][i]); children[1][i] = 0.5 * ((1 - beta) * parents[0][i] + (1 + beta) * parents[1][i]);
@ -107,7 +103,7 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverESSBX) { if (crossover instanceof CrossoverESSBX) {
CrossoverESSBX cross = (CrossoverESSBX) crossover; CrossoverESSBX cross = (CrossoverESSBX) crossover;
if (this.m_Eta != cross.m_Eta) { if (this.eta != cross.eta) {
return false; return false;
} }
return true; return true;
@ -127,7 +123,7 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -182,7 +178,7 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
CrossoverESSBX cross = new CrossoverESSBX(); CrossoverESSBX cross = new CrossoverESSBX();
cross.m_Eta = 0.2; cross.eta = 0.2;
AbstractEAIndividual[] offsprings; AbstractEAIndividual[] offsprings;
for (int i = 0; i < 5000; i++) { for (int i = 0; i < 5000; i++) {
offsprings = cross.mate(indy1, pop); offsprings = cross.mate(indy1, pop);
@ -232,11 +228,11 @@ public class CrossoverESSBX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Eta = a; this.eta = a;
} }
public double getEta() { public double getEta() {
return this.m_Eta; return this.eta;
} }
public String etaTipText() { public String etaTipText() {

View File

@ -11,24 +11,20 @@ import eva2.tools.math.Mathematics;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 09.02.2005
* Time: 14:27:22
* To change this template use File | Settings | File Templates.
*/ */
public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable { public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private double m_Epsilon = 1.2; private double epsilon = 1.2;
public CrossoverESSPX() { public CrossoverESSPX() {
} }
public CrossoverESSPX(CrossoverESSPX c) { public CrossoverESSPX(CrossoverESSPX c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.m_Epsilon = c.m_Epsilon; this.epsilon = c.epsilon;
} }
/** /**
@ -77,7 +73,7 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
// calculate the Y vectors // calculate the Y vectors
for (int i = 0; i < parents.length; i++) { for (int i = 0; i < parents.length; i++) {
Y[i] = Mathematics.vvAdd(g, Mathematics.svMult(this.m_Epsilon, Mathematics.vvSub(parents[i], g))); Y[i] = Mathematics.vvAdd(g, Mathematics.svMult(this.epsilon, Mathematics.vvSub(parents[i], g)));
} }
// now for each child the C vectors and the result // now for each child the C vectors and the result
@ -135,7 +131,7 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -204,7 +200,7 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
} }
CrossoverESSPX cross = new CrossoverESSPX(); CrossoverESSPX cross = new CrossoverESSPX();
cross.m_Epsilon = 1.2; cross.epsilon = 1.2;
AbstractEAIndividual[] offsprings; AbstractEAIndividual[] offsprings;
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
offsprings = cross.mate(indy1, pop); offsprings = cross.mate(indy1, pop);
@ -250,11 +246,11 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Epsilon = a; this.epsilon = a;
} }
public double getEpsilon() { public double getEpsilon() {
return this.m_Epsilon; return this.epsilon;
} }
public String epsilonTipText() { public String epsilonTipText() {

View File

@ -37,18 +37,18 @@ import java.util.ArrayList;
*/ */
public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable { public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private double m_Eta = 0.2; private double eta = 0.2;
private double m_Zeta = 0.2; private double zeta = 0.2;
public CrossoverESUNDX() { public CrossoverESUNDX() {
} }
public CrossoverESUNDX(CrossoverESUNDX c) { public CrossoverESUNDX(CrossoverESUNDX c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
this.m_Eta = c.m_Eta; this.eta = c.eta;
this.m_Zeta = c.m_Zeta; this.zeta = c.zeta;
} }
/** /**
@ -109,13 +109,13 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
// then the given coordinates // then the given coordinates
for (int j = 0; j < givenCoordinates.size(); j++) { for (int j = 0; j < givenCoordinates.size(); j++) {
tmpD = (double[]) givenCoordinates.get(j); tmpD = (double[]) givenCoordinates.get(j);
w = RNG.gaussianDouble(this.m_Zeta); w = RNG.gaussianDouble(this.zeta);
children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD)); children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD));
} }
// now the missing stuff // now the missing stuff
for (int j = 0; j < missingCorrdinates.size(); j++) { for (int j = 0; j < missingCorrdinates.size(); j++) {
tmpD = (double[]) missingCorrdinates.get(j); tmpD = (double[]) missingCorrdinates.get(j);
w = RNG.gaussianDouble(this.m_Eta); w = RNG.gaussianDouble(this.eta);
children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD)); children[i] = Mathematics.vvAdd(children[i], Mathematics.svMult(w, tmpD));
} }
} }
@ -219,7 +219,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -288,8 +288,8 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
} }
CrossoverESUNDX cross = new CrossoverESUNDX(); CrossoverESUNDX cross = new CrossoverESUNDX();
cross.m_Eta = 0.2; cross.eta = 0.2;
cross.m_Zeta = 0.2; cross.zeta = 0.2;
AbstractEAIndividual[] offsprings; AbstractEAIndividual[] offsprings;
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
offsprings = cross.mate(indy1, pop); offsprings = cross.mate(indy1, pop);
@ -335,11 +335,11 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Eta = a; this.eta = a;
} }
public double getEta() { public double getEta() {
return this.m_Eta; return this.eta;
} }
public String etaTipText() { public String etaTipText() {
@ -350,11 +350,11 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
if (a < 0) { if (a < 0) {
a = 0; a = 0;
} }
this.m_Zeta = a; this.zeta = a;
} }
public double getZeta() { public double getZeta() {
return this.m_Zeta; return this.zeta;
} }
public String zetaTipText() { public String zetaTipText() {

View File

@ -7,21 +7,17 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
import eva2.tools.math.RNG; import eva2.tools.math.RNG;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 02.12.2003
* Time: 14:14:52
* To change this template use Options | File Templates.
*/ */
public class CrossoverESUniformDiscrete implements InterfaceCrossover, java.io.Serializable { public class CrossoverESUniformDiscrete implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverESUniformDiscrete() { public CrossoverESUniformDiscrete() {
} }
public CrossoverESUniformDiscrete(CrossoverESUniformDiscrete c) { public CrossoverESUniformDiscrete(CrossoverESUniformDiscrete c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -113,7 +109,7 @@ public class CrossoverESUniformDiscrete implements InterfaceCrossover, java.io.S
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -10,21 +10,17 @@ import eva2.tools.math.RNG;
import java.util.BitSet; import java.util.BitSet;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 03.04.2003
* Time: 15:03:55
* To change this template use Options | File Templates.
*/ */
public class CrossoverGABitSimulated implements InterfaceCrossover, java.io.Serializable { public class CrossoverGABitSimulated implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverGABitSimulated() { public CrossoverGABitSimulated() {
} }
public CrossoverGABitSimulated(CrossoverGABitSimulated c) { public CrossoverGABitSimulated(CrossoverGABitSimulated c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -124,7 +120,7 @@ public class CrossoverGABitSimulated implements InterfaceCrossover, java.io.Seri
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -11,20 +11,17 @@ import java.util.BitSet;
/** /**
* This operator performs one-point crossover. * This operator performs one-point crossover.
* <p/>
* Created by IntelliJ IDEA. User: streiche Date: 03.04.2003 Time: 10:34:17 To
* change this template use Options | File Templates.
*/ */
public class CrossoverGADefault implements InterfaceCrossover, public class CrossoverGADefault implements InterfaceCrossover,
java.io.Serializable { java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverGADefault() { public CrossoverGADefault() {
} }
public CrossoverGADefault(CrossoverGADefault c) { public CrossoverGADefault(CrossoverGADefault c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -127,7 +124,7 @@ public class CrossoverGADefault implements InterfaceCrossover,
@Override @Override
public void init(AbstractEAIndividual individual, public void init(AbstractEAIndividual individual,
InterfaceOptimizationProblem opt) { InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -20,8 +20,7 @@ import java.util.BitSet;
* @author mkron, streiche * @author mkron, streiche
*/ */
public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializable { public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializable {
// private InterfaceOptimizationProblem m_OptimizationProblem; private int numberOfCrossovers = 3;
private int m_NumberOfCrossovers = 3;
private static boolean TRACE = false; private static boolean TRACE = false;
public CrossoverGAGINPoint() { public CrossoverGAGINPoint() {
@ -34,8 +33,7 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
} }
public CrossoverGAGINPoint(CrossoverGAGINPoint mutator) { public CrossoverGAGINPoint(CrossoverGAGINPoint mutator) {
// this.m_OptimizationProblem = mutator.m_OptimizationProblem; this.numberOfCrossovers = mutator.numberOfCrossovers;
this.m_NumberOfCrossovers = mutator.m_NumberOfCrossovers;
} }
/** /**
@ -89,12 +87,12 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
System.out.println("Before CO: " + BeanInspector.toString(newGenotypes)); System.out.println("Before CO: " + BeanInspector.toString(newGenotypes));
} }
int mixer = RNG.randomInt(0, partners.size()); // partner index with which to exchange genes int mixer = RNG.randomInt(0, partners.size()); // partner index with which to exchange genes
int[] crossoverPoints = getCrossoverPoints(length, m_NumberOfCrossovers); int[] crossoverPoints = getCrossoverPoints(length, numberOfCrossovers);
if (TRACE) { if (TRACE) {
System.out.println("CO points: " + BeanInspector.toString(crossoverPoints)); System.out.println("CO points: " + BeanInspector.toString(crossoverPoints));
} }
for (int i = 0; i < length; i++) { // loop positions for (int i = 0; i < length; i++) { // loop positions
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
if (i == crossoverPoints[j]) { if (i == crossoverPoints[j]) {
mixer++; mixer++;
} // possibly switch partner to exchange with } // possibly switch partner to exchange with
@ -182,10 +180,10 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
// length = Math.max(length, ((InterfaceGAIndividual)partners.get(i)).getGenotypeLength()); // length = Math.max(length, ((InterfaceGAIndividual)partners.get(i)).getGenotypeLength());
// } // }
// //
// crossoverPoints=getCrossoverPoints(length, m_NumberOfCrossovers); // crossoverPoints=getCrossoverPoints(length, numberOfCrossovers);
// //
// for (int i = 0; i < length; i++) { // for (int i = 0; i < length; i++) {
// for (int j = 0; j < this.m_NumberOfCrossovers; j++) { // for (int j = 0; j < this.numberOfCrossovers; j++) {
// if (i == crossoverPoints[j]) mixer++; // if (i == crossoverPoints[j]) mixer++;
// } // }
// for (int j = 0; j < tmpBitSet[0].length; j++) { // for (int j = 0; j < tmpBitSet[0].length; j++) {
@ -230,7 +228,7 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverGAGINPoint) { if (crossover instanceof CrossoverGAGINPoint) {
CrossoverGAGINPoint cross = (CrossoverGAGINPoint) crossover; CrossoverGAGINPoint cross = (CrossoverGAGINPoint) crossover;
if (this.m_NumberOfCrossovers != cross.m_NumberOfCrossovers) { if (this.numberOfCrossovers != cross.numberOfCrossovers) {
return false; return false;
} }
return true; return true;
@ -250,7 +248,7 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
// this.m_OptimizationProblem = opt; // this.optimizationProblem = opt;
} }
@Override @Override
@ -290,11 +288,11 @@ public class CrossoverGAGINPoint implements InterfaceCrossover, java.io.Serializ
if (crossovers < 0) { if (crossovers < 0) {
crossovers = 0; crossovers = 0;
} }
this.m_NumberOfCrossovers = crossovers; this.numberOfCrossovers = crossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {

View File

@ -17,14 +17,14 @@ import java.util.BitSet;
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class CrossoverGAUniform implements InterfaceCrossover, java.io.Serializable { public class CrossoverGAUniform implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverGAUniform() { public CrossoverGAUniform() {
} }
public CrossoverGAUniform(CrossoverGAUniform c) { public CrossoverGAUniform(CrossoverGAUniform c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -118,7 +118,7 @@ public class CrossoverGAUniform implements InterfaceCrossover, java.io.Serializa
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -8,22 +8,17 @@ import eva2.tools.math.RNG;
/** /**
* One-point crossover on integer individuals. * One-point crossover on integer individuals.
* <p/>
* User: mkron, streiche
* Date: 18.05.2005
* Time: 17:10:28
* To change this template use File | Settings | File Templates.
*/ */
public class CrossoverGIDefault implements InterfaceCrossover, java.io.Serializable { public class CrossoverGIDefault implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverGIDefault() { public CrossoverGIDefault() {
} }
public CrossoverGIDefault(CrossoverGIDefault c) { public CrossoverGIDefault(CrossoverGIDefault c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -125,7 +120,7 @@ public class CrossoverGIDefault implements InterfaceCrossover, java.io.Serializa
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -14,16 +14,16 @@ import eva2.tools.math.RNG;
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializable { public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private int m_NumberOfCrossovers = 3; private int numberOfCrossovers = 3;
public CrossoverGINPoint() { public CrossoverGINPoint() {
} }
public CrossoverGINPoint(CrossoverGINPoint mutator) { public CrossoverGINPoint(CrossoverGINPoint mutator) {
this.m_OptimizationProblem = mutator.m_OptimizationProblem; this.optimizationProblem = mutator.optimizationProblem;
this.m_NumberOfCrossovers = mutator.m_NumberOfCrossovers; this.numberOfCrossovers = mutator.numberOfCrossovers;
} }
/** /**
@ -58,7 +58,7 @@ public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializab
if ((indy1 instanceof InterfaceGIIndividual) && (partners.get(0) instanceof InterfaceGIIndividual)) { if ((indy1 instanceof InterfaceGIIndividual) && (partners.get(0) instanceof InterfaceGIIndividual)) {
int length = ((InterfaceGIIndividual) indy1).getGenotypeLength(); int length = ((InterfaceGIIndividual) indy1).getGenotypeLength();
int mixer = RNG.randomInt(0, partners.size()); int mixer = RNG.randomInt(0, partners.size());
int[] crossoverPoints = new int[this.m_NumberOfCrossovers]; int[] crossoverPoints = new int[this.numberOfCrossovers];
int[][][] tmpInts = new int[2][partners.size() + 1][]; int[][][] tmpInts = new int[2][partners.size() + 1][];
tmpInts[0][0] = ((InterfaceGIIndividual) indy1).getIGenotype(); tmpInts[0][0] = ((InterfaceGIIndividual) indy1).getIGenotype();
@ -70,12 +70,12 @@ public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializab
length = Math.max(length, ((InterfaceGIIndividual) partners.get(i)).getGenotypeLength()); length = Math.max(length, ((InterfaceGIIndividual) partners.get(i)).getGenotypeLength());
} }
for (int i = 0; i < this.m_NumberOfCrossovers; i++) { for (int i = 0; i < this.numberOfCrossovers; i++) {
crossoverPoints[i] = RNG.randomInt(0, length - 1); crossoverPoints[i] = RNG.randomInt(0, length - 1);
//System.out.println("crpoint: "+crossoverPoints[i]); //System.out.println("crpoint: "+crossoverPoints[i]);
} }
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
if (i == crossoverPoints[j]) { if (i == crossoverPoints[j]) {
mixer++; mixer++;
} }
@ -110,7 +110,7 @@ public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializab
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverGINPoint) { if (crossover instanceof CrossoverGINPoint) {
CrossoverGINPoint cross = (CrossoverGINPoint) crossover; CrossoverGINPoint cross = (CrossoverGINPoint) crossover;
if (this.m_NumberOfCrossovers != cross.m_NumberOfCrossovers) { if (this.numberOfCrossovers != cross.numberOfCrossovers) {
return false; return false;
} }
return true; return true;
@ -130,7 +130,7 @@ public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializab
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override
@ -170,11 +170,11 @@ public class CrossoverGINPoint implements InterfaceCrossover, java.io.Serializab
if (crossovers < 0) { if (crossovers < 0) {
crossovers = 0; crossovers = 0;
} }
this.m_NumberOfCrossovers = crossovers; this.numberOfCrossovers = crossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {

View File

@ -16,16 +16,16 @@ import java.util.BitSet;
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializable { public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private int m_NumberOfCrossovers = 3; private int numberOfCrossovers = 3;
public CrossoverGINPointVL() { public CrossoverGINPointVL() {
} }
public CrossoverGINPointVL(CrossoverGINPointVL mutator) { public CrossoverGINPointVL(CrossoverGINPointVL mutator) {
this.m_OptimizationProblem = mutator.m_OptimizationProblem; this.optimizationProblem = mutator.optimizationProblem;
this.m_NumberOfCrossovers = mutator.m_NumberOfCrossovers; this.numberOfCrossovers = mutator.numberOfCrossovers;
} }
/** /**
@ -60,7 +60,7 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
if ((indy1 instanceof InterfaceGIIndividual) && (partners.get(0) instanceof InterfaceGIIndividual)) { if ((indy1 instanceof InterfaceGIIndividual) && (partners.get(0) instanceof InterfaceGIIndividual)) {
int[] length = new int[partners.size() + 1]; int[] length = new int[partners.size() + 1];
int mixer = RNG.randomInt(0, partners.size()); int mixer = RNG.randomInt(0, partners.size());
int[][] crossoverPoints = new int[length.length][this.m_NumberOfCrossovers]; int[][] crossoverPoints = new int[length.length][this.numberOfCrossovers];
int[][] parents = new int[partners.size() + 1][]; int[][] parents = new int[partners.size() + 1][];
int[][] offsprings = new int[partners.size() + 1][]; int[][] offsprings = new int[partners.size() + 1][];
@ -76,14 +76,14 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
for (int i = 0; i < offsprings.length; i++) { for (int i = 0; i < offsprings.length; i++) {
index = 0; index = 0;
tmpLen = 0; tmpLen = 0;
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
tmpLen += fragments[(i + j) % fragments.length][index].length; tmpLen += fragments[(i + j) % fragments.length][index].length;
index++; index++;
} }
offsprings[i] = new int[tmpLen]; offsprings[i] = new int[tmpLen];
index = 0; index = 0;
tmpLen = 0; tmpLen = 0;
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
System.arraycopy(fragments[(i + j) % fragments.length][index], 0, offsprings[i], tmpLen, fragments[(i + j) % fragments.length][index].length); System.arraycopy(fragments[(i + j) % fragments.length][index], 0, offsprings[i], tmpLen, fragments[(i + j) % fragments.length][index].length);
tmpLen += fragments[(i + j) % fragments.length][index].length; tmpLen += fragments[(i + j) % fragments.length][index].length;
index++; index++;
@ -108,19 +108,19 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
* This method will return n fragments from the int arrays * This method will return n fragments from the int arrays
*/ */
private int[][][] getNFragmentsFrom(int[][] parents) { private int[][][] getNFragmentsFrom(int[][] parents) {
int[][][] result = new int[parents.length][this.m_NumberOfCrossovers][]; int[][][] result = new int[parents.length][this.numberOfCrossovers][];
for (int i = 0; i < parents.length; i++) { for (int i = 0; i < parents.length; i++) {
// for each parents get n fragments // for each parents get n fragments
if (this.m_NumberOfCrossovers + 2 > parents[i].length) { if (this.numberOfCrossovers + 2 > parents[i].length) {
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
result[i][j] = new int[parents[i].length]; result[i][j] = new int[parents[i].length];
System.arraycopy(parents[i], 0, result[i][j], 0, parents[i].length); System.arraycopy(parents[i], 0, result[i][j], 0, parents[i].length);
} }
} else { } else {
int[] crossoverpoints = this.getCrossoverPoints(parents[i].length); int[] crossoverpoints = this.getCrossoverPoints(parents[i].length);
int lastPoint = 0; int lastPoint = 0;
for (int j = 0; j < this.m_NumberOfCrossovers; j++) { for (int j = 0; j < this.numberOfCrossovers; j++) {
result[i][j] = new int[crossoverpoints[j] - lastPoint]; result[i][j] = new int[crossoverpoints[j] - lastPoint];
System.arraycopy(parents[i], lastPoint, result[i][j], 0, crossoverpoints[j] - lastPoint); System.arraycopy(parents[i], lastPoint, result[i][j], 0, crossoverpoints[j] - lastPoint);
lastPoint = crossoverpoints[j]; lastPoint = crossoverpoints[j];
@ -138,10 +138,10 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
* @return int[] the list of crossover points * @return int[] the list of crossover points
*/ */
private int[] getCrossoverPoints(int length) { private int[] getCrossoverPoints(int length) {
int[] result = new int[this.m_NumberOfCrossovers]; int[] result = new int[this.numberOfCrossovers];
BitSet bitset = new BitSet(length); BitSet bitset = new BitSet(length);
while (bitset.cardinality() < this.m_NumberOfCrossovers) { while (bitset.cardinality() < this.numberOfCrossovers) {
bitset.set(RNG.randomInt(1, length - 2)); bitset.set(RNG.randomInt(1, length - 2));
} }
int index = 0; int index = 0;
@ -165,7 +165,7 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
public boolean equals(Object crossover) { public boolean equals(Object crossover) {
if (crossover instanceof CrossoverGINPointVL) { if (crossover instanceof CrossoverGINPointVL) {
CrossoverGINPointVL cross = (CrossoverGINPointVL) crossover; CrossoverGINPointVL cross = (CrossoverGINPointVL) crossover;
if (this.m_NumberOfCrossovers != cross.m_NumberOfCrossovers) { if (this.numberOfCrossovers != cross.numberOfCrossovers) {
return false; return false;
} }
return true; return true;
@ -185,7 +185,7 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override
@ -225,11 +225,11 @@ public class CrossoverGINPointVL implements InterfaceCrossover, java.io.Serializ
if (crossovers < 0) { if (crossovers < 0) {
crossovers = 0; crossovers = 0;
} }
this.m_NumberOfCrossovers = crossovers; this.numberOfCrossovers = crossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {

View File

@ -16,14 +16,14 @@ import eva2.tools.math.RNG;
*/ */
public class CrossoverGIUniform implements InterfaceCrossover, java.io.Serializable { public class CrossoverGIUniform implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
public CrossoverGIUniform() { public CrossoverGIUniform() {
} }
public CrossoverGIUniform(CrossoverGIUniform c) { public CrossoverGIUniform(CrossoverGIUniform c) {
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -117,7 +117,7 @@ public class CrossoverGIUniform implements InterfaceCrossover, java.io.Serializa
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -21,7 +21,7 @@ public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializa
* *
*/ */
private static final long serialVersionUID = 8900427365914281930L; private static final long serialVersionUID = 8900427365914281930L;
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
private boolean maintainMaxDepth = true; private boolean maintainMaxDepth = true;
private static final boolean TRACE = false; private static final boolean TRACE = false;
@ -30,7 +30,7 @@ public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializa
public CrossoverGPDefault(CrossoverGPDefault c) { public CrossoverGPDefault(CrossoverGPDefault c) {
this.maintainMaxDepth = c.maintainMaxDepth; this.maintainMaxDepth = c.maintainMaxDepth;
this.m_OptimizationProblem = c.m_OptimizationProblem; this.optimizationProblem = c.optimizationProblem;
} }
/** /**
@ -157,7 +157,7 @@ public class CrossoverGPDefault implements InterfaceCrossover, java.io.Serializa
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -5,14 +5,10 @@ import eva2.optimization.population.Population;
import eva2.optimization.problems.InterfaceOptimizationProblem; import eva2.optimization.problems.InterfaceOptimizationProblem;
/** /**
* Created by IntelliJ IDEA. *
* User: streiche
* Date: 25.03.2003
* Time: 11:18:54
* To change this template use Options | File Templates.
*/ */
public class NoCrossover implements InterfaceCrossover, java.io.Serializable { public class NoCrossover implements InterfaceCrossover, java.io.Serializable {
private InterfaceOptimizationProblem m_OptimizationProblem; private InterfaceOptimizationProblem optimizationProblem;
/** /**
* A constructor. * A constructor.
@ -79,7 +75,7 @@ public class NoCrossover implements InterfaceCrossover, java.io.Serializable {
*/ */
@Override @Override
public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) { public void init(AbstractEAIndividual individual, InterfaceOptimizationProblem opt) {
this.m_OptimizationProblem = opt; this.optimizationProblem = opt;
} }
@Override @Override

View File

@ -1,46 +1,42 @@
package eva2.optimization.operator.crossover; package eva2.optimization.operator.crossover;
/** /**
* Created by IntelliJ IDEA. *
* User: Dante Alighieri
* Date: 21.05.2005
* Time: 17:34:15
* To change this template use File | Settings | File Templates.
*/ */
public class PropertyCrossoverMixer implements java.io.Serializable { public class PropertyCrossoverMixer implements java.io.Serializable {
public InterfaceCrossover[] m_AvailableTargets; public InterfaceCrossover[] availableTargets;
public InterfaceCrossover[] m_SelectedTargets; public InterfaceCrossover[] selectedTargets;
public double[] m_Weights; public double[] weights;
public String m_DescriptiveString = "No Description given."; public String descriptiveString = "No Description given.";
public String m_WeightsLabel = "-"; public String weightsLabel = "-";
public boolean m_NormalizationEnabled = true; public boolean normalizationEnabled = true;
public PropertyCrossoverMixer(InterfaceCrossover[] d) { public PropertyCrossoverMixer(InterfaceCrossover[] d) {
this.m_Weights = new double[d.length]; this.weights = new double[d.length];
for (int i = 0; i < d.length; i++) { for (int i = 0; i < d.length; i++) {
this.m_Weights[i] = 1 / ((double) d.length); this.weights[i] = 1 / ((double) d.length);
} }
this.m_AvailableTargets = d; this.availableTargets = d;
this.m_SelectedTargets = null; this.selectedTargets = null;
} }
public PropertyCrossoverMixer(PropertyCrossoverMixer d) { public PropertyCrossoverMixer(PropertyCrossoverMixer d) {
this.m_DescriptiveString = d.m_DescriptiveString; this.descriptiveString = d.descriptiveString;
this.m_WeightsLabel = d.m_WeightsLabel; this.weightsLabel = d.weightsLabel;
this.m_NormalizationEnabled = d.m_NormalizationEnabled; this.normalizationEnabled = d.normalizationEnabled;
this.m_AvailableTargets = new InterfaceCrossover[d.m_AvailableTargets.length]; this.availableTargets = new InterfaceCrossover[d.availableTargets.length];
for (int i = 0; i < this.m_AvailableTargets.length; i++) { for (int i = 0; i < this.availableTargets.length; i++) {
//this.availableTargets[i] = (InterfaceMutation)d.availableTargets[i].clone(); //this.availableTargets[i] = (InterfaceMutation)d.availableTargets[i].clone();
this.m_AvailableTargets[i] = d.m_AvailableTargets[i]; this.availableTargets[i] = d.availableTargets[i];
} }
this.m_SelectedTargets = new InterfaceCrossover[d.m_SelectedTargets.length]; this.selectedTargets = new InterfaceCrossover[d.selectedTargets.length];
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
this.m_SelectedTargets[i] = (InterfaceCrossover) d.m_SelectedTargets[i].clone(); this.selectedTargets[i] = (InterfaceCrossover) d.selectedTargets[i].clone();
} }
if (d.m_Weights != null) { if (d.weights != null) {
this.m_Weights = new double[d.m_Weights.length]; this.weights = new double[d.weights.length];
System.arraycopy(d.m_Weights, 0, this.m_Weights, 0, this.m_Weights.length); System.arraycopy(d.weights, 0, this.weights, 0, this.weights.length);
} }
} }
@ -55,32 +51,32 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @param d The InterfaceOptimizationTarget[] * @param d The InterfaceOptimizationTarget[]
*/ */
public void setSelectedCrossers(InterfaceCrossover[] d) { public void setSelectedCrossers(InterfaceCrossover[] d) {
this.m_SelectedTargets = d; this.selectedTargets = d;
if (this.m_Weights == null) { if (this.weights == null) {
this.m_Weights = new double[d.length]; this.weights = new double[d.length];
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] = 1 / ((double) d.length); this.weights[i] = 1 / ((double) d.length);
} }
return; return;
} }
if (d.length == this.m_Weights.length) { if (d.length == this.weights.length) {
return; return;
} }
if (d.length > this.m_Weights.length) { if (d.length > this.weights.length) {
double[] newWeights = new double[d.length]; double[] newWeights = new double[d.length];
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
this.m_Weights = newWeights; this.weights = newWeights;
} else { } else {
double[] newWeights = new double[d.length]; double[] newWeights = new double[d.length];
for (int i = 0; i < d.length; i++) { for (int i = 0; i < d.length; i++) {
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
this.m_Weights = newWeights; this.weights = newWeights;
} }
} }
@ -90,7 +86,7 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @return The InterfaceOptimizationTarget[]. * @return The InterfaceOptimizationTarget[].
*/ */
public InterfaceCrossover[] getSelectedCrossers() { public InterfaceCrossover[] getSelectedCrossers() {
return this.m_SelectedTargets; return this.selectedTargets;
} }
/** /**
@ -99,7 +95,7 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @return The InterfaceOptimizationTarget[]. * @return The InterfaceOptimizationTarget[].
*/ */
public InterfaceCrossover[] getAvailableCrossers() { public InterfaceCrossover[] getAvailableCrossers() {
return this.m_AvailableTargets; return this.availableTargets;
} }
/** /**
@ -108,13 +104,13 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @return the weights * @return the weights
*/ */
public double[] getWeights() { public double[] getWeights() {
return this.m_Weights; return this.weights;
} }
public void setWeights(double[] d) { public void setWeights(double[] d) {
this.m_Weights = d; this.weights = d;
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] = Math.abs(this.m_Weights[i]); this.weights[i] = Math.abs(this.weights[i]);
} }
} }
@ -124,11 +120,11 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @return the string * @return the string
*/ */
public String getDescriptiveString() { public String getDescriptiveString() {
return this.m_DescriptiveString; return this.descriptiveString;
} }
public void setDescriptiveString(String d) { public void setDescriptiveString(String d) {
this.m_DescriptiveString = d; this.descriptiveString = d;
} }
/** /**
@ -137,21 +133,21 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @return the string * @return the string
*/ */
public String getWeigthsLabel() { public String getWeigthsLabel() {
return this.m_WeightsLabel; return this.weightsLabel;
} }
public void setWeightsLabel(String d) { public void setWeightsLabel(String d) {
this.m_WeightsLabel = d; this.weightsLabel = d;
} }
public void normalizeWeights() { public void normalizeWeights() {
double sum = 0; double sum = 0;
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
sum += this.m_Weights[i]; sum += this.weights[i];
} }
if (sum > 0) { if (sum > 0) {
for (int i = 0; i < this.m_Weights.length; i++) { for (int i = 0; i < this.weights.length; i++) {
this.m_Weights[i] /= sum; this.weights[i] /= sum;
} }
} }
} }
@ -162,22 +158,22 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @param index The index of the target to be removed. * @param index The index of the target to be removed.
*/ */
public void removeCrosser(int index) { public void removeCrosser(int index) {
if ((index < 0) || (index >= this.m_SelectedTargets.length)) { if ((index < 0) || (index >= this.selectedTargets.length)) {
return; return;
} }
InterfaceCrossover[] newList = new InterfaceCrossover[this.m_SelectedTargets.length - 1]; InterfaceCrossover[] newList = new InterfaceCrossover[this.selectedTargets.length - 1];
double[] newWeights = new double[this.m_Weights.length - 1]; double[] newWeights = new double[this.weights.length - 1];
int j = 0; int j = 0;
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
if (index != i) { if (index != i) {
newList[j] = this.m_SelectedTargets[i]; newList[j] = this.selectedTargets[i];
newWeights[j] = this.m_Weights[i]; newWeights[j] = this.weights[i];
j++; j++;
} }
} }
this.m_SelectedTargets = newList; this.selectedTargets = newList;
this.m_Weights = newWeights; this.weights = newWeights;
} }
/** /**
@ -186,15 +182,15 @@ public class PropertyCrossoverMixer implements java.io.Serializable {
* @param optTarget * @param optTarget
*/ */
public void addCrossers(InterfaceCrossover optTarget) { public void addCrossers(InterfaceCrossover optTarget) {
InterfaceCrossover[] newList = new InterfaceCrossover[this.m_SelectedTargets.length + 1]; InterfaceCrossover[] newList = new InterfaceCrossover[this.selectedTargets.length + 1];
double[] newWeights = new double[this.m_Weights.length + 1]; double[] newWeights = new double[this.weights.length + 1];
for (int i = 0; i < this.m_SelectedTargets.length; i++) { for (int i = 0; i < this.selectedTargets.length; i++) {
newList[i] = this.m_SelectedTargets[i]; newList[i] = this.selectedTargets[i];
newWeights[i] = this.m_Weights[i]; newWeights[i] = this.weights[i];
} }
newList[this.m_SelectedTargets.length] = optTarget; newList[this.selectedTargets.length] = optTarget;
newWeights[this.m_SelectedTargets.length] = 1.0; newWeights[this.selectedTargets.length] = 1.0;
this.m_SelectedTargets = newList; this.selectedTargets = newList;
this.m_Weights = newWeights; this.weights = newWeights;
} }
} }

View File

@ -32,73 +32,69 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
/** /**
* Handles property change notification * Handles property change notification
*/ */
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
/**
* The label for when we can't edit that type
*/
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
/** /**
* The filePath that is to be edited * The filePath that is to be edited
*/ */
private PropertyCrossoverMixer m_CrossoversWithWeights; private PropertyCrossoverMixer crossoverMixer;
/** /**
* The gaphix stuff * The gaphix stuff
*/ */
private JComponent m_Editor; private JComponent editor;
private JPanel m_TargetList; private JPanel targetList;
private JTextField[] m_Weights; private JTextField[] weights;
private JComponent[] m_Targets; private JComponent[] targets;
private JButton[] m_Delete; private JButton[] deleteButtons;
private JScrollPane m_ScrollTargets; private JScrollPane scrollTargets;
private GeneralOptimizationEditorProperty[] m_Editors; private GeneralOptimizationEditorProperty[] editors;
private GeneralGEOFaker m_Component; private GeneralGEOFaker component;
private PropertyChangeListener m_self; private PropertyChangeListener self;
public PropertyCrossoverMixerEditor() { public PropertyCrossoverMixerEditor() {
m_self = this; self = this;
} }
/** /**
* This method will init the CustomEditor Panel * This method will init the CustomEditor Panel
*/ */
private void initCustomEditor() { private void initCustomEditor() {
m_self = this; self = this;
this.m_Editor = new JPanel(); this.editor = new JPanel();
this.m_Editor.setPreferredSize(new Dimension(450, 200)); this.editor.setPreferredSize(new Dimension(450, 200));
this.m_Editor.setMinimumSize(new Dimension(450, 200)); this.editor.setMinimumSize(new Dimension(450, 200));
// init the editors // init the editors
InterfaceCrossover[] list = this.m_CrossoversWithWeights.getSelectedCrossers(); InterfaceCrossover[] list = this.crossoverMixer.getSelectedCrossers();
this.m_Editors = new GeneralOptimizationEditorProperty[list.length]; this.editors = new GeneralOptimizationEditorProperty[list.length];
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
this.m_Editors[i] = new GeneralOptimizationEditorProperty(); this.editors[i] = new GeneralOptimizationEditorProperty();
this.m_Editors[i].name = list[i].getStringRepresentation(); this.editors[i].name = list[i].getStringRepresentation();
try { try {
this.m_Editors[i].value = list[i]; this.editors[i].value = list[i];
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(this.m_Editors[i].value.getClass()); this.editors[i].editor = PropertyEditorProvider.findEditor(this.editors[i].value.getClass());
if (this.m_Editors[i].editor == null) { if (this.editors[i].editor == null) {
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(InterfaceCrossover.class); this.editors[i].editor = PropertyEditorProvider.findEditor(InterfaceCrossover.class);
} }
if (this.m_Editors[i].editor instanceof GenericObjectEditor) { if (this.editors[i].editor instanceof GenericObjectEditor) {
((GenericObjectEditor) this.m_Editors[i].editor).setClassType(InterfaceCrossover.class); ((GenericObjectEditor) this.editors[i].editor).setClassType(InterfaceCrossover.class);
} }
this.m_Editors[i].editor.setValue(this.m_Editors[i].value); this.editors[i].editor.setValue(this.editors[i].value);
this.m_Editors[i].editor.addPropertyChangeListener(this); this.editors[i].editor.addPropertyChangeListener(this);
AbstractObjectEditor.findViewFor(this.m_Editors[i]); AbstractObjectEditor.findViewFor(this.editors[i]);
if (this.m_Editors[i].view != null) { if (this.editors[i].view != null) {
this.m_Editors[i].view.repaint(); this.editors[i].view.repaint();
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
} }
this.m_TargetList = new JPanel(); this.targetList = new JPanel();
this.updateTargetList(); this.updateTargetList();
this.m_ScrollTargets = new JScrollPane(this.m_TargetList); this.scrollTargets = new JScrollPane(this.targetList);
this.m_Editor.setLayout(new BorderLayout()); this.editor.setLayout(new BorderLayout());
this.m_Editor.add(this.m_ScrollTargets, BorderLayout.CENTER); this.editor.add(this.scrollTargets, BorderLayout.CENTER);
// The Button Panel // The Button Panel
JPanel buttonPanel = new JPanel(); JPanel buttonPanel = new JPanel();
@ -111,7 +107,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
buttonPanel.add(normButton); buttonPanel.add(normButton);
buttonPanel.add(addButton); buttonPanel.add(addButton);
this.m_Editor.add(buttonPanel, BorderLayout.SOUTH); this.editor.add(buttonPanel, BorderLayout.SOUTH);
// Some description would be nice // Some description would be nice
JTextArea jt = new JTextArea(); JTextArea jt = new JTextArea();
@ -119,7 +115,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
jt.setEditable(false); jt.setEditable(false);
jt.setLineWrap(true); jt.setLineWrap(true);
jt.setWrapStyleWord(true); jt.setWrapStyleWord(true);
jt.setText(this.m_CrossoversWithWeights.getDescriptiveString()); jt.setText(this.crossoverMixer.getDescriptiveString());
jt.setBackground(getBackground()); jt.setBackground(getBackground());
JPanel jp = new JPanel(); JPanel jp = new JPanel();
jp.setBorder(BorderFactory.createCompoundBorder( jp.setBorder(BorderFactory.createCompoundBorder(
@ -136,7 +132,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
jp.add(p2, BorderLayout.EAST); jp.add(p2, BorderLayout.EAST);
GridBagConstraints gbConstraints = new GridBagConstraints(); GridBagConstraints gbConstraints = new GridBagConstraints();
this.m_Editor.add(jp, BorderLayout.NORTH); this.editor.add(jp, BorderLayout.NORTH);
this.updateEditor(); this.updateEditor();
} }
@ -147,15 +143,15 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
private void updateTargetList() { private void updateTargetList() {
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes; byte[] bytes;
InterfaceCrossover[] list = this.m_CrossoversWithWeights.getSelectedCrossers(); InterfaceCrossover[] list = this.crossoverMixer.getSelectedCrossers();
double[] weights = this.m_CrossoversWithWeights.getWeights(); double[] weights = this.crossoverMixer.getWeights();
this.m_TargetList.removeAll(); this.targetList.removeAll();
this.m_TargetList.setLayout(new GridBagLayout()); this.targetList.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
this.m_Weights = new JTextField[list.length]; this.weights = new JTextField[list.length];
this.m_Targets = new JComponent[list.length]; this.targets = new JComponent[list.length];
this.m_Delete = new JButton[list.length]; this.deleteButtons = new JButton[list.length];
String[] cups = new String[8]; String[] cups = new String[8];
for (int i = 0; i < cups.length; i++) { for (int i = 0; i < cups.length; i++) {
cups[i] = "" + (i + 1); cups[i] = "" + (i + 1);
@ -165,52 +161,52 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 2; gbc.weightx = 2;
this.m_TargetList.add(new JLabel(this.m_CrossoversWithWeights.getWeigthsLabel()), gbc); this.targetList.add(new JLabel(this.crossoverMixer.getWeigthsLabel()), gbc);
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 10; gbc.weightx = 10;
this.m_TargetList.add(new JLabel("Target"), gbc); this.targetList.add(new JLabel("Target"), gbc);
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
this.m_TargetList.add(new JLabel("Remove"), gbc); this.targetList.add(new JLabel("Remove"), gbc);
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
// the weight // the weight
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0; gbc.gridx = 0;
gbc.weightx = 2; gbc.weightx = 2;
this.m_Weights[i] = new JTextField("" + weights[i]); this.weights[i] = new JTextField("" + weights[i]);
this.m_Weights[i].addKeyListener(this.readDoubleArrayAction); this.weights[i].addKeyListener(this.readDoubleArrayAction);
this.m_TargetList.add(this.m_Weights[i], gbc); this.targetList.add(this.weights[i], gbc);
// the status indicator // the status indicator
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 10; gbc.weightx = 10;
this.m_Targets[i] = this.m_Editors[i].view; this.targets[i] = this.editors[i].view;
this.m_TargetList.add(this.m_Targets[i], gbc); this.targetList.add(this.targets[i], gbc);
// The delete button // The delete button
gbc.anchor = GridBagConstraints.WEST; gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("images/Sub24.gif", true); bytes = loader.getBytesFromResourceLocation("images/Sub24.gif", true);
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.deleteButtons[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
this.m_Delete[i].addActionListener(deleteTarget); this.deleteButtons[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.targetList.add(this.deleteButtons[i], gbc);
} }
this.m_TargetList.repaint(); this.targetList.repaint();
this.m_TargetList.validate(); this.targetList.validate();
if (this.m_ScrollTargets != null) { if (this.scrollTargets != null) {
this.m_ScrollTargets.validate(); this.scrollTargets.validate();
this.m_ScrollTargets.repaint(); this.scrollTargets.repaint();
} }
if (this.m_Editor != null) { if (this.editor != null) {
this.m_Editor.validate(); this.editor.validate();
this.m_Editor.repaint(); this.editor.repaint();
} }
} }
@ -230,13 +226,13 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
ActionListener addTarget = new ActionListener() { ActionListener addTarget = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_CrossoversWithWeights.addCrossers((InterfaceCrossover) m_CrossoversWithWeights.getAvailableCrossers()[0].clone()); crossoverMixer.addCrossers((InterfaceCrossover) crossoverMixer.getAvailableCrossers()[0].clone());
int l = m_CrossoversWithWeights.getSelectedCrossers().length; int l = crossoverMixer.getSelectedCrossers().length;
GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l]; GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l];
for (int i = 0; i < m_Editors.length; i++) { for (int i = 0; i < editors.length; i++) {
newEdit[i] = m_Editors[i]; newEdit[i] = editors[i];
} }
InterfaceCrossover[] list = m_CrossoversWithWeights.getSelectedCrossers(); InterfaceCrossover[] list = crossoverMixer.getSelectedCrossers();
l--; l--;
newEdit[l] = new GeneralOptimizationEditorProperty(); newEdit[l] = new GeneralOptimizationEditorProperty();
newEdit[l].name = list[l].getStringRepresentation(); newEdit[l].name = list[l].getStringRepresentation();
@ -250,7 +246,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
((GenericObjectEditor) newEdit[l].editor).setClassType(InterfaceCrossover.class); ((GenericObjectEditor) newEdit[l].editor).setClassType(InterfaceCrossover.class);
} }
newEdit[l].editor.setValue(newEdit[l].value); newEdit[l].editor.setValue(newEdit[l].value);
newEdit[l].editor.addPropertyChangeListener(m_self); newEdit[l].editor.addPropertyChangeListener(self);
AbstractObjectEditor.findViewFor(newEdit[l]); AbstractObjectEditor.findViewFor(newEdit[l]);
if (newEdit[l].view != null) { if (newEdit[l].view != null) {
newEdit[l].view.repaint(); newEdit[l].view.repaint();
@ -258,7 +254,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
m_Editors = newEdit; editors = newEdit;
updateTargetList(); updateTargetList();
} }
}; };
@ -269,17 +265,17 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
ActionListener deleteTarget = new ActionListener() { ActionListener deleteTarget = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
int l = m_CrossoversWithWeights.getSelectedCrossers().length, j = 0; int l = crossoverMixer.getSelectedCrossers().length, j = 0;
GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l - 1]; GeneralOptimizationEditorProperty[] newEdit = new GeneralOptimizationEditorProperty[l - 1];
for (int i = 0; i < m_Delete.length; i++) { for (int i = 0; i < deleteButtons.length; i++) {
if (event.getSource().equals(m_Delete[i])) { if (event.getSource().equals(deleteButtons[i])) {
m_CrossoversWithWeights.removeCrosser(i); crossoverMixer.removeCrosser(i);
} else { } else {
newEdit[j] = m_Editors[i]; newEdit[j] = editors[i];
j++; j++;
} }
} }
m_Editors = newEdit; editors = newEdit;
updateTargetList(); updateTargetList();
} }
}; };
@ -290,7 +286,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
ActionListener normalizeWeights = new ActionListener() { ActionListener normalizeWeights = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_CrossoversWithWeights.normalizeWeights(); crossoverMixer.normalizeWeights();
updateTargetList(); updateTargetList();
} }
}; };
@ -309,18 +305,18 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
@Override @Override
public void keyReleased(KeyEvent event) { public void keyReleased(KeyEvent event) {
double[] newW = m_CrossoversWithWeights.getWeights(); double[] newW = crossoverMixer.getWeights();
for (int i = 0; i < newW.length; i++) { for (int i = 0; i < newW.length; i++) {
try { try {
double d = 0; double d = 0;
d = new Double(m_Weights[i].getText()).doubleValue(); d = new Double(weights[i].getText()).doubleValue();
newW[i] = d; newW[i] = d;
} catch (Exception e) { } catch (Exception e) {
} }
} }
m_CrossoversWithWeights.setWeights(newW); crossoverMixer.setWeights(newW);
} }
}; };
@ -328,13 +324,13 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
* The object may have changed update the editor. * The object may have changed update the editor.
*/ */
private void updateEditor() { private void updateEditor() {
if (this.m_Editor != null) { if (this.editor != null) {
this.m_TargetList.validate(); this.targetList.validate();
this.m_TargetList.repaint(); this.targetList.repaint();
this.m_ScrollTargets.validate(); this.scrollTargets.validate();
this.m_ScrollTargets.repaint(); this.scrollTargets.repaint();
this.m_Editor.validate(); this.editor.validate();
this.m_Editor.repaint(); this.editor.repaint();
} }
} }
@ -346,7 +342,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
@Override @Override
public void setValue(Object o) { public void setValue(Object o) {
if (o instanceof PropertyCrossoverMixer) { if (o instanceof PropertyCrossoverMixer) {
this.m_CrossoversWithWeights = (PropertyCrossoverMixer) o; this.crossoverMixer = (PropertyCrossoverMixer) o;
this.updateEditor(); this.updateEditor();
} }
} }
@ -358,7 +354,7 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
*/ */
@Override @Override
public Object getValue() { public Object getValue() {
return this.m_CrossoversWithWeights; return this.crossoverMixer;
} }
@Override @Override
@ -396,7 +392,6 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
* @param a The action listener. * @param a The action listener.
*/ */
public void addOkListener(ActionListener a) { public void addOkListener(ActionListener a) {
//m_OKButton.addActionListener(a);
} }
/** /**
@ -405,7 +400,6 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
* @param a The action listener * @param a The action listener
*/ */
public void removeOkListener(ActionListener a) { public void removeOkListener(ActionListener a) {
//m_OKButton.removeActionListener(a);
} }
/** /**
@ -449,11 +443,11 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
*/ */
@Override @Override
public Component getCustomEditor() { public Component getCustomEditor() {
if (this.m_Component == null) { if (this.component == null) {
this.initCustomEditor(); this.initCustomEditor();
this.m_Component = new GeneralGEOFaker((PropertyEditor) this, (JPanel) this.m_Editor); this.component = new GeneralGEOFaker((PropertyEditor) this, (JPanel) this.editor);
} }
return this.m_Component; return this.component;
} }
/** /**
@ -471,18 +465,18 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
@Override @Override
public void addPropertyChangeListener(PropertyChangeListener l) { public void addPropertyChangeListener(PropertyChangeListener l) {
if (m_Support == null) { if (propertyChangeSupport == null) {
m_Support = new PropertyChangeSupport(this); propertyChangeSupport = new PropertyChangeSupport(this);
} }
m_Support.addPropertyChangeListener(l); propertyChangeSupport.addPropertyChangeListener(l);
} }
@Override @Override
public void removePropertyChangeListener(PropertyChangeListener l) { public void removePropertyChangeListener(PropertyChangeListener l) {
if (m_Support == null) { if (propertyChangeSupport == null) {
m_Support = new PropertyChangeSupport(this); propertyChangeSupport = new PropertyChangeSupport(this);
} }
m_Support.removePropertyChangeListener(l); propertyChangeSupport.removePropertyChangeListener(l);
} }
/** /**
@ -495,35 +489,34 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
Object newVal = evt.getNewValue(); Object newVal = evt.getNewValue();
Object oldVal = evt.getOldValue(); Object oldVal = evt.getOldValue();
InterfaceCrossover[] list = this.m_CrossoversWithWeights.getSelectedCrossers(); InterfaceCrossover[] list = this.crossoverMixer.getSelectedCrossers();
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (oldVal.equals(list[i])) { if (oldVal.equals(list[i])) {
list[i] = (InterfaceCrossover) newVal; list[i] = (InterfaceCrossover) newVal;
this.m_Editors[i].name = list[i].getStringRepresentation(); this.editors[i].name = list[i].getStringRepresentation();
try { try {
this.m_Editors[i].value = list[i]; this.editors[i].value = list[i];
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(this.m_Editors[i].value.getClass()); this.editors[i].editor = PropertyEditorProvider.findEditor(this.editors[i].value.getClass());
if (this.m_Editors[i].editor == null) { if (this.editors[i].editor == null) {
this.m_Editors[i].editor = PropertyEditorProvider.findEditor(InterfaceCrossover.class); this.editors[i].editor = PropertyEditorProvider.findEditor(InterfaceCrossover.class);
} }
if (this.m_Editors[i].editor instanceof GenericObjectEditor) { if (this.editors[i].editor instanceof GenericObjectEditor) {
((GenericObjectEditor) this.m_Editors[i].editor).setClassType(InterfaceCrossover.class); ((GenericObjectEditor) this.editors[i].editor).setClassType(InterfaceCrossover.class);
} }
this.m_Editors[i].editor.setValue(this.m_Editors[i].value); this.editors[i].editor.setValue(this.editors[i].value);
this.m_Editors[i].editor.addPropertyChangeListener(this); this.editors[i].editor.addPropertyChangeListener(this);
AbstractObjectEditor.findViewFor(this.m_Editors[i]); AbstractObjectEditor.findViewFor(this.editors[i]);
if (this.m_Editors[i].view != null) { if (this.editors[i].view != null) {
this.m_Editors[i].view.repaint(); this.editors[i].view.repaint();
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Darn can't read the value..."); System.out.println("Darn can't read the value...");
} }
this.m_Targets[i] = this.m_Editors[i].view; this.targets[i] = this.editors[i].view;
i = list.length; i = list.length;
} }
} }
//this.m_OptimizationTargets.setSelectedTargets(list);
this.updateCenterComponent(evt); // Let our panel update before guys downstream this.updateCenterComponent(evt); // Let our panel update before guys downstream
m_Support.firePropertyChange("", m_CrossoversWithWeights, m_CrossoversWithWeights); propertyChangeSupport.firePropertyChange("", crossoverMixer, crossoverMixer);
} }
} }

View File

@ -25,108 +25,107 @@ import java.awt.event.WindowEvent;
* To change this template use Options | File Templates. * To change this template use Options | File Templates.
*/ */
public class TestESCrossover implements java.io.Serializable { public class TestESCrossover implements java.io.Serializable {
private JFrame m_Frame; private JFrame frame;
private JPanel m_MainPanel, m_GraphPanel, m_ButtonPanel; private JPanel mainPanel, buttonPanel;
private JComponent m_OptionsPanel; private JComponent optionsPanel;
private JButton m_InitButton, m_Init2Button, m_Init3Button, m_CrossButton; private JButton initButton, init2Button, init3Button, crossButton;
private InterfaceOptimizationProblem m_Problem = new F1Problem(); private InterfaceOptimizationProblem optimizationProblem = new F1Problem();
private InterfaceCrossover m_Crossover = new CrossoverESUNDX(); private InterfaceCrossover crossover = new CrossoverESUNDX();
private Population m_Partners; private Population partners;
private AbstractEAIndividual m_Daddy; private AbstractEAIndividual daddy;
private AbstractEAIndividual[] m_OffSprings;
private int m_NumberOfCrossovers = 100; private int numberOfCrossovers = 100;
private int m_Dimension = 2; private int dimension = 2;
private int m_NumberOfPartners = 1; private int numberOfPartners = 1;
double[] pff; double[] pff;
private Plot m_Plot; private Plot plot;
private void initFrame() { private void initFrame() {
// init the main frame // init the main frame
this.m_Frame = new JFrame(); this.frame = new JFrame();
this.m_Frame.setTitle("ES Crossover Tester"); this.frame.setTitle("ES Crossover Tester");
this.m_Frame.setSize(300, 400); this.frame.setSize(300, 400);
this.m_Frame.setLocation(530, 50); this.frame.setLocation(530, 50);
this.m_Frame.addWindowListener(new WindowAdapter() { this.frame.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent ev) { public void windowClosing(WindowEvent ev) {
System.exit(0); System.exit(0);
} }
}); });
// build the main panel // build the main panel
this.m_MainPanel = new JPanel(); this.mainPanel = new JPanel();
this.m_Frame.getContentPane().add(this.m_MainPanel); this.frame.getContentPane().add(this.mainPanel);
this.m_MainPanel.setLayout(new BorderLayout()); this.mainPanel.setLayout(new BorderLayout());
// build the button panel // build the button panel
this.m_ButtonPanel = new JPanel(); this.buttonPanel = new JPanel();
this.m_InitButton = new JButton("Init"); this.initButton = new JButton("Init");
this.m_InitButton.addActionListener(this.initListener); this.initButton.addActionListener(this.initListener);
this.m_InitButton.setEnabled(true); this.initButton.setEnabled(true);
this.m_Init2Button = new JButton("Init 2"); this.init2Button = new JButton("Init 2");
this.m_Init2Button.addActionListener(this.init2Listener); this.init2Button.addActionListener(this.init2Listener);
this.m_Init2Button.setEnabled(true); this.init2Button.setEnabled(true);
this.m_Init3Button = new JButton("Init 3"); this.init3Button = new JButton("Init 3");
this.m_Init3Button.addActionListener(this.init3Listener); this.init3Button.addActionListener(this.init3Listener);
this.m_Init3Button.setEnabled(true); this.init3Button.setEnabled(true);
this.m_CrossButton = new JButton("X"); this.crossButton = new JButton("X");
this.m_CrossButton.addActionListener(this.XListener); this.crossButton.addActionListener(this.XListener);
this.m_CrossButton.setEnabled(true); this.crossButton.setEnabled(true);
this.m_ButtonPanel.add(this.m_InitButton); this.buttonPanel.add(this.initButton);
this.m_ButtonPanel.add(this.m_Init2Button); this.buttonPanel.add(this.init2Button);
this.m_ButtonPanel.add(this.m_Init3Button); this.buttonPanel.add(this.init3Button);
this.m_ButtonPanel.add(this.m_CrossButton); this.buttonPanel.add(this.crossButton);
this.m_MainPanel.add(this.m_ButtonPanel, BorderLayout.NORTH); this.mainPanel.add(this.buttonPanel, BorderLayout.NORTH);
// build the Options Panel // build the Options Panel
this.m_OptionsPanel = (new JParaPanel(this, "MyGUI").makePanel()); this.optionsPanel = (new JParaPanel(this, "MyGUI").makePanel());
this.m_MainPanel.add(this.m_OptionsPanel, BorderLayout.CENTER); this.mainPanel.add(this.optionsPanel, BorderLayout.CENTER);
// The plot frame // The plot frame
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0; tmpD[0] = 0;
tmpD[1] = 0; tmpD[1] = 0;
// ToDo: Fix plot (it's internal and not showing) // ToDo: Fix plot (it's internal and not showing)
this.m_Plot = new Plot("ES Crossover Tester", "x", "y", tmpD, tmpD); this.plot = new Plot("ES Crossover Tester", "x", "y", tmpD, tmpD);
// validate and show // validate and show
this.m_Frame.validate(); this.frame.validate();
this.m_Frame.setVisible(true); this.frame.setVisible(true);
} }
ActionListener initListener = new ActionListener() { ActionListener initListener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_Partners = new Population(); partners = new Population();
m_Partners.setTargetSize(m_NumberOfPartners); partners.setTargetSize(numberOfPartners);
m_Partners.clear(); partners.clear();
InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData(); InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData();
AbstractEAIndividual tmpIndyEA; AbstractEAIndividual tmpIndyEA;
double[][] newRange = new double[m_Dimension][2]; double[][] newRange = new double[dimension][2];
for (int i = 0; i < m_Dimension; i++) { for (int i = 0; i < dimension; i++) {
newRange[i][0] = -2; newRange[i][0] = -2;
newRange[i][1] = 2; newRange[i][1] = 2;
} }
tmpIndyD.setDoubleDataLength(m_Dimension); tmpIndyD.setDoubleDataLength(dimension);
tmpIndyD.setDoubleRange(newRange); tmpIndyD.setDoubleRange(newRange);
for (int i = 0; i < m_Partners.getTargetSize(); i++) { for (int i = 0; i < partners.getTargetSize(); i++) {
tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
tmpIndyEA.init(m_Problem); tmpIndyEA.init(optimizationProblem);
m_Partners.add(tmpIndyEA); partners.add(tmpIndyEA);
} }
m_Partners.init(); partners.init();
m_Daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
m_Daddy.init(m_Problem); daddy.init(optimizationProblem);
m_Plot.clearAll(); plot.clearAll();
m_Plot.setUnconnectedPoint(-2, -2, 0); plot.setUnconnectedPoint(-2, -2, 0);
m_Plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
double[] x; double[] x;
x = ((InterfaceDataTypeDouble) m_Daddy).getDoubleData(); x = ((InterfaceDataTypeDouble) daddy).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
for (int i = 0; i < m_Partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
x = ((InterfaceDataTypeDouble) m_Partners.get(i)).getDoubleData(); x = ((InterfaceDataTypeDouble) partners.get(i)).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
pff = x; pff = x;
} }
} }
@ -135,42 +134,42 @@ public class TestESCrossover implements java.io.Serializable {
ActionListener init2Listener = new ActionListener() { ActionListener init2Listener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_Partners = new Population(); partners = new Population();
m_Partners.setTargetSize(2); partners.setTargetSize(2);
m_Partners.clear(); partners.clear();
InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData(); InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData();
AbstractEAIndividual tmpIndyEA; AbstractEAIndividual tmpIndyEA;
double[][] newRange = new double[m_Dimension][2]; double[][] newRange = new double[dimension][2];
for (int i = 0; i < m_Dimension; i++) { for (int i = 0; i < dimension; i++) {
newRange[i][0] = -2; newRange[i][0] = -2;
newRange[i][1] = 2; newRange[i][1] = 2;
} }
tmpIndyD.setDoubleDataLength(m_Dimension); tmpIndyD.setDoubleDataLength(dimension);
tmpIndyD.setDoubleRange(newRange); tmpIndyD.setDoubleRange(newRange);
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 1; tmpD[0] = 1;
tmpD[1] = 1; tmpD[1] = 1;
((AbstractEAIndividual) tmpIndyD).initByValue(tmpD, m_Problem); ((AbstractEAIndividual) tmpIndyD).initByValue(tmpD, optimizationProblem);
tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
tmpD = new double[2]; tmpD = new double[2];
tmpD[0] = -1; tmpD[0] = -1;
tmpD[1] = -1; tmpD[1] = -1;
((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, m_Problem); ((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, optimizationProblem);
m_Partners.addIndividual(tmpIndyEA); partners.addIndividual(tmpIndyEA);
m_Daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
m_Plot.clearAll(); plot.clearAll();
m_Plot.setUnconnectedPoint(-2, -2, 0); plot.setUnconnectedPoint(-2, -2, 0);
m_Plot.setUnconnectedPoint(2, 2, 0); plot.setUnconnectedPoint(2, 2, 0);
double[] x; double[] x;
x = ((InterfaceDataTypeDouble) m_Daddy).getDoubleData(); x = ((InterfaceDataTypeDouble) daddy).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
for (int i = 0; i < m_Partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
x = ((InterfaceDataTypeDouble) m_Partners.get(i)).getDoubleData(); x = ((InterfaceDataTypeDouble) partners.get(i)).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
pff = x; pff = x;
} }
} }
@ -179,48 +178,48 @@ public class TestESCrossover implements java.io.Serializable {
ActionListener init3Listener = new ActionListener() { ActionListener init3Listener = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
m_Partners = new Population(); partners = new Population();
m_Partners.setTargetSize(3); partners.setTargetSize(3);
m_Partners.clear(); partners.clear();
InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData(); InterfaceDataTypeDouble tmpIndyD = new ESIndividualDoubleData();
AbstractEAIndividual tmpIndyEA; AbstractEAIndividual tmpIndyEA;
double[][] newRange = new double[m_Dimension][2]; double[][] newRange = new double[dimension][2];
for (int i = 0; i < m_Dimension; i++) { for (int i = 0; i < dimension; i++) {
newRange[i][0] = -2; newRange[i][0] = -2;
newRange[i][1] = 2; newRange[i][1] = 2;
} }
tmpIndyD.setDoubleDataLength(m_Dimension); tmpIndyD.setDoubleDataLength(dimension);
tmpIndyD.setDoubleRange(newRange); tmpIndyD.setDoubleRange(newRange);
double[] tmpD = new double[2]; double[] tmpD = new double[2];
tmpD[0] = 0.5; tmpD[0] = 0.5;
tmpD[1] = 1.1; tmpD[1] = 1.1;
((AbstractEAIndividual) tmpIndyD).initByValue(tmpD, m_Problem); ((AbstractEAIndividual) tmpIndyD).initByValue(tmpD, optimizationProblem);
tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
tmpD = new double[2]; tmpD = new double[2];
tmpD[0] = 0.1; tmpD[0] = 0.1;
tmpD[1] = -0.65; tmpD[1] = -0.65;
((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, m_Problem); ((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, optimizationProblem);
m_Partners.addIndividual(tmpIndyEA); partners.addIndividual(tmpIndyEA);
tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); tmpIndyEA = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
tmpD = new double[2]; tmpD = new double[2];
tmpD[0] = -0.85; tmpD[0] = -0.85;
tmpD[1] = 0.3; tmpD[1] = 0.3;
((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, m_Problem); ((AbstractEAIndividual) tmpIndyEA).initByValue(tmpD, optimizationProblem);
m_Partners.addIndividual(tmpIndyEA); partners.addIndividual(tmpIndyEA);
m_Daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone(); daddy = (AbstractEAIndividual) ((AbstractEAIndividual) tmpIndyD).clone();
m_Plot.clearAll(); plot.clearAll();
m_Plot.setUnconnectedPoint(-2, -2, 2); plot.setUnconnectedPoint(-2, -2, 2);
m_Plot.setUnconnectedPoint(2, 2, 2); plot.setUnconnectedPoint(2, 2, 2);
double[] x; double[] x;
x = ((InterfaceDataTypeDouble) m_Daddy).getDoubleData(); x = ((InterfaceDataTypeDouble) daddy).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
for (int i = 0; i < m_Partners.size(); i++) { for (int i = 0; i < partners.size(); i++) {
x = ((InterfaceDataTypeDouble) m_Partners.get(i)).getDoubleData(); x = ((InterfaceDataTypeDouble) partners.get(i)).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 1); plot.setUnconnectedPoint(x[0], x[1], 1);
m_Plot.setUnconnectedPoint(x[0], x[1], 1); plot.setUnconnectedPoint(x[0], x[1], 1);
pff = x; pff = x;
} }
} }
@ -231,13 +230,13 @@ public class TestESCrossover implements java.io.Serializable {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
double[] x; double[] x;
AbstractEAIndividual[] result; AbstractEAIndividual[] result;
for (int i = 0; i < m_NumberOfCrossovers; i++) { for (int i = 0; i < numberOfCrossovers; i++) {
result = m_Crossover.mate(m_Daddy, m_Partners); result = crossover.mate(daddy, partners);
for (int j = 0; j < result.length; j++) { for (int j = 0; j < result.length; j++) {
x = ((InterfaceDataTypeDouble) result[j]).getDoubleData(); x = ((InterfaceDataTypeDouble) result[j]).getDoubleData();
m_Plot.setUnconnectedPoint(x[0], x[1], 0); plot.setUnconnectedPoint(x[0], x[1], 0);
m_Plot.setUnconnectedPoint(pff[0], pff[1], 1); plot.setUnconnectedPoint(pff[0], pff[1], 1);
m_Plot.setUnconnectedPoint(2, 2, 2); plot.setUnconnectedPoint(2, 2, 2);
} }
} }
} }
@ -255,11 +254,11 @@ public class TestESCrossover implements java.io.Serializable {
} }
public void setCrossover(InterfaceCrossover NumberOfCrossovers) { public void setCrossover(InterfaceCrossover NumberOfCrossovers) {
this.m_Crossover = NumberOfCrossovers; this.crossover = NumberOfCrossovers;
} }
public InterfaceCrossover getCrossover() { public InterfaceCrossover getCrossover() {
return this.m_Crossover; return this.crossover;
} }
public String crossoverTipText() { public String crossoverTipText() {
@ -267,11 +266,11 @@ public class TestESCrossover implements java.io.Serializable {
} }
public void setNumberOfCrossovers(int NumberOfCrossovers) { public void setNumberOfCrossovers(int NumberOfCrossovers) {
this.m_NumberOfCrossovers = NumberOfCrossovers; this.numberOfCrossovers = NumberOfCrossovers;
} }
public int getNumberOfCrossovers() { public int getNumberOfCrossovers() {
return this.m_NumberOfCrossovers; return this.numberOfCrossovers;
} }
public String numberOfCrossoversTipText() { public String numberOfCrossoversTipText() {
@ -279,11 +278,11 @@ public class TestESCrossover implements java.io.Serializable {
} }
public void setNumberOfPartners(int NumberOfCrossovers) { public void setNumberOfPartners(int NumberOfCrossovers) {
this.m_NumberOfPartners = NumberOfCrossovers; this.numberOfPartners = NumberOfCrossovers;
} }
public int getNumberOfPartners() { public int getNumberOfPartners() {
return this.m_NumberOfPartners; return this.numberOfPartners;
} }
public String numberOfPartnersTipText() { public String numberOfPartnersTipText() {

View File

@ -8,15 +8,10 @@ import eva2.optimization.population.Population;
/** /**
* The fitness modifier are defunct and are to be moved to * The fitness modifier are defunct and are to be moved to
* the selection operators... * the selection operators...
* Created by IntelliJ IDEA.
* User: streiche
* Date: 30.03.2004
* Time: 17:51:45
* To change this template use File | Settings | File Templates.
*/ */
public class FitnessAdaptiveClustering implements java.io.Serializable, InterfaceFitnessModifier { public class FitnessAdaptiveClustering implements java.io.Serializable, InterfaceFitnessModifier {
private InterfaceClustering m_ClusteringAlgorithm = new ClusteringDensityBased(); private InterfaceClustering clusteringAlgorithm = new ClusteringDensityBased();
/** /**
* This method allows you to modify the fitness of the individuals * This method allows you to modify the fitness of the individuals
@ -49,9 +44,9 @@ public class FitnessAdaptiveClustering implements java.io.Serializable, Interfac
// also note that if all individual achieve equal fitness the sum will be zero // also note that if all individual achieve equal fitness the sum will be zero
result[i] = data[i][x] - min + 0.1; result[i] = data[i][x] - min + 0.1;
} }
this.m_ClusteringAlgorithm.initClustering(population); this.clusteringAlgorithm.initClustering(population);
// Now search for clusters // Now search for clusters
Population[] ClusterResult = this.m_ClusteringAlgorithm.cluster(population, population); Population[] ClusterResult = this.clusteringAlgorithm.cluster(population, population);
Population cluster; Population cluster;
for (int i = 1; i < ClusterResult.length; i++) { for (int i = 1; i < ClusterResult.length; i++) {
cluster = ClusterResult[i]; cluster = ClusterResult[i];
@ -85,11 +80,11 @@ public class FitnessAdaptiveClustering implements java.io.Serializable, Interfac
* @return The current clustering method * @return The current clustering method
*/ */
public InterfaceClustering getClusteringAlgorithm() { public InterfaceClustering getClusteringAlgorithm() {
return this.m_ClusteringAlgorithm; return this.clusteringAlgorithm;
} }
public void setClusteringAlgorithm(InterfaceClustering b) { public void setClusteringAlgorithm(InterfaceClustering b) {
this.m_ClusteringAlgorithm = b; this.clusteringAlgorithm = b;
} }
public String clusteringAlgorithmTipText() { public String clusteringAlgorithmTipText() {

View File

@ -8,16 +8,11 @@ import eva2.optimization.population.Population;
/** /**
* The fitness modifier are defunct and are to be moved to * The fitness modifier are defunct and are to be moved to
* the selection operators... * the selection operators...
* Created by IntelliJ IDEA.
* User: streiche
* Date: 30.03.2004
* Time: 17:46:22
* To change this template use File | Settings | File Templates.
*/ */
public class FitnessSharing implements java.io.Serializable, InterfaceFitnessModifier { public class FitnessSharing implements java.io.Serializable, InterfaceFitnessModifier {
private double m_SharingDistance = 0.05; private double sharingDistance = 0.05;
private InterfaceDistanceMetric m_Metric = new PhenotypeMetric(); private InterfaceDistanceMetric distanceMetric = new PhenotypeMetric();
/** /**
* This method allows you to modify the fitness of the individuals * This method allows you to modify the fitness of the individuals
@ -56,8 +51,8 @@ public class FitnessSharing implements java.io.Serializable, InterfaceFitnessMod
tmpIndy = (AbstractEAIndividual) population.get(i); tmpIndy = (AbstractEAIndividual) population.get(i);
fitnessSharing = 0; fitnessSharing = 0;
for (int j = 0; j < population.size(); j++) { for (int j = 0; j < population.size(); j++) {
if (this.m_SharingDistance < this.m_Metric.distance(tmpIndy, (AbstractEAIndividual) population.get(j))) { if (this.sharingDistance < this.distanceMetric.distance(tmpIndy, (AbstractEAIndividual) population.get(j))) {
fitnessSharing += 1 - (this.m_Metric.distance(tmpIndy, (AbstractEAIndividual) population.get(j)) / this.m_SharingDistance); fitnessSharing += 1 - (this.distanceMetric.distance(tmpIndy, (AbstractEAIndividual) population.get(j)) / this.sharingDistance);
} }
} }
result[i] /= fitnessSharing; result[i] /= fitnessSharing;
@ -87,11 +82,11 @@ public class FitnessSharing implements java.io.Serializable, InterfaceFitnessMod
* @param SharingDistance * @param SharingDistance
*/ */
public void setSharingDistance(double SharingDistance) { public void setSharingDistance(double SharingDistance) {
this.m_SharingDistance = SharingDistance; this.sharingDistance = SharingDistance;
} }
public double getSharingDistance() { public double getSharingDistance() {
return this.m_SharingDistance; return this.sharingDistance;
} }
public String sharingDistanceTipText() { public String sharingDistanceTipText() {
@ -104,11 +99,11 @@ public class FitnessSharing implements java.io.Serializable, InterfaceFitnessMod
* @param Metric * @param Metric
*/ */
public void setMetric(InterfaceDistanceMetric Metric) { public void setMetric(InterfaceDistanceMetric Metric) {
this.m_Metric = Metric; this.distanceMetric = Metric;
} }
public InterfaceDistanceMetric getMetric() { public InterfaceDistanceMetric getMetric() {
return this.m_Metric; return this.distanceMetric;
} }
public String metricTipText() { public String metricTipText() {