c_sa_wrapper_type Derived Type

type, public, 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.


Inherits

type~~c_sa_wrapper_type~~InheritsGraph type~c_sa_wrapper_type c_sa_wrapper_type type~simulated_annealing_type simulated_annealing_type type~c_sa_wrapper_type->type~simulated_annealing_type

Components

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)


Type-Bound Procedures

procedure, public :: initialize => initialize_sa

  • private subroutine initialize_sa(me, n, lb, ub, c, maximize, eps, ns, nt, neps, maxevl, iprint, iseed1, iseed2, step_mode, vms, iunit, use_initial_guess, n_resets, cooling_schedule, cooling_param, optimal_f_specified, optimal_f, optimal_f_tol, distribution_mode, dist_std_dev, dist_scale, dist_shape, fcn, n_inputs_to_send, fcn_parallel_input, fcn_parallel_output, ireport, report)

    Initialize the class.

    Read more…

    Arguments

    Type IntentOptional 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 f value is known, it can be specified by optimal_f. [Default is False]

    real(kind=wp), intent(in), optional :: optimal_f

    if optimal_f_specified=True the solver will stop if this value is achieved.

    real(kind=wp), intent(in), optional :: optimal_f_tol

    absolute tolerance for the optimal_f check

    integer, intent(in), optional, dimension(:) :: distribution_mode

    distribution for perturbations (per variable):

    Read more…
    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 x here will be one of the ones sent via sa_func_parallel_inputs_func, The algorithm will only process one at the time.

    integer, intent(in), optional :: ireport

    how often to report intermediate results to the user via report function:

    Read more…
    procedure(sa_report_func), optional :: report

    if associated, this function is called to report intermediate results to the user.

procedure, public :: optimize => sa

  • private subroutine sa(me, x, rt, t, vm, xopt, fopt, nacc, nfcnev, ier)

    Continuous simulated annealing global optimization algorithm

    Read more…

    Arguments

    Type IntentOptional 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 t=0, then all downhill steps will be rejected

    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 vm=0.0, then it is set to abs(xu-xl)`.

    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:

    Read more…

procedure, public :: destroy => destroy_sa

procedure, public :: perturb_variable

this is public so we can use it in the tests

  • private function perturb_variable(me, ivar, x, mode, lower, upper) result(r)

    Perturb a single variable using its assigned distribution and parameters.

    Arguments

    Type IntentOptional 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 distribution_mode for details)

    real(kind=wp), intent(in) :: lower

    lower bound

    real(kind=wp), intent(in) :: upper

    upper bound

    Return Value real(kind=wp)

    perturbed value

Source Code

    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