Package estrutura

Examples of estrutura.Caminho


  int k=0;


  //M�todo que define a primeira gera��o de caminhos.
  public void criaPrimeiraGeracao(){
    Caminho c1 = new Caminho();
    Caminho c2 = new Caminho();
    Caminho c3 = new Caminho();
    Caminho c4 = new Caminho();
    Caminho c5 = new Caminho();
    Caminho c6 = new Caminho();

    //caminhos que compoem a primeira gera��o;
    c1.getCaminho().add(4); c1.getCaminho().add(3); c1.getCaminho().add(2); c1.getCaminho().add(1);
    c1.getCaminho().add(5); c1.getCaminho().add(4); c1.setAptidaoAbsoluta(22); //0

    c2.getCaminho().add(1); c2.getCaminho().add(2); c2.getCaminho().add(3); c2.getCaminho().add(4);
    c2.getCaminho().add(5); c2.getCaminho().add(1); c2.setAptidaoAbsoluta(22); //1

    c3.getCaminho().add(2); c3.getCaminho().add(1); c3.getCaminho().add(5); c3.getCaminho().add(4);
    c3.getCaminho().add(3); c3.getCaminho().add(2); c3.setAptidaoAbsoluta(22); //2

    c4.getCaminho().add(3); c4.getCaminho().add(4); c4.getCaminho().add(5); c4.getCaminho().add(1);
    c4.getCaminho().add(2); c4.getCaminho().add(3); c4.setAptidaoAbsoluta(22); //3

    c5.getCaminho().add(5); c5.getCaminho().add(4); c5.getCaminho().add(3); c5.getCaminho().add(2);
    c5.getCaminho().add(1); c5.getCaminho().add(5); c5.setAptidaoAbsoluta(22); //4

    c6.getCaminho().add(1); c6.getCaminho().add(5); c6.getCaminho().add(3); c6.getCaminho().add(4);
    c6.getCaminho().add(2); c6.getCaminho().add(1); c6.setAptidaoAbsoluta(22); //5
   
    System.out.println("Teste");


    geracao.add(c1); geracao.add(c2); geracao.add(c3); geracao.add(c4); geracao.add(c5); geracao.add(c6)
View Full Code Here


  public void crossover(){
    for (int m=0; m<pais.size(); m=m+2){
      ArrayList<Integer> mapeamento1 = new ArrayList<Integer>();
      ArrayList<Integer> mapeamento2 = new ArrayList<Integer>();
      Caminho filho1 = new Caminho();
      Caminho filho2 = new Caminho();
     
      for(int q=0; q<6; q++){
        filho1.getCaminho().add(0);
        filho2.getCaminho().add(0);
      }
     
      filho1.getCaminho().set(1, pais.get(m+1).getCaminho().get(2));
      filho1.getCaminho().set(1, pais.get(m+1).getCaminho().get(3));
      filho2.getCaminho().set(2, pais.get(m).getCaminho().get(2));
      filho2.getCaminho().set(2, pais.get(m).getCaminho().get(3));
     
      mapeamento1.add(pais.get(m).getCaminho().get(2));
      mapeamento1.add(pais.get(m+1).getCaminho().get(2));
      mapeamento2.add(pais.get(m).getCaminho().get(3));
      mapeamento2.add(pais.get(m+1).getCaminho().get(3));
     
      for (int n=0; n<6; n++){
        if (n != 2 || n != 3){
          if(!(mapeamento1.contains(pais.get(m).getCaminho().get(n)))){
            filho1.getCaminho().set(n, pais.get(m).getCaminho().get(n));
            filho2.getCaminho().set(n, pais.get(m+1).getCaminho().get(n));
          }
          else {
            int index = mapeamento1.indexOf(pais.get(m).getCaminho().get(n));
            if ((index % 2) == 0){
              filho1.getCaminho().set(n, mapeamento1.get(index+1));
            }
            else{
              filho1.getCaminho().set(n, mapeamento1.get(index-1));
            }
          }
        }
      }
     
      for (int p=0; p<6; p++){
        if (p != 2 || p != 3){
          if(!(mapeamento2.contains(pais.get(m+1).getCaminho().get(p)))){
            filho2.getCaminho().set(p, pais.get(m+1).getCaminho().get(p));
          }
          else {
            int index = mapeamento2.indexOf(pais.get(m+1).getCaminho().get(p));
            if ((index % 2) == 0){
              filho2.getCaminho().set(p, mapeamento2.get(index+1));
            }
            else{
              filho2.getCaminho().set(p, mapeamento2.get(index-1));
            }
          }
        } 
      }
     
View Full Code Here

TOP

Related Classes of estrutura.Caminho

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.