Пример #1
0
    def test_case3(self):
        """
        Case 3. Reference front: [[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]], front: [[1.0, 1.0, 1.0]]
        Expected result: the distance to the nearest point of the reference front is 0.0. Example with three objectives

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

        result = indicator.compute(front)

        self.assertEqual(0.0, result)
Пример #2
0
    def test_should_gd_return_0(self):
        solution1 = Solution(1, 3)
        solution1.objectives = [1, 0, 1]

        solution2 = Solution(1, 3)
        solution2.objectives = [0, 1, 0]

        reference_front = [solution1, solution2]

        gd = GenerationalDistance(reference_front)
        value = gd.compute(reference_front)

        self.assertEqual(0.0, value)
Пример #3
0
    def test_case1(self):
        """
        Case 1. Reference front: [[1.0, 1.0]], front: [[1.0, 1.0]]
        Expected result: the distance to the nearest point of the reference front is 0.0

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

        result = indicator.compute(front)

        self.assertEqual(0.0, result)
Пример #4
0
    def test_should_gd_return_the_closest_point_case_a(self):
        solution1 = Solution(1, 3)
        solution1.objectives = [1, 1, 1]

        solution2 = Solution(1, 3)
        solution2.objectives = [2, 2, 2]

        reference_front = [solution1, solution2]

        gd = GenerationalDistance(reference_front)
        value = gd.compute([solution1])

        self.assertEqual(0, value)
Пример #5
0
    def test_case5(self):
        """
        Case 5. reference front: [[1.0, 1.0], [2.1, 2.1]], front: [[1.5, 1.5]]
        Expected result: the distance to the nearest point of the reference front is the euclidean distance
        to the nearest point of the reference front ([1.0, 1.0])

        :return:
        """
        indicator = GenerationalDistance(np.array([[1.0, 1.0], [2.1, 2.1]]))
        front = np.array([[1.5, 1.5]])

        result = indicator.compute(front)

        self.assertEqual(np.sqrt(pow(1.0 - 1.5, 2) + pow(1.0 - 1.5, 2)), result)
        self.assertEqual(np.sqrt(pow(2.0 - 1.5, 2) + pow(2.0 - 1.5, 2)), result)
Пример #6
0
    def test_case6(self):
        """
        Case 6. reference front: [[1.0, 1.0], [2.1, 2.1]], front: [[1.5, 1.5], [2.2, 2.2]]
        Expected result: the distance to the nearest point of the reference front is the average of the sum of each point
        of the front to the nearest point of the reference front

        :return:
        """
        indicator = GenerationalDistance(np.array([[1.0, 1.0], [2.1, 2.1]]))
        front = np.array([[1.5, 1.5], [2.2, 2.2]])

        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.1 - 2.2, 2) + pow(2.1 - 2.2, 2))

        self.assertEqual((distance_of_first_point + distance_of_second_point) / 2.0, result)
Пример #7
0
 def test_get_short_name_return_the_right_value(self):
     self.assertEqual("GD", GenerationalDistance([]).get_short_name())
Пример #8
0
 def test_should_constructor_create_a_non_null_object(self) -> None:
     indicator = GenerationalDistance([])
     self.assertIsNotNone(indicator)
Пример #9
0
        for r, _, fl in os.walk(output_directory):
            for file in fl:
                if 'FUN' in file and prb in r:
                    with open(os.path.join(r, file), 'r') as f:
                        line = f.readline()
                        while line:
                            tokens = line.split()
                            fitness = [float(x) for x in tokens]
                            s = Solution(None, fitness)
                            population.append(s)
                            line = f.readline()

        population = non_dominated_population(population,
                                              maximize=False,
                                              filter_duplicate=False)
        # save to file
        pf_file = os.path.dirname(output_directory).join(prb + ".pf")
        with open(pf_file, 'w') as f:
            for s in population:
                f.write("".join([str(v) + "\t" for v in s.fitness]))
                f.write("\n")

    # Generate summary file
    generate_summary_from_experiment(
        input_dir=output_directory,
        quality_indicators=[
            GenerationalDistance(reference_front=output_directory),
            EpsilonIndicator(reference_front=output_directory),
            HyperVolume([0, 0])
        ])
Пример #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)