Example #1
0
 def _select(self, pop):
   node = Node(self.problem, pop, self.settings.pop_size).divide(sqrt(pop))
   non_dom_leafs = node.nonpruned_leaves()
   all_leafs = node.leaves()
   # Counting number of evals
   evals = 0
   for leaf in all_leafs:
     for row in leaf._pop:
       if row.evaluated:
         evals+=1
   return non_dom_leafs, evals
Example #2
0
    def _select(self, pop):
        node = Node(self.problem, pop,
                    self.settings.pop_size).divide(sqrt(pop))
        non_dom_leafs = node.nonpruned_leaves()
        all_leafs = node.leaves()

        # Counting number of evals
        evals = 0
        for leaf in all_leafs:
            for row in leaf._pop:
                if row.evaluated:
                    evals += 1
        return non_dom_leafs, evals
Example #3
0
    def run(algo, id=0):
        gen = 0
        best_solutions = []
        size = algo.settings.pop_size
        max_gens = per_core(algo.settings.gens)
        population = Node.format(algo.problem.populate(size))
        total_evals = 0
        while gen < max_gens:
            say(".")
            selectees, evals = algo.select(population)
            solutions, evals = algo.get_best(selectees)
            best_solutions += solutions
            total_evals += evals

            # EVOLUTION
            selectees, evals = algo.evolve(selectees)
            total_evals += evals

            population, evals = algo.recombine(selectees,
                                               algo.settings.pop_size)
            total_evals += evals
            gen += 1
        if RANK == 0:
            for i in range(1, SIZE):
                best_solutions += COMM.recv(source=i, tag=id)
            return best_solutions
        else:
            COMM.send(best_solutions, dest=0, tag=id)
Example #4
0
  def run(self, init_pop=None):
    gen = 0
    best_solutions = []
    max_gens = self.settings.max_gens
    population = init_pop
    total_evals = 0
    try:
      if population is None:
        population = Node.format(self.problem.populate(self.settings.pop_size))
      while gen < max_gens:
        say(".")
        selectees, evals =  self.select(population)
        total_evals += evals

        solutions, evals = self.get_best(selectees)
        best_solutions.append(solutions)
        total_evals += evals

        # EVOLUTION
        selectees, evals = self.evolve(selectees)
        total_evals += evals

        population, evals = self.recombine(selectees, self.settings.pop_size)
        total_evals += evals
        gen += 1
    except RuntimeException as e:
      e.print_trace()
      return best_solutions, total_evals
    return best_solutions, total_evals
Example #5
0
  def run(algo, id = 0):
    gen = 0
    best_solutions = []
    size = algo.settings.pop_size
    max_gens = per_core(algo.settings.gens)
    population = Node.format(algo.problem.populate(size))
    total_evals = 0
    while gen < max_gens:
      say(".")
      selectees, evals =  algo.select(population)
      solutions, evals = algo.get_best(selectees)
      best_solutions += solutions
      total_evals += evals

      # EVOLUTION
      selectees, evals = algo.evolve(selectees)
      total_evals += evals

      population, evals = algo.recombine(selectees, algo.settings.pop_size)
      total_evals += evals
      gen += 1
    if RANK == 0:
      for i in range(1, SIZE):
        best_solutions += COMM.recv(source=i, tag = id)
      return best_solutions
    else:
      COMM.send(best_solutions, dest=0, tag = id)
Example #6
0
 def _recombine(self, mutants, total_size):
     remaining = total_size - len(mutants)
     pop = []
     for _ in range(remaining):
         pop.append(self.problem.generate())
     return mutants + Node.format(pop), 0
Example #7
0
 def _recombine(self, mutants, total_size):
   remaining = total_size - len(mutants)
   pop = []
   for _ in range(remaining):
     pop.append(self.problem.generate())
   return mutants + Node.format(pop), 0