def configurar_NSGAIII(self): algorithm = NSGAIII( problem=self.problema, reference_directions = UniformReferenceDirectionFactory(5, n_points=91), population_size=self.maxima_poblacion, mutation=PolynomialMutation(probability = self.probabilidad , distribution_index=0.20), crossover=SBXCrossover(probability= self.probabilidad, distribution_index=20), termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones), dominance_comparator=DominanceComparator()) return algorithm
def _run_mo(self): """ Runs a multi objective EA optimization """ self.ea_problem.reset_initial_population_counter() if self.algorithm_name in moea_map.keys(): f = moea_map[self.algorithm_name] else: if self.ea_problem.number_of_objectives > 2: self.algorithm_name == 'NSGAIII' else: f = moea_map['SPEA2'] args = { 'problem': self.ea_problem, 'population_size': self.population_size, 'mutation': self.mutation, 'crossover': self.crossover, 'termination_criterion': StoppingByEvaluations(max_evaluations=self.max_evaluations) } if self.mp: args['population_evaluator'] = get_evaluator(self.ea_problem) print(f"Running {self.algorithm_name}") if self.algorithm_name == 'NSGAIII': args['reference_directions'] = UniformReferenceDirectionFactory(self.ea_problem.number_of_objectives, n_points=self.population_size-1) algorithm = NSGAIII(**args) else: args['offspring_population_size'] = self.population_size algorithm = f(**args) if self.visualizer: algorithm.observable.register(observer=VisualizerObserver()) algorithm.observable.register(observer=PrintObjectivesStatObserver()) algorithm.run() result = algorithm.solutions return result
Configuration = CarBehindAndInFrontConfigure(target_dir) Goal_num = Configuration.goal_num """===============================实例化问题对象============================""" problem = CarBehindAndInFrontProblem(Goal_num, Configuration) """=================================算法参数设置============================""" max_evaluations = Configuration.maxIterations algorithm = NSGAIII( population_evaluator=MultiprocessEvaluator(Configuration.ProcessNum), # population_evaluator=SequentialEvaluator(), 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() ) """==========================调用算法模板进行种群进化=========================""" progress_bar = ProgressBarObserver(max=max_evaluations) algorithm.observable.register(progress_bar) algorithm.run() front = algorithm.get_result() """==================================输出结果==============================""" # Save results to file
from jmetal.util.observer import ProgressBarObserver from jmetal.util.solutions import read_solutions from jmetal.util.termination_criterion import StoppingByEvaluations if __name__ == '__main__': problem = DTLZ1() problem.reference_front = read_solutions( filename='esources/reference_front/DTLZ1.3D.pf') max_evaluations = 25000 algorithm = NSGAIII( problem=problem, population_size=92, reference_directions=UniformReferenceDirectionFactory(3, n_points=91), mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=30), termination_criterion=StoppingByEvaluations(max=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) algorithm.run() front = algorithm.get_result() # Plot front plot_front = Plot(plot_title='Pareto front approximation', axis_labels=problem.obj_labels) plot_front.plot(front, label=algorithm.label)
from jmetal.problem import DTLZ1 from jmetal.util.comparator import RankingAndCrowdingDistanceComparator from jmetal.util.observer import ProgressBarObserver, VisualizerObserver from jmetal.util.solution_list import read_solutions, print_function_values_to_file, print_variables_to_file from jmetal.util.termination_criterion import StoppingByEvaluations from jmetal.util.visualization import Plot, InteractivePlot if __name__ == '__main__': problem = DTLZ1() problem.reference_front = read_solutions(filename='../../resources/reference_front/DTLZ1.3D.pf') max_evaluations = 10000 algorithm = NSGAIII( problem=problem, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator()), 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, display_frequency=1000)) algorithm.run() front = algorithm.get_result() label = algorithm.get_name() + "." + problem.get_name() algorithm_name = label # Plot front
def configure_experiment(problems: dict, n_run: int): jobs = [] num_processes = config.num_cpu population = 10 generations = 10 max_evaluations = population * generations for run in range(n_run): for problem_tag, problem in problems.items(): reference_point = FloatSolution([0, 0], [1, 1], problem.number_of_objectives, ) reference_point.objectives = np.repeat(1, problem.number_of_objectives).tolist() jobs.append( Job( algorithm=NSGAIII( problem=problem, population_size=population, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), population_evaluator=MultiprocessEvaluator(processes=num_processes), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), reference_directions=UniformReferenceDirectionFactory(4, n_points=100), ), algorithm_tag='NSGAIII', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=GDE3( problem=problem, population_size=population, population_evaluator=MultiprocessEvaluator(processes=num_processes), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), cr=0.5, f=0.5, ), algorithm_tag='GDE3', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=SPEA2( problem=problem, population_size=population, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), population_evaluator=MultiprocessEvaluator(processes=num_processes), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), offspring_population_size=population, ), algorithm_tag='SPEA2', problem_tag=problem_tag, run=run, ) ) return jobs
models=["CF-user_rec", "CF-user_artist"], metrics=['MAR', 'Cov', 'Pers', 'Nov'], year=2008, k=10, K=10, set_=1) population_size = 10 max_generations = 2 max_evaluations = population_size * max_generations algorithm = NSGAIII( problem=problem, population_size=population_size, reference_directions=UniformReferenceDirectionFactory( problem.number_of_objectives, n_points=50), mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), population_evaluator=MultiprocessEvaluator(processes=num_cpu), termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations)) algorithm.observable.register(observer=ProgressBarObserver( max=max_evaluations)) # algorithm.observable.register( # observer=VisualizerObserver(reference_front=problem.reference_front, display_frequency=100)) algorithm.run() front = algorithm.get_result() print(front) plot_front = Plot(title='Pareto front approximation', reference_front=problem.reference_front,
import numpy as np from jmetal.algorithm.multiobjective.moead import MOEAD from extract_data import create, keep_trace1 import numpy as np import statistics solutions = [] problem = MOOC() all2 = np.zeros([31, 5]) all3 = [] print(all2) algorithm1 = NSGAIII( problem=problem, population_size=174, #offspring_population_size=400, reference_directions=UniformReferenceDirectionFactory(5, n_points=180), mutation=IntegerPolynomialMutation(probability=1 / problem.number_of_variables, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.9, distribution_index=20), termination_criterion=StoppingByEvaluations(max_evaluations=25000)) progress_bar = ProgressBarObserver(max=25000) algorithm1.observable.register(progress_bar) print("NSGAiii") def transform(): for i in range(2): print(i) algorithm1.run()
def configure_experiment(problems: dict, n_run: int): jobs = [] for run in range(n_run): for problem_tag, problem in problems.items(): jobs.append( Job( algorithm=NSGAII( problem=problem, population_size=POPULATION_SIZE, offspring_population_size=POPULATION_SIZE, mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='NSGAII') # termination_criterion=stopCriterion ), algorithm_tag='NSGAII', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=NSGAIII( problem=problem, population_size=POPULATION_SIZE, mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20), reference_directions=UniformReferenceDirectionFactory(2, n_points=91), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='NSGAIII') # termination_criterion=stopCriterion ), algorithm_tag='NSGAIII', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=SPEA2( problem=problem, population_size=POPULATION_SIZE, offspring_population_size=POPULATION_SIZE, mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='SPEA2') ), algorithm_tag='SPEA2', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=HYPE( problem=problem, reference_point=reference_point, population_size=POPULATION_SIZE, offspring_population_size=POPULATION_SIZE, mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='HYPE') ), algorithm_tag='HYPE', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=MOCell( problem=problem, population_size=POPULATION_SIZE, neighborhood=C9(4, 4), archive=CrowdingDistanceArchive(100), mutation=IntegerPolynomialMutation(probability=0.05, distribution_index=20), crossover=IntegerSBXCrossover(probability=0.3, distribution_index=20), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='MOCell') ), algorithm_tag='MOCELL', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=OMOPSO( problem=problem, swarm_size=swarm_size, epsilon=0.0075, uniform_mutation=UniformMutation(probability=0.05, perturbation=0.5), non_uniform_mutation=NonUniformMutation(mutation_probability, perturbation=0.5, max_iterations=int(max_evaluations / swarm_size)), leaders=CrowdingDistanceArchive(10), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='OMOPSO') ), algorithm_tag='OMOPSO', problem_tag=problem_tag, run=run, ) ) jobs.append( Job( algorithm=SMPSO( problem=problem, swarm_size=POPULATION_SIZE, mutation=PolynomialMutation(probability=0.05, distribution_index=20), leaders=CrowdingDistanceArchive(20), termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations, reference_point=REFERENCE_POINT, AlgorithmName='SMPSO') ), algorithm_tag='SMPSO', problem_tag=problem_tag, run=run, ) ) return jobs