Minor addition to GI individual
This commit is contained in:
parent
d27b78092b
commit
5b10b4b6ed
@ -21,7 +21,7 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
protected int[] m_Genotype;
|
||||
|
||||
public GIIndividualIntegerData() {
|
||||
this.m_MutationProbability = 0.1;
|
||||
this.m_MutationProbability = 0.2;
|
||||
this.m_MutationOperator = new MutateDefault();
|
||||
this.m_CrossoverProbability = 0.7;
|
||||
this.m_CrossoverOperator = new CrossoverGIDefault();
|
||||
@ -276,7 +276,20 @@ public class GIIndividualIntegerData extends AbstractEAIndividual implements Int
|
||||
|
||||
public void defaultInit(InterfaceOptimizationProblem prob) {
|
||||
int[][] range = m_Range;
|
||||
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange)prob).getInitRange()!=null)) range = (int[][])((InterfaceHasInitRange)prob).getInitRange();
|
||||
if ((prob != null) && (prob instanceof InterfaceHasInitRange) && (((InterfaceHasInitRange)prob).getInitRange()!=null)) {
|
||||
Object rng = ((InterfaceHasInitRange)prob).getInitRange();
|
||||
if (rng instanceof double[][]) {
|
||||
double[][] dblRng = (double[][])rng;
|
||||
range = new int[dblRng.length][dblRng[0].length];
|
||||
for (int i=0; i<range.length; i++) {
|
||||
for (int j=0; j<range[0].length ; j++) {
|
||||
range[i][j]=(int)dblRng[i][j];
|
||||
}
|
||||
}
|
||||
} else if (rng instanceof int[][]){
|
||||
range = (int[][])rng;
|
||||
} else System.err.println("Error, invalid initial range provided by " + prob + ", expecting int[][] or double[][], disregarding initialization range");
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.m_Genotype.length; i++) {
|
||||
this.m_Genotype[i] = RNG.randomInt(range[i][0], range[i][1]);
|
||||
|
@ -34,6 +34,10 @@ public class GenotypeMetricBitSet implements InterfaceDistanceMetric, java.io.Se
|
||||
* @return double
|
||||
*/
|
||||
public double distance(AbstractEAIndividual indy1, AbstractEAIndividual indy2) {
|
||||
return GenotypeMetricBitSet.dist(indy1, indy2);
|
||||
}
|
||||
|
||||
public static double dist(AbstractEAIndividual indy1, AbstractEAIndividual indy2) {
|
||||
BitSet dIndy1, dIndy2;
|
||||
double result = 0;
|
||||
int length = 0;
|
||||
|
@ -17,6 +17,7 @@ import eva2.server.go.PopulationInterface;
|
||||
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||
import eva2.server.go.individuals.AbstractEAIndividualComparator;
|
||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
||||
import eva2.server.go.individuals.InterfaceESIndividual;
|
||||
import eva2.server.go.individuals.InterfaceGAIndividual;
|
||||
import eva2.server.go.operators.distancemetric.EuclideanMetric;
|
||||
import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric;
|
||||
@ -1788,19 +1789,27 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
|
||||
double maxDist = Double.MIN_VALUE;
|
||||
double minDist = Double.MAX_VALUE;
|
||||
|
||||
for (int i = 0; i < pop.size(); i++) {
|
||||
for (int j = i+1; j < pop.size(); j++) {
|
||||
try {
|
||||
if (metric == null) d = EuclideanMetric.euclideanDistance(AbstractEAIndividual.getDoublePositionShallow(pop.get(i)),
|
||||
AbstractEAIndividual.getDoublePositionShallow(pop.get(j)));
|
||||
else d = metric.distance((AbstractEAIndividual)pop.get(i), (AbstractEAIndividual)pop.get(j));
|
||||
} catch (Exception e) {
|
||||
EVAERROR.errorMsgOnce("Exception when calculating population measures ... possibly no double position available?");
|
||||
d = 0;
|
||||
}
|
||||
distSum += d;
|
||||
if (d < minDist) minDist = d;
|
||||
if (d > maxDist) maxDist = d;
|
||||
for (int i = 0; i < pop.size(); i++) {
|
||||
for (int j = i+1; j < pop.size(); j++) {
|
||||
try {
|
||||
if (metric == null) {
|
||||
if (pop.get(i) instanceof InterfaceESIndividual) {
|
||||
// short cut if the distance may directly work on the genotype
|
||||
d = EuclideanMetric.euclideanDistance(AbstractEAIndividual.getDoublePositionShallow(pop.get(i)),
|
||||
AbstractEAIndividual.getDoublePositionShallow(pop.get(j)));
|
||||
} else {
|
||||
d = PhenotypeMetric.dist(pop.get(i), pop.get(j));
|
||||
}
|
||||
} else {
|
||||
d = metric.distance((AbstractEAIndividual)pop.get(i), (AbstractEAIndividual)pop.get(j));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
EVAERROR.errorMsgOnce("Exception when calculating population measures ... possibly no double position available?");
|
||||
d = 0;
|
||||
}
|
||||
distSum += d;
|
||||
if (d < minDist) minDist = d;
|
||||
if (d > maxDist) maxDist = d;
|
||||
}
|
||||
}
|
||||
res[1] = minDist;
|
||||
|
Loading…
x
Reference in New Issue
Block a user