Skip to content

Commit

Permalink
fixes an issue with genetic algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed Aug 23, 2021
1 parent 5d08e9c commit 19fd59e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions msi.gama.core/src/msi/gama/kernel/batch/Chromosome.java
Expand Up @@ -23,15 +23,15 @@

public class Chromosome implements Comparable<Chromosome> {

private double[] genes;
private Object[] genes;
private final String[] phenotype;
private double fitness;

public double[] getGenes() {
public Object[] getGenes() {
return genes;
}

public void setGenes(final double[] genes) {
public void setGenes(final Object[] genes) {
this.genes = genes;
}

Expand All @@ -45,7 +45,7 @@ public void setFitness(final double fitness) {

public Chromosome(final Chromosome chromosome) {

genes = new double[chromosome.genes.length];
genes = new Object[chromosome.genes.length];
phenotype = new String[chromosome.phenotype.length];

for (int i = 0; i < genes.length; i++) {
Expand All @@ -65,7 +65,7 @@ public void update(final IScope scope, final ParametersSet solution) {
}

public Chromosome(final IScope scope, final List<IParameter.Batch> variables, final boolean reInitVal) {
genes = new double[variables.size()];
genes = new Object[variables.size()];
phenotype = new String[variables.size()];
int cpt = 0;
for (final IParameter.Batch var : variables) {
Expand Down
2 changes: 1 addition & 1 deletion msi.gama.core/src/msi/gama/kernel/batch/CrossOver1Pt.java
Expand Up @@ -31,7 +31,7 @@ public Set<Chromosome> crossOver(final IScope scope, final Chromosome parent1, f
final Chromosome child1 = new Chromosome(parent1);
final Chromosome child2 = new Chromosome(parent2);
for (int i = 0; i < cutPt; i++) {
final double val1 = child1.getGenes()[i];
final Object val1 = child1.getGenes()[i];
child1.getGenes()[i] = child2.getGenes()[i];
child2.getGenes()[i] = val1;
}
Expand Down

0 comments on commit 19fd59e

Please sign in to comment.