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);
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    System.out.println("mTSPEDA_20150731DOE_totalDistance");
    double crossoverRate[], mutationRate[];
    crossoverRate = new double[] {1, 0.5}; // 1, 0.5
    mutationRate = new double[] {0.1, 0.5}; // 1, 0.5
    int counter = 0;
    double elitism[] = new double[] {0.1};
    int generations[] = new int[] {1000}; // 50000
    int numInstances = 33; // 33
    int numberOfSalesmen[] = new int[] {3, 5, 10, 20, 30}; // 2, 3, 5, 10, 20, 30
    int repeat = 5;

    // EDA parameters.
    double[] lamda = new double[] {0.1}; // learning rate{0.1, 0.5, 0.9}
    int numberOfCrossoverTournament[] = new int[] {2}; // {1, 2, 4}
    int numberOfMutationTournament[] = new int[] {2}; // {1, 2, 4}
    int startingGenDividen[] = new int[] {4}; // {2, 4}{4}

    // to test different kinds of combinations.
    for (int i = 0; i <= numInstances; i++) { // numInstances
      // initiate scheduling data, we get the data from a program.
      openga.applications.data.TSPInstances TSPInstances1 =
          new openga.applications.data.TSPInstances();
      String instanceName = TSPInstances1.getFileName(i); // getFileName getCaterFileName
      TSPInstances1.setData(instanceName);
      TSPInstances1.getDataFromFile();
      TSPInstances1.calcEuclideanDistanceMatrix();
      int length = TSPInstances1.getSize();

      for (int j = 0; j < crossoverRate.length; j++) {
        for (int k = 0; k < mutationRate.length; k++) {
          for (int n = 0; n < elitism.length; n++) {
            for (int p = 0; p < numberOfSalesmen.length; p++) {

              for (int q = 0; q < lamda.length; q++) {
                for (int m = 0; m < numberOfCrossoverTournament.length; m++) {
                  for (int r = 0; r < numberOfMutationTournament.length; r++) {
                    for (int s = 0; s < startingGenDividen.length; s++) {
                      for (int t = 0; t < repeat; t++) {
                        System.out.print("counter " + counter + "\t");
                        mTSPSGA_SGGA TSP1 = new mTSPSGA_SGGA();

                        TSP1.setParameter(
                            i,
                            crossoverRate[j],
                            mutationRate[k],
                            counter,
                            elitism[n],
                            generations[0],
                            numberOfSalesmen[p],
                            TSPInstances1.getOriginalPoint(),
                            TSPInstances1.getCoordinates(),
                            TSPInstances1.getDistanceMatrix(),
                            TSPInstances1.getSize(),
                            instanceName);
                        TSP1.setEDAinfo(
                            lamda[q],
                            numberOfCrossoverTournament[m],
                            numberOfMutationTournament[r],
                            startingGenDividen[s]);
                        TSP1.initiateVars();
                        TSP1.startMain();
                        counter++;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    } // end for
    System.exit(0);
  }