Beispiel #1
0
    def test_should_is_feasible_return_true_if_the_solution_has_no_constraints(
            self) -> None:
        solution = Solution(number_of_variables=2,
                            number_of_objectives=2,
                            number_of_constraints=0)

        self.assertEqual(True, is_feasible(solution))
Beispiel #2
0
    def update_external_archive(self):
        feasible_solutions = []
        for solution in self.solutions:
            if is_feasible(solution):
                feasible_solutions.append(copy.deepcopy(solution))

        if len(feasible_solutions) > 0:
            feasible_solutions = feasible_solutions + self.archive
            ranking = FastNonDominatedRanking()
            ranking.compute_ranking(feasible_solutions)

            first_rank_solutions = ranking.get_subfront(0)
            if len(first_rank_solutions) <= self.population_size:
                self.archive = []
                for solution in first_rank_solutions:
                    self.archive.append(copy.deepcopy(solution))
            else:
                crowding_distance = CrowdingDistance()
                while len(first_rank_solutions) > self.population_size:
                    crowding_distance.compute_density_estimator(
                        first_rank_solutions)
                    first_rank_solutions = sorted(
                        first_rank_solutions,
                        key=lambda x: x.attributes['crowding_distance'],
                        reverse=True)
                    first_rank_solutions.pop()

                self.archive = []
                for solution in first_rank_solutions:
                    self.archive.append(copy.deepcopy(solution))
Beispiel #3
0
    def test_should_is_feasible_return_false_if_the_solution_has_is_not_feasible(
            self) -> None:
        solution = Solution(number_of_variables=2,
                            number_of_objectives=2,
                            number_of_constraints=1)
        solution.constraints[0] = -1

        self.assertEqual(False, is_feasible(solution))