public Fourmis mutate() { string[] label = { "if", "move", "right", "left", "prog2", "prog3" }; Fourmis f = new Fourmis(fDNA.clone()); Fourmis a = new Fourmis(new DNA(label[Random.Range(0, 6)])); a.getDNA().createRandom(5); f.fDNA.setDnaAt((Random.Range(0, f.fDNA.getSize())), (a.getDNA().clone())); f.energy = initEnergy; return(f); }
Fourmis[] initiatePopulation() { Fourmis[] populationFourmis = new Fourmis[nbPopulation]; for (int i = 0; i < nbPopulation; i++) { Fourmis a = new Fourmis(new DNA(label[Random.Range(0, 6)])); a.getDNA().createRandom(5); a.fullProg(); populationFourmis[i] = a; } return(populationFourmis); }
public Fourmis crossOver(Fourmis a) { Fourmis f = new Fourmis(fDNA.clone()); Fourmis f1 = new Fourmis(a.getDNA().clone()); int ind1 = (Random.Range(0, f.fDNA.getSize())); //int ind1 = (Random.Range(f.fDNA.getSize()/2, f.fDNA.getSize())); //int ind1 = (f.fDNA.getSize()-1); // int ind2 = (Random.Range(0, f1.getDNA().getSize())); int ind2 = (Random.Range(0, f1.getDNA().getSize())); f.fDNA.setDnaAt(ind1, (f1.fDNA.getDnaAt(ind2).clone())); f.energy = initEnergy; return(f); }