/* init() function initializes values too all the parameters and also initial v,s values */ void init() { w=0.50; /* inertia factor*/ c1=2.0; /* c1 denotes local search weight*/ c2=2.0; /* c2 denotes global search weight*/ noi=900; /* no of iterations*/ nop=13; /*no of particles*/ int i; for(i=0;i<nop;i++) { scanf("%lf %lf %lf\n",&size[i],&eval[i],&me[i]); // printf("%lf %lf %lf\n",size[i],eval[i],me[i]); } for(i=0;i<nop;i++){ sa[i]=rnd_range(0,10); va[i]=rnd_range(0,5); sb[i]=rnd_range(0,5); vb[i]=rnd_range(0,2); sc[i]=rnd_range(0,1); vc[i]=rnd_range(0,1); sd[i]=rnd_range(0,2); vd[i]=rnd_range(0,2); pbesta[i]=sa[i]; pbestb[i]=sb[i]; pbestc[i]=sc[i]; pbestd[i]=sd[i]; f[i]=fn(pbesta[i],pbestb[i],pbestc[i],pbestd[i]); } find_gbest(); }
/* init() function initializes values too all the parameters and also initial v,s values */ void init() { w=0.50; /* inertia factor*/ c1=2.5; /* c1 denotes local search weight*/ c2=0.5; /* c2 denotes global search weight*/ noi=500; /* no of iterations*/ nop=18; /*no of particles*/ int i; for(i=0;i<nop;i++) { scanf("%lf %lf %lf\n",&size[i],&eval[i],&me[i]); } /* initialization of particle position and velocities*/ for(i=0;i<nop;i++){ sa[i]=rnd_range(0,10); va[i]=rnd_range(0,2); sb[i]=rnd_range(0,5); vb[i]=rnd_range(0,2); sc[i]=rnd_range(0,1); vc[i]=rnd_range(0,1); pbesta[i]=sa[i]; pbestb[i]=sb[i]; pbestc[i]=sc[i]; f[i]=fn(pbesta[i],pbestb[i],pbestc[i]); } find_gbest(); }
/* init() function initializes values too all the parameters and also initial v,s values */ void init() { w=0.50; c1=2.0; c2=2.0; noi=500; /* no of iterations*/ nop=20; /*no of particles*/ val=21; int i; for(i=0;i<val;i++) { scanf("%lf %lf %lf\n",&size[i],&eval[i],&eaf[i]); } for(i=0;i<nop;i++){ sa[i]=rnd_range(0,5); va[i]=rnd_range(0,2); sb[i]=rnd_range(0,5); vb[i]=rnd_range(0,2); sc[i]=rnd_range(0,5); vc[i]=rnd_range(0,2); pbesta[i]=sa[i]; pbestb[i]=sb[i]; pbestc[i]=sc[i]; f[i]=fn(pbesta[i],pbestb[i],pbestc[i]); } find_gbest(); }
int main() { int i,k; init(); /* initialize values*/ for(i=0;i<noi;i++) { for(k=0;k<nop;k++) { updatea(k); /*update to find new a value*/ updateb(k); /*update particle to new b value*/ cal_fn(k); /* calculate function fn value*/ find_pbest(k); /* find the personal best for this particle*/ } find_gbest(); /* find global best position traversed so far*/ } printf("a=%lf \n b=%lf\n",gbesta,gbestb); printf ("estimated effort \t original effort\n"); printf("---------------------------------------\n"); for(i=0;i<val;i++) { gfunc=gbesta*pow(size[i],gbestb)*eaf[i]; printf("%lf \t\t %lf\n",gfunc,eval[i]); } printf("\n #### MARE =%lf###\n",fn(gbesta,gbestb)*100); return 0; }
int main() { int i,k; init(); /* initialize values*/ //printf("va\t vb\t vc\t sa\t sb\t sc\t f\t pa\t pb\t pc\n"); for(i=0;i<noi;i++) { update_param(i); //printf("a=%lf \n b=%lf\n c=%lf\n",gbesta,gbestb,gbestc); for(k=0;k<nop;k++) {/* following line to be added to view iterations*/ //printf("%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",vc[k],sa[k],sb[k],sc[k],f[k],pbesta[k],pbestb[k],pbestc[k]); updatea(k); /*update to find new a value*/ updateb(k); /*update particle to new b value*/ updatec(k); cal_fn(k); /* calculate function fn value*/ find_pbest(k); update_param(k); /* find the personal best for this particle*/ } find_gbest(); /* find global best position traversed so far*/ } printf("a=%lf \n b=%lf\nc=%lf\n",gbesta,gbestb,gbestc); double mare=0,tmre=0; printf("Estimated effort \t actual effort\n"); printf("---------------------------------------------\n"); for(i=0;i<nop;i++) /* calculation of efort values from final values of a,b,c*/ { gfunc=gbesta*pow(size[i],gbestb)+(gbestc*me[i]); mare=gfunc-eval[i]; mare=mare<0?-mare:mare; tmre+=mare; printf("%lf\t\t %lf\n",gfunc,eval[i]); } /* displaying the MARE value*/ tmre=tmre/nop; printf("total mre=%lf\n",tmre); return 0; }
int main() { int i,k; init(); /* initialize values*/ for(i=0;i<noi;i++) { for(k=0;k<nop;k++) { updatea(k); /*update to find new a value*/ updateb(k); /*update particle to new b value*/ updatec(k); updated(k); cal_fn(k); /* calculate function fn value*/ find_pbest(k); /* find the personal best for this particle*/ } find_gbest(); /* find global best position traversed so far*/ } printf("a=%lf \n b=%lf\nc=%lf\nd=%lf\n",gbesta,gbestb,gbestc,gbestd); printf("estimated value \t actual value\n"); printf("---------------------------------------\n"); double mare=0,tmre=0; /* final effort values calculated using a,b,c,d values obtained*/ for(i=0;i<nop;i++) { gfunc=gbesta*pow(size[i],gbestb)+(gbestc*me[i])+gbestd; mare=gfunc-eval[i]; mare=mare<0?-mare:mare; tmre+=mare; printf("%lf\t\t%lf\n",gfunc,eval[i]); } tmre=tmre/nop; printf("total mre=%lf",tmre); return 0; }
void pso(void) { int i, iter_num; iter_num = 1; while (iter_num < MAX_ITERATIONS) { for (i = 0 ; i < 10; i++) { if (fitness(p[i].current) < fitness(p[i].pbest)) { p[i].pbest = p[i].current; } } find_gbest(); adjust_v(); for (i = 0; i < 10; i++) { p[i].current += v[i]; } iter_num++; } }
int main() { int i,k; init(); /* initialize values*/ for(i=0;i<noi;i++) { for(k=0;k<nop;k++) { updatea(k); /*update to find new a value*/ updateb(k); /*update particle to new b value*/ updatec(k); cal_fn(k); /* calculate function fn value*/ find_pbest(k); /* find the personal best for this particle*/ } find_rankings(); find_gbest(); /* find global best position traversed so far*/ } printf("a=%lf \n b=%lf\nc=%lf\n",gbesta,gbestb,gbestc); double mare=0,tmre=0; printf("Estimated effort \t actual effort\n"); printf("---------------------------------------------\n"); for(i=0;i<val;i++) /* calculation of efoort values from final values of a,b,c*/ { gfunc=gbesta*pow(size[i],gbestb)*eaf[i]+gbestc; printf("%lf\t\t %lf\n",gfunc,eval[i]); } printf("\n number of values below 25=%d",find_count(gbesta,gbestb,gbestc)); //end:printf("\n %lf",gfunc); printf("\n #### MARE =%lf###\n",fn(gbesta,gbestb,gbestc)*100); return 0; }