crossover=SBX(probability=1.0, distribution_index=20),
                       selection=BinaryTournamentSelection(
                           comparator=RankingAndCrowdingDistanceComparator()))

    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='NSGAII for ZDT1',
        number_of_objectives=problem.number_of_objectives)
    pareto_front.plot(front,
                      reference=problem.get_reference_front(),
                      output='NSGAII-ZDT1',
                      show=False)

    # Save variables to file
    SolutionList.print_function_values_to_file(
        front, 'FUN.NSGAII.' + problem.get_name())
    SolutionList.print_variables_to_file(front,
                                         'VAR.NSGAII.' + problem.get_name())

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
        progress_bar = ProgressBarObserver(step=10, maximum=250)
        #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='NSGAII for IoT-Min', number_of_objectives=problem.number_of_objectives)
        #pareto_front.plot(front, reference=problem.get_reference_front(), output='NSGAII-IoT-Min', show=False)

        # Save variables to file
        SolutionList.print_function_values_to_file(
            front, 'FUN.NSGAII.' + problem.run_id + '.' + problem.get_name())
        SolutionList.print_variables_to_file(
            front, 'VAR.NSGAII.' + problem.run_id + '.' + problem.get_name())

        reference_point = [1, 1, 1, 1]
        hv = HyperVolume(reference_point)
        value = hv.compute(front)
        with open("HV." + problem.run_id + '.' + problem.get_name(),
                  "w") as text_file:
            print(f"{value}", file=text_file)
        print('Algorithm (binary problem): ' + algorithm.get_name())
        print('Problem: ' + problem.get_name())
        print('HyperVolume: %f' % value)
        print('Computing time: ' + str(algorithm.total_computing_time))
        problem.sf.plog.logError(
            'Repeated solutions:' +
            str(len(problem.sf.js_engine_helper.tested_solutions)) + '\n')
示例#3
0
    algorithm = NSGAII(
        problem=problem,
        population_size=100,
        max_evaluations=25000,
        mutation=Polynomial(probability=1.0 / problem.number_of_variables, distribution_index=20),
        crossover=SBX(probability=1.0, distribution_index=20),
        selection=BinaryTournamentSelection(comparator=RankingAndCrowdingDistanceComparator())
    )

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

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

    # Plot frontier to file
    pareto_front = FrontPlot(plot_title='NSGAII-ZDT1', axis_labels=problem.obj_labels)
    pareto_front.plot(front, reference_front=problem.reference_front)
    pareto_front.to_html(filename='NSGAII-ZDT1')

    # Save variables to file
    SolutionList.print_function_values_to_file(front, 'FUN.NSGAII.ZDT1')
    SolutionList.print_variables_to_file(front, 'VAR.NSGAII.ZDT1')

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))