示例#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);
  }
示例#2
0
  public static void main(String[] args) {

    System.out.println("SingleMachine_ProbMatrix_Evaporation080302");
    // openga.applications.data.singleMachine singleMachineData = new
    // openga.applications.data.singleMachine();
    int jobSets[] = new int[] {20, 30, 40, 50, 60, 90}; // 20, 30, 40, 50, 60, 90, 100, 200
    int counter = 0;
    int popSize[] = new int[] {100}; // 50, 100, 155, 210
    double crossoverRate[] = new double[] {0.9}, // 0.8, 0.5
        mutationRate[] = new double[] {0.5}; // 0.6, 0.3
    int populationSize[] = new int[] {100}; // 200, 100
    int repeatExperiments = 30;

    int startingGeneration[] = new int[] {200}; // 200, 500
    double startingGenerationPercent[] = new double[] {0.5}; // 0.1, 0.3, 0.5
    int interval[] = new int[] {10};
    double intervalPercent[] = new double[] {0.02}; // 0.01, 0.05, 0.1

    int strategy[] = new int[] {0};
    boolean applyEvaporation = false;
    String evaporationMethod[] =
        new String[] {"add"}; // "constant", "method1", "method2", "Threshold", "add"

    double lamdalearningrate[] = new double[] {1}; // 0.7
    double betalearningrate[] = new double[] {1}; // 0.1
    double w1 = 1;
    double w2 = 1;

    // Sourd Instance
    for (int m = 0; m < jobSets.length; m++) { // jobSets.length
      for (int k = 0; k < 49; k++) { // 49 9
        // if((jobSets[m] <= 50 && (k == 0 || k == 3 || k == 6 || k == 21 || k == 24 || k == 27 || k
        // == 42 || k == 45 || k == 48)) ||  (jobSets[m] > 50 && k < 9)){
        if ((jobSets[m] <= 50) || (jobSets[m] > 50 && k < 9)) {
          for (int j = 0; j < startingGeneration.length; j++) {
            for (int n = 0; n < interval.length; n++) {
              for (int p = 0; p < strategy.length; p++) {
                for (int q = 0; q < evaporationMethod.length; q++) {
                  for (int i = 0; i < repeatExperiments; i++) {
                    singleMachinePREDA singleMachine1 = new singleMachinePREDA();
                    System.out.println("Combinations: " + counter);
                    openga.applications.data.singleMachine readSingleMachineData1 =
                        new openga.applications.data.singleMachine();
                    int numberOfJobs = jobSets[m];
                    String fileName = readSingleMachineData1.getFileName(numberOfJobs, k);
                    // fileName = "bky"+numberOfJobs+"_1";
                    // fileName = "sks388a";
                    System.out.print(fileName + "\t");
                    readSingleMachineData1.setData("sks/" + fileName + ".txt");
                    readSingleMachineData1.getDataFromFile();
                    int dueDate[] = readSingleMachineData1.getDueDate();
                    int processingTime[] = readSingleMachineData1.getPtime();

                    singleMachine1.setData(numberOfJobs, dueDate, processingTime, fileName);
                    singleMachine1.setProbabilityMatrixData(startingGeneration[j], interval[n]);
                    singleMachine1.setSequenceStrategy(strategy[p]);
                    singleMachine1.setLearning(lamdalearningrate[0], betalearningrate[0]);
                    singleMachine1.setEvaporationMethod(applyEvaporation, evaporationMethod[q]);
                    singleMachine1.initiateVars();
                    singleMachine1.start();
                    counter++;
                  } // end for
                }
              }
            }
          }
        } // end if
      }
    }

    System.exit(0);

    /*
    //BKY Instance
    int incrementSteps = 5;
    for(int i = 0 ; i < repeatExperiments ; i ++ ){
    for(int j = 0 ; j < jobSets.length ; j ++ ){//jobSets.length
    for(int k = 0 ; k < startingGeneration.length ; k ++ ){
    for (int m = 0; m < interval.length; m++) {
    for (int n = 0; n < strategy.length; n++) {
    for(int p = 296 ; p < 297 ; ){
    openga.applications.data.readSingleMachine readSingleMachineData1 = new openga.applications.data.readSingleMachine();
    int numberOfJobs = jobSets[j];
    String fileName = readSingleMachineData1.getFileName(numberOfJobs, p);
    readSingleMachineData1.setData("instances/SingleMachineBKS/"+fileName+".txt");
    if(readSingleMachineData1.testReadData()){//to test whether the file exist
    singleMachinewithProbMatrix singleMachine1 = new singleMachinewithProbMatrix();
    System.out.println("Combinations: "+counter+"\t"+fileName);
    //System.out.print(fileName+"\t");
    readSingleMachineData1.getDataFromFile();
    int dueDate[] = readSingleMachineData1.getDueDate();
    int processingTime[] = readSingleMachineData1.getPtime();

    singleMachine1.setData(numberOfJobs, dueDate, processingTime, fileName);
    singleMachine1.setParameters(popSize[0], crossoverRate[0], mutationRate[0], 100000);

    singleMachine1.setProbabilityMatrixData(startingGeneration[k], interval[m]);
    singleMachine1.setSequenceStrategy(strategy[n]);
    singleMachine1.setEvaporationMethod(false, evaporationMethod[0]);

    singleMachine1.initiateVars();
    singleMachine1.start();
    counter ++;
    }
    p += incrementSteps;
    }
    }
    }
    }
    }
    }//end for of BKY
     */

  }
