Exemple #1
0
 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
Exemple #2
0
    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
Exemple #3
0
        problem = CarBehindAndInFrontProblem(Goal_num, Configuration)
        """=================================算法参数设置============================"""
        max_evaluations = Configuration.maxIterations
        # StoppingEvaluator = StoppingByEvaluations(max_evaluations=max_evaluations, problem=problem)
        StoppingEvaluator = StoppingByEvaluations(
            max_evaluations=max_evaluations)

        algorithm = NSGAIII(
            target_pattern=goal_selection_flag,
            target_value_threshold=target_values,
            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=0.4, distribution_index=20),
            # selection=RouletteWheelSelection(),
            termination_criterion=StoppingEvaluator
            # 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()
Exemple #4
0
from jmetal.problem import DTLZ1
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)
Exemple #5
0
def dtlz_test(p: FloatProblemGD, label: str = '', experiment: int = 50):
    # problem.reference_front = read_solutions(filename='resources/reference_front/DTLZ2.3D.pf')

    max_evaluations = 25000

    # references = ReferenceDirectionFromSolution(p)
    algorithm = NSGA3C(
        problem=p,
        population_size=100,
        reference_directions=UniformReferenceDirectionFactory(p.instance_.n_obj, n_points=92),
        mutation=PolynomialMutation(probability=1.0 / p.number_of_variables, distribution_index=20),
        crossover=SBXCrossover(probability=1.0, distribution_index=30),
        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
    )
    bag = []
    total_time = 0
    for i in range(experiment):
        algorithm = NSGA3C(
            problem=p,
            population_size=92,
            reference_directions=UniformReferenceDirectionFactory(p.instance_.n_obj, n_points=91),
            mutation=PolynomialMutation(probability=1.0 / p.number_of_variables, distribution_index=20),
            crossover=SBXCrossover(probability=1.0, distribution_index=30),
            termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
        )
        progress_bar = ProgressBarObserver(max=max_evaluations)
        algorithm.observable.register(progress_bar)
        algorithm.run()
        total_time += algorithm.total_computing_time
        bag = bag + algorithm.get_result()
    print(len(bag))
    print('Total computing time:', total_time)
    print('Average time: ', str(total_time / experiment))
    print_solutions_to_file(bag, DIRECTORY_RESULTS + 'Solutions.bag._class_' + label + algorithm.label)
    ranking = FastNonDominatedRanking()

    ranking.compute_ranking(bag)
    front_ = ranking.get_subfront(0)
    print('Front 0 size : ', len(front_))
    alabels = []
    for obj in range(p.number_of_objectives):
        alabels.append('Obj-' + str(obj))
    plot_front = Plot(title='Pareto front approximation' + ' ' + label,
                      axis_labels=alabels)
    plot_front.plot(front_, label=label + 'F0 ' + algorithm.label,
                    filename=DIRECTORY_RESULTS + 'F0_class_' + 'original_' + label + algorithm.label,
                    format='png')
    class_fronts = [[], [], [], []]

    for s in front_:
        _class = problem.classifier.classify(s)
        if _class[0] > 0:
            class_fronts[0].append(s)
        elif _class[1] > 0:
            class_fronts[1].append(s)
        elif _class[2] > 0:
            class_fronts[2].append(s)
        else:
            class_fronts[3].append(s)
    print(len(class_fronts[0]), len(class_fronts[1]), len(class_fronts[2]), len(class_fronts[3]))

    _front = class_fronts[0] + class_fronts[1]
    if len(_front) == 0:
        _front = class_fronts[2] + class_fronts[3]
    print('Class : ', len(_front))
    # Save results to file
    print_solutions_to_file(_front, DIRECTORY_RESULTS + 'Class_F0' + label + algorithm.label)

    print(f'Algorithm: ${algorithm.get_name()}')
    print(f'Problem: ${p.get_name()}')

    plot_front = Plot(title=label + 'F_' + p.get_name(), axis_labels=alabels)
    plot_front.plot(_front, label=label + 'F_' + p.get_name(),
                    filename=DIRECTORY_RESULTS + 'Class_F0' + label + p.get_name(),
                    format='png')
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
problem = RecSysProblem(RS_or_EA="RS",
                        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',
Exemple #8
0
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)
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