Esempio n. 1
0
    def update(self, *args, **kwargs):
        problem = kwargs['PROBLEM']
        solutions = kwargs['SOLUTIONS']

        if solutions:
            if isinstance(problem, DynamicProblem):
                termination_criterion_is_met = kwargs.get(
                    'TERMINATION_CRITERIA_IS_MET', None)

                if termination_criterion_is_met:
                    if self.counter > 0:
                        igd = InvertedGenerationalDistance(self.last_front)
                        igd_value = igd.compute(solutions)
                    else:
                        igd_value = 1

                    if igd_value > 0.005:
                        self.fronts += solutions
                        self.plot_front.plot([self.fronts],
                                             label=[problem.get_name()],
                                             filename='{}/front-{}'.format(
                                                 self.directory, self.counter))

                    self.counter += 1
                    self.last_front = solutions
            else:
                self.plot_front.plot([solutions],
                                     filename='{}/front-{}'.format(
                                         self.directory, self.counter))
                self.counter += 1
    def replacement(self, population: List[S],
                    offspring_population: List[S]) -> List[List[S]]:

        ranking = StrengthRanking(self.dominance_comparator)
        density_estimator = KNearestNeighborDensityEstimator()

        r = RankingAndDensityEstimatorReplacement(ranking, density_estimator,
                                                  RemovalPolicyType.SEQUENTIAL)
        solutions = r.replace(population, offspring_population)
        front = get_non_dominated_solutions(solutions)
        objective1 = -1 / self.Uobjecive1 * np.array(
            [solution.objectives[0] for solution in front])
        objective2 = -1 / self.Uobjecive2 * np.array(
            [solution.objectives[1] for solution in front])
        HV = calculateHypervolume(list(zip(objective1, objective2)))
        print('Hypervolume;', HV)
        self.hypervolumeByGeneration.append(HV)
        # DO IGD calculation here
        IGD = InvertedGenerationalDistance(self.reference_front)
        igd = IGD.compute(
            list(
                zip(-np.array([solution.objectives[0] for solution in front]),
                    -np.array([solution.objectives[1]
                               for solution in front]))))
        print('IGD1:', igd)
        # obj1front=1/self.Uobjecive1*self.reference_front[:, 0]
        # obj2front=1/self.Uobjecive2*self.reference_front[:,1]
        # igd2 = calculateIGD(list(zip(objective1,objective2)), list(zip(obj1front,obj2front)))
        # print('IGD2:',igd2)
        self.IGDbyGeneration.append(igd)
        return solutions
Esempio n. 3
0
 def igd(true_front: NonDominatedSolutionsArchive,
         solution_list: List[Solution]) -> float:
     # prepare indicator
     array_true_front = ResultHandler.to_numpy_array(
         true_front.solution_list)
     indicator = InvertedGenerationalDistance(array_true_front)
     # calculate
     solutions = ResultHandler.to_numpy_array(solution_list)
     return indicator.compute(solutions)
Esempio n. 4
0
    def test_case1(self):
        """
        Case 1. Reference front: [[1.0, 1.0]], front: [[1.0, 1.0]]
        Expected result = 0.0
        Comment: simplest case

        :return:
        """
        indicator = InvertedGenerationalDistance(np.array([[1.0, 1.0]]))
        front = np.array([[1.0, 1.0]])

        result = indicator.compute(front)

        self.assertEqual(0.0, result)
Esempio n. 5
0
    def test_case5(self):
        """
        Case 5. reference front: [[1.0, 1.0], [2.1, 2.1]], front: [[1.5, 1.5], [2.2, 2.2], [1.9, 1.9]]
        Expected result: average of the sum of the distances of the points of the reference front to the front.
        Example with three objectives

        :return:
        """
        indicator = InvertedGenerationalDistance(np.array([[1.0, 1.0], [2.0, 2.0]]))
        front = np.array([[1.5, 1.5], [2.2, 2.2], [1.9, 1.9]])

        result = indicator.compute(front)
        distance_of_first_point = np.sqrt(pow(1.0 - 1.5, 2) + pow(1.0 - 1.5, 2))
        distance_of_second_point = np.sqrt(pow(2.0 - 1.9, 2) + pow(2.0 - 1.9, 2))

        self.assertEqual((distance_of_first_point + distance_of_second_point) / 2.0, result)
Esempio n. 6
0
    def test_case2(self):
        """
        Case 2. Reference front: [[1.0, 1.0], [2.0, 2.0], front: [[1.0, 1.0]]
        Expected result: average of the sum of the distances of the points of the reference front to the front

        :return:
        """
        indicator = InvertedGenerationalDistance(np.array([[1.0, 1.0], [2.0, 2.0]]))
        front = np.array([[1.0, 1.0]])

        result = indicator.compute(front)

        distance_of_first_point = np.sqrt(pow(1.0 - 1.0, 2) + pow(1.0 - 1.0, 2))
        distance_of_second_point = np.sqrt(pow(2.0 - 1.0, 2) + pow(2.0 - 1.0, 2))

        self.assertEqual((distance_of_first_point + distance_of_second_point) / 2.0, result)
Esempio n. 7
0
    def update(self, *args, **kwargs):
        problem = kwargs["PROBLEM"]
        solutions = kwargs["SOLUTIONS"]
        evaluations = kwargs["EVALUATIONS"]

        if solutions:
            if (evaluations % self.step) == 0:
                if isinstance(problem, DynamicProblem):
                    termination_criterion_is_met = kwargs.get(
                        "TERMINATION_CRITERIA_IS_MET", None)

                    if termination_criterion_is_met:
                        if self.counter > 0:
                            igd = InvertedGenerationalDistance(
                                np.array(
                                    [s.objectives for s in self.last_front]))
                            igd_value = igd.compute(
                                np.array([s.objectives for s in solutions]))
                        else:
                            igd_value = 1

                        if igd_value > 0.005:
                            self.fronts += solutions
                            self.plot_front.plot(
                                [self.fronts],
                                label=problem.get_name(),
                                filename=
                                f"{self.directory}/front-{evaluations}",
                            )
                        self.counter += 1
                        self.last_front = solutions
                else:
                    self.plot_front.plot(
                        [solutions],
                        label=f"{evaluations} evaluations",
                        filename=f"{self.directory}/front-{evaluations}",
                    )
                    self.counter += 1