/* 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=53; int i; for(i=0;i<val;i++) { scanf("%lf %lf %lf",&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); pbesta[i]=sa[i]; pbestb[i]=sb[i]; f[i]=fn(pbesta[i],pbestb[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.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(); }
int main(int argc, char *argv[]) { rnd_state_t state; uint64_t size_min, size_max, size; struct timeval tv0, tv1; if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: %s <amount-min> <amount-max> [seed]\n", argv[0]); return 1; } size_min = atoll(argv[1]); size_max = atoll(argv[2]); uint64_t seed; if (argv[3]) { seed = strtoll(argv[3], NULL, 16); } else { seed = make_seed(); } fprintf(stderr,"Seed: %012lx\n", seed); rnd_seed(&state, seed); size = rnd_range(&state, size_min, size_max); gettimeofday(&tv0, NULL); if (gen(&state, size) < 0) { perror("fwrite failed"); return 2; } gettimeofday(&tv1, NULL); double t = (tv1.tv_sec - tv0.tv_sec) + (tv1.tv_usec - tv0.tv_usec)/1000000.0; double speed = size / 1048576.0 / t; fprintf(stderr,"Speed: %.0fMB/s, Filesize: %llu\n", speed, (long long)size); return 0; }
void _loop_float(void *dst,void *src,int count,int size) { if(src) { int i; float *s=(float *)src; float *d=(float *)dst; int p=0; for(i=0;i<count;i++) { if(size>=1) d[p+0]=s[p+0]; if(size>=2) d[p+1]=s[p+1]; if(size>=3) d[p+2]=s[p+2]; if(size>=4) d[p+3]=s[p+3]; p+=size; } } else { int i; float *d=(float *)dst; int p=0; float pp=.0001; for(i=0;i<count;i++) { if(size>=1) d[p+0]+=rnd_range(0,100)*pp; if(size>=2) d[p+1]+=rnd_range(0,100)*pp; if(size>=3) d[p+2]+=rnd_range(0,100)*pp; if(size>=4) d[p+3]+=rnd_range(0,100)*pp; p+=size; } } }
/* 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(); }
float _rnd( void) { return( .34 + ( rndf() * .8 * ( rnd_range(0,2) % 2))); }