Beispiel #1
0
  /** evolve Array of solvers solvers in sequencial (no MultiThread) */
  @Override
  public void iterate() {
    this.numEvaluations = 0;
    this.numGeneration = 0;
    parents.clear();
    // evolve all solvers
    for (EAsolver s : arrayOfSolvers) {
      if (!s.stop.isDone(s)) {
        s.iterate(); // iterate solver
        updateHallOfFame(s.parents);
      }
      parents.addAll(s.hallOfFame);
      // get maximum of evaluations
      this.numEvaluations =
          s.numEvaluations > this.numEvaluations ? s.numEvaluations : this.numEvaluations;
      // get max of generation
      this.numGeneration =
          s.numGeneration > this.numGeneration ? s.numGeneration : this.numGeneration;

      //            this.numEvaluations += s.numEvaluations;
      //            this.numGeneration += s.numGeneration;
    }
    // parents.addAll(hallOfFame);

    // update stastistics
    ((ReportSolverArray) report).updateStats(arrayOfSolvers);
  }
Beispiel #2
0
 public void iterate() {
   // solver not done
   if (!mySolver.isDone()) {
     // next generation
     mySolver.iterate();
     // notify changes
     fireEvolutionChanges(mySolver);
     // solver done
     if (mySolver.isDone()) {
       // notify complete
       fireEvolutionComplete(mySolver);
     }
   }
 }
Beispiel #3
0
 public void run() {
   System.out.println("Start " + Thread.currentThread().getName() + " -> " + solver.solverName);
   solver.random.setSeed(solver.randomSeed);
   solver.solve(solver.report.verbose);
   solver.report.save();
   System.out.println("Stop " + Thread.currentThread().getName() + " -> " + solver.solverName);
 }
Beispiel #4
0
 @Override
 public void run() {
   while (autorun != null && !mySolver.isDone()) {
     try {
       iterate();
       Thread.sleep(getTimeToSleep());
     } catch (Exception ex) {
       return; // thread abborted
     }
   }
   // clean autorun
   autorun = null;
 }
Beispiel #5
0
  /**
   * start sequencial evolution
   *
   * @param verbose
   */
  public void InitializeEvolution(boolean verbose) {
    // init random generator
    if (template.randomSeed == 0) {
      template.random.setSeed(template.random.nextLong());
    } else {
      template.random.setSeed(template.randomSeed);
    }
    if (arrayOfSolvers == null) {
      arrayOfSolvers = createArrayOfSolvers(template);
    }
    // create random population
    parents = parents.getCleanClone();
    parents.createRandom(problem);
    parents.evaluate();

    for (EAsolver s : arrayOfSolvers) {
      s.InitializeEvolution(verbose);
    }
    // start statistics
    report.startStats(this, verbose);

    updateEvolutionStats();
  }
Beispiel #6
0
 /**
  * creates an array of solvers based on a template random seeds of solvers are generate by random
  * object of templeta
  *
  * @param template solver to clonate
  * @return array of smart cloned templates
  */
 public static EAsolver[] createArrayOfSolvers(EAsolver template) {
   EAsolver[] arrayOfSolvers = new EAsolver[template.numberOfRun];
   // initialize solver
   template.random.setSeed(template.randomSeed);
   // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   // build solvers
   for (int i = 0; i < arrayOfSolvers.length; i++) {
     arrayOfSolvers[i] = template.getSolverClone();
     arrayOfSolvers[i].solverName = template.solverName + String.format("_%03d", i);
     // one run
     arrayOfSolvers[i].numberOfRun = 1;
     // random seed initialized by template.random
     arrayOfSolvers[i].randomSeed = template.random.nextLong();
     arrayOfSolvers[i].updateSolverAtributes();
     // create simple report
     arrayOfSolvers[i].report = new ReportSolver();
     arrayOfSolvers[i].report.setSolver(template, i);
   }
   return arrayOfSolvers;
 }
Beispiel #7
0
 @Override
 public String toString() {
   return mySolver.toString();
 }
