Exemplo n.º 1
0
    def test_should_feasibility_ratio_return_zero_if_all_the_solutions_in_a_list_are_unfeasible(
            self) -> None:
        solution1 = Solution(2, 2, 2)
        solution2 = Solution(2, 2, 2)
        solution1.constraints[0] = 0
        solution1.constraints[1] = -1
        solution2.constraints[0] = -2
        solution2.constraints[1] = 0

        self.assertEqual(0, feasibility_ratio([solution1, solution2]))
Exemplo n.º 2
0
    def test_should_feasibility_ratio_return_the_right_percentage_of_feasible_solutions(
            self) -> None:
        solution1 = Solution(2, 2, 1)
        solution2 = Solution(2, 2, 1)
        solution3 = Solution(2, 2, 1)
        solution1.constraints[0] = -1
        solution2.constraints[0] = 0
        solution3.constraints[0] = -2

        self.assertEqual(1 / 3,
                         feasibility_ratio([solution1, solution2, solution3]))
Exemplo n.º 3
0
    def update_progress(self) -> None:
        super().update_progress()

        if self.evaluations % self.population_size == 0:
            self.update_external_archive()
            self.generation_counter += 1
            self.rk = feasibility_ratio(self.solutions)
            if self.generation_counter >= self.tc:
                self.epsilon_k = 0
            else:
                if self.rk < 0.95:
                    self.epsilon_k = (1 - self.tao) * self.epsilon_k
                else:
                    self.epsilon_k = self.phi_max * (1 + self.tao)
Exemplo n.º 4
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
Exemplo n.º 5
0
 def test_should_feasibility_ratio_raise_and_exception_if_the_solution_list_is_empty(
         self) -> None:
     with self.assertRaises(Exception):
         feasibility_ratio([])