   program Swarm_CEC08_benchmark;
   {$APPTYPE CONSOLE}
   {$W-,M-,Q-,I-}
   uses sysutils,math,CEC08_Benchmark;
   var i, k,m,simul, II,SS,fois,fois1:integer; a,s,s1,moyfit,deviation_val:double; timeDEb,timeFin,moyfitT:TdateTime;
       str:string;
   begin  { programme principal}
   fdejon:=1 ; MaxVel:= 4; MinVel:=-4; randomize; Initialise; FE:=5000*Dim;
   for simul:=0 to nb_eval-1 do
   begin
    timeDeb:=gettime();
    for k:=0 to nb_group-1 do begin pas2[k]:=0.4; pas[k]:=0.4;InertWW[k]:=2; end;
    Init_Spop();  generation:=1;
    Evaluation();
    if generation=1 then begin writeln;writeln('Run :',simul);writeln('Gen: ',generation,'Error: ',abs(SwarmPop[Gbest].BestFitness-biase)); end;

    While (Not Arret(simul)) do
    begin
     if (generation=1) then tabsauv[simul].g1:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=50) then tabsauv[simul].g50:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=100) then tabsauv[simul].g100:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=500) then tabsauv[simul].g500:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=1000)then tabsauv[simul].g1000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=1200)then tabsauv[simul].g1200:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=3000)then tabsauv[simul].g3000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=4000)then tabsauv[simul].g4000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=5000)then tabsauv[simul].g5000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=10000) then  tabsauv[simul].g10000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=25000)then tabsauv[simul].g25000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=50000)then tabsauv[simul].g50000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=100000) then  tabsauv[simul].g100000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=250000)then  tabsauv[simul].g250000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=500000)then  tabsauv[simul].g500000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=1000000)then  tabsauv[simul].g1000000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=2500000)then  tabsauv[simul].g2500000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if (generation=5000000)then  tabsauv[simul].g5000000:=abs(SwarmPop[Gbest].BestFitness-biase);
     if ((generation=100) or(generation=500) or (generation=1200)or (generation=3000) or (generation=4000) or (generation=5000) or (generation=10000) or(generation=25000) or (generation=50000) or (generation=100000) or (generation=250000) or (generation=300000) or (generation=400000)or(generation=500000)or(generation=1000000)or(generation=2500000)or(generation=5000000)) then  writeln('Gen: ',generation,'fit: ',SwarmPop[Gbest].BestFitness,' Error: ',abs(SwarmPop[Gbest].BestFitness-biase));
     Update();
     Evaluation();generation:=generation+1;
    end;
    case Dim of
      50: tabsauv[simul].eval:=tabsauv[simul].g250000;
     100: tabsauv[simul].eval:=tabsauv[simul].g500000;
     200: tabsauv[simul].eval:=tabsauv[simul].g1000000;
     450..500: tabsauv[simul].eval:=tabsauv[simul].g2500000;
    1000: tabsauv[simul].eval:=tabsauv[simul].g5000000;
    end;
    timeFin:=gettime(); str:=TimeToStr(timeFin-timeDeb);tabsauv[simul].time:=str;
   end;
   Tri;  writeln; writeln;
   writeln('Valeur Best Fitness   Eval est = ',tabsauv[0].eval);
   writeln('Valeur Median Fitness Eval est = ',tabsauv[12].eval);
   writeln('Valeur Worst Fitness  Eval est = ',tabsauv[24].eval);
   writeln;
   writeln('Valeur Best Time    est = ',tabsauv[0].time);
   writeln('Valeur Median Time  est = ',tabsauv[12].time);
   writeln('Valeur Worst Time  est = ',tabsauv[24].time);
   writeln;

   moyfit:=0; deviation_val:=0;
   for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].eval;
   moyfit:=moyfit/nb_eval; writeln(' Moyenne Fitness Eval : ',moyfit);
   for i:=0 to nb_eval-1 do deviation_val:=deviation_val+sqr(tabsauv[i].eval-moyfit);
   deviation_val:=sqrt(deviation_val/nb_eval); writeln('Ecart de Deviation Eval : ',deviation_val);

   writeln(' ------------  Performances Mesures Best Solution -----------------');
   writeln('G1: ',tabsauv[0].g1);writeln('G50: ',tabsauv[0].g50);writeln('G100: ',tabsauv[0].g100);
   writeln('G500: ',tabsauv[0].g500);writeln('G1000: ',tabsauv[0].g1000); writeln('G1200: ',tabsauv[0].g1200);
   writeln('G3000: ',tabsauv[0].g3000);   writeln('G4000: ',tabsauv[0].g4000); writeln('G5000: ',tabsauv[0].g5000);
   writeln('G10000: ',tabsauv[0].g10000);  writeln('G25000: ',tabsauv[0].g25000);
   writeln('G50000: ',tabsauv[0].g50000);
   writeln('G100000: ',tabsauv[0].g100000); writeln('G250000: ',tabsauv[0].g250000);
   writeln('G500000: ',tabsauv[0].g500000);writeln('G1000000: ',tabsauv[0].g1000000);
   writeln('G2500000: ',tabsauv[0].g2500000); writeln('G5000000: ',tabsauv[0].g5000000);

   writeln(' ------------  Performances Mesures Average Solution -----------------');
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g1; moyfit:=moyfit/nb_eval;
   writeln('G1: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g50; moyfit:=moyfit/nb_eval;
   writeln('G50: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g100; moyfit:=moyfit/nb_eval;
   writeln('G100: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g500; moyfit:=moyfit/nb_eval;
   writeln('G500: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g1000; moyfit:=moyfit/nb_eval;
   writeln('G1000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g1200; moyfit:=moyfit/nb_eval;
   writeln('G1200: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g3000; moyfit:=moyfit/nb_eval;
   writeln('G3000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g4000; moyfit:=moyfit/nb_eval;
   writeln('G4000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g5000; moyfit:=moyfit/nb_eval;
   writeln('G5000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g10000; moyfit:=moyfit/nb_eval;
   writeln('G10000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g25000; moyfit:=moyfit/nb_eval;
   writeln('G25000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g50000; moyfit:=moyfit/nb_eval;
   writeln('G50000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g100000; moyfit:=moyfit/nb_eval;
   writeln('G100000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g250000; moyfit:=moyfit/nb_eval;
   writeln('G250000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g500000; moyfit:=moyfit/nb_eval;
   writeln('G500000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g1000000; moyfit:=moyfit/nb_eval;
   writeln('G1000000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g2500000; moyfit:=moyfit/nb_eval;
   writeln('G2500000: ',moyfit);
   moyfit:=0; for i:=0 to nb_eval-1 do moyfit:=moyfit+tabsauv[i].g5000000; moyfit:=moyfit/nb_eval;
   writeln('G5000000: ',moyfit);
   readln;
End.


