Пример #1
0
def main() -> None:
    problem = ZDT1()
    algorithm = NSGAII[FloatSolution, List[FloatSolution]](
        problem=problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(1.0 / problem.number_of_variables,
                            distribution_index=20),
        crossover=SBX(1.0, distribution_index=20),
        #selection=BinaryTournamentSelection(RankingAndCrowdingDistanceComparator()))
        selection=BinaryTournament2Selection([
            SolutionAttributeComparator("dominance_ranking"),
            SolutionAttributeComparator("crowding_distance",
                                        lowest_is_best=False)
        ]))

    algorithm.run()
    result = algorithm.get_result()

    SolutionListOutput[FloatSolution].print_function_values_to_file(
        "FUN." + problem.get_name(), result)

    logger.info("Algorithm (continuous problem): " + algorithm.get_name())
    logger.info("Problem: " + problem.get_name())
    logger.info("Computing time: " + str(algorithm.total_computing_time))
Пример #2
0
 def __init__(self, maximum_size: int, reference_point: List[float]):
     super(CrowdingDistanceArchiveWithReferencePoint, self).__init__(
         maximum_size=maximum_size,
         reference_point=reference_point,
         comparator=SolutionAttributeComparator("crowding_distance",
                                                lowest_is_best=False),
         density_estimator=CrowdingDistance())
Пример #3
0
    def test_should_compare_works_properly_case4(self):
        """Case 4: solution1.attribute > solution2.attribute (highest is best)"""
        solution1 = Solution(1, 1)
        solution2 = Solution(1, 1)
        solution1.attributes["attribute"] = 1.0
        solution2.attributes["attribute"] = 0.0

        comparator = SolutionAttributeComparator("attribute", False)
        self.assertEqual(-1, comparator.compare(solution1, solution2))
def main() -> None:
    problem = ZDT1()
    algorithm = NSGAII[FloatSolution, List[FloatSolution]](
        problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(1.0/problem.number_of_variables, distribution_index=20),
        crossover=SBX(1.0, distribution_index=20),
        #selection=BinaryTournament(RankingAndCrowdingDistanceComparator()))
        selection = BinaryTournament2([SolutionAttributeComparator("dominance_ranking"),
                                       SolutionAttributeComparator("crowding_distance", lowest_is_best=False)]))

    observer = AlgorithmObserver(animation_speed=1*10e-8)
    algorithm.observable.register(observer=observer)

    algorithm.run()

    logger.info("Algorithm (continuous problem): " + algorithm.get_name())
    logger.info("Problem: " + problem.get_name())
Пример #5
0
    def __init__(self, maximum_size: int):
        super(CrowdingDistanceArchive, self).__init__(maximum_size)

        self.__non_dominated_solution_archive = NonDominatedSolutionListArchive[
            S]()
        self.__comparator = SolutionAttributeComparator("crowding_distance",
                                                        lowest_is_best=False)
        self.__crowding_distance = CrowdingDistance()
        self.solution_list = self.__non_dominated_solution_archive.get_solution_list(
        )
Пример #6
0
    def __init__(
        self,
        problem: Problem,
        reference_point: Solution,
        population_size: int,
        offspring_population_size: int,
        mutation: Mutation,
        crossover: Crossover,
        termination_criterion: TerminationCriterion = store.
        default_termination_criteria,
        population_generator: Generator = store.default_generator,
        population_evaluator: Evaluator = store.default_evaluator,
        dominance_comparator: Comparator = store.default_comparator,
    ):
        """This is an implementation of the Hypervolume Estimation Algorithm for Multi-objective Optimization
        proposed in:

        * J. Bader and E. Zitzler. HypE: An Algorithm for Fast Hypervolume-Based Many-Objective
        Optimization. TIK Report 286, Computer Engineering and Networks Laboratory (TIK), ETH
        Zurich, November 2008.

        It uses the Exact Hypervolume-based indicator formulation, which once computed, guides both
        the environmental selection and the binary tournament selection operator

        Please note that as per the publication above, the evaluator and replacement should not be changed
        anyhow. It also requires that Problem() has a reference_point with objective values defined, e.g.

        problem = ZDT1()
        reference_point = FloatSolution(problem.number_of_variables,problem.number_of_objectives, [0], [1])
        reference_point.objectives = [1., 1.]
        """

        selection = BinaryTournamentSelection(
            comparator=SolutionAttributeComparator(key="fitness",
                                                   lowest_is_best=False))
        self.ranking_fitness = RankingAndFitnessSelection(
            population_size,
            dominance_comparator=dominance_comparator,
            reference_point=reference_point)
        self.reference_point = reference_point
        self.dominance_comparator = dominance_comparator

        super(HYPE, self).__init__(
            problem=problem,
            population_size=population_size,
            offspring_population_size=offspring_population_size,
            mutation=mutation,
            crossover=crossover,
            selection=selection,
            termination_criterion=termination_criterion,
            population_evaluator=population_evaluator,
            population_generator=population_generator,
        )
