Exemple #1
0
    def update_current_subproblem_neighborhood(self, new_solution, population):
        if self.phi_max < overall_constraint_violation_degree(new_solution):
            self.phi_max = overall_constraint_violation_degree(new_solution)

        permuted_neighbors_indexes = self.generate_permutation_of_neighbors(
            self.current_subproblem)
        replacements = 0

        for i in range(len(permuted_neighbors_indexes)):
            k = permuted_neighbors_indexes[i]

            f1 = self.fitness_function.compute(
                population[k].objectives, self.neighbourhood.weight_vectors[k])
            f2 = self.fitness_function.compute(
                new_solution.objectives, self.neighbourhood.weight_vectors[k])

            cons1 = abs(overall_constraint_violation_degree(self.solutions[k]))
            cons2 = abs(overall_constraint_violation_degree(new_solution))

            if cons1 < self.epsilon_k and cons2 <= self.epsilon_k:
                if f2 < f1:
                    population[k] = copy.deepcopy(new_solution)
                    replacements += 1
            elif cons1 == cons2:
                if f2 < f1:
                    population[k] = copy.deepcopy(new_solution)
                    replacements += 1
            elif cons2 < cons1:
                population[k] = copy.deepcopy(new_solution)
                replacements += 1

            if replacements >= self.max_number_of_replaced_solutions:
                break

        return population
Exemple #2
0
    def test_should_constraint_violation_degree_return_zero_if_the_solution_has_not_violated_constraints(
            self) -> None:
        solution = Solution(number_of_variables=2,
                            number_of_objectives=2,
                            number_of_constraints=2)

        self.assertEqual(0, overall_constraint_violation_degree(solution))
    def compare(self, solution1: Solution, solution2: Solution) -> int:
        violation_degree_solution_1 = overall_constraint_violation_degree(solution1)
        violation_degree_solution_2 = overall_constraint_violation_degree(solution2)
        if violation_degree_solution_1 < 0 and violation_degree_solution_2 < 0:
            if violation_degree_solution_1 > violation_degree_solution_2:
                result = -1
            elif violation_degree_solution_2 > violation_degree_solution_1:
                result = 1
            else:
                result = 0
        elif violation_degree_solution_1 == 0 and violation_degree_solution_2 < 0:
            result = -1
        elif violation_degree_solution_2 == 0 and violation_degree_solution_1 < 0:
            result = 1
        else:
            result = 0

        return result
Exemple #4
0
    def test_should_constraint_violation_degree_return_the_right_violation_degree(
            self) -> None:
        solution = Solution(number_of_variables=2,
                            number_of_objectives=2,
                            number_of_constraints=2)
        solution.constraints[0] = -1
        solution.constraints[1] = -2

        self.assertEqual(-3, overall_constraint_violation_degree(solution))
    def select_final_population(self, population: List[S], mu: int) -> List[S]:
        population_pool = copy(population)
        population_pool.sort(key=lambda s: (
            overall_constraint_violation_degree(s), s.objectives[0]))

        new_population = []
        for i in range(mu):
            new_population.append(population_pool[i])

        return new_population
    def replacement(self, population: List[S],
                    offspring_population: List[S]) -> List[S]:
        population_pool = offspring_population

        population_pool.sort(key=lambda s: (
            overall_constraint_violation_degree(s), s.objectives[0]))

        new_population = []
        for i in range(self.population_size):
            new_population.append(population_pool[i])

        return new_population
Exemple #7
0
    def init_progress(self) -> None:
        super().init_progress()

        # for i in range(self.population_size):
        #    self.constraints[i] = get_overall_constraint_violation_degree(self.permutation[i])
        self.constraints = [overall_constraint_violation_degree(self.solutions[i])
                            for i in range(0, self.population_size)]

        sorted(self.constraints)
        self.epsilon_zero = abs(self.constraints[int(ceil(0.05 * self.population_size))])

        if self.phi_max < abs(self.constraints[0]):
            self.phi_max = abs(self.constraints[0])

        self.rk = feasibility_ratio(self.solutions)
        self.epsilon_k = self.epsilon_zero
Exemple #8
0
    def replacement(self, population: List[S],
                    offspring_population: List[S]) -> List[S]:
        population_pool = []

        if self.elitist:
            population_pool = population
            population_pool.extend(offspring_population)
        else:
            population_pool.extend(offspring_population)

        population_pool.sort(key=lambda s: (
            overall_constraint_violation_degree(s), s.objectives[0]))

        new_population = []
        for i in range(self.mu):
            new_population.append(population_pool[i])

        return new_population