Sei que esse erro é bem trivial, mas não estou conseguindo resolver sozinho
Alguém pode me ajudar?
import java.util.Random;
/*
-
To change this license header, choose License Headers in Project Properties.
-
To change this template file, choose Tools | Templates
-
and open the template in the editor.
/
/* -
@author Thiago Tolentino
*/
public class Algoritmo {Populacao pop =
new Populacao();
Individuo[] ind =new Individuo[pop.getQtdePopulacao()];Algoritmo(){ for(int i = 0; i < pop.getQtdePopulacao(); i++){ ind[i] = new Individuo(); }// for }
public boolean CrossOver() { Random x, r = new Random(); int nx, nr; x = new Random(); int total;
total = (int) pop.getQtdePopulacao() / 2; Individuo[] individuo = new Individuo[pop.getQtdePopulacao()]; String filho1, filho2; ind = BubbleSort(ind); int pontoDeCorte1, pontoDeCorte2; pontoDeCorte1 = (int) (ind[0].getCorpo().length() * ind[0].getTaxaCrossOver()); for (int i = 0; i < total; i += 2) { nr = r.nextInt(total); do { nx = x.nextInt(total); } while (nx != nr); filho1 = ind[nx].getCorpo().substring(0, pontoDeCorte1); filho1 += ind[nr].getCorpo().substring(pontoDeCorte1, ind[nr].getCorpo().length()); filho2 = ind[nr].getCorpo().substring(0, pontoDeCorte1); filho2 += ind[nx].getCorpo().substring(pontoDeCorte1, ind[nx].getCorpo().length()); individuo[i].setCorpo(filho1); individuo[i + 1].setCorpo(filho2); if(individuo[i].getCorpo().equals(pop.getSolucao())){ individuo[i].setPerfeito(true); return true; } // if if(individuo[i+1].getCorpo().equals(pop.getSolucao())){ individuo[i+1].setPerfeito(true); return true; } // if } // for ind = individuo; pop.setNumGeracao(pop.getNumGeracao()+1); return false;
} // CrossOver
public Individuo[] BubbleSort(Individuo[] ind) { Individuo aux; for (int i = ind.length; i >= 1; i–) { for (int j = 1; j < i; j++) { if (ind[j - 1].getPotencial() > ind[j].getPotencial()) { aux = ind[j]; ind[j] = ind[j - 1]; ind[j - 1] = aux; }// if }// for }//for return ind; } // BubbleSort
public void GerarPotencial() { String solucao; solucao = pop.getSolucao(); for (int y = 0; y < pop.getQtdePopulacao(); y++) { for (int i = 0; i < solucao.length(); i++) { if (solucao.charAt(i) == ind[y].getCorpo().charAt(i)) { ind[y].setPotencial(ind[y].getPotencial()+1); } // if } //for } //for }//
public void GerarCorpo() { String corpo; Individuo[] ind = new Individuo[pop.getQtdePopulacao()]; corpo = pop.getCaracteres(); Random r = new Random(); int aleatorio; for (int i = 0; i < pop.getQtdePopulacao(); i++) { for (int y = 0; y < pop.getSolucao().length(); y++) { aleatorio = r.nextInt(corpo.length()); ind[i].setCorpo(ind[i].getCorpo() + pop.getCaracteres().charAt(aleatorio)); System.out.println(" GetCorpo: "+ind[i].getCorpo() + " Indice: "+i); if (ind[i].getCorpo().equals(pop.getSolucao())) { // return true; } } //for }// for } // GerarCorpo
public String exibir(){
String todos;todos = "O Melhor possui: Corpo: "+ ind[0].getCorpo() + " Geração: " + pop.getNumGeracao() + " Aptidão: "+ind[0].getPotencial(); return todos;
}
public void Ordem() { boolean terminado = false; GerarCorpo(); GerarPotencial(); System.out.println(exibir()); while(terminado){ terminado = CrossOver(); GerarPotencial(); System.out.println(exibir()); } //while }//Ordem } // algoritmo