예제 #1
0
    def test_should_add_work_properly_case6(self):
        """ Case 6: add a non-dominated solution when the archive is full should not include
        the solution if it has the highest distance crowding value.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [1.1, 1.9]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(4, archive.size())
        self.assertTrue(new_solution not in archive.solution_list)
예제 #2
0
    def test_should_compute_density_estimator_work_properly_case3(self):
        """ Case 3: The archive contains two solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)

        archive.compute_density_estimator()

        self.assertEqual(3, archive.size())
        self.assertEqual(float("inf"),
                         solution1.attributes["crowding_distance"])
        self.assertEqual(float("inf"),
                         solution3.attributes["crowding_distance"])
        self.assertTrue(
            solution2.attributes["crowding_distance"] < float("inf"))
예제 #3
0
    def test_should_add_work_properly_case7(self):
        """ Case 7: add a non-dominated solution when the archive is full should remove all the dominated solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [-1.0, -1.0]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(1, archive.size())
        self.assertTrue(new_solution in archive.solution_list)
예제 #4
0
    def test_should_add_work_properly_case7(self):
        """ Case 7: add a non-dominated solution when the archive is full should remove all the dominated solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [-1.0, -1.0]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(1, archive.size())
        self.assertTrue(new_solution in archive.solution_list)
예제 #5
0
    def test_should_add_work_properly_case6(self):
        """ Case 6: add a non-dominated solution when the archive is full should not include
        the solution if it has the highest distance crowding value.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]
        solution4 = Solution(2, 2)
        solution4.objectives = [3.0, 0.0]

        new_solution = Solution(2, 2)
        new_solution.objectives = [1.1, 1.9]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)
        archive.add(solution4)
        archive.add(new_solution)

        self.assertEqual(4, archive.size())
        self.assertTrue(new_solution not in archive.solution_list)
예제 #6
0
    def test_should_compute_density_estimator_work_properly_case1(self):
        """ Case 1: The archive contains one solution.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        archive.add(solution1)

        archive.compute_density_estimator()

        self.assertEqual(1, archive.size())
        self.assertEqual(float("inf"),
                         solution1.attributes["crowding_distance"])
예제 #7
0
def main() -> None:
    problem = Kursawe()
    algorithm = SMPSO(problem=problem,
                      swarm_size=100,
                      max_evaluations=25000,
                      mutation=Polynomial(1.0 / problem.number_of_variables,
                                          distribution_index=20),
                      leaders=CrowdingDistanceArchive(100))

    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())
예제 #8
0
    def test_should_compute_density_estimator_work_properly_case1(self):
        """ Case 1: The archive contains one solution.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        archive.add(solution1)

        archive.compute_density_estimator()

        self.assertEqual(1, archive.size())
        self.assertEqual(float("inf"), solution1.attributes["crowding_distance"])
예제 #9
0
    def test_should_compute_density_estimator_work_properly_case3(self):
        """ Case 3: The archive contains two solutions.
        """
        archive = CrowdingDistanceArchive(4)

        solution1 = Solution(2, 2)
        solution1.objectives = [0.0, 3.0]
        solution2 = Solution(2, 2)
        solution2.objectives = [1.0, 2.0]
        solution3 = Solution(2, 2)
        solution3.objectives = [2.0, 1.5]

        archive.add(solution1)
        archive.add(solution2)
        archive.add(solution3)

        archive.compute_density_estimator()

        self.assertEqual(3, archive.size())
        self.assertEqual(float("inf"), solution1.attributes["crowding_distance"])
        self.assertEqual(float("inf"), solution3.attributes["crowding_distance"])
        self.assertTrue(solution2.attributes["crowding_distance"] < float("inf"))
예제 #10
0
from jmetal.component.archive import CrowdingDistanceArchive
from jmetal.problem import ZDT1
from jmetal.operator import Polynomial
from jmetal.util.graphic import ScatterMatplotlib
from jmetal.util.solution_list_output import SolutionList

if __name__ == '__main__':
    problem = ZDT1()

    algorithm = SMPSO(problem=problem,
                      swarm_size=100,
                      max_evaluations=25000,
                      mutation=Polynomial(probability=1.0 /
                                          problem.number_of_variables,
                                          distribution_index=20),
                      leaders=CrowdingDistanceArchive(100))

    observer = VisualizerObserver(problem)
    progress_bar = ProgressBarObserver(step=100, maximum=25000)
    algorithm.observable.register(observer=observer)
    algorithm.observable.register(observer=progress_bar)

    algorithm.run()
    front = algorithm.get_result()

    # Plot frontier to file
    pareto_front = ScatterMatplotlib(
        plot_title='SMPSO for ' + problem.get_name(),
        number_of_objectives=problem.number_of_objectives)
    pareto_front.plot(front,
                      reference=problem.get_reference_front(),
예제 #11
0
algorithm = [(NSGAII, {
    'population_size':
    100,
    'max_evaluations':
    25000,
    'mutation':
    NullMutation(),
    'crossover':
    SBX(1.0, 20),
    'selection':
    BinaryTournamentSelection(RankingAndCrowdingDistanceComparator())
}),
             (NSGAII(population_size=100,
                     max_evaluations=25000,
                     mutation=NullMutation(),
                     crossover=SBX(1.0, 20),
                     selection=BinaryTournamentSelection(
                         RankingAndCrowdingDistanceComparator()),
                     problem=ZDT1()), {}),
             (SMPSO, {
                 'swarm_size': 100,
                 'max_evaluations': 25000,
                 'mutation': NullMutation(),
                 'leaders': CrowdingDistanceArchive(100)
             })]
metric = [HyperVolume(reference_point=[1, 1])]
problem = [(ZDT1, {}), (ZDT2, {})]

results = experiment(algorithm, metric, problem)
display(results)