示例#1
0
                problem=problem,
                termination_criterion=StoppingByEvaluations(
                    max_evaluations=max_evaluations))
        """==========================调用算法模板进行种群进化========================="""
        # progress_bar = ProgressBarObserver(max=max_evaluations)
        # algorithm.observable.register(progress_bar)
        algorithm.run()
        front = algorithm.get_result()
        """==================================输出结果=============================="""
        file_name = target_dir + '/searched_violation_pattern_' + str(
            round_index) + '.txt'
        numpy.savetxt(file_name, searched_violation_pattern, fmt="%d")  # 保存为整数
        file_name = target_dir + '/violation_pattern_ranking_removed_' + str(
            round_index) + '.txt'
        numpy.savetxt(file_name, violation_pattern_ranking_removed,
                      fmt="%d")  # 保存为整数

        # Save results to file
        fun_name = 'FUN.' + str(round_index) + '_' + algorithm.label
        print_function_values_to_file(front,
                                      os.path.join(target_dir, fun_name))
        var_name = 'VAR.' + str(round_index) + '_' + algorithm.label
        print_variables_to_file(front, os.path.join(target_dir, var_name))

        print(f'Algorithm: ${algorithm.get_name()}')
        print(f'Problem: ${problem.get_name()}')
        print(f'Computing time: ${algorithm.total_computing_time}')

        # print(search_round,round_index,total_search_round)
        round_index = round_index + 1
示例#2
0
        reference_front=problem.reference_front, display_frequency=100))

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

    # Plot front
    plot_front = Plot(title='Pareto front approximation. Problem: ' +
                      problem.get_name(),
                      reference_front=problem.reference_front,
                      axis_labels=problem.obj_labels)
    plot_front.plot(front,
                    label=algorithm.label,
                    filename=algorithm.get_name())

    # Plot interactive front
    plot_front = InteractivePlot(
        title='Pareto front approximation. Problem: ' + problem.get_name(),
        reference_front=problem.reference_front,
        axis_labels=problem.obj_labels)
    plot_front.plot(front,
                    label=algorithm.label,
                    filename=algorithm.get_name())

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

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
示例#3
0
if __name__ == "__main__":
    problem = LZ09_F2()

    problem.reference_front = read_solutions(filename="resources/reference_front/LZ09_F2.pf")

    max_evaluations = 150000

    algorithm = MOEAD(
        problem=problem,
        population_size=300,
        crossover=DifferentialEvolutionCrossover(CR=1.0, F=0.5),
        mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20),
        aggregative_function=Tschebycheff(dimension=problem.number_of_objectives),
        neighbor_size=20,
        neighbourhood_selection_probability=0.9,
        max_number_of_replaced_solutions=2,
        weight_files_path="resources/MOEAD_weights",
        termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
    )

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

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

    print(f"Algorithm: {algorithm.get_name()}")
    print(f"Problem: {problem.get_name()}")
    print(f"Computing time: {algorithm.total_computing_time}")
示例#4
0
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == "__main__":
    problem = Rastrigin(10)

    max_evaluations = 100000

    algorithm = SimulatedAnnealing(
        problem=problem,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20.0),
        termination_criterion=StoppingByEvaluations(
            max_evaluations=max_evaluations),
    )

    algorithm.run()
    result = algorithm.get_result()

    # Save results to file
    print_function_values_to_file(
        result, "FUN." + algorithm.get_name() + "." + problem.get_name())
    print_variables_to_file(
        result, "VAR." + algorithm.get_name() + "." + problem.get_name())

    print("Algorithm: " + algorithm.get_name())
    print("Problem: " + problem.get_name())
    print("Solution: " + str(result.variables[0]))
    print("Fitness:  " + str(result.objectives[0]))
    print("Computing time: " + str(algorithm.total_computing_time))
if __name__ == '__main__':
    problem = ZDT1Modified()
    problem.reference_front = read_solutions(
        filename='resources/reference_front/ZDT1.pf')

    max_evaluations = 100
    algorithm = SMPSO(
        problem=problem,
        swarm_size=10,
        mutation=PolynomialMutation(probability=1.0 /
                                    problem.number_of_variables,
                                    distribution_index=20),
        leaders=CrowdingDistanceArchive(10),
        termination_criterion=StoppingByEvaluations(max=max_evaluations),
        swarm_evaluator=SparkEvaluator(),
    )

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

    # 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())

    print('Algorithm (continuous problem): ' + algorithm.get_name())
    print('Problem: ' + problem.get_name())
    print('Computing time: ' + str(algorithm.total_computing_time))
示例#6
0
    Configuration = configure()
    # global BestPopulation
    BestPopulation = BestPop(Configuration)
    # config.createfolders()
    Goal_num = Configuration.goal_num

    # file_name = text_create(Configuration )
    # output = sys.stdout
    # outputfile = codecs.open(file_name,  'w', 'utf-8')
    # sys.stdout = outputfile
    """===============================实例化问题对象============================"""
    problem = OvertakeProblem(Goal_num, Configuration, BestPopulation)
    """=================================算法参数设置============================"""
    max_evaluations = Configuration.maxIterations
    algorithm = RandomSearch(problem=problem,
                             termination_criterion=StoppingByEvaluations(
                                 max_evaluations=max_evaluations))

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

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

    print(f'Algorithm: ${algorithm.get_name()}')
    print(f'Problem: ${problem.get_name()}')
    print(f'Computing time: ${algorithm.total_computing_time}')