-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmo_opt_functions.f90
5625 lines (4747 loc) · 143 KB
/
mo_opt_functions.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MODULE mo_opt_functions
! This modules provides test functions for minimisation routines
! Written, Jul 2012 Matthias Cuntz
! Modified, Matthias Cuntz, Aug 2020
! - rewrite ext_rosenbrock_parabolic_valley to remove compiler warning:
! Array reference at (1) out of bounds (0 < 1) in loop beginning at (2) [-Wdo-subscript]
! License
! -------
! This file is part of the JAMS Fortran package, distributed under the MIT License.
!
! Copyright (c) 2012 Matthias Cuntz - mc (at) macu (dot) de
!
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
! in the Software without restriction, including without limitation the rights
! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
! copies of the Software, and to permit persons to whom the Software is
! furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in all
! copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
! SOFTWARE.
use mo_kind, only: i4, dp
IMPLICIT NONE
PRIVATE
! ------------------------------------------------------------------
! test_min package of John Burkardt
PUBLIC :: quadratic ! Simple quadratic, (x-2)^2+1.
PUBLIC :: quadratic_exponential ! Quadratic plus exponential, x^2 + e^(-x).
PUBLIC :: quartic ! Quartic, x^4 + 2x^2 + x + 3.
PUBLIC :: steep_valley ! Steep valley, e^x + 1/(100x).
PUBLIC :: steep_valley2 ! Steep valley, e^x - 2x + 1/(100x) - 1/(1000000x^2)
PUBLIC :: dying_snake ! The dying snake, ( x + sin(x) ) * e^(-x^2).
PUBLIC :: thin_pole ! The "Thin Pole", x^2+1+log((pi-x)^2)/pi^4
PUBLIC :: oscillatory_parabola ! The oscillatory parabola
PUBLIC :: cosine_combo ! The cosine combo
PUBLIC :: abs1 ! 1 + |3x-1|
! ------------------------------------------------------------------
! test_opt package of John Burkardt
PUBLIC :: fletcher_powell_helical_valley ! The Fletcher-Powell helical valley function, N = 3.
PUBLIC :: biggs_exp6 ! The Biggs EXP6 function, N = 6.
PUBLIC :: gaussian ! The Gaussian function, N = 3.
PUBLIC :: powell_badly_scaled ! The Powell badly scaled function, N = 2.
PUBLIC :: box_3dimensional ! The Box 3-dimensional function, N = 3.
PUBLIC :: variably_dimensioned ! The variably dimensioned function, 1 <= N.
PUBLIC :: watson ! The Watson function, 2 <= N.
PUBLIC :: penalty1 ! The penalty function #1, 1 <= N.
PUBLIC :: penalty2 ! The penalty function #2, 1 <= N.
PUBLIC :: brown_badly_scaled ! The Brown badly scaled function, N = 2.
PUBLIC :: brown_dennis ! The Brown and Dennis function, N = 4.
PUBLIC :: gulf_rd ! The Gulf R&D function, N = 3.
PUBLIC :: trigonometric ! The trigonometric function, 1 <= N.
PUBLIC :: ext_rosenbrock_parabolic_valley ! The extended Rosenbrock parabolic valley function, 1 <= N.
PUBLIC :: ext_powell_singular_quartic ! The extended Powell singular quartic function, 4 <= N.
PUBLIC :: beale ! The Beale function, N = 2.
PUBLIC :: wood ! The Wood function, N = 4.
PUBLIC :: chebyquad ! The Chebyquad function, 1 <= N.
PUBLIC :: leon_cubic_valley ! Leon''s cubic valley function, N = 2.
PUBLIC :: gregory_karney_tridia_matrix ! Gregory and Karney''s Tridiagonal Matrix Function, 1 <= N.
PUBLIC :: hilbert ! The Hilbert function, 1 <= N.
PUBLIC :: de_jong_f1 ! The De Jong Function F1, N = 3.
PUBLIC :: de_jong_f2 ! The De Jong Function F2, N = 2.
PUBLIC :: de_jong_f3 ! The De Jong Function F3 (discontinuous), N = 5.
PUBLIC :: de_jong_f4 ! The De Jong Function F4 (Gaussian noise), N = 30.
PUBLIC :: de_jong_f5 ! The De Jong Function F5, N = 2.
PUBLIC :: schaffer_f6 ! The Schaffer Function F6, N = 2.
PUBLIC :: schaffer_f7 ! The Schaffer Function F7, N = 2.
PUBLIC :: goldstein_price_polynomial ! The Goldstein Price Polynomial, N = 2.
PUBLIC :: branin_rcos ! The Branin RCOS Function, N = 2.
PUBLIC :: shekel_sqrn5 ! The Shekel SQRN5 Function, N = 4.
PUBLIC :: shekel_sqrn7 ! The Shekel SQRN7 Function, N = 4.
PUBLIC :: shekel_sqrn10 ! The Shekel SQRN10 Function, N = 4.
PUBLIC :: six_hump_camel_back_polynomial ! The Six-Hump Camel-Back Polynomial, N = 2.
PUBLIC :: shubert ! The Shubert Function, N = 2.
PUBLIC :: stuckman ! The Stuckman Function, N = 2.
PUBLIC :: easom ! The Easom Function, N = 2.
PUBLIC :: bohachevsky1 ! The Bohachevsky Function #1, N = 2.
PUBLIC :: bohachevsky2 ! The Bohachevsky Function #2, N = 2.
PUBLIC :: bohachevsky3 ! The Bohachevsky Function #3, N = 2.
PUBLIC :: colville_polynomial ! The Colville Polynomial, N = 4.
PUBLIC :: powell3d ! The Powell 3D function, N = 3.
PUBLIC :: himmelblau ! The Himmelblau function, N = 2.
! ------------------------------------------------------------------
! Miscellaneous functions
PUBLIC :: griewank ! Griewank function, N = 2 or N = 10.
PUBLIC :: rosenbrock ! Rosenbrock parabolic valley function, N = 2.
PUBLIC :: sphere_model ! Sphere model, N >= 1.
PUBLIC :: rastrigin ! Rastrigin function, N >= 2.
PUBLIC :: schwefel ! Schwefel function, N >= 2.
PUBLIC :: ackley ! Ackley function, N >= 2.
PUBLIC :: michalewicz ! Michalewicz function, N >= 2.
PUBLIC :: booth ! Booth function, N = 2.
PUBLIC :: hump ! Hump function, N = 2.
PUBLIC :: levy ! Levy function, N >= 2.
PUBLIC :: matyas ! Matyas function, N = 2.
PUBLIC :: perm ! Perm function, N = 4.
PUBLIC :: power_sum ! Power sum function, N = 4.
! ------------------------------------------------------------------
! test_optimization package of John Burkardt - inputs are x(n) and output f(m), e.g. compare
! rosenbrock = 100.0_dp * (x(2)-x(1)**2)**2 + (1.0_dp-x(1))**2
! rosenbrock_2d(j) = sum((1.0_dp-x(1:m,j))**2) + sum((x(2:m,j)-x(1:m-1,j))**2)
PUBLIC :: sphere_model_2d ! The sphere model, (M,N).
PUBLIC :: axis_parallel_hyper_ellips_2d ! The axis-parallel hyper-ellipsoid function, (M,N).
PUBLIC :: rotated_hyper_ellipsoid_2d ! The rotated hyper-ellipsoid function, (M,N).
PUBLIC :: rosenbrock_2d ! Rosenbrock''s valley, (M,N).
PUBLIC :: rastrigin_2d ! Rastrigin''s function, (M,N).
PUBLIC :: schwefel_2d ! Schwefel''s function, (M,N).
PUBLIC :: griewank_2d ! Griewank''s function, (M,N).
PUBLIC :: power_sum_2d ! The power sum function, (M,N).
PUBLIC :: ackley_2d ! Ackley''s function, (M,N).
PUBLIC :: michalewicz_2d ! Michalewicz''s function, (M,N).
PUBLIC :: drop_wave_2d ! The drop wave function, (M,N).
PUBLIC :: deceptive_2d ! The deceptive function, (M,N).
! ------------------------------------------------------------------
! test_optimization functions of Kalyanmoy Deb
! found in Deb et al. (2002), Zitzler et al. (2000) and in Matlab Central file exchange
! http://www.mathworks.com/matlabcentral/fileexchange/31166-ngpm-a-nsga-ii-program-in-matlab-v1-4/
! content/TP_NSGA2/
public :: dtlz2_3d ! 3-d objective function (spherical pareto front)
public :: dtlz2_5d ! 5-d objective function (spherical pareto front)
public :: dtlz2_10d ! 10-d objective function (spherical pareto front)
public :: fon_2d ! 2-d objective function (nonconvex pareto front)
public :: kur_2d ! 2-d objective function (nonconvex, disconnected pareto front)
public :: pol_2d ! 2-d objective function (nonconvex, disconnected pareto front)
public :: sch_2d ! 2-d objective function ( convex pareto front)
public :: zdt1_2d ! 2-d objective function ( convex pareto front)
public :: zdt2_2d ! 2-d objective function (nonconvex pareto front)
public :: zdt3_2d ! 2-d objective function ( convex, disconnected pareto front)
public :: zdt4_2d ! 2-d objective function (nonconvex pareto front)
public :: zdt6_2d ! 2-d objective function (nonconvex, nonuniformly disconnected pareto front)
CONTAINS
! ------------------------------------------------------------------
!
! Simple quadratic, (x-2)^2+1
! Solution: x = 2.0
! With Brent method:
! A, X*, B: 1.9999996 2.0000000 2.0000004
! FA, FX*, FB: 1.0000000 1.0000000 1.0000000
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 25 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function quadratic( x )
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: quadratic
if (size(x,1) .gt. 1_i4) stop 'quadratic: Input has to be array of size 1'
quadratic = ( x(1) - 2.0_dp ) * ( x(1) - 2.0_dp ) + 1.0_dp
end function quadratic
! ------------------------------------------------------------------
!
! Quadratic plus exponential, x^2 + e^(-x)
! Solution: x = 0.35173370
! With Brent method:
! A, X*, B: 0.35173337 0.35173370 0.35173404
! FA, FX*, FB: 0.82718403 0.82718403 0.82718403
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! LE Scales,
! Introduction to Non-Linear Optimization,
! Springer, 1985.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function quadratic_exponential( x )
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: quadratic_exponential
if (size(x,1) .gt. 1_i4) stop 'quadratic_exponential: Input has to be array of size 1'
quadratic_exponential = x(1) * x(1) + exp ( - x(1) )
end function quadratic_exponential
! ------------------------------------------------------------------
!
! Quartic, x^4 + 2x^2 + x + 3
! Solution: x = -0.23673291
! With Brent method:
! A, X*, B: -0.23673324 -0.23673291 -0.23673257
! FA, FX*, FB: 2.8784928 2.8784928 2.8784928
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! LE Scales,
! Introduction to Non-Linear Optimization,
! Springer, 1985.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function quartic( x )
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: quartic
if (size(x,1) .gt. 1_i4) stop 'quartic: Input has to be array of size 1'
quartic = ( ( x(1) * x(1) + 2.0_dp ) * x(1) + 1.0_dp ) * x(1) + 3.0_dp
end function quartic
! ------------------------------------------------------------------
!
! Steep valley, e^x + 1/(100x)
! Solution:
! if x > 0.0 : x = 0.95344636E-01
! if x < -0.1 : x = -8.99951
! Search domain: x <= -0.1
!
! With Brent method:
! A, X*, B: 0.95344301E-01 0.95344636E-01 0.95344971E-01
! FA, FX*, FB: 1.2049206 1.2049206 1.2049206
!
! Discussion:
!
! This function has a pole at x = 0,
! near which
! f -> negative infinity for x -> 0-0 (left) and
! f -> positive infinity for x -> 0+0 (right)
! f has a local maximum at x ~ -0.105412 .
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! LE Scales,
! Introduction to Non-Linear Optimization,
! Springer, 1985.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function steep_valley( x )
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: steep_valley
if (size(x,1) .gt. 1_i4) stop 'steep_valley: Input has to be array of size 1'
steep_valley = exp ( x(1) ) + 0.01_dp / x(1)
steep_valley = steep_valley + 0.0009877013_dp
end function steep_valley
! ------------------------------------------------------------------
!
! Steep valley2, e^x - 2x + 1/(100x) - 1/(1000000x^2)
!
! Solution: x = 0.70320487
! Search domain: 0.001 <= x
!
! With Brent method:
! A, X*, B: 0.70320453 0.70320487 0.70320521
! FA, FX*, FB: 0.62802572 0.62802572 0.62802572
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! LE Scales,
! Introduction to Non-Linear Optimization,
! Springer, 1985.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function steep_valley2( x )
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: steep_valley2
if (size(x,1) .gt. 1_i4) stop 'steep_valley2: Input has to be array of size 1'
steep_valley2 = exp( x(1) ) - 2.0_dp * x(1) + 0.01_dp / x(1) - 0.000001_dp / x(1) / x(1)
end function steep_valley2
! ------------------------------------------------------------------
!
! The dying snake, ( x + sin(x) ) * e^(-x^2)
! Solution: x = -0.67957876
! With Brent method:
! A, X*, B: -0.67957911 -0.67957876 -0.67957842
! FA, FX*, FB: -0.82423940 -0.82423940 -0.82423940
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 February 2002
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! Richard Brent,
! Algorithms for Minimization Without Derivatives,
! Prentice Hall 1973,
! Reprinted Dover, 2002
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function dying_snake(x)
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: dying_snake
if (size(x,1) .gt. 1_i4) stop 'dying_snake: Input has to be array of size 1'
dying_snake = ( x(1) + sin ( x(1) ) ) * exp ( - x(1) * x(1) )
dying_snake = dying_snake + 0.8242393985_dp
end function dying_snake
! ------------------------------------------------------------------
!
! The "Thin Pole", 3x^2+1+log((pi-x)^2)/pi^4
! Solution:
! x = 0.00108963
! f(x) = 1.0235
!
! With Brent method:
! A, X*, B: 2.0000000 2.0000007 2.0000011
! FA, FX*, FB: 13.002719 13.002727 13.002732
!
! Discussion:
!
! This function looks positive, but has a pole at x = pi,
! near which f -> negative infinity, and has two zeroes nearby.
! None of this will show up computationally.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 19 February 2003
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! Arnold Krommer, Christoph Ueberhuber,
! Numerical Integration on Advanced Systems,
! Springer, 1994, pages 185-186.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function thin_pole(x)
use mo_constants, only: pi_dp
use mo_utils, only: eq
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: thin_pole
if (size(x,1) .gt. 1_i4) stop 'thin_pole: Input has to be array of size 1'
if ( eq(x(1),pi_dp) ) then
thin_pole = - 10000.0_dp
else
thin_pole = 3.0_dp * x(1) * x(1) + 1.0_dp + ( log ( ( x(1) - pi_dp ) * ( x(1) - pi_dp ) ) ) / pi_dp**4
end if
end function thin_pole
! ------------------------------------------------------------------
!
! The oscillatory parabola x^2 - 10*sin(x^2-3x+2)
! Solution:
! x = 0.146623
! f(x) = -9.97791
! With Brent method:
! A, X*, B: -1.3384524 -1.3384521 -1.3384517
! FA, FX*, FB: -8.1974224 -8.1974224 -8.1974224
!
! Discussion:
!
! This function is oscillatory, with many local minima.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 25 January 2008
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function oscillatory_parabola(x)
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: oscillatory_parabola
if (size(x,1) .gt. 1_i4) stop 'oscillatory_parabola: Input has to be array of size 1'
oscillatory_parabola = x(1) * x(1) - 10.0_dp * sin ( x(1) * x(1) - 3.0_dp * x(1) + 2.0_dp )
oscillatory_parabola = oscillatory_parabola + 9.9779149346_dp
end function oscillatory_parabola
! ------------------------------------------------------------------
!
! The cosine combo cos(x)+5cos(1.6x)-2cos(2x)+5cos(4.5x)+7cos(9x)
! Solution:
! x = -21.9443 + 62.831853 * k , k = Integer
! x = 21.9443 - 62.831853 * k , k = Integer
! f(x) = -14.6772
!
! With Brent method:
! A, X*, B: 1.0167817 1.0167821 1.0167824
! FA, FX*, FB: -6.2827509 -6.2827509 -6.2827509
!
! Discussion:
!
! This function is symmetric, oscillatory, and has many local minima.
!
! The function has a local minimum at 1.0167817.
!
! The global optimum which function value -14.6772
! appears infinite times.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 09 February 2009
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! Isabel Beichl, Dianne O'Leary, Francis Sullivan,
! Monte Carlo Minimization and Counting: One, Two, Too Many,
! Computing in Science and Engineering,
! Volume 9, Number 1, January/February 2007.
!
! Dianne O'Leary,
! Scientific Computing with Case Studies,
! SIAM, 2008,
! ISBN13: 978-0-898716-66-5,
! LC: QA401.O44.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function cosine_combo(x)
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: cosine_combo
if (size(x,1) .gt. 1_i4) stop 'cosine_combo: Input has to be array of size 1'
cosine_combo = cos ( x(1) ) &
+ 5.0_dp * cos ( 1.6_dp * x(1) ) &
- 2.0_dp * cos ( 2.0_dp * x(1) ) &
+ 5.0_dp * cos ( 4.5_dp * x(1) ) &
+ 7.0_dp * cos ( 9.0_dp * x(1) )
cosine_combo = cosine_combo + 14.6771885214_dp
end function cosine_combo
! ------------------------------------------------------------------
!
! abs1, 1 + |3x-1|
! Solution: x = 1./3.
! With Brent method:
! A, X*, B: 0.33333299 0.33333351 0.33333385
! FA, FX*, FB: 1.0000010 1.0000005 1.0000015
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 03 February 2012
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) X, the argument of the objective function.
!
function abs1(x)
implicit none
real(dp), dimension(:), intent(in) :: x
real(dp) :: abs1
if (size(x,1) .gt. 1_i4) stop 'abs1: Input has to be array of size 1'
abs1 = 1.0_dp + abs ( 3.0_dp * x(1) - 1.0_dp )
end function abs1
! ------------------------------------------------------------------
!
! R8_AINT truncates an R8 argument to an integer.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 18 October 2011
!
! Author:
!
! John Burkardt.
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) X, the argument.
!
! Output, real(dp) VALUE, the truncated version of X.
!
function r8_aint( x )
implicit none
real(dp) :: r8_aint
real(dp) :: val
real(dp) :: x
if ( x < 0.0_dp ) then
val = -int( abs ( x ) )
else
val = int( abs ( x ) )
end if
r8_aint = val
end function r8_aint
!*****************************************************************************80
!
!! NORMAL_01_SAMPLE samples the standard Normal PDF.
!
! Discussion:
!
! The standard normal distribution has mean 0 and standard
! deviation 1.
!
! Method:
!
! The Box-Muller method is used.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 01 December 2000
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Output, real(dp) X, a sample of the PDF.
!
subroutine normal_01_sample ( x )
use mo_constants, only: pi_dp
use mo_utils, only: le
implicit none
integer(i4), save :: iset = -1
real(dp) v1
real(dp) v2
real(dp) x
real(dp), save :: xsave = 0.0_dp
if ( iset == -1 ) then
call random_seed ( )
iset = 0
end if
if ( iset == 0 ) then
call random_number ( harvest = v1 )
if ( le(v1,0.0_dp) ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'NORMAL_01_SAMPLE - Fatal error!'
write ( *, '(a)' ) ' V1 <= 0.'
write ( *, '(a,g14.6)' ) ' V1 = ', v1
stop
end if
call random_number ( harvest = v2 )
if ( le(v2,0.0_dp) ) then
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'NORMAL_01_SAMPLE - Fatal error!'
write ( *, '(a)' ) ' V2 <= 0.'
write ( *, '(a,g14.6)' ) ' V2 = ', v2
stop
end if
x = sqrt ( - 2.0_dp * log ( v1 ) ) * cos ( 2.0_dp * pi_dp * v2 )
xsave = sqrt ( - 2.0_dp * log ( v1 ) ) * sin ( 2.0_dp * PI_dp * v2 )
iset = 1
else
x = xsave
iset = 0
end if
return
end subroutine normal_01_sample
! ------------------------------------------------------------------
!
! The Fletcher-Powell helical valley function, N = 3.
! Solution: x(1:3) = (/ 1.0_dp, 0.0_dp, 0.0_dp /)
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 15 March 2000
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! Richard Brent,
! Algorithms for Minimization with Derivatives,
! Dover, 2002,
! ISBN: 0-486-41998-3,
! LC: QA402.5.B74.
!
! Parameters:
!
! Input, real(dp) :: X(N), the argument of the objective function.
!
function fletcher_powell_helical_valley(x)
use mo_constants, only: pi_dp
implicit none
! integer(i4) :: n
real(dp) :: fletcher_powell_helical_valley
real(dp) :: th
real(dp), dimension(:), intent(in) :: x
if ( 0.0_dp < x(1) ) then
th = 0.5_dp * atan ( x(2) / x(1) ) / pi_dp
else if ( x(1) < 0.0_dp ) then
th = 0.5_dp * atan ( x(2) / x(1) ) / pi_dp + 0.5_dp
else if ( 0.0_dp < x(2) ) then
th = 0.25_dp
else if ( x(2) < 0.0_dp ) then
th = - 0.25_dp
else
th = 0.0_dp
end if
!call p01_th ( x, th )
fletcher_powell_helical_valley = 100.0_dp * ( x(3) - 10.0_dp * th )**2 &
+ 100.0_dp * ( sqrt ( x(1) * x(1) + x(2) * x(2) ) - 1.0_dp )**2 &
+ x(3) * x(3)
end function fletcher_powell_helical_valley
! ------------------------------------------------------------------
!
! The Biggs EXP6 function, N = 6.
! Solution: x(1:6) = (/ 1.0_dp, 10.0_dp, 1.0_dp, 5.0_dp, 4.0_dp, 3.0_dp /)
! at f(x*) = 0.0
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 04 May 2000
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) :: X(N), the argument of the objective function.
!
function biggs_exp6(x)
implicit none
! integer(i4) :: n
real(dp) :: c
real(dp) :: biggs_exp6
real(dp) :: fi
integer(i4) ::i
real(dp), dimension(:), intent(in) :: x
biggs_exp6 = 0.0_dp
do i = 1, 13
c = - real ( i, dp ) / 10.0_dp
fi = x(3) * exp ( c * x(1) ) - x(4) * exp ( c * x(2) ) &
+ x(6) * exp ( c * x(5) ) - exp ( c ) &
+ 5.0_dp * exp ( 10.0_dp * c ) - 3.0_dp * exp ( 4.0_dp * c )
biggs_exp6 = biggs_exp6 + fi * fi
end do
end function biggs_exp6
! ------------------------------------------------------------------
!
! The Gaussian function, N = 3.
! Search domain: -Pi <= xi <= Pi, i = 1, 2, 3.
! Solution:
! x(1:n) = (/ 0.39895613783875655_dp, 1.0000190844878036_dp, 0.0_dp /)
! at f(x*) = 0.0
! found with Mathematica
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 24 March 2000
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Parameters:
!
! Input, real(dp) :: X(N), the argument of the objective function.
!
function gaussian(x)
implicit none
! integer(i4) :: n
real(dp), dimension(:), intent(in) :: x
real(dp) :: gaussian
integer(i4) :: i
real(dp) :: t
real(dp) :: y(15)
y(1:15) = (/ 0.0009_dp, 0.0044_dp, 0.0175_dp, 0.0540_dp, 0.1295_dp, &
0.2420_dp, 0.3521_dp, 0.3989_dp, 0.3521_dp, 0.2420_dp, &
0.1295_dp, 0.0540_dp, 0.0175_dp, 0.0044_dp, 0.0009_dp /)
gaussian = 0.0_dp
do i = 1, 15
! avoiding underflow
t = - 0.5_dp * x(2) * &
( 3.5_dp - 0.5_dp * real ( i - 1, dp ) - x(3) )**2
if ( t .lt. -709._dp ) then
t = -y(i)
else
t = x(1) * exp ( t ) - y(i)
end if
gaussian = gaussian + t * t
end do
end function gaussian
! ------------------------------------------------------------------
!
! The Powell badly scaled function, N = 2.
! Solution: x(1:2) = (/ 1.098159D-05, 9.106146_dp /)
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 04 May 2000
!
! Author:
!
! John Burkardt
! Modified Jul 2012 Matthias Cuntz - function, dp, etc.
!
! Reference:
!
! Richard Brent,
! Algorithms for Minimization with Derivatives,
! Dover, 2002,
! ISBN: 0-486-41998-3,
! LC: QA402.5.B74.
!
! Parameters:
!
! Input, real(dp) :: X(N), the argument of the objective function.
!
function powell_badly_scaled(x)
implicit none
! integer(i4) :: n
real(dp) :: powell_badly_scaled
real(dp) :: f1
real(dp) :: f2
real(dp), dimension(:), intent(in) :: x
f1 = 10000.0_dp * x(1) * x(2) - 1.0_dp
f2 = exp ( - x(1) ) + exp ( - x(2) ) - 1.0001_dp
powell_badly_scaled = f1 * f1 + f2 * f2
end function powell_badly_scaled
! ------------------------------------------------------------------
!
! The Box 3-dimensional function, N = 3.
! Solution: x(1:3) = (/ 1.0_dp, 10.0_dp, 1.0_dp /)
! seems to be not the only solution
!