void find_count(node_t root, int* count) { if(root != NULL) { find_count(root -> llink, count); *count = *count + 1; find_count(root -> rlink, count); } }
/* cal_fn(k) function calculates function value for kth particle by accessing fn(a,b) function*/ void cal_fn( int k) { double newy; newy=fn(sa[k],sb[k],sc[k]); f[k]=newy; temp_mare[k]=f[k]; //new added temp_count[k]=find_count(sa[k],sb[k],sc[k]); // printf("\n%d",temp_count[k]); }
/*find_pbest(k) function finds the personal best values of the kth particle*/ void find_pbest(int k) { double newy,oldy,newc,oldc; newy=f[k]; newc=temp_count[k]; oldy=fn(pbesta[k],pbestb[k],pbestc[k]); oldc=find_count(pbesta[k],pbestb[k],pbestc[k]); if((newy<oldy && newy>breakpc) || (newy<breakpc && oldy<breakpc && newc>oldc)||(newy<oldy && newy<breakpc && oldy>=breakpc)) { pbesta[k]=sa[k]; pbestb[k]=sb[k]; pbestc[k]=sc[k]; } }
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; }
void RG_create_path(QDP_ColorMatrix *pr_wlink[RG_Ncn], QDP_ColorMatrix *link_qdp[RG_Nd], QDP_Sub_Block s,int len) { int i,j,k,t,x[4]; int count,c2,space_only; QDP_ColorMatrix *path_1[4]; QDP_ColorMatrix *path_2[12]; QDP_ColorMatrix *path_3[24]; QDP_ColorMatrix *path_4[24]; QDP_ColorMatrix *wlink[RG_Ncn]; QDP_Shift offset; shift_v *d1,*d2,*d3,*d4; QLA_Real c = 1.0; QLA_Real fact2 = 1.0/2.0; QLA_Real fact3 = 1.0/6.0; QLA_Real fact4 = 1.0/24.0; QLA_Complex unit; d1 = (shift_v *) malloc(4*sizeof(shift_v)); d2 = (shift_v *) malloc(12*sizeof(shift_v)); d3 = (shift_v *) malloc(24*sizeof(shift_v)); d4 = (shift_v *) malloc(24*sizeof(shift_v)); for (i = 0; i < RG_Ncn; i++) wlink[i] = QDP_create_M(); for (i = 0; i < 4; i++) path_1[i] = QDP_create_M(); for (i = 0; i < 4; i++) SQDP_M_eq_M(path_1[i],link_qdp[i],s); for (i = 0; i < 12; i++) path_2[i] = QDP_create_M(); for (i = 0; i < 24; i++) { path_3[i] = QDP_create_M(); path_4[i] = QDP_create_M(); } // printf("Start building paths %d\n",this_node); fflush(stdout); for (i = 0; i < RG_Nd; i++) { x[0] = i; d1[i] = create_shift(x,1,len); } // printf("First shift %d\n",this_node);fflush(stdout); count = 0; for (i = 0; i < RG_Nd; i++) { x[0] = i; c2 = find_count(d1,x,1); offset = QDP_create_shift(d1[c2].s); for (j = 0; j < RG_Nd ; j++) if ( j != i) { x[1] = j; d2[count] = create_shift(x,2,len); SQDP_M_eq_M_times_sM(path_2[count],path_1[c2],link_qdp[j],offset,QDP_forward,s); count ++; } QDP_destroy_shift(offset); } // printf("Second shift %d\n",this_node);fflush(stdout); count = 0; for (i = 0; i < RG_Nd; i++) for (j = 0; j < RG_Nd; j++) if (j != i) { x[0] = i; x[1] = j; c2 = find_count(d2,x,2); offset = QDP_create_shift(d2[c2].s); for (k = 0; k < RG_Nd; k++) if (k != i) if (k != j) { x[2] = k; d3[count] = create_shift(x,3,len); SQDP_M_eq_M_times_sM(path_3[count],path_2[c2],link_qdp[k],offset,QDP_forward,s); count++; } QDP_destroy_shift(offset); } // printf("Third shift %d\n",this_node);fflush(stdout); count = 0; for (i = 0; i < RG_Nd; i++) for (j = 0; j < RG_Nd; j++) if (j != i) for (k = 0; k < RG_Nd; k++) if (k != i) if (k != j) { x[0] = i; x[1] = j; x[2] = k; c2 = find_count(d3,x,3); offset = QDP_create_shift(d3[c2].s); for (t = 0; t < RG_Nd; t++) if (t != i) if (t != j) if (t != k) { x[3] = t; d4[count] = create_shift(x,4,len); SQDP_M_eq_M_times_sM(path_4[count],path_3[c2],link_qdp[t],offset,QDP_forward,s); count++; } QDP_destroy_shift(offset); } // printf("Fourth shift %d\n",this_node);fflush(stdout); QLA_C_eq_R(&unit,&c); SQDP_M_eq_c(wlink[0],&unit,s); for (i=1;i<5;i++) SQDP_M_eq_M(wlink[i],path_1[i-1],s); for (i=5;i<RG_Ncn;i++) { SQDP_M_eq_zero(wlink[i],s); for (j=0;j<12;j++) if(d2[j].rv == i) SQDP_M_peq_r_times_M(wlink[i],&fact2,path_2[j],s); for (j=0;j<24;j++) if(d3[j].rv == i) SQDP_M_peq_r_times_M(wlink[i],&fact3,path_3[j],s); for (j=0;j<24;j++) if(d4[j].rv == i) SQDP_M_peq_r_times_M(wlink[i],&fact4,path_3[j],s); } space_only = RG_Ncn; // printf("projection %d\n",this_node);fflush(stdout); project_qdp(wlink, pr_wlink,&space_only); for (i = 0; i < 4; i++) QDP_destroy_M(path_1[i]); for (i = 0; i < 12; i++) QDP_destroy_M(path_2[i]); for (i = 0; i < 24; i++) { QDP_destroy_M(path_3[i]); QDP_destroy_M(path_4[i]); } for (i = 0; i < RG_Ncn; i++) QDP_destroy_M(wlink[i]); free(d1); free(d2); free(d3); free(d4); return; }
int main(int argc, char **argv) { int n, m; COUNTS **vector = typeCalloc((size_t) argc, COUNTS *); int *widths = typeCalloc((size_t) (argc + 1), int); char **labels; int lwidth; while ((n = getopt(argc, argv, "mp")) != EOF) { switch (n) { case 'm': m_opt = 1; break; case 'p': p_opt = 1; break; default: usage(); } } if (optind >= argc) usage(); /* count everything */ labels = argv + optind; for (n = optind, m = 0; n < argc; n++) { widths[m] = (int) strlen(argv[n]) + 1; if (widths[m] < 8) widths[m] = 8; vector[m++] = chrcount(argv[n]); } /* FIXME: should expand the first column to allow for names that appear * in other columns, but not in the first */ /* compute the label-width */ for (n = 0, lwidth = 8; vector[0][n].name != 0; n++) { if (lwidth < (int) strlen(vector[0][n].name) + 1) lwidth = (int) strlen(vector[0][n].name) + 1; } /* write the header */ printf("%-*.*s", lwidth, lwidth, "filename"); for (n = 0; labels[n] != 0; n++) printf("%*s", widths[n], labels[n]); printf("\n"); /* write the rows */ for (n = 0; vector[0][n].name != 0; n++) { printf("%-*.*s", lwidth, lwidth, vector[0][n].name); for (m = 0; labels[m] != 0; m++) { long value = find_count(vector[0][n].name, vector[m]); if (value >= 0) { if (p_opt && vector[0][n].count) { printf("%*.1f%%", widths[m] - 1, (100.0 * (double) value) / (double) vector[0][n].count); } else { printf("%*ld", widths[m], value); } } else printf("%*s", widths[m], "n/a"); } printf("\n"); } free(vector); free(widths); return EXIT_SUCCESS; }