Beispiel #1
0
    def elite_evaluation(new_population, old_population, problem):

        # Verify if crossover returned better individuals
        new_population.sort(
            key=lambda x: Chromosome.compute_makespan(x, problem))
        old_population.sort(
            key=lambda x: Chromosome.compute_makespan(x, problem))
        min_value_op = Chromosome.compute_makespan(new_population[0], problem)
        min_value_np = Chromosome.compute_makespan(old_population[0], problem)

        if min_value_np < min_value_op:
            return new_population
        else:
            elite_population = []
            # elite selection
            define_10 = int(len(old_population) * 0.1)
            best_10 = old_population[0:define_10]

            # This takes only 90% of the best
            best_90_sel = new_population[:-define_10]

            elite_population.extend(best_10)
            elite_population.extend(best_90_sel)
            assert len(elite_population) == len(new_population)
            return elite_population
 def best_makespan(self, population):
     best_makespan = 9999999999
     best_chromosome = None
     for chromosome in population:
         makespan = Chromosome.compute_makespan(chromosome, self.problem)
         if makespan < best_makespan:
             best_makespan = makespan
             best_chromosome = chromosome
     return best_makespan, best_chromosome
    def k_tournament(self, population, k):

        if len(population) < k and len(population) != 0:
            return population[0]

        parents = []

        for i in range(0, k):
            parent = None
            while True:
                parent = random.choice(population)
                if parent not in parents:
                    break
            parents.append(parent)

        return min(parents, key=lambda x: Chromosome.compute_makespan(x, self.problem))
Beispiel #4
0
    def k_tournament(population, k, problem):

        selected = []
        total = len(population)

        while len(selected) != total:
            if len(population) < k and len(population) != 0:
                return population[0]

            parents = []

            for i in range(0, k):
                parent = None
                while True:
                    parent = random.choice(population)
                    if parent not in parents:
                        break
                parents.append(parent)

            chosen = min(parents,
                         key=lambda x: Chromosome.compute_makespan(x, problem))
            selected.append(chosen)

        return selected
Beispiel #5
0
    def conditional_precedence_reserving_mutation(problem, child, probability):
        new_child = Heuristics.mutation_operation(child, probability)
        new_child2 = Heuristics.mutation_machine(new_child, probability)

        return min([child, new_child, new_child2],
                   key=lambda x: Chromosome.compute_makespan(x, problem))