This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

GA_framework : mutation_amp

  • Loading branch information...
arnaudjuracek committed May 2, 2016
1 parent d11062c commit a2ef38c3bb0ded95eaf409375f36fe89fb14c498
@@ -40,13 +40,19 @@ public class Dna{
// -------------------------------------------------------------------------
// DNA MUTATION :
// replace randomly picked genes (based on mutation_rates) with new random ones
// replace randomly picked genes (based on mutation_rate) with new random ones
public void mutate(float mutation_rate){
for(int i=0; i<this.GENES.length; i++){
if(random(1) < mutation_rate) this.GENES[i] = random(0,1);
}
}
// add a random mutation constrained within a mutation amplitute on randomly picked (based on mutation_rate) genes
public void mutate(float mutation_rate, float mutation_amp){
for(int i=0; i<this.GENES.length; i++){
if(random(1) < mutation_rate) this.GENES[i] = constrain(this.GENES[i] + random(-mutation_amp, mutation_amp), 0, 1);
}
}
// -------------------------------------------------------------------------
@@ -1,7 +1,7 @@
public class Population{
public Organism[] ORGANISMS;
public ArrayList<Organism> MATING_POOL;
public float MUTATION_RATE;
public float MUTATION_RATE, MUTATION_AMP;
public int GENERATION;
public ArrayList<Organism[]> PREVIOUS_GENERATIONS;
@@ -11,9 +11,10 @@ public class Population{
// CONSTRUCTOR :
// Create a new population of *num* organisms
// with an assigned mutation_rate
public Population(int num, float mutation_rate){
public Population(int num, float mutation_rate, float mutation_amp){
this.ORGANISMS = new Organism[num];
this.MUTATION_RATE = mutation_rate;
this.MUTATION_AMP = mutation_amp;
this.MATING_POOL = new ArrayList<Organism>();
this.GENERATION = 0;
@@ -82,7 +83,8 @@ public class Population{
// Mate their genes into a child, then mutate it
Dna childDNA = mom.DNA.recombinate(dad.DNA);
childDNA.mutate(this.MUTATION_RATE);
// childDNA.mutate(this.MUTATION_RATE);
childDNA.mutate(this.MUTATION_RATE, this.MUTATION_AMP);
// Fill the new population with the new child
this.ORGANISMS[i] = new Organism(childDNA, mom, dad);
@@ -11,7 +11,7 @@ Population population;
void setup(){
size(800, 800, P2D);
population = new Population(35, 0.01);
population = new Population(35, 0.5, .1);
}
void draw(){

0 comments on commit a2ef38c

Please sign in to comment.