コード例 #1
0
class SequentialEvaluatorTestCases(unittest.TestCase):
    def setUp(self):
        self.evaluator = SequentialEvaluator()
        self.problem = MockedProblem()

    def test_should_constructor_create_a_non_null_object(self):
        self.assertIsNotNone(self.evaluator)

    def test_should_evaluate_a_list_of_problem_work_properly_with_a_solution(
            self):
        problem_list = [self.problem.create_solution() for _ in range(1)]

        self.evaluator.evaluate(problem_list, self.problem)

        self.assertEqual(1.2, problem_list[0].objectives[0])
        self.assertEqual(2.3, problem_list[0].objectives[1])

    def test_should_evaluate_a_list_of_problem_work_properly(self):
        problem_list = [self.problem.create_solution() for _ in range(10)]

        self.evaluator.evaluate(problem_list, self.problem)

        for i in range(10):
            self.assertEqual(1.2, problem_list[i].objectives[0])
            self.assertEqual(2.3, problem_list[i].objectives[1])
コード例 #2
0
    def __init__(
            self,
            problem: Problem,
            mu: int,
            lambda_: int,
            elitist: bool,
            mutation: Mutation,
            termination_criterion: TerminationCriterion,
            population_generator: Generator = RandomGenerator(),
            population_evaluator: Evaluator = SequentialEvaluator(),
    ):
        super(EvolutionStrategy,
              self).__init__(problem=problem,
                             population_size=mu,
                             offspring_population_size=lambda_)
        self.mu = mu
        self.lambda_ = lambda_
        self.elitist = elitist

        self.mutation_operator = mutation

        self.population_generator = population_generator
        self.population_evaluator = population_evaluator

        self.termination_criterion = termination_criterion
        self.observable.register(termination_criterion)
コード例 #3
0
    def __init__(self,
                 problem: Problem,
                 initial_population_size: int,
                 initial_inidividual_energy: float,
                 reproduction_threshold: float,
                 energy_exchange_operator: EnergyExchange,
                 death_operator: Death,
                 termination_criterion: TerminationCriterion,
                 neighbours_operator: Neighbours,
                 reproduction_operator: Reproduction,
                 population_generator: Generator = RandomGenerator(),
                 population_evaluator: Evaluator = SequentialEvaluator()):

        super(Emas, self).__init__()
        self.reproduction_operator = reproduction_operator
        self.reproduction_threshold = reproduction_threshold
        self.initial_inidividual_energy = initial_inidividual_energy
        self.neighbours_operator = neighbours_operator
        self.problem = problem
        self.initial_population_size = initial_population_size
        self.population_generator = population_generator
        self.population_evaluator = population_evaluator
        self.termination_criterion = termination_criterion
        self.observable.register(termination_criterion)
        self.death_operator = death_operator
        self.energy_exchange_operator = energy_exchange_operator
コード例 #4
0
 def __init__(self,
              problem: Problem,
              mu: int,
              lambda_: int,
              elitist: bool,
              mutation: Mutation,
              termination_criterion: TerminationCriterion,
              population_generator: Generator = RandomGenerator(),
              population_evaluator: Evaluator = SequentialEvaluator()):
     super(EvolutionStrategyWithHistory,
           self).__init__(problem=problem,
                          mu=mu,
                          lambda_=lambda_,
                          elitist=elitist,
                          mutation=mutation,
                          termination_criterion=termination_criterion,
                          population_generator=population_generator,
                          population_evaluator=population_evaluator)
     self.history = []
コード例 #5
0
    def __init__(self,
                 problem: Problem,
                 population_size: int,
                 offspring_population_size: int,
                 mutation: Mutation,
                 cloning_param: float,
                 termination_criterion: TerminationCriterion,
                 population_generator: Generator = RandomGenerator(),
                 population_evaluator: Evaluator = SequentialEvaluator()):
        super(CloneAlg, self).__init__(
            problem=problem,
            population_size=population_size,
            offspring_population_size=offspring_population_size)
        self.population_size = population_size
        self.offspring_population_size = offspring_population_size

        self.mutation_operator = mutation
        self.cloning_param = cloning_param

        self.population_generator = population_generator
        self.population_evaluator = population_evaluator

        self.termination_criterion = termination_criterion
        self.observable.register(termination_criterion)
コード例 #6
0
    def __init__(self,
                 problem: Problem,
                 strategies_params: List[StrategyParams],
                 termination_criterion: TerminationCriterion,
                 population_generator: Generator = RandomGenerator(),
                 population_evaluator: Evaluator = SequentialEvaluator()):
        super(SocioCognitiveEvolutionStrategy, self).__init__()

        self.strategies = [EvolutionStrategy(problem=problem,
        mu=params.mu,
        lambda_=params.lambda_,
        elitist=params.elitist,
        mutation=CognitivePolynomialMutation(probability=1.0 / problem.number_of_variables, look_at_others_probability=params.look_at_others_probability),
        termination_criterion=termination_criterion) for params in strategies_params]

        self.problem = problem

        self.termination_criterion = termination_criterion
        self.observable.register(termination_criterion)

        self.population_generator = population_generator
        self.population_evaluator = population_evaluator

        self.history = []
コード例 #7
0
 def default_evaluator(self) -> Evaluator:
     return SequentialEvaluator()
コード例 #8
0
 def setUp(self):
     self.evaluator = SequentialEvaluator()
     self.problem = MockedProblem()
コード例 #9
0
        file_name = target_dir + '/violation_pattern_to_search_' + str(
            round_idx) + '.txt'
        numpy.savetxt(file_name, violation_pattern_to_search,
                      fmt="%d")  # 保存为整数
        file_name = target_dir + '/pattern_count_' + str(round_idx) + '.txt'
        numpy.savetxt(file_name, pattern_count, fmt="%d")  # 保存为整数
        """===============================实例化问题对象============================"""
        problem = CarBehindAndInFrontProblem(Goal_num, Configuration,
                                             target_value_threshold)
        """=================================算法参数设置============================"""
        max_evaluations = population * search_round
        # print(max_evaluations)

        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()
        )