Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
    def run(self, init_pop=None):
        if init_pop is None:
            init_pop = self.problem.populate(self.settings.pop_size)
        population = Node.format(init_pop)
        best_solutions = []
        gen = 0
        while gen < self.settings.gens:
            say(".")
            total_evals = 0
            # SELECTION
            selectees, evals = self.select(population)
            solutions, evals = self.get_best(selectees)
            best_solutions += 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
        print("")
        return best_solutions
Ejemplo n.º 4
0
 def initialize(self):
   if not self.population:
     self.population = self.problem.populate(self.settings.pop_size)
   self.population = Node.format(self.population)
   threshold = 2 * len(self.population) ** 0.5
   leaves = Node(self.problem, self.population, len(self.population)).divide(threshold).leaves()
   references = self.random_weights(len(leaves))
   self.assign_references(leaves, references)
   self.leaves = leaves
   for leaf in leaves:
     leaf.max_size = len(leaf.get_pop())
     leaf.set_pop(get_quartile_range(leaf.get_pop()))
     print(len(leaf.get_pop()))
   return None
Ejemplo n.º 5
0
  def run(self):
    start = get_time()
    if not self.population:
      self.population = self.problem.populate(self.settings.pop_size)
    population = Node.format(self.population)
    best_solutions = []
    while self.gen < self.settings.gens:
      say(".")
      self.gen += 1
      # SELECTION
      selectees = self.select(population)
      solutions = self.get_best(selectees)
      self.stat.update(solutions)
      best_solutions += solutions

      # EVOLUTION
      selectees = self.evolve(selectees)

      population = self.recombine(selectees, self.settings.pop_size)
    self.stat.runtime = get_time() - start
    return best_solutions
Ejemplo n.º 6
0
  def run(self, init_pop=None):
    if init_pop is None:
      init_pop = self.problem.populate(self.settings.pop_size)
    population = Node.format(init_pop)
    best_solutions = []
    gen = 0
    while gen < self.settings.gens:
      say(".")
      total_evals = 0
      # SELECTION
      selectees, evals =  self.select(population)
      solutions, evals = self.get_best(selectees)
      best_solutions += 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
    print("")
    return best_solutions
Ejemplo n.º 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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def _select(self, pop):
   node = Node(self.problem, pop, self.settings.pop_size).divide(sqrt(pop))
   non_dom_leafs = node.nonpruned_leaves()
   return non_dom_leafs