Пример #7
0
    def test_should_execute_work_properly_case1(self):
        solution1 = Solution(3, 2)
        solution1.objectives = [2, 3]
        solution2 = Solution(3, 2)
        solution2.objectives = [1, 4]
        solution1.attributes["dominance_ranking"] = 1
        solution2.attributes["dominance_ranking"] = 1

        solution_list = [solution1, solution2]
        operator = BinaryTournament2Selection[Solution]([SolutionAttributeComparator("key")])
        selection1 = operator.execute(solution_list)

        self.assertTrue(1, selection1.attributes["dominance_ranking"])
Пример #8
0
    def __init__(
        self,
        problem: Problem,
        population_size: int,
        offspring_population_size: int,
        mutation: Mutation,
        crossover: Crossover,
        kappa: float,
        termination_criterion: TerminationCriterion = store.default_termination_criteria,
        population_generator: Generator = store.default_generator,
        population_evaluator: Evaluator = store.default_evaluator,
    ):
        """Epsilon IBEA implementation as described in

        * Zitzler, Eckart, and Simon Künzli. "Indicator-based selection in multiobjective search."
        In International Conference on Parallel Problem Solving from Nature, pp. 832-842. Springer,
        Berlin, Heidelberg, 2004.

        https://link.springer.com/chapter/10.1007/978-3-540-30217-9_84

        IBEA is a genetic algorithm (GA), i.e. it belongs to the evolutionary algorithms (EAs)
        family. The multi-objective search in IBEA is guided by a fitness associated to every solution,
        which is in turn controlled by a binary quality indicator. This implementation uses the so-called
        additive epsilon indicator, along with a binary tournament mating selector.

        :param problem: The problem to solve.
        :param population_size: Size of the population.
        :param mutation: Mutation operator (see :py:mod:`jmetal.operator.mutation`).
        :param crossover: Crossover operator (see :py:mod:`jmetal.operator.crossover`).
        :param kappa: Weight in the fitness computation.
        """

        selection = BinaryTournamentSelection(
            comparator=SolutionAttributeComparator(key="fitness", lowest_is_best=False)
        )
        self.kappa = kappa

        super(IBEA, self).__init__(
            problem=problem,
            population_size=population_size,
            offspring_population_size=offspring_population_size,
            mutation=mutation,
            crossover=crossover,
            selection=selection,
            termination_criterion=termination_criterion,
            population_evaluator=population_evaluator,
            population_generator=population_generator,
        )
Пример #9
0
    def __init__(self,
                 problem: Problem,
                 population_size: int,
                 offspring_population_size: int,
                 mutation: Mutation,
                 crossover: Crossover,
                 selection: Selection = BinaryTournamentSelection(MultiComparator([SolutionAttributeComparator(key = "fitness")])),
                 termination_criterion: TerminationCriterion = store.default_termination_criteria,
                 population_generator: Generator = store.default_generator,
                 population_evaluator: Evaluator = store.default_evaluator,
                 dominance_comparator: Comparator = store.default_comparator):

        super(MOGA, self).__init__(
            problem=problem,
            population_size=population_size,
            offspring_population_size=offspring_population_size,
            mutation=mutation,
            crossover=crossover,
            selection=selection,
            termination_criterion=termination_criterion,
            population_evaluator=population_evaluator,
            population_generator=population_generator
        )
        self.dominance_comparator = dominance_comparator
Пример #10
0
 def setUp(self):
     self.comparator = SolutionAttributeComparator("attribute")
Пример #11
0
 def get_comparator(cls) -> Comparator:
     return SolutionAttributeComparator("crowding_distance",
                                        lowest_is_best=False)
Пример #12
0
 def get_comparator(cls) -> Comparator:
     return SolutionAttributeComparator("knn_density", lowest_is_best=False)
Пример #13
0
 def __init__(self,
              maximum_size: int):
     super(CrowdingDistanceArchive, self).__init__(
         maximum_size=maximum_size,
         comparator=SolutionAttributeComparator("crowding_distance", lowest_is_best=False),
         density_estimator=CrowdingDistance())
Пример #14
0
 def get_comparator(cls) -> Comparator:
     return SolutionAttributeComparator('strength_ranking')
Пример #15
0
 def get_comparator(cls) -> Comparator:
     return SolutionAttributeComparator('dominance_ranking')