cma.f90 3.92 KB
Newer Older
ofgeorg's avatar
ofgeorg committed
1 2 3 4 5 6 7 8 9 10 11 12 13
      !-------------------------------------------------------------------------
      !  Program	  :          cma
      !-------------------------------------------------------------------------
      !
      !  Purpose      : This is the main entry point for pcmalib
      !                
      !  Remarks      : 
      !
      !  References   :
      !
      !  Revisions    :
      !-------------------------------------------------------------------------
      !-------------------------------------------------------------------------
14 15 16 17
      !  pCMALib: a parallel fortran 90 library for the evolution strategy with
      !           covariance matrix adaptation
      !  Christian L. Mueller, Benedikt Baumgartner, Georg Ofenbeck, Christian L. Mueller
      !  MOSAIC group, ETH Zurich, Switzerland
ofgeorg's avatar
ofgeorg committed
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
      !-------------------------------------------------------------------------
      
      PROGRAM cma
      USE cmaes_mod
      USE cmaes_param_mod
      USE cmaes_opts_mod
      USE CEC2005
      IMPLICIT NONE
#ifdef __HAVE_MPI__      
      INCLUDE "mpif.h"
#endif      
      INTERFACE cmaes_start
      	SUBROUTINE cmaes_start(fitfun,xstart,insigma,varargin)
	      USE cmaes_param_mod
    	  USE cmaes_mod, ONLY : input
    	  IMPLICIT NONE
	      EXTERNAL							:: fitfun	      
    	  REAL(MK), INTENT(in) 				:: xstart(:)
    	  REAL(MK), INTENT(in)				:: insigma(:)
      	  REAL(MK), INTENT(in), OPTIONAL 	:: varargin
      	END SUBROUTINE cmaes_start
      END INTERFACE cmaes_start
      
      !-------------------------------------------------------------------------
      ! Here starts the interesting part!
      ! Feel free to edit the following lines
      !-------------------------------------------------------------------------
      INTEGER 				:: ierr,i
!      REAL(MK),DIMENSION(d) :: xstart
      
      CHARACTER(len=10)		:: proc
	  ! Random number generator
	  INTEGER				:: seed
      REAL(MK)				:: ZBQLUAB
	  CHARACTER(len=256)    :: ctrlfile
      
      
      EXTERNAL                          :: benchmark_bobb
      EXTERNAL                          :: LJ
      EXTERNAL                          :: TIP4P
      EXTERNAL                          :: LJ_POT_COMP
      EXTERNAL                          :: DoubleFunnel
      EXTERNAL                          :: random_landscape
      CALL GETARG(1 , ctrlfile)
 !     WRITE(*,*) ctrlfile

   



#ifdef __HAVE_MPI__
      CALL MPI_INIT(ierr)
      CALL MPI_COMM_RANK(MPI_COMM_WORLD, MY_RANK, ierr)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, NUM_CMA_RUNS, ierr)
      WRITE(proc,'(I10)') MY_RANK
#endif
      
      CALL CPU_TIME(time_start)
      CALL cmaes_readparams(ctrlfile,ierr)



      ! Start CMA-ES/PS-CMA-ES
      IF (options%use_TIP .EQ. .TRUE.) THEN
        CALL cmaes_start(TIP4P,options%xstart,options%insigma)
      ELSEIF (options%use_LJ .EQ. .TRUE.) THEN      
        CALL cmaes_start(LJ,options%xstart,options%insigma)
      ELSEIF (options%use_LJ_comp .EQ. .TRUE.) THEN
        CALL cmaes_start(LJ_POT_COMP,options%xstart,options%insigma)
      ELSEIF (options%use_DF .EQ. .TRUE.) THEN
        CALL cmaes_start(DoubleFunnel,options%xstart,options%insigma)        
      ELSEIF (options%use_CEC .EQ. .TRUE.) THEN 
	    CALL cmaes_start(benchmark,options%xstart,options%insigma)
	  ELSEIF (options%use_BOBB .EQ. .TRUE.) THEN
	    CALL cmaes_start(benchmark_bobb,options%xstart,options%insigma)
	  ELSEIF (options%use_RANDOM_LANDSCAPE .EQ. .TRUE.) THEN
	    CALL ZBQLINI(1)
	    CALL cmaes_start(random_landscape,options%xstart,options%insigma) !this is mainly to test CMA-ES behaviour
	  ELSE
	  
	    ! your costum function here
	    !CALL cmaes_start(YOUR_FITNESS_FUNCTION,options%xstart,options%insigma)
	    !   will be called with 
	    !   CALL fitfun(f,x(N),N,1,options%LBounds,options%UBounds)
	  END IF

	  
#ifdef __HAVE_MPI__
	  CALL MPI_FINALIZE(ierr)
#endif

	  
      END PROGRAM cma