Skip to content
Snippets Groups Projects
Commit 6da312a4 authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

test: update test_mo_anneal to use optimizee input

parent bec1d851
No related branches found
No related tags found
1 merge request!81Rework optimization routines
...@@ -4,10 +4,9 @@ module test_mo_anneal ...@@ -4,10 +4,9 @@ module test_mo_anneal
use mo_kind, only: dp, i4, i8 use mo_kind, only: dp, i4, i8
use mo_anneal, only: anneal !, anneal_valid use mo_anneal, only: anneal !, anneal_valid
use mo_anneal, only: GetTemperature !, GetTemperature_valid use mo_anneal, only: GetTemperature !, GetTemperature_valid
use mo_cost, only: range_dp, cost_objective !, cost_valid_dp use mo_cost, only: range_dp, cost_dp
use mo_xor4096, only: get_timeseed use mo_xor4096, only: get_timeseed
use mo_opt_functions, only: eval_dummy use mo_optimization_utils, only: function_optimizee
use mo_optimization_utils, only: eval_interface, objective_interface
use mo_message, only: error_message use mo_message, only: error_message
implicit none implicit none
...@@ -30,8 +29,7 @@ module test_mo_anneal ...@@ -30,8 +29,7 @@ module test_mo_anneal
real(dp) :: Tstart, Tend real(dp) :: Tstart, Tend
real(dp), dimension(:,:), allocatable :: history real(dp), dimension(:,:), allocatable :: history
procedure(eval_interface), pointer :: eval type(function_optimizee) :: objective
procedure(objective_interface), pointer :: obj_func
! time dependent seeds ! time dependent seeds
call get_timeseed(seeds) call get_timeseed(seeds)
...@@ -44,16 +42,15 @@ module test_mo_anneal ...@@ -44,16 +42,15 @@ module test_mo_anneal
para(3) = 0.5_dp para(3) = 0.5_dp
para(4) = 0.4_dp para(4) = 0.4_dp
eval => eval_dummy objective%func_pointer => cost_dp
obj_func => cost_objective
! Initialization ! Initialization
print*, '-----------------------------------' print*, '-----------------------------------'
print*, ' INITIALIZATION ' print*, ' INITIALIZATION '
print*, '-----------------------------------' print*, '-----------------------------------'
print*, 'Initial parameter set: ',para print*, 'Initial parameter set: ',para
print*, 'Initial cost function value: ',cost_objective(para(:), eval) print*, 'Initial cost function value: ',objective%evaluate(para(:))
costbestAll = cost_objective(para(:), eval) costbestAll = objective%evaluate(para(:))
parabestAll = para(:) parabestAll = para(:)
print*, '-----------------------------------' print*, '-----------------------------------'
print*, ' INITIAL TEMPERATURE ' print*, ' INITIAL TEMPERATURE '
...@@ -62,7 +59,7 @@ module test_mo_anneal ...@@ -62,7 +59,7 @@ module test_mo_anneal
seeds(1) = 854_i8 seeds(1) = 854_i8
seeds(2) = seeds(1) + 1000_i8 seeds(2) = seeds(1) + 1000_i8
print*, 'seeds used: ', seeds(1:2) print*, 'seeds used: ', seeds(1:2)
temperature = GetTemperature( eval, obj_func, para, 0.95_dp, & temperature = GetTemperature(objective, para, 0.95_dp, &
! optionals ! optionals
prange_func=range_dp, & prange_func=range_dp, &
samplesize=500_i4, & samplesize=500_i4, &
...@@ -82,7 +79,7 @@ module test_mo_anneal ...@@ -82,7 +79,7 @@ module test_mo_anneal
print*, 'seeds used: ', seeds(1:3) print*, 'seeds used: ', seeds(1:3)
! !
call cpu_time(Tstart) call cpu_time(Tstart)
parabest = anneal(eval, obj_func, para, & parabest = anneal(objective, para, &
! optionals ! optionals
prange_func=range_dp, & prange_func=range_dp, &
maxit=.false., & maxit=.false., &
...@@ -122,9 +119,9 @@ module test_mo_anneal ...@@ -122,9 +119,9 @@ module test_mo_anneal
print*, ' parabest = ', parabestAll print*, ' parabest = ', parabestAll
! Is program running properly? costbestAll = 3.1142480812726376E-02 ! Is program running properly? costbestAll = 3.1142480812726376E-02
@assertEqual(costbestAll, 3.1142480812726376E-02_dp, tolerance=t) @assertEqual(costbestAll, 3.1142480812726376E-02_dp, tolerance=t)
end subroutine test_anneal_dp end subroutine test_anneal_dp
end module test_mo_anneal end module test_mo_anneal
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment