Wrapper type that encapsulates the C interface. extend the fortran type to hold the C function pointers.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| procedure(c_sa_func), | public, | pointer, nopass | :: | c_fcn_ptr | => | null() | |
| procedure(c_sa_func_parallel_inputs), | public, | pointer, nopass | :: | c_n_inputs_ptr | => | null() | |
| procedure(c_sa_func_parallel_inputs_func), | public, | pointer, nopass | :: | c_fcn_parallel_input_ptr | => | null() | |
| procedure(c_sa_func_parallel_output_func), | public, | pointer, nopass | :: | c_fcn_parallel_output_ptr | => | null() | |
| procedure(c_sa_report_func), | public, | pointer, nopass | :: | c_report_ptr | => | null() | |
| integer(kind=c_intptr_t), | public | :: | iproblem | = | 0 |
pointer to this wrapper (for callbacks) |
Initialize the class.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | n | |||
| real(kind=wp), | intent(in), | dimension(n) | :: | lb | ||
| real(kind=wp), | intent(in), | dimension(n) | :: | ub | ||
| real(kind=wp), | intent(in), | optional, | dimension(n) | :: | c | |
| logical, | intent(in), | optional | :: | maximize | ||
| real(kind=wp), | intent(in), | optional | :: | eps | ||
| integer, | intent(in), | optional | :: | ns | ||
| integer, | intent(in), | optional | :: | nt | ||
| integer, | intent(in), | optional | :: | neps | ||
| integer, | intent(in), | optional | :: | maxevl | ||
| integer, | intent(in), | optional | :: | iprint | ||
| integer, | intent(in), | optional | :: | iseed1 | ||
| integer, | intent(in), | optional | :: | iseed2 | ||
| integer, | intent(in), | optional | :: | step_mode | ||
| real(kind=wp), | intent(in), | optional | :: | vms | ||
| integer, | intent(in), | optional | :: | iunit | ||
| logical, | intent(in), | optional | :: | use_initial_guess | ||
| integer, | intent(in), | optional | :: | n_resets | ||
| integer, | intent(in), | optional | :: | cooling_schedule |
temperature reduction schedule (1-5) |
|
| real(kind=wp), | intent(in), | optional | :: | cooling_param |
parameter for cooling schedules 3 and 5 |
|
| logical, | intent(in), | optional | :: | optimal_f_specified |
if the optional |
|
| real(kind=wp), | intent(in), | optional | :: | optimal_f |
if |
|
| real(kind=wp), | intent(in), | optional | :: | optimal_f_tol |
absolute tolerance for the |
|
| integer, | intent(in), | optional, | dimension(:) | :: | distribution_mode |
distribution for perturbations (per variable): |
| real(kind=wp), | intent(in), | optional, | dimension(:) | :: | dist_std_dev |
std dev for normal/truncated_normal (per variable or scalar) |
| real(kind=wp), | intent(in), | optional, | dimension(:) | :: | dist_scale |
scale for cauchy/pareto (per variable or scalar) |
| real(kind=wp), | intent(in), | optional, | dimension(:) | :: | dist_shape |
shape for pareto (per variable or scalar) |
| procedure(sa_func), | optional | :: | fcn |
the user's function for scalar evaluation. if not present, the user must provide all of n_inputs_to_send, fcn_parallel_input and fcn_parallel_output for parallel evaluation. |
||
| procedure(sa_func_parallel_inputs), | optional | :: | n_inputs_to_send |
if the user wants to evaluate multiple points in parallel, this function should return the number of input points that will be sent for evaluation at a time. |
||
| procedure(sa_func_parallel_inputs_func), | optional | :: | fcn_parallel_input |
this function receives the input points for evaluation |
||
| procedure(sa_func_parallel_output_func), | optional | :: | fcn_parallel_output |
this function receives the output points from the parallel
evaluation. The |
||
| integer, | intent(in), | optional | :: | ireport |
how often to report intermediate results to the user via |
|
| procedure(sa_report_func), | optional | :: | report |
if associated, this function is called to report intermediate results to the user. |
Continuous simulated annealing global optimization algorithm
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(inout), | dimension(me%n) | :: | x |
on input: the starting values for the variables of the function to be optimized. [Will be replaced by final point] |
|
| real(kind=wp), | intent(in) | :: | rt |
the temperature reduction factor. the value suggested by corana et al. is .85. see goffe et al. for more advice. |
||
| real(kind=wp), | intent(inout) | :: | t |
on input, the initial temperature. see goffe et al. for advice.
on output, the final temperature. Note that if |
||
| real(kind=wp), | intent(inout), | dimension(me%n) | :: | vm |
the step length vector. on input it should encompass the region of
interest given the starting value x. for point x(i), the next
trial point is selected is from x(i) - vm(i) to x(i) + vm(i).
since vm is adjusted so that about half of all points are accepted,
the input value is not very important (i.e. if the value is off,
sa adjusts vm to the correct value).
note: if |
|
| real(kind=wp), | intent(out), | dimension(me%n) | :: | xopt |
the variables that optimize the function. |
|
| real(kind=wp), | intent(out) | :: | fopt |
the optimal value of the function. |
||
| integer, | intent(out) | :: | nacc |
the number of accepted function evaluations. |
||
| integer, | intent(out) | :: | nfcnev |
the total number of function evaluations. in a minor point, note that the first evaluation is not used in the core of the algorithm; it simply initializes the algorithm. |
||
| integer, | intent(out) | :: | ier |
the error return number: |
Destructor.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(out) | :: | me |
this is public so we can use it in the tests
Perturb a single variable using its assigned distribution and parameters.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | ivar |
variable index |
||
| real(kind=wp), | intent(in) | :: | x |
variable value to perturb |
||
| integer, | intent(in) | :: | mode |
perturbation distribution mode (see |
||
| real(kind=wp), | intent(in) | :: | lower |
lower bound |
||
| real(kind=wp), | intent(in) | :: | upper |
upper bound |
perturbed value
type,extends(simulated_annealing_type) :: c_sa_wrapper_type !! Wrapper type that encapsulates the C interface. !! extend the fortran type to hold the C function pointers. procedure(c_sa_func), pointer, nopass :: c_fcn_ptr => null() procedure(c_sa_func_parallel_inputs), pointer, nopass :: c_n_inputs_ptr => null() procedure(c_sa_func_parallel_inputs_func), pointer, nopass :: c_fcn_parallel_input_ptr => null() procedure(c_sa_func_parallel_output_func), pointer, nopass :: c_fcn_parallel_output_ptr => null() procedure(c_sa_report_func), pointer, nopass :: c_report_ptr => null() integer(c_intptr_t) :: iproblem = 0 !! pointer to this wrapper (for callbacks) end type c_sa_wrapper_type