Exemple #1
0
    def test_should_the_solution_remain_unchanged_if_the_probability_is_zero(
            self):
        operator = PolynomialMutation(0.0)
        solution = FloatSolution(2, 1, [-5, -5, -5], [5, 5, 5])
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)
        self.assertEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Exemple #2
0
    def test_should_the_solution_change__if_the_probability_is_one(self):
        operator = PolynomialMutation(1.0)
        solution = FloatSolution([-5, -5, -5], [5, 5, 5], 2)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)

        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Exemple #3
0
    def test_should_execute_raise_and_exception_if_the_types_of_the_solutions_do_not_match_the_operators(
            self):
        operator = CompositeMutation(
            [PolynomialMutation(1.0, 5.0),
             PolynomialMutation(0.9, 25.0)])

        float_solution = FloatSolution([2.0], [3.9], 3)
        binary_solution = BinarySolution(1, 3, 0)
        float_solution.variables = [3.0]

        composite_solution = CompositeSolution(
            [float_solution, binary_solution])

        with self.assertRaises(InvalidConditionException):
            operator.execute(composite_solution)
Exemple #4
0
    def test_should_constructor_create_a_valid_operator_when_adding_a_single_mutation_operator(
            self):
        mutation: Mutation = PolynomialMutation(0.9, 20.0)

        operator = CompositeMutation([mutation])
        self.assertIsNotNone(operator)
        self.assertEqual(1, len(operator.mutation_operators_list))
Exemple #5
0
    def setUp(self) -> None:
        problem1 = OneMax(number_of_bits=512)

        self.emas1 = Emas(
            problem=problem1,
            initial_population_size=1000,
            initial_inidividual_energy=10,
            reproduction_threshold=20,
            energy_exchange_operator=FractionEnergyExchange(0.5),
            death_operator=ThresholdDeath(threshold=5, neighbours_operator=RandomNeighbours()),
            termination_criterion=StoppingByEvaluations(max_evaluations=100000),
            neighbours_operator=RandomNeighbours(),
            reproduction_operator=FractionEnergyReproduction(0.5, BitFlipMutation(0.5), SPXCrossover(0.5))
        )

        problem2 = Sphere(number_of_variables=10)
        self.emas2 = Emas(
            problem=problem2,
            initial_population_size=1000,
            initial_inidividual_energy=10,
            reproduction_threshold=20,
            energy_exchange_operator=FractionEnergyExchange(0.5),
            death_operator=ThresholdDeath(threshold=5, neighbours_operator=RandomNeighbours()),
            termination_criterion=StoppingByEvaluations(max_evaluations=50000),
            neighbours_operator=RandomNeighbours(),
            reproduction_operator=FractionEnergyReproduction(0.5, PolynomialMutation(0.5), SBXCrossover(0.5))
        )
Exemple #6
0
    def configurar_SMPSO(self):

        algorithm = SMPSO(
                problem=self.problema,
                swarm_size=self.maxima_poblacion,
                mutation=PolynomialMutation(probability=self.probabilidad, distribution_index=20),
                leaders=CrowdingDistanceArchive(100),
                termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones))
        return algorithm
Exemple #7
0
    def test_should_execute_work_with_a_solution_subclass_of_float_solution(
            self):
        class NewFloatSolution(FloatSolution):
            def __init__(self,
                         lower_bound: List[float],
                         upper_bound: List[float],
                         number_of_objectives: int,
                         number_of_constraints: int = 0):
                super(NewFloatSolution,
                      self).__init__(lower_bound, upper_bound,
                                     number_of_objectives,
                                     number_of_constraints)

        operator = PolynomialMutation(1.0)
        solution = NewFloatSolution([-5, -5, -5], [5, 5, 5], 2)
        solution.variables = [1.0, 2.0, 3.0]

        mutated_solution = operator.execute(solution)

        self.assertNotEqual([1.0, 2.0, 3.0], mutated_solution.variables)
Exemple #8
0
    def configurar_SPEA2(self):

        algorithm = SPEA2(
                problem=self.problema,
                population_size=self.maxima_poblacion,
                offspring_population_size=self.maxima_poblacion,
                mutation=PolynomialMutation(probability=self.probabilidad, distribution_index=0.20),
                crossover=SBXCrossover(probability=self.probabilidad, distribution_index=20),
                termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones),
                dominance_comparator=DominanceComparator())
        return algorithm
Exemple #9
0
 def configurar_NSGAIII(self):
     
     algorithm = NSGAIII(
             problem=self.problema,
             reference_directions = UniformReferenceDirectionFactory(5, n_points=91),
             population_size=self.maxima_poblacion,
             mutation=PolynomialMutation(probability = self.probabilidad , distribution_index=0.20),
             crossover=SBXCrossover(probability= self.probabilidad, distribution_index=20),
             termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones),
             dominance_comparator=DominanceComparator())
     return algorithm
Exemple #10
0
    def test_should_constructor_create_a_valid_operator_when_adding_two_mutation_operators(
            self):
        polynomial_mutation = PolynomialMutation(1.0, 20.0)
        bit_flip_mutation = BitFlipMutation(0.01)

        operator = CompositeMutation([polynomial_mutation, bit_flip_mutation])

        self.assertIsNotNone(operator)
        self.assertEqual(2, len(operator.mutation_operators_list))
        self.assertTrue(
            issubclass(operator.mutation_operators_list[0].__class__,
                       PolynomialMutation))
        self.assertTrue(
            issubclass(operator.mutation_operators_list[1].__class__,
                       BitFlipMutation))
    client = Client('192.168.213.3:8786')

    ncores = sum(client.ncores().values())
    print(f'{ncores} cores available on cluster')

    # creates the problem
    problem = ZDT1()

    # creates the algorithm
    max_evaluations = 25000

    algorithm = DistributedNSGAII(
        problem=problem,
        population_size=100,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=20),
        termination_criterion=StoppingByEvaluations(
            max_evaluations=max_evaluations),
        number_of_cores=ncores,
        client=client)

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver())

    algorithm.run()
    front = algorithm.get_result()

    print('Computing time: ' + str(algorithm.total_computing_time))
Exemple #12
0
 def test_should_constructor_raise_an_exception_if_the_probability_is_lower_than_zero(
         self):
     with self.assertRaises(Exception):
         PolynomialMutation(-12)
Exemple #13
0
 def test_should_constructor_raise_an_exception_if_the_probability_is_greater_than_one(
         self):
     with self.assertRaises(Exception):
         PolynomialMutation(2)
Exemple #14
0
 def test_should_constructor_create_a_valid_operator(self):
     operator = PolynomialMutation(0.5, 20)
     self.assertEqual(0.5, operator.probability)
     self.assertEqual(20, operator.distribution_index)
Exemple #15
0
 def test_should_constructor_create_a_non_null_object(self):
     mutation = PolynomialMutation(1.0)
     self.assertIsNotNone(mutation)
Exemple #16
0
 def test_should_constructor_raises_an_exception_is_probability_is_higher_than_one(
         self) -> None:
     with self.assertRaises(Exception):
         PolynomialMutation(1.01)
Exemple #17
0
 def test_should_constructor_raises_an_exception_is_probability_is_negative(
         self) -> None:
     with self.assertRaises(Exception):
         PolynomialMutation(-1)