Beispiel #8
0
 public static EAsolver loadSolver(String txtFile, String simulFileName) {
   // defined solvers
   ArrayList<Genetic> solvers = loadGenetic(txtFile, SOLVER_TYPE, SOLVER_TYPE_LIB);
   // no defined solver
   if (solvers.isEmpty()) {
     showError("No solvers defined !", simulFileName);
     return null;
   }
   EAsolver solver = (EAsolver) solvers.get(0);
   // ---------------------------------------------------------------------------
   // read information about solver
   // ---------------------------------------------------------------------------
   // solver name
   solver.solverName = loadString(txtFile, SOLVER_NAME);
   if (solver.solverName.isEmpty()) {
     solver.solverName = solver.getSimpleName();
   }
   // random seed
   long randomSeed = loadInteger(txtFile, RANDOM_SEED);
   if (randomSeed == -1) { // not defined
     randomSeed = solver.random.nextLong(); // random number
   }
   solver.randomSeed = randomSeed;
   // number of runs
   int numberOfRun = (int) loadInteger(txtFile, NUMBER_OF_RUNS);
   solver.numberOfRun = numberOfRun > 0 ? numberOfRun : 1;
   if (solver.numberOfRun > 1) { // report to array
     solver.report = new ReportSolverArray();
   }
   // stop simulation
   ArrayList<Genetic> stop = loadGenetic(txtFile, STOP_CRITERIA, STOP_CRITERIA_LIB);
   if (!stop.isEmpty()) {
     solver.stop = (StopCriteria) stop.get(0);
   }
   // problem
   ArrayList<Genetic> problems = loadGenetic(txtFile, PROBLEM_NAME, PROBLEM_NAME_LIB);
   if (!problems.isEmpty()) {
     solver.problem = (Solution) problems.get(0);
   }
   // population
   ArrayList<Genetic> populations = loadGenetic(txtFile, POPULATION_TYPE, POPULATION_TYPE_LIB);
   if (!populations.isEmpty()) {
     solver.parents = (SimplePopulation) populations.get(0);
   }
   // Selection
   ArrayList<Genetic> selections =
       loadGenetic(txtFile, OPERATOR_SELECTION, OPERATOR_SELECTION_LIB);
   if (!selections.isEmpty()) {
     solver.selection = (GeneticOperator) selections.get(0);
   }
   // recombination
   ArrayList<Genetic> recombinations =
       loadGenetic(txtFile, OPERATOR_RECOMBINATION, OPERATOR_RECOMBINATION_LIB);
   if (!recombinations.isEmpty()) {
     solver.recombination = (GeneticOperator) recombinations.get(0);
   }
   // mutation
   ArrayList<Genetic> mutations = loadGenetic(txtFile, OPERATOR_MUTATION, OPERATOR_MUTATION_LIB);
   if (!mutations.isEmpty()) {
     solver.mutation = (GeneticOperator) mutations.get(0);
   }
   // replacement
   ArrayList<Genetic> replacement =
       loadGenetic(txtFile, OPERATOR_REPLACEMENT, OPERATOR_REPLACEMENT_LIB);
   if (!replacement.isEmpty()) {
     solver.replacement = (GeneticOperator) replacement.get(0);
   }
   // Rescaling
   ArrayList<Genetic> rescaling = loadGenetic(txtFile, OPERATOR_RESCALING, OPERATOR_RESCALING_LIB);
   if (!rescaling.isEmpty()) {
     solver.rescaling = (GeneticOperator) rescaling.get(0);
   }
   ArrayList<Genetic> statistics = loadGenetic(txtFile, STATISTIC, STATISTIC_LIB);
   // add AbstractStatistics
   for (Genetic stat : statistics) {
     solver.report.addStatistic((AbstractStatistics) stat);
   }
   solver.report.setFileName(
       simulFileName.isEmpty() ? solver.solverName : simulFileName); // filename or solverName
   solver.updateSolverAtributes();
   solver.report.startStats(solver, false); // reset stats
   return loadEvolution(solver, txtFile);
 }
Beispiel #9
0
 // :::::::::::::::::::::::::::  Copyright(c) M@nso  2016  :::::::::::::::::::
 ///////////////////////////////////////////////////////////////////////////
 public static void main(String[] args) {
   EAsolver solver = FileSolver.load("_test/solver10.txt");
   System.out.println(solver.toString());
   System.out.println("evolution\n\n" + solver.report.getEvolutionString());
   solver.solve(true);
 }
Beispiel #10
0
 public static String getSolverInfo(EAsolver solver) {
   StringBuffer txt = new StringBuffer();
   txt.append(
       MyString.LINE + "\n S O L V E R \n" + MyString.LINE + "\n" + solver.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n S T O P   C R I T E R I A \n"
           + MyString.LINE
           + "\n"
           + solver.stop.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n P R O B L E M \n"
           + MyString.LINE
           + "\n"
           + solver.problem.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n P O P U L A T I O N \n"
           + MyString.LINE
           + "\n"
           + solver.parents.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n S E L E C T I O N\n"
           + MyString.LINE
           + "\n"
           + solver.selection.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n R E C O M B I N A T I O N\n"
           + MyString.LINE
           + "\n"
           + solver.recombination.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n M U T A T I O N\n"
           + MyString.LINE
           + "\n"
           + solver.mutation.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n R E P L A C E M E N T\n"
           + MyString.LINE
           + "\n"
           + solver.replacement.getInformation());
   txt.append(
       "\n\n"
           + MyString.LINE
           + "\n R E S C A L I N G\n"
           + MyString.LINE
           + "\n"
           + solver.rescaling.getInformation());
   txt.append("\n\n" + MyString.LINE + "\n STATISTICS\n" + MyString.LINE + "\n");
   for (AbstractStatistics s : solver.report.getStatistics()) {
     txt.append(MyString.LINE + "\n");
     txt.append(s.getInformation() + "\n");
   }
   return txt.toString();
 }