Example #1
0
class PlotFrontToFileObserver(Observer):
    def __init__(self, output_directory: str) -> None:
        self.directory = output_directory
        self.plot_front = Plot(plot_title='Pareto front approximation')
        self.last_front = []
        self.fronts = []
        self.counter = 0

        if Path(self.directory).is_dir():
            LOGGER.warning('Directory {} exists. Removing contents.'.format(
                self.directory))
            for file in os.listdir(self.directory):
                os.remove('{0}/{1}'.format(self.directory, file))
        else:
            LOGGER.warning('Directory {} does not exist. Creating it.'.format(
                self.directory))
            Path(self.directory).mkdir(parents=True)

    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
Example #2
0
    def __init__(self, output_directory: str) -> None:
        self.directory = output_directory
        self.plot_front = Plot(plot_title='Pareto front approximation')
        self.last_front = []
        self.fronts = []
        self.counter = 0

        if Path(self.directory).is_dir():
            LOGGER.warning('Directory {} exists. Removing contents.'.format(
                self.directory))
            for file in os.listdir(self.directory):
                os.remove('{0}/{1}'.format(self.directory, file))
        else:
            LOGGER.warning('Directory {} does not exist. Creating it.'.format(
                self.directory))
            Path(self.directory).mkdir(parents=True)
Example #3
0
            comparator=RankingAndCrowdingDistanceComparator()),
        dominance_comparator=GDominanceComparator(reference_point),
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(
        observer=VisualizerObserver(reference_front=problem.reference_front,
                                    reference_point=(reference_point)))

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

    # Plot front
    plot_front = Plot(plot_title='Pareto front approximation',
                      axis_labels=problem.obj_labels,
                      reference_point=reference_point,
                      reference_front=problem.reference_front)
    plot_front.plot(front, label='gNSGAII-ZDT1', filename='gNSGAII-ZDT1')

    # Plot interactive front
    plot_front = InteractivePlot(plot_title='Pareto front approximation',
                                 axis_labels=problem.obj_labels,
                                 reference_point=reference_point,
                                 reference_front=problem.reference_front)
    plot_front.plot(front, label='gNSGAII-ZDT1', filename='gNSGAII-ZDT1')

    # Save results to file
    print_function_values_to_file(
        front, 'FUN.' + algorithm.get_name() + "." + problem.get_name())
    print_variables_to_file(
        front, 'VAR.' + algorithm.get_name() + "." + problem.get_name())
Example #4
0
            comparator=RankingAndCrowdingDistanceComparator()),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        dominance_comparator=DominanceComparator())

    algorithm.observable.register(observer=ProgressBarObserver(
        max=max_evaluations))
    algorithm.observable.register(observer=VisualizerObserver(
        reference_front=problem.reference_front))

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

    label = algorithm.get_name() + "." + problem.get_name()
    algorithm_name = label
    # Plot front
    plot_front = Plot(plot_title='Pareto front approximation',
                      axis_labels=problem.obj_labels)
    plot_front.plot(front, label=label, filename=algorithm_name)

    # Plot interactive front
    plot_front = InteractivePlot(plot_title='Pareto front approximation',
                                 axis_labels=problem.obj_labels)
    plot_front.plot(front, label=label, filename=algorithm_name)

    # Save results to file
    print_function_values_to_file(front, 'FUN.' + label)
    print_variables_to_file(front, 'VAR.' + label)

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
Example #5
0
                                    problem.number_of_variables,
                                    distribution_index=20),
        reference_points=reference_point,
        leaders=archives_with_reference_points,
        termination_criterion=StoppingByEvaluations(max=max_evaluations))

    algorithm.observable.register(
        observer=VisualizerObserver(reference_front=problem.reference_front,
                                    reference_point=reference_point))

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

    # Plot front
    plot_front = Plot(plot_title='SMPSORP-ZDT1',
                      reference_front=problem.reference_front,
                      reference_point=algorithm.reference_points,
                      axis_labels=problem.obj_labels)
    plot_front.plot(algorithm.get_result(), filename='SMPSORP-ZDT1')

    # Plot interactive front
    plot_front = InteractivePlot(plot_title='SMPSORP-ZDT1',
                                 reference_front=problem.reference_front,
                                 reference_point=algorithm.reference_points,
                                 axis_labels=problem.obj_labels)
    plot_front.plot(front, filename='SMPSORP-ZDT1')

    # Save results to file
    print_function_values_to_file(
        front, 'FUN.' + algorithm.get_name() + "." + problem.get_name())
    print_variables_to_file(
        front, 'VAR.' + algorithm.get_name() + "." + problem.get_name())
Example #6
0
                                                  distribution_index=20),
                      leaders=CrowdingDistanceArchive(100),
                      termination_criterion=StoppingByEvaluations(max=25000))

    algorithm.observable.register(observer=ProgressBarObserver(max=25000))

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

    # Plot front
    label = '{}-{} with {} objectives'.format(algorithm.get_name(),
                                              problem.get_name(),
                                              problem.number_of_objectives)

    plot_front = Plot(plot_title='Pareto front approximation',
                      reference_front=problem.reference_front,
                      axis_labels=problem.obj_labels)
    plot_front.plot(front, label=label, filename=label)

    # Plot interactive front
    plot_front = InteractivePlot(plot_title='Pareto front approximation',
                                 reference_front=problem.reference_front,
                                 axis_labels=problem.obj_labels)
    plot_front.plot(front, label=label, filename=label, normalize=True)

    # Save variables to file
    print_function_values_to_file(front, 'FUN-' + label)
    print_variables_to_file(front, 'VAR-' + label)

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())