Exemple #1
0
    def configurar_OMOPSO(self):


        algorithm = OMOPSO(
                problem=self.problema,
                swarm_size=self.maxima_poblacion,
                epsilon=0.0075,
                uniform_mutation=UniformMutation(probability=self.probabilidad, perturbation=0.5),
                non_uniform_mutation=NonUniformMutation(probability=self.probabilidad, perturbation=0.5),
                leaders=CrowdingDistanceArchive(100),
                termination_criterion=StoppingByEvaluations(max_evaluations=self.evaluaciones))
        return algorithm
    problem = ZDT1Modified()
    problem.reference_front = read_solutions(
        filename='../../resources/reference_front/{}.pf'.format(
            problem.get_name()))
    mutation_probability = 1.0 / problem.number_of_variables

    max_evaluations = 100
    swarm_size = 10
    algorithm = OMOPSO(
        problem=problem,
        swarm_size=swarm_size,
        epsilon=0.0075,
        uniform_mutation=UniformMutation(probability=mutation_probability,
                                         perturbation=0.5),
        non_uniform_mutation=NonUniformMutation(
            mutation_probability,
            perturbation=0.5,
            max_iterations=max_evaluations / swarm_size),
        leaders=CrowdingDistanceArchive(10),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        swarm_evaluator=SparkEvaluator(),
    )

    algorithm.run()
    front = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(
        front, 'FUN.' + algorithm.get_name() + "." + problem.get_name())
    print_variables_to_file(
        front, 'VAR.' + algorithm.get_name() + "." + problem.get_name())
Exemple #3
0
def get_algorithm_instance(algo_name):
    algos = {
        'smpso':
        SMPSO(problem=objective_function,
              swarm_size=swarm_size,
              mutation=PolynomialMutation(probability=mutation_probability,
                                          distribution_index=20),
              leaders=CrowdingDistanceArchive(100),
              termination_criterion=StoppingByEvaluations(
                  max_evaluations=max_evaluations)),
        'omopso':
        OMOPSO(problem=objective_function,
               swarm_size=swarm_size,
               epsilon=0.0075,
               uniform_mutation=UniformMutation(
                   probability=mutation_probability, perturbation=0.5),
               non_uniform_mutation=NonUniformMutation(
                   mutation_probability,
                   perturbation=0.5,
                   max_iterations=int(max_evaluations / swarm_size)),
               leaders=CrowdingDistanceArchive(100),
               termination_criterion=StoppingByEvaluations(
                   max_evaluations=max_evaluations)),
        'nsgaii':
        NSGAII(problem=objective_function,
               population_size=30,
               offspring_population_size=30,
               mutation=PolynomialMutation(probability=mutation_probability,
                                           distribution_index=20),
               crossover=SBXCrossover(probability=1.0, distribution_index=20),
               termination_criterion=StoppingByEvaluations(
                   max_evaluations=max_evaluations)),
        'spea2':
        SPEA2(problem=objective_function,
              population_size=30,
              offspring_population_size=30,
              mutation=PolynomialMutation(probability=mutation_probability,
                                          distribution_index=20),
              crossover=SBXCrossover(probability=1.0, distribution_index=20),
              termination_criterion=StoppingByEvaluations(
                  max_evaluations=max_evaluations)),
        'moead':
        MOEAD(
            problem=objective_function,
            population_size=30,
            crossover=DifferentialEvolutionCrossover(CR=1.0, F=0.5, K=0.5),
            mutation=PolynomialMutation(probability=mutation_probability,
                                        distribution_index=20),
            aggregative_function=Tschebycheff(
                dimension=objective_function.number_of_objectives),
            neighbor_size=5,
            neighbourhood_selection_probability=0.9,
            max_number_of_replaced_solutions=2,
            weight_files_path='resources/MOEAD_weights',
            termination_criterion=StoppingByEvaluations(max_evaluations=700)),
        'ibea':
        IBEA(problem=objective_function,
             kappa=1.0,
             population_size=30,
             offspring_population_size=30,
             mutation=PolynomialMutation(probability=mutation_probability,
                                         distribution_index=20),
             crossover=SBXCrossover(probability=1.0, distribution_index=20),
             termination_criterion=StoppingByEvaluations(max_evaluations))
    }
    return algos[algo_name]
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