C ================================================================= C PROGRAM TO FIND GLOBAL MINIMUM BY REPULSIVE PARTICLE SWARM METHOD C WRITTEN BY SK MISHRA, DEPT. OF ECONOMICS, NEHU, SHILLONG (INDIA) C ----------------------------------------------------------------- PARAMETER (N=30,NN=15,MX=50,NSTEP=11,ITRN=10000,NSIGMA=1,ITOP=3) C PARAMETER(N=50,NN=25,MX=100,NSTEP=9,ITRN=10000,NSIGMA=1,ITOP=3) C PARAMETER (N=100,NN=15,MX=100,NSTEP=9,ITRN=10000,NSIGMA=1,ITOP=3) C IN CERTAIN CASES THE ONE OR THE OTHER SPECIFICATION WORKS BETTER C DIFFERENT SPECIFICATIONS OF PARAMETERS MAY SUIT DIFFERENT TYPES C OF FUNCTIONS OR DIMENSIONS - ONE HAS TO DO SOME TRIAL AND ERROR C ----------------------------------------------------------------- C N = POPULATION SIZE. IN MOST OF THE CASES N=30 IS OK. ITS VALUE C MAY BE INCREASED TO 50 OR 100 TOO. THE PARAMETER NN IS THE SIZE OF C RANDOMLY CHOSEN NEIGHBOURS. 15 TO 25 (BUT SUFFICIENTLY LESS THAN C N) IS A GOOD CHOICE. MX IS THE MAXIMAL SIZE OF DECISION VARIABLES. C IN F(X1, X2,...,XM) M SHOULD BE LESS THAN OR EQUAL TO MX. ITRN IS C THE NO. OF ITERATIONS. IT MAY DEPEND ON THE PROBLEM. 200(AT LEAST) C TO 500 ITERATIONS MAY BE GOOD ENOUGH. BUT FOR FUNCTIONS LIKE C ROSENBROCKOR GRIEWANK OF LARGE SIZE (SAY M=30) IT IS NEEDED THAT C ITRN IS LARGE, SAY 5000 OR EVEN 10000. C SIGMA INTRODUCES PERTURBATION & HELPS THE SEARCH JUMP OUT OF LOCAL C OPTIMA. FOR EXAMPLE : RASTRIGIN FUNCTION OF DMENSION 3O OR LARGER C NSTEP DOES LOCAL SEARCH BY TUNNELLING AND WORKS WELL BETWEEN 5 AND C 15, WHICH IS MUCH ON THE HIGHER SIDE. C ITOP <=1 (RING); ITOP=2 (RING AND RANDOM); ITOP=>3 (RANDOM) C NSIGMA=0 (NO CHAOTIC PERTURBATION);NSIGMA=1 (CHAOTIC PERTURBATION) C NOTE THAT NSIGMA=1 NEED NOT ALWAYS WORK BETTER (OR WORSE) C SUBROUTINE FUNC( ) DEFINES OR CALLS THE FUNCTION TO BE OPTIMIZED. IMPLICIT DOUBLE PRECISION (A-H,O-Z) COMMON /RNDM/IU,IV COMMON /KFF/KF,NFCALL,FTIT INTEGER IU,IV CHARACTER *70 FTIT COMMON /XYDATA/X0,Y0,ALIM,NPOINTS DIMENSION X0(200),Y0(200),ALIM(2,4) ! IF MORE DATA INCREASE THESE DIMENSION X(N,MX),V(N,MX),A(MX),VI(MX) DIMENSION XX(N,MX),F(N),V1(MX),V2(MX),V3(MX),V4(MX),BST(MX) C A1 A2 AND A3 ARE CONSTANTS AND W IS THE INERTIA WEIGHT. C OCCASIONALLY, TINKERING WITH THESE VALUES, ESPECIALLY A3, MAY BE C NEEDED. DATA A1,A2,A3,W,SIGMA,EPSI /.5D0,.5D0,5.D-04,.5D00,1.D-03,1.D-08/ C ----------------------------------------------------------------- M=4 ! NO OF PARAMETERS C ----------------------------------------------------------------- GGBEST=1.D30 ! TO BE USED FOR TERMINATION CRITERION LCOUNT=0 NFCALL=0 WRITE(*,*)'PROVIDE A FOUR-DIGIT POSITIVE ODD INTEGER, SAY, 1171' READ(*,*) IU ! COULD BE ANY OTHER 4 OR 5 DIGIT ODD INTEGER FMIN=1.0E30 C GENERATE N-SIZE POPULATION OF M-TUPLE PARAMETERS X(I,J) RANDOMLY DO I=1,N DO J=1,M CALL RANDOM(RAND) !GENERATE X WITHIN X(I,J)=(RAND-0.5D00)*200 ! GENERATE X WITHIN C WE GENERATE RANDOM(-1000,1000). HERE MULTIPLIER IS 200. C TINKERING IN SOME CASES MAY BE NEEDED ENDDO F(I)=1.0D30 ENDDO C INITIALISE VELOCITIES V(I) FOR EACH INDIVIDUAL IN THE POPULATION DO I=1,N DO J=1,M CALL RANDOM(RAND) V(I,J)=(RAND-0.5D+00) C V(I,J)=RAND ENDDO ENDDO DO 100 ITER=1,ITRN C LET EACH INDIVIDUAL SEARCH FOR THE BEST IN ITS NEIGHBOURHOOD DO I=1,N DO J=1,M A(J)=X(I,J) VI(J)=V(I,J) ENDDO CALL LSRCH(A,M,VI,NSTEP,FI) IF(FI.LT.F(I)) THEN F(I)=FI DO IN=1,M BST(IN)=A(IN) ENDDO C F(I) CONTAINS THE LOCAL BEST VALUE OF FUNCTION FOR ITH INDIVIDUAL C XX(I,J) IS THE M-TUPLE VALUE OF X ASSOCIATED WITH LOCAL BEST F(I) DO J=1,M XX(I,J)=A(J) ENDDO ENDIF ENDDO C NOW LET EVERY INDIVIDUAL RANDOMLY COSULT NN(<