예제 #1
0
    def test_should_evaluate_work_properly_if_the_bitset_only_contains_ones(
            self):
        problem = OneMax(512)
        solution = problem.create_solution()
        solution.variables[0] = [True for i in range(problem.number_of_bits)]

        problem.evaluate(solution)
        self.assertEqual(512.0, solution.objectives[0])
예제 #2
0
def binary_example() -> None:
    bits = 256
    problem = OneMax(bits)
    algorithm = ElitistEvolutionStrategy[BinarySolution, BinarySolution]\
        (problem, mu=1, lambdA=10, max_evaluations= 5000, mutation_operator=BitFlip(1.0/bits))

    algorithm.run()
    result = algorithm.get_result()
    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables[0]))
    print("Fitness:  " + str(result.objectives[0]))
예제 #3
0
    def test_should_constructor_create_a_valid_problem_with_512_bits(self):
        problem = OneMax(512)
        self.assertEqual(1, problem.number_of_variables)
        self.assertEqual(1, problem.number_of_objectives)
        self.assertEqual(0, problem.number_of_constraints)

        self.assertEqual(512, problem.number_of_bits)
예제 #4
0
    def test_should_constructor_create_a_valid_problem_with_default_settings(
            self):
        problem = OneMax()
        self.assertEqual(1, problem.number_of_variables)
        self.assertEqual(1, problem.number_of_objectives)
        self.assertEqual(0, problem.number_of_constraints)

        self.assertEqual(256, problem.number_of_bits)
예제 #5
0
 def test_should_get_name_return_the_right_name(self):
     problem = OneMax()
     self.assertEqual("OneMax", problem.get_name())
예제 #6
0
    def test_should_create_solution_a_valid_binary_solution(self):
        problem = OneMax(256)
        solution = problem.create_solution()

        self.assertEqual(256, len(solution.variables[0]))
예제 #7
0
 def test_should_constructor_create_a_non_null_object(self):
     problem = OneMax()
     self.assertIsNotNone(problem)