Commit 3a879d67e4b33e9b20a8994a10a6cdee69b6ef2b

Added a run number counter
src/de.c
(18 / 5)
  
317317 int prngType;
318318 int gen, genmax, seed;
319319 long nfeval; /* number of function evaluations */
320 int no_runs; /* number of consecutive runs to make */
320321 double trial_cost; /* buffer variable */
321322 double tmp[MAXDIM], best[MAXDIM], bestit[MAXDIM]; /* members */
322323 double cost[MAXPOP]; /* obj. funct. values */
372372 if (!config_lookup_int(cf, "D", &D))
373373 {printf("D is not defined\n");exit(12);}
374374
375 if (!config_lookup_int(cf, "no_runs", &no_runs))
376 {printf("no_runs is not defined, using 1\n"); no_runs=1;}
377
375378 if (!config_lookup_int(cf, "NP", &NP))
376379 {printf("NP is not defined\n");exit(12);}
377380
392392 printf("target_file: %s\n",target_file);
393393 printf("genMax: %d\n",genmax); /*---maximum number of generations------*/
394394 printf("refresh: %d\n",refresh); /*---output refresh cycle---------------*/
395 printf("no_runs: %d\n",no_runs);
395396 printf("D: %d\n",D); /*---number of parameters---------------*/
396397 printf("Spop:%d\n",NP); /*---population size.-------------------*/
397398 printf("PRNG:%d\n",prngType); /*---which PRNG to use------------------*/
423423 if(refresh <= 0){printf("\nError! refresh=%d, should be > 0\n",refresh);exit(1);}
424424 if(genmax <= 0){printf("\nError! genmax=%d, should be > 0\n",genmax);exit(1);}
425425
426
427 /* Initialize random number generator--------------------------------------*/
428 initRandom(prngType);
429
430// Loop for consecutive runs
431for (int run_number=0; run_number<no_runs; run_number++) {
426432 /* Open output file -------------------------------------------------------*/
427 fpout_ptr = fopen(target_file,"w");
433 char target[50];
434 if (no_runs == 1) {sprintf(target,"%s",target_file);}
435 else {sprintf(target,"%s%d",target_file,run_number);}
436
437 fpout_ptr = fopen(target,"w");
428438 if (fpout_ptr == NULL)
429439 {printf("\nCannot open output file\n");exit(1);}
430440 fprintf(fpout_ptr,"#EvaluationCount\tFitness\n");
431441
432 /* Initialize random number generator--------------------------------------*/
433 initRandom(prngType);
434
435442 nfeval=0; /* reset number of function evaluations */
436443
437444 /* Initialization of the population ---------------------------------------*/
571571 printf("\n\n\n * * * * * * * * S O L U T I O N * * * * * * * *");
572572 trial_cost=evaluate(D,2,best,&nfeval,func_number); /* Evaluate best vector again */
573573 printf("\n f(X)=%lf\n",trial_cost);
574 printf("output is in: %s\n",target_file);
574 printf("output is in: %s\n",target);
575575 printf("\n * * * P R O G R A M T E R M I N A T E D * * *\n");
576576 fclose(fpout_ptr);
577}
577578 //fclose(ftest_ptr); //****TESTCODE*****
578579 config_destroy(cf);
579580 return(0);