Пример #1
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
Пример #2
0
        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
    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()}')
    print(f'Problem: ${problem.get_name()}')
    print(f'Computing time: ${algorithm.total_computing_time}')