def main() -> None: problem = ZDT1() 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=BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())) selection=BinaryTournament2Selection([ SolutionAttributeComparator("dominance_ranking"), SolutionAttributeComparator("crowding_distance", lowest_is_best=False) ])) 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()) logger.info("Computing time: " + str(algorithm.total_computing_time))
def test_should_constructor_create_a_valid_problem_with_default_settings(self) -> None: problem = ZDT1() self.assertEqual(30, problem.number_of_variables) self.assertEqual(2, problem.number_of_objectives) self.assertEqual(0, problem.number_of_constraints) self.assertEqual(30 * [0.0], problem.lower_bound) self.assertEqual(30 * [1.0], problem.upper_bound)
def test_should_create_solution_create_a_valid_float_solution(self) -> None: problem = ZDT1() solution = problem.create_solution() self.assertEqual(30, solution.number_of_variables) self.assertEqual(30, 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(30 * [0.0], problem.lower_bound) self.assertEqual(30 * [1.0], problem.upper_bound) self.assertTrue(all(value >= 0.0 for value in solution.variables)) self.assertTrue(all(value <= 1.0 for value in solution.variables))
def main() -> None: problem = ZDT1() 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=BinaryTournament(RankingAndCrowdingDistanceComparator())) selection = BinaryTournament2([SolutionAttributeComparator("dominance_ranking"), SolutionAttributeComparator("crowding_distance", lowest_is_best=False)])) observer = AlgorithmObserver(animation_speed=1*10e-8) algorithm.observable.register(observer=observer) algorithm.run() logger.info("Algorithm (continuous problem): " + algorithm.get_name()) logger.info("Problem: " + problem.get_name())
def main() -> None: problem = ZDT1() 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 = BinaryTournament(RankingAndCrowdingDistanceComparator())) observer = BasicAlgorithmConsumer(1000) algorithm.observable.register(observer=observer) 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()) logger.info("Computing time: " + str(algorithm.total_computing_time))
def test_should_constructor_create_a_non_null_object(self) -> None: problem = ZDT1() self.assertIsNotNone(problem)
def test_should_get_name_return_the_right_name(self): problem = ZDT1() self.assertEqual("ZDT1", problem.get_name())
# Solving SCH Problem using NSGAII from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.operator import SBXCrossover, PolynomialMutation from jmetal.util.termination_criterion import StoppingByEvaluations from jmetal.util.observer import ProgressBarObserver, VisualizerObserver from jmetal.lab.visualization import Plot, InteractivePlot from jmetal.problem.multiobjective.zdt import ZDT1 if __name__ == '__main__': problem = ZDT1() max_evaluations = 20000 algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=0.05, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) algorithm.observable.register(observer=VisualizerObserver( reference_front=problem.reference_front)) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(plot_title='Pareto front approximation', reference_front=problem.reference_front, axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label,