Пример #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
Пример #2
0
    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
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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
Пример #8
0
 def test_get_short_name_return_the_right_value(self):
     self.assertEqual("IGD", InvertedGenerationalDistance([]).get_short_name())
Пример #9
0
 def test_should_constructor_create_a_non_null_object(self) -> None:
     indicator = InvertedGenerationalDistance([])
     self.assertIsNotNone(indicator)
Пример #10
0
from jmetal.core.quality_indicator import GenerationalDistance, InvertedGenerationalDistance, HyperVolume
import numpy as np
import os

file_folder_orgin = os.path.abspath(os.path.join(os.getcwd(), ".."))
var_file = file_folder_orgin + "/FUN.NSGAII.OvertakeProblem"
solution_file = file_folder_orgin + "/VAR.NSGAII.OvertakeProblem"

var = np.loadtxt(var_file)
solution = np.loadtxt(solution_file)

# print(var, solution)

indicator1 = GenerationalDistance(solution)
GD = indicator1.compute(solution)
print(GD)
indicator1 = InvertedGenerationalDistance(solution)
GD = indicator1.compute(solution)
print(GD)
Пример #11
0
                        termination_criterion=StoppingByEvaluationsCustom(max_evaluations=max_evaluations,
                                                                          reference_point=REFERENCE_POINT,
                                                                          AlgorithmName='SMPSO')
                    ),
                    algorithm_tag='SMPSO',
                    problem_tag=problem_tag,
                    run=run,
                )
            )
    return jobs


if __name__ == '__main__':
    # Configure the experiments
    jobs = configure_experiment(problems={'OTN': problemOTN}, n_run=TIMES_TO_RUN)

    # Run the study
    output_directory = 'data'
    experiment = Experiment(output_dir=output_directory, jobs=jobs)
    experiment.run()

    Filter.RemovePenalty(output_directory)

    # Reference fronts is the folder where is the reference to be compared with.
    generate_summary_from_experiment(
        input_dir=output_directory,
        reference_fronts='C:\\Users\\aryss\\Documents\\Repositories\\OTN_Mastering\\Output\\CT3\\8 services',
        quality_indicators=[InvertedGenerationalDistance(), EpsilonIndicator(), HyperVolume(REFERENCE_POINT)]
        #quality_indicators = [HyperVolume(REFERENCE_POINT)]
    )