from jmetal.algorithm.multiobjective.random_search import RandomSearch 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') max_evaluations = 1000 algorithm = RandomSearch(problem=problem, termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations)) 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}')
algorithm = NSGAIII( population_evaluator=MultiprocessEvaluator(Configuration.ProcessNum), problem=problem, population_size = Configuration.population, reference_directions=UniformReferenceDirectionFactory(Configuration.goal_num, n_points= Configuration.population - 1), # offspring_population_size = Configuration.population, 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) # termination_criterion = StoppingByQualityIndicator(quality_indicator=HyperVolume, expected_value=1, # degree=0.9) # selection = BinaryTournamentSelection() ) elif Configuration.algorithm == 'Random': algorithm = RandomSearch( problem=problem, termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations) ) """==========================调用算法模板进行种群进化=========================""" progress_bar = ProgressBarObserver(max=max_evaluations) algorithm.observable.register(progress_bar) algorithm.run() front = algorithm.get_result() """==================================输出结果==============================""" # Save results to file print_function_values_to_file(front, os.path.join(target_dir, '/FUN.' + algorithm.label)) print_variables_to_file(front, os.path.join(target_dir, '/VAR.' + algorithm.label)) print(f'Algorithm: ${algorithm.get_name()}')
def configurar_RandomSearch(self): algorithm = RandomSearch( problem = self.problema, termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones)) return algorithm
from jmetal.lab.visualization import Plot, InteractivePlot from jmetal.problem import ZDT1 from jmetal.util.observer import ProgressBarObserver, VisualizerObserver from jmetal.util.solutions_utils 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') max_evaluations = 1000 algorithm = RandomSearch( problem=problem, termination_criterion=StoppingByEvaluations(max=max_evaluations)) progress_bar = ProgressBarObserver(max=max_evaluations) algorithm.observable.register(observer=progress_bar) 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,