Beispiel #1
0
  public double calculaGasolina(Cromossoma temp, ArrayList<Vertex> listabombas) {
    AStar as = new AStar(nodes);
    double result = 0;
    for (int i = 0; i < temp.size() - 2; i += 2) {
      int begin = temp.get(i).convertToInt();
      int end = temp.get(i + 2).convertToInt();
      if (temp.get(i + 1).isBomba()) {
        ArrayList<Double> escolhas = new ArrayList<Double>();
        for (int j = 0; j < listabombas.size(); j++) {
          double d;
          LinkedList<Integer> x = as.calculateFitness(begin, listabombas.get(j).getId());
          d = calcularDistancia(x);

          x = as.calculateFitness(listabombas.get(j).getId(), end);
          d += calcularDistancia(x);
          escolhas.add(d);
        }
        result += Collections.min(escolhas);
        result -= adicionarCombustivel;
      } else {
        LinkedList<Integer> x = as.calculateFitness(begin, end);
        result += calcularDistancia(x);
      }
    }
    return result;
  }
Beispiel #2
0
  public void printBetterSolution(Cromossoma better, ArrayList<Vertex> listabombas) {
    AStar as = new AStar(nodes);
    for (int i = 0; i < better.size() - 1; i += 2) {
      int begin = better.get(i).convertToInt();
      int end = better.get(i + 2).convertToInt();
      if (better.get(i + 1).isBomba()) {
        // ArrayList<Double> escolhas= new ArrayList<Double>();
        for (int j = 0; j < listabombas.size(); j++) {
          as.calculateFitness(begin, listabombas.get(j).getId());
          as.print();
          // d=calcular(x);

          as.calculateFitness(listabombas.get(j).getId(), end);
          as.print();
          // d+=calcular(x);
          // escolhas.add(d);
        }
        // Collections.min(escolhas);
      } else {
        as.calculateFitness(begin, end);
        as.print();
      }
    }
  }