from jmetal.algorithm.multiobjective.ibea import IBEA from jmetal.operator import SBXCrossover, PolynomialMutation from jmetal.problem import ZDT1 from jmetal.util.solution import read_solutions, print_function_values_to_file, print_variables_to_file from jmetal.util.termination_criterion import StoppingByEvaluations if __name__ == '__main__': problem = ZDT1() problem.reference_front = read_solutions( filename='resources/reference_front/ZDT1.pf') algorithm = IBEA(problem=problem, kappa=1., population_size=100, offspring_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(25000)) algorithm.run() front = algorithm.get_result() # Save results to file print_function_values_to_file(front, 'FUN.' + algorithm.label) print_variables_to_file(front, 'VAR.' + algorithm.label) print(f'Algorithm: ${algorithm.get_name()}') print(f'Problem: ${problem.get_name()}') print(f'Computing time: ${algorithm.total_computing_time}')
def configure_experiment(problems: dict, n_run: int): """Configures the experiments Args: problems (dict): The MEWpy optimization problem n_run (int): the number of runs of each MOEA Returns: a list of jobs """ from mewpy.optimization.jmetal.operators import UniformCrossoverOU, GrowMutationOU, ShrinkMutation, \ SingleMutationOU, MutationContainer crossover = UniformCrossoverOU(0.5, max_size=candidate_max_size) mutators = [] mutators.append(GrowMutationOU(1.0, max_size=candidate_max_size)) mutators.append(ShrinkMutation(1.0, min_size=candidate_max_size)) mutators.append(SingleMutationOU(1.0)) mutation = MutationContainer(0.3, mutators=mutators) jobs = [] for run in range(n_run): for problem_tag, problem in problems.items(): jobs.append( Job( algorithm=NSGAII( problem=problem, population_evaluator=MultiprocessEvaluator(N_CPU), population_size=100, offspring_population_size=100, mutation=mutation, crossover=crossover, termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations)), algorithm_tag='NSGAII', problem_tag=problem_tag, run=run, )) jobs.append( Job(algorithm=SPEA2( problem=problem, population_evaluator=MultiprocessEvaluator(N_CPU), population_size=100, offspring_population_size=100, mutation=mutation, crossover=crossover, termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations)), algorithm_tag='SPEA2', problem_tag=problem_tag, run=run)) jobs.append( Job( algorithm=IBEA( problem=problem, population_evaluator=MultiprocessEvaluator(N_CPU), kappa=1., population_size=100, offspring_population_size=100, mutation=mutation, crossover=crossover, termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations)), algorithm_tag='IBEA', problem_tag=problem_tag, run=run, )) return jobs