def test_should_create_solution_create_a_valid_float_solution(self) -> None: problem = Kursawe(3) solution = problem.create_solution() self.assertEqual(3, solution.number_of_variables) self.assertEqual(3, len(solution.variables)) self.assertEqual(2, solution.number_of_objectives) self.assertEqual(2, len(solution.objectives)) self.assertEqual(0, problem.number_of_constraints) self.assertEqual([-5.0, -5.0, -5.0], problem.lower_bound) self.assertEqual([5.0, 5.0, 5.0], problem.upper_bound) self.assertTrue(all(variable >= -5.0 for variable in solution.variables)) self.assertTrue(all(variable <= 5.0 for variable in solution.variables))
def test_should_constructor_create_a_valid_problem_with_default_settings(self) -> None: problem = Kursawe() self.assertEqual(3, problem.number_of_variables) self.assertEqual(2, problem.number_of_objectives) self.assertEqual(0, problem.number_of_constraints) self.assertEqual([-5.0, -5.0, -5.0], problem.lower_bound) self.assertEqual([5.0, 5.0, 5.0], problem.upper_bound)
def main() -> None: problem = Kursawe() algorithm = NSGAII[FloatSolution, List[FloatSolution]]( problem=problem, population_size=100, max_evaluations=25000, mutation=Polynomial(1.0/problem.number_of_variables, distribution_index=20), crossover=SBX(1.0, distribution_index=20), selection = BinaryTournament(RankingAndCrowdingDistanceComparator())) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].print_function_values_to_file("FUN."+problem.get_name(), result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
def main() -> None: problem = Kursawe() algorithm = SMPSO(problem=problem, swarm_size=100, max_evaluations=25000, mutation=Polynomial(1.0 / problem.number_of_variables, distribution_index=20), leaders=CrowdingDistanceArchive(100)) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].print_function_values_to_file( "FUN." + problem.get_name(), result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
def main() -> None: problem = Kursawe() algorithm = NSGAII[FloatSolution, List[FloatSolution]]( problem, population_size=100, max_evaluations=25000, mutation=Polynomial(1.0 / problem.number_of_variables, distribution_index=20), crossover=SBX(1.0, distribution_index=20), selection=BinaryTournamentSelection()) algorithm.run() result = algorithm.get_result() SolutionListOutput[FloatSolution].plot_scatter_to_file(result, file_name="FUN." + problem.get_name(), output_format='eps', dpi=200) SolutionListOutput[FloatSolution].plot_scatter_to_screen(result) logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
def test_should_get_name_return_the_right_name(self): problem = Kursawe() self.assertEqual("Kursawe", problem.get_name())
def test_should_constructor_create_a_non_null_object(self) -> None: problem = Kursawe(3) self.assertIsNotNone(problem)