Beispiel #1
0
def execute_simulated_annealing(args):
    objective_function = instantiate_objective_function(
        args.objective_function)

    from metaheuristic_algorithms.simulated_annealing import SimulatedAnnealing
    simulated_annealing = SimulatedAnnealing(objective_function,
                                             args.number_of_variables,
                                             args.objective)

    result = simulated_annealing.search(
        args.temperature,
        args.minimal_temperature,
        args.bolzmann_constant,
        args.energy_norm,
        maximum_number_of_rejections=args.maximum_number_of_rejections,
        maximum_number_of_runs=args.maximum_number_of_runs,
        maximum_number_of_acceptances=args.maximum_number_of_acceptances,
        cooling_factor=args.cooling_factor,
        standard_diviation_for_estimation=args.
        standard_diviation_for_estimation,
        ratio_of_energy_delta_over_evaluation_delta=args.
        ratio_of_energy_delta_over_evaluation_delta)

    print('best_decision_variable_values=',
          result["best_decision_variable_values"])
    print('best_objective_function_value=',
          result["best_objective_function_value"])
Beispiel #2
0
    def test_find_glocal_minimum_for_rosenbrook_function(self):

        rosenbrook_function_wrapper = RosenbrookFunctionWrapper()

        number_of_variables = 2
        objective = "minimization"

        simulated_annealing = SimulatedAnnealing(rosenbrook_function_wrapper,
                                                 number_of_variables,
                                                 objective)

        temperature = 1.0
        minimal_temperature = 1e-10  # Final stopping temperature
        # minimal_temperature = 1e-1 # Final stopping temperature
        maximum_number_of_rejections = 2500
        # maximum_number_of_rejections = 1000
        maximum_number_of_runs = 500
        # maximum_number_of_runs = 100
        maximum_number_of_acceptances = 15
        bolzmann_constant = 1
        cooling_factor = 0.95
        energy_norm = 1e-8
        # energy_norm = 1e-1
        standard_diviation_for_estimation = 1
        ratio_of_energy_delta_over_evaluation_delta = 1

        result = simulated_annealing.search(
            temperature,
            minimal_temperature,
            bolzmann_constant,
            energy_norm,
            maximum_number_of_rejections=maximum_number_of_rejections,
            maximum_number_of_runs=maximum_number_of_runs,
            maximum_number_of_acceptances=maximum_number_of_acceptances,
            cooling_factor=cooling_factor,
            standard_diviation_for_estimation=standard_diviation_for_estimation,
            ratio_of_energy_delta_over_evaluation_delta=
            ratio_of_energy_delta_over_evaluation_delta)

        self.assertAlmostEqual(result["best_decision_variable_values"][0],
                               1.0112,
                               delta=1)
        self.assertAlmostEqual(result["best_decision_variable_values"][1],
                               0.9988,
                               delta=1)
        self.assertAlmostEqual(result["best_objective_function_value"],
                               0.0563,
                               delta=1)
def execute_simulated_annealing(args):
    objective_function = instantiate_objective_function(args.objective_function)

    from metaheuristic_algorithms.simulated_annealing import SimulatedAnnealing
    simulated_annealing = SimulatedAnnealing(objective_function, args.number_of_variables, args.objective)

    result = simulated_annealing.search(args.temperature, args.minimal_temperature, 
                                        args.bolzmann_constant, args.energy_norm, 
                                        maximum_number_of_rejections = args.maximum_number_of_rejections, 
                                        maximum_number_of_runs = args.maximum_number_of_runs, 
                                        maximum_number_of_acceptances = args.maximum_number_of_acceptances, 
                                        cooling_factor = args.cooling_factor, 
                                        standard_diviation_for_estimation = args.standard_diviation_for_estimation, 
                                        ratio_of_energy_delta_over_evaluation_delta = args.ratio_of_energy_delta_over_evaluation_delta)

    print('best_decision_variable_values=', result["best_decision_variable_values"])
    print('best_objective_function_value=', result["best_objective_function_value"])
    def test_find_glocal_minimum_for_rosenbrook_function(self):

        rosenbrook_function_wrapper = RosenbrookFunctionWrapper()

        number_of_variables = 2
        objective = "minimization"

        simulated_annealing = SimulatedAnnealing(rosenbrook_function_wrapper, number_of_variables, objective)

        temperature = 1.0
        minimal_temperature = 1e-10 # Final stopping temperature
        # minimal_temperature = 1e-1 # Final stopping temperature
        maximum_number_of_rejections = 2500
        # maximum_number_of_rejections = 1000
        maximum_number_of_runs = 500
        # maximum_number_of_runs = 100
        maximum_number_of_acceptances = 15
        bolzmann_constant = 1
        cooling_factor = 0.95
        energy_norm = 1e-8
        # energy_norm = 1e-1
        standard_diviation_for_estimation = 1
        ratio_of_energy_delta_over_evaluation_delta = 1

        result = simulated_annealing.search(temperature, minimal_temperature, 
                                            bolzmann_constant, energy_norm, 
                                            maximum_number_of_rejections = maximum_number_of_rejections, 
                                            maximum_number_of_runs = maximum_number_of_runs, 
                                            maximum_number_of_acceptances = maximum_number_of_acceptances, 
                                            cooling_factor = cooling_factor, 
                                            standard_diviation_for_estimation = standard_diviation_for_estimation, 
                                            ratio_of_energy_delta_over_evaluation_delta = ratio_of_energy_delta_over_evaluation_delta)

        self.assertAlmostEqual(result["best_decision_variable_values"][0], 1.0112, delta = 1)
        self.assertAlmostEqual(result["best_decision_variable_values"][1], 0.9988, delta = 1)
        self.assertAlmostEqual(result["best_objective_function_value"], 0.0563, delta = 1)