Ejemplo n.º 1
0
  public void initiateVars() {
    GaMain =
        new singleThreadGAwithEDA(); // singleThreadGA singleThreadGAwithSecondFront
                                     // singleThreadGAwithMultipleCrossover adaptiveGA
    Population = new population();
    Selection = new binaryTournament(); // binaryTournament
    Crossover =
        new twoPointCrossover2EDA(); // twoPointCrossover2 oneByOneChromosomeCrossover
                                     // twoPointCrossover2withAdpative
                                     // twoPointCrossover2withAdpativeThreshold
    Mutation =
        new swapMutationEDA(); // shiftMutation shiftMutationWithAdaptive
                               // shiftMutationWithAdaptiveThreshold
    ObjectiveFunction = new ObjectiveFunctionTSPI[numberOfObjs];
    ObjectiveFunction[0] = new ObjectiveFunctionMTSPHeu();
    Fitness = new singleObjectiveFitness();
    objectiveMinimization = new boolean[numberOfObjs];
    objectiveMinimization[0] = true;
    encodeType = true;

    if (numberOfSalesmen >= length) {
      System.out.println(
          "The number of salesmen is "
              + numberOfSalesmen
              + ", which should be greater than the number of visiting locations.");
      System.out.println("The program will exit.");
      System.exit(0);
    }

    localSearch1 = new localSearchBy2OptForMTSP();
    // localSearch1.setMTSPData(Population, distanceMatrix, numberOfSalesmen);

    ObjectiveFunction[0].setTSPData(originalPoint, coordinates, numberOfSalesmen);
    ObjectiveFunction[0].setObjectiveFunctionType("TotalDistance");

    // set the data to the GA main program.
    GaMain.setData(
        Population,
        Selection,
        Crossover,
        Mutation,
        ObjectiveFunction,
        Fitness,
        DEFAULT_generations,
        DEFAULT_PopSize,
        DEFAULT_PopSize,
        length,
        DEFAULT_crossoverRate,
        DEFAULT_mutationRate,
        objectiveMinimization,
        numberOfObjs,
        encodeType,
        elitism);
    GaMain.setLocalSearchOperator(localSearch1, applyLocalSearch, 20);
    GaMain.setSecondaryCrossoverOperator(Crossover2, false);
    GaMain.setSecondaryMutationOperator(Mutation2, false);

    GaMain.setEDAinfo(
        lamda, numberOfCrossoverTournament, numberOfMutationTournament, startingGenDividen);
  }