Ejemplo n.º 1
0
def run_optimization(max_eval, num_nodes, pop_size, offspring, trial_name, year):

    os_fold = os_sep()
    if not os.path.exists('results' + os_fold + year):
        os.makedirs('results' + os_fold + year)

    multiprocessing.freeze_support()
    problem = cequal()
    max_evaluations = max_eval


    algorithm = NSGAII(
        population_evaluator=MultiprocessEvaluator(num_nodes),
        problem=problem,
        population_size=pop_size,
        offspring_population_size=offspring,
        mutation=PolynomialMutation(probability= 0.2, distribution_index=20),
        crossover=SBXCrossover(probability=0.8, distribution_index=20),
        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
        dominance_comparator=DominanceComparator()
    )

    algorithm.observable.register(ProgressBarObserver(max=max_evaluations))
    algorithm.observable.register(observer=BasicObserver())

    algorithm.run()
    print(os.getcwd())
    front = algorithm.get_result()

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time/3600))

    print_function_values_to_file(front, 'results' + os_fold + year + os_fold + 'OBJ_' + algorithm.get_name() + "_" + trial_name + '.txt')
    print_variables_to_file(front, 'results' + os_fold + year + os_fold + 'VAR_' + algorithm.get_name() + "_" + trial_name + '.txt')
Ejemplo n.º 2
0
        numpy.savetxt(file_name, violation_pattern_to_search,
                      fmt="%d")  # 保存为整数
        file_name = target_dir + '/pattern_count_' + str(round_index) + '.txt'
        numpy.savetxt(file_name, pattern_count, fmt="%d")  # 保存为整数
        """===============================实例化问题对象============================"""
        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()
Ejemplo n.º 3
0
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
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import SBXCrossover, PolynomialMutation
from jmetal.problem.multiobjective.zdt import ZDT1Modified
from jmetal.util.evaluator import MultiprocessEvaluator
from jmetal.util.solution import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
    problem = ZDT1Modified()

    max_evaluations = 100

    algorithm = NSGAII(population_evaluator=MultiprocessEvaluator(8),
                       problem=problem,
                       population_size=10,
                       offspring_population_size=10,
                       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))

    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)
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.operator import PolynomialMutation, SBXCrossover
from jmetal.problem.multiobjective.zdt import ZDT1Modified
from jmetal.util.evaluator import MultiprocessEvaluator
from jmetal.util.solution import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == "__main__":
    problem = ZDT1Modified()

    max_evaluations = 100

    algorithm = NSGAII(
        population_evaluator=MultiprocessEvaluator(8),
        problem=problem,
        population_size=10,
        offspring_population_size=10,
        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),
    )

    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)
Ejemplo n.º 6
0
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