Beispiel #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);
  }
Beispiel #2
0
 /**
  * For single objective problem
  *
  * @param arch1
  * @return
  */
 public int getBestSolnIndex(populationI arch1) {
   int index = 0;
   double bestobj = Double.MAX_VALUE;
   for (int k = 0; k < GaMain.getArchieve().getPopulationSize(); k++) {
     if (bestobj > GaMain.getArchieve().getObjectiveValues(k)[0]) {
       bestobj = GaMain.getArchieve().getObjectiveValues(k)[0];
       index = k;
     }
   }
   return index;
 }
Beispiel #3
0
 public void startMain() {
   openga.util.timeClock timeClock1 = new openga.util.timeClock();
   timeClock1.start();
   GaMain.startGA();
   timeClock1.end();
   // to output the implementation result.
   String implementResult = "";
   int bestInd = getBestSolnIndex(GaMain.getArchieve());
   implementResult =
       instanceName
           + "\t"
           + DEFAULT_crossoverRate
           + "\t"
           + DEFAULT_mutationRate
           + "\t"
           + lamda
           + "\t"
           + (length + 1)
           + "\t"
           + numberOfSalesmen
           + "\t"
           + startingGenDividen
           + "\t"
           + numberOfCrossoverTournament
           + "\t"
           + numberOfMutationTournament
           + "\t"
           + startingGenDividen
           + "\t"
           + GaMain.getArchieve().getSingleChromosome(bestInd).getObjValue()[0]
           + "\t"
           + timeClock1.getExecutionTime() / 1000.0
           + "\n"; // +"\t"+GaMain.getArchieve().getSingleChromosome(0).toString1()
   writeFile("mTSPEDA_20150731DOE_totalDistance", implementResult);
   System.out.print(implementResult);
 }