示例#3
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);
  }
  public static void main(String[] args) {
    System.out.println("SPGA2_forParallel 20060302 Mining Gene Clone Mating with Archive");
    int numberOfSubPopulations[] = new int[] {40}; // 10, 20, 30, 40
    int popSize[] = new int[] {210}; // 100, 155, 210
    int numberOfJob[] = new int[] {35, 50, 65}; // 35, 50, 65
    int numberOfMachines[] = new int[] {10, 15, 18}; // 10, 15, 18
    int totalSolnsToExamine[] = new int[] {1000000}; // 1000000, 1500000, 2000000
    boolean applySecCRX[] = new boolean[] {false}; // false, true
    boolean applySecMutation[] = new boolean[] {true};
    boolean applyClone[] = new boolean[] {false, true};
    int tournamentSize[] = new int[] {10}; // 2, 10
    int cloneStrategies[] =
        new int[] {2}; // 0: random, 1: swap, 2:inverse, 3:shift, 4:adjacent.0, 1, 2, 3, 4
    double timeToClone[] = new double[] {0}; // 0, 0.25, 0.5, 0.75

    double crossoverRate = 0.9, mutationRate = 0.1, elitism = 0.2;
    int repeatExperiments = 15;
    int counter = 0;

    /*
        for(int i = 0 ; i < repeatExperiments ; i ++ ){
          for(int j = 0 ; j < applyClone.length ; j ++ ){
            for(int k = 0 ; k < tournamentSize.length ; k ++ ){
              for(int r = 0 ; r < numberOfJob.length ; r ++ ){
                System.out.println("combinations: "+counter++);
                SPGA2_forParallelMachine SPGA2_forParallelMachine1 = new SPGA2_forParallelMachine();
                SPGA2_forParallelMachine1.setParallelMachineData(numberOfJob[r], numberOfMachines[r]);
                SPGA2_forParallelMachine1.setParameters(numberOfSubPopulations[0], popSize[0],
                    totalSolnsToExamine[0], crossoverRate, mutationRate, elitism, applySecCRX[0], applySecMutation[0]);
                SPGA2_forParallelMachine1.setCloneActive(applyClone[j]);
                SPGA2_forParallelMachine1.setTournamentSize(tournamentSize[k]);
                SPGA2_forParallelMachine1.initiateVars();
                SPGA2_forParallelMachine1.start();
                SPGA2_forParallelMachine1 = null;
                System.gc();
              }
            }
          }
        }// end i

         for(int i = 0 ; i < repeatExperiments ; i ++ ){
          for(int j = 0 ; j < numberOfJob.length ; j ++ ){
             for(int r = 0 ; r < cloneStrategies.length ; r ++ ){
                for(int k = 0 ; k < timeToClone.length ; k ++ ){
                  System.out.println("combinations: "+counter++);
                  SPGA2_forParallelMachine SPGA2_forParallelMachine1 = new SPGA2_forParallelMachine();
                  SPGA2_forParallelMachine1.setParallelMachineData(numberOfJob[j], numberOfMachines[j]);
                  SPGA2_forParallelMachine1.setParameters(numberOfSubPopulations[0], popSize[0],
                      totalSolnsToExamine[0], crossoverRate, mutationRate, elitism, applySecCRX[0], applySecMutation[0]);
                  SPGA2_forParallelMachine1.setCloneActive(applyClone[0], cloneStrategies[r]);
                  SPGA2_forParallelMachine1.setTournamentSize(tournamentSize[0]);
                  SPGA2_forParallelMachine1.initiateVars();
                  SPGA2_forParallelMachine1.setTimeToClone(timeToClone[k]);
                  SPGA2_forParallelMachine1.start();
                  SPGA2_forParallelMachine1 = null;
                  System.gc();
                }
             }
          }
        }// end i

    */

    for (int i = 0; i < repeatExperiments; i++) {
      for (int r = 0; r < numberOfJob.length; r++) {
        System.out.println("combinations: " + counter++);
        SPGA2_forParallelMachine SPGA2_forParallelMachine1 = new SPGA2_forParallelMachine();
        SPGA2_forParallelMachine1.setParallelMachineData(numberOfJob[r], numberOfMachines[r]);
        SPGA2_forParallelMachine1.setParameters(
            numberOfSubPopulations[0],
            popSize[0],
            totalSolnsToExamine[0],
            crossoverRate,
            mutationRate,
            elitism,
            applySecCRX[0],
            applySecMutation[0]);
        SPGA2_forParallelMachine1.setCloneActive(applyClone[0], 2);
        SPGA2_forParallelMachine1.initiateVars();
        SPGA2_forParallelMachine1.start();
        SPGA2_forParallelMachine1.setTimeToClone(timeToClone[0]);
        SPGA2_forParallelMachine1 = null;
        System.gc();
      } // end r
    } // end i

    /*
        for(int i = 0 ; i < repeatExperiments ; i ++ ){
          for(int j = 0 ; j < numberOfSubPopulations.length ; j ++ ){
            for(int k = 0 ; k < popSize.length ; k ++ ){
              for(int L = 0 ; L < applySecCRX.length ; L ++ ){
                for(int m = 0 ; m < applySecMutation.length ; m ++ ){
                  for(int r = 0 ; r < numberOfJob.length ; r ++ ){
                    System.out.println(numberOfJob[r]+"\t"+numberOfSubPopulations[j]+"\t"+ popSize[k]);
                    System.out.println("combinations: "+counter++);
                    SPGA2_forParallelMachine SPGA2_forParallelMachine1 = new SPGA2_forParallelMachine();
                    SPGA2_forParallelMachine1.setParallelMachineData(numberOfJob[r], numberOfMachines[r]);
                    SPGA2_forParallelMachine1.setParameters(numberOfSubPopulations[j], popSize[k],
                        totalSolnsToExamine[0], crossoverRate, mutationRate, elitism, applySecCRX[L], applySecMutation[m]);
                    SPGA2_forParallelMachine1.initiateVars();
                    SPGA2_forParallelMachine1.start();
                    SPGA2_forParallelMachine1 = null;
                    System.gc();
                    //System.exit(0);
                  }//end r
                }//end m
              }// end L
            }// end k
          }// end j
        }// end i
    */
    System.exit(0);
  }