start_temperature


This function calculates the initial temperature with an acceptance rate greater than 80% of the initial solutions. Fixed at 500 attempts.

t_0mean, report = start_temperature(n_population, obj_function,
                                        x_pop, of_pop, x_lower,
                                        x_upper, n_dimensions,
                                        pdf, cov, none_variable=None)

Input variables

Name Description Type
n_population Number of population. Integer
obj_function Objective function. The Metapy user defined this function. Py function (def)
x_pop Population design variables List
of_pop Population objective function values List
x_lower Lower limit of the design variables List
x_upper Upper limit of the design variables List
n_dimensions Problem dimension Integer
pdf Probability density function. Options: 'gaussian' or 'uniform' String
cov Coefficient of variation in percentage Float
none_variable None variable. Default is None. User can use this variable in objective function None, list, float, dictionary, str or any

Output variables

Name Description Type
t_0mean Initial temperature Float
report Report of the algorithm execution String

Example 1

Use the start_temperature function to calculate the initial temperature.

# Import
from metapy_toolbox import initial_population_01, start_temperature # or import *

# Data
nPop = 10
xL = [-5, -5]
xU = [5, 5]
d = len(xU) # or d = len(xL) or d = 2
pdf = 'uniform'
cov = 20
none_variable = None

# Objective function
def obj_function(x, none_variable):
    """Example objective function"""
    x0 = x[0]
    x1 = x[1]
    of = x0 ** 2 + x1 ** 2
    return of

# Calculate initial temperature
xPop = initial_population_01(nPop, d, xL, xU)
ofPop = [obj_function(x, none_variable) for x in xPop]
t0Mean, report = start_temperature(nPop, obj_function, xPop, ofPop, xL, xU, d, pdf, cov, none_variable)

# Output details
print(f"t_0: {t0Mean}")
t_0: 11.075177109777801

To check the start temperature report just apply the following instruction.

# Report details
arq = "report_example_start_temp_sa.txt"

# Writing report
with open(arq, "w") as file:
    file.write(report)

Open report_example_start_temp_sa.txt.

Automotic initial temperature
    sum_t0 = 30120.743224553567, number of accepted moves (delta_e > 0) = 2510, t_mean = 12.000296105399828