C interface wrapper for the simulated annealing optimization algorithm. This can be used to call the Fortran implementation from C or other languages that can interface with C (such as Python).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | value | :: | iproblem | |||
| real(kind=c_double), | intent(in), | dimension(n) | :: | x | ||
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| real(kind=c_double), | intent(out) | :: | f | |||
| integer(kind=c_int), | intent(out) | :: | istat |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | value | :: | iproblem | |||
| integer(kind=c_int), | intent(out) | :: | n_inputs |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | value | :: | iproblem | |||
| real(kind=c_double), | intent(in), | dimension(n, n_inputs) | :: | x |
C's x[n_inputs][n] maps to Fortran's x(n,n_inputs) due to row/column-major difference |
|
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| integer(kind=c_int), | intent(in), | value | :: | n_inputs |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | value | :: | iproblem | |||
| real(kind=c_double), | intent(out), | dimension(n) | :: | x | ||
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| real(kind=c_double), | intent(out) | :: | f | |||
| integer(kind=c_int), | intent(out) | :: | istat |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | value | :: | iproblem | |||
| real(kind=c_double), | intent(in), | dimension(n) | :: | x | ||
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| real(kind=c_double), | intent(in), | value | :: | f | ||
| integer(kind=c_int), | intent(in), | value | :: | istat |
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) |
| procedure, public :: initialize => initialize_sa | |
| procedure, public :: optimize => sa | |
| procedure, public :: destroy => destroy_sa | |
| procedure, public :: perturb_variable | this is public so we can use it in the tests |
Convert an integer pointer to a c_sa_wrapper_type pointer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | intent(in) | :: | iproblem |
integer pointer from C |
||
| type(c_sa_wrapper_type), | pointer | :: | p |
fortran pointer |
Wrapper procedures for C callbacks (module-level, work with wrapper type)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x | ||
| real(kind=wp), | intent(out) | :: | f | |||
| integer, | intent(out) | :: | istat |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| integer, | intent(out) | :: | n_inputs |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:, :) | :: | x |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(out), | dimension(:) | :: | x | ||
| real(kind=wp), | intent(out) | :: | f | |||
| integer, | intent(out) | :: | istat |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(simulated_annealing_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x | ||
| real(kind=wp), | intent(in) | :: | f | |||
| integer, | intent(in) | :: | istat |
create a simulated_annealing_type from C
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | intent(out) | :: | iproblem | |||
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | lb | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | ub | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | c | ||
| logical(kind=c_bool), | intent(in), | value | :: | maximize | ||
| real(kind=c_double), | intent(in), | value | :: | eps | ||
| integer(kind=c_int), | intent(in), | value | :: | ns | ||
| integer(kind=c_int), | intent(in), | value | :: | nt | ||
| integer(kind=c_int), | intent(in), | value | :: | neps | ||
| integer(kind=c_int), | intent(in), | value | :: | maxevl | ||
| integer(kind=c_int), | intent(in), | value | :: | iprint | ||
| integer(kind=c_int), | intent(in), | value | :: | iseed1 | ||
| integer(kind=c_int), | intent(in), | value | :: | iseed2 | ||
| integer(kind=c_int), | intent(in), | value | :: | step_mode | ||
| real(kind=c_double), | intent(in), | value | :: | vms | ||
| integer(kind=c_int), | intent(in), | value | :: | iunit | ||
| logical(kind=c_bool), | intent(in), | value | :: | use_initial_guess | ||
| integer(kind=c_int), | intent(in), | value | :: | n_resets | ||
| integer(kind=c_int), | intent(in), | value | :: | cooling_schedule | ||
| real(kind=c_double), | intent(in), | value | :: | cooling_param | ||
| logical(kind=c_bool), | intent(in), | value | :: | optimal_f_specified | ||
| real(kind=c_double), | intent(in), | value | :: | optimal_f | ||
| real(kind=c_double), | intent(in), | value | :: | optimal_f_tol | ||
| integer(kind=c_int), | intent(in), | dimension(n) | :: | distribution_mode | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | dist_std_dev | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | dist_scale | ||
| real(kind=c_double), | intent(in), | dimension(n) | :: | dist_shape | ||
| type(c_funptr), | intent(in), | value | :: | fcn |
C function pointer (can be C_NULL_FUNPTR) |
|
| type(c_funptr), | intent(in), | value | :: | n_inputs_to_send |
C function pointer (can be C_NULL_FUNPTR) |
|
| type(c_funptr), | intent(in), | value | :: | fcn_parallel_input |
C function pointer (can be C_NULL_FUNPTR) |
|
| type(c_funptr), | intent(in), | value | :: | fcn_parallel_output |
C function pointer (can be C_NULL_FUNPTR) |
|
| integer(kind=c_int), | intent(in), | value | :: | ireport |
how often to report |
|
| type(c_funptr), | intent(in), | value | :: | report |
C function pointer for reporting (can be C_NULL_FUNPTR) |
destroy a simulated_annealing_type from C
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | intent(in), | value | :: | iproblem |
solve optimization problem using simulated annealing from C
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=c_intptr_t), | intent(in), | value | :: | iproblem | ||
| integer(kind=c_int), | intent(in), | value | :: | n | ||
| real(kind=c_double), | intent(inout), | dimension(n) | :: | x | ||
| real(kind=c_double), | intent(in), | value | :: | rt | ||
| real(kind=c_double), | intent(inout) | :: | t | |||
| real(kind=c_double), | intent(inout), | dimension(n) | :: | vm | ||
| real(kind=c_double), | intent(out), | dimension(n) | :: | xopt | ||
| real(kind=c_double), | intent(out) | :: | fopt | |||
| integer(kind=c_int), | intent(out) | :: | nacc | |||
| integer(kind=c_int), | intent(out) | :: | nfcnev | |||
| integer(kind=c_int), | intent(out) | :: | ier |