public void recombinar(Cromossomo mae) { String genP, genM; int pontoCorte = ((int) Math.round(Math.random() * (getTamanho() - 2)) + 1); if (Math.round(Math.random()) == 0) { genP = this.getGenotipo() .substring(0, pontoCorte) .concat(mae.getGenotipo().substring(pontoCorte, mae.getTamanho())); genM = mae.getGenotipo() .substring(0, pontoCorte) .concat(this.getGenotipo().substring(pontoCorte, this.getTamanho())); } else { genM = this.getGenotipo() .substring(0, pontoCorte) .concat(mae.getGenotipo().substring(pontoCorte, mae.getTamanho())); genP = mae.getGenotipo() .substring(0, pontoCorte) .concat(this.getGenotipo().substring(pontoCorte, this.getTamanho())); } this.setGenotipo(new StringBuffer(genP)); mae.setGenotipo(new StringBuffer(genM)); }
public boolean compare(Cromossomo c) { String gen = this.getGenotipo().toString(); String genC = c.getGenotipo().toString(); return (gen.equals(genC)); }