📄 addmp_eval.cpp
字号:
/* ctr[i] ... retrieval rate */ /* cur[i] ... update rate */ /* I interpreted this formula: Overall Transaction Rate =( ( Sum of transaction rates - highest transaction rate ) * resource contention value ) + highest transaction rate as follows: sum of transaction rates for i is just sum of its Retrieval and Update Rates. So, the formula reduces to: OTR = minimum of (retrieval rate, update rate) * overlap + maximum of (retrieval rate,update rate) */ for(i=0;i<nodes;i++) otr[i] = (double)(min(crt[i],cur[i])*col[i]) + (double)(max(crt[i],cur[i])); /* sa 10^6 -- 10^-3 for 1000, cr = 0.9795 5000 0.9959 */ /* Now populating the array L (called acomms) with the update rate for each client. Eg: acomms[i][j] refers to client i and server j (note acomms[i][j] is equivalent to acomms[nodes*i+j]) so acomms[i][j] will now contain the update rate for client i, for every j */ for(i=0;i<nodes;i++) for(j=0;j<nodes;j++) acomms[nodes*i+j] = (double)(cur[i]); /* now we want acomms[i][j] to be the overall transaction rate for i, in just those cases where the solution connects i to server j. In other cases, acomms[i][j] remains being the update rate for client i. ( the solution vector is genotype, so that genotype[i] gives the server connected to by client i. */ for(i=0;i<nodes;i++) acomms[nodes*i + genotype[i]] = otr[i]; /* now effective communication overhead delays: not too sure about this bit cod[i][j] is the comms overhead delay for client i and server j. I make cod[i][j] = Response Time (formula {1}) = 1/ (1/btt[i][j] - acomms[i][j] ) In the below `respr' is 1/btt - tar . I check this isn't zero before reciprocating it */ for(i=0;i<nodes;i++) for(j=0;j<nodes;j++) {
respr = 1.0/bcomms[i*nodes+j] - acomms[nodes*i + j]; if(respr<0.0001) respr=0.000000001; cod[nodes*i + j] = 1.0/respr; } /* Now -- to actually work out the over */ /* Find those being used as servers */ for(i=0;i<nodes;i++) serv[i]=0; for(i=0;i<nodes;i++) serv[genotype[i]]=1; nservers=0; for(i=0;i<nodes;i++) if (serv[i]==1) nservers++; /* the array tserv[i] will add up all the transaction rates being processed on server i */ for(i=0;i<nodes;i++) /* for each server */ {
/* work out the sum of trans rates on it, and highest */ str=0.0; htr=0.0; for(j=0;j<nodes;j++)
{ ttr = acomms[nodes*j+i]; str+=ttr; if(ttr>htr) htr=ttr; } tserv[i] = (str-htr)*scr + htr; /* now use this as the transaction rate in formula {1} */ respr = 1.0/btt[i] - tserv[i]; if(respr<0.0001) respr = 0.000000001; tserv[i] = 1.0/respr; } /* now, for each server, find the client in cod with worst time, and add to tserv */ for(i=0;i<nodes;i++) { /* find worst client */ htr=0.0; for(j=0;j<nodes;j++) if(cod[j*nodes+i]>htr) htr=cod[j*nodes+i]; tserv[i]+=htr; } shell_sort(tserv, nodes); median = (tserv[nodes/2-1]+tserv[nodes/2])/2.0; worst = tserv[nodes-1]; *one = worst; *two = median; return 1.0;}double eval_adb3(int *genotype, double *one, double *two, double *three){ int i,j, nservers, serv[2000]; double respr, tserv[2000], worst, sec_worst, median, htr, str, ttr; /* calculate overall transaction rate per client */ /* otr[i] will hold the overall transaction rate of client i */ /* ctr[i] ... retrieval rate */ /* cur[i] ... update rate */ /* I interpreted this formula: Overall Transaction Rate =( ( Sum of transaction rates - highest transaction rate ) * resource contention value ) + highest transaction rate as follows: sum of transaction rates for i is just sum of its Retrieval and Update Rates. So, the formula reduces to: OTR = minimum of (retrieval rate, update rate) * overlap + maximum of (retrieval rate,update rate) */ for(i=0;i<nodes;i++) otr[i] = (double)(min(crt[i],cur[i])*col[i]) + (double)(max(crt[i],cur[i])); /* sa 10^6 -- 10^-3 for 1000, cr = 0.9795 5000 0.9959 */ /* Now populating the array L (called acomms) with the update rate for each client. Eg: acomms[i][j] refers to client i and server j (note acomms[i][j] is equivalent to acomms[nodes*i+j]) so acomms[i][j] will now contain the update rate for client i, for every j */ for(i=0;i<nodes;i++) for(j=0;j<nodes;j++) acomms[nodes*i+j] = (double)(cur[i]); /* now we want acomms[i][j] to be the overall transaction rate for i, in just those cases where the solution connects i to server j. In other cases, acomms[i][j] remains being the update rate for client i. ( the solution vector is genotype, so that genotype[i] gives the server connected to by client i. */ for(i=0;i<nodes;i++) acomms[nodes*i + genotype[i]] = otr[i]; /* now effective communication overhead delays: not too sure about this bit cod[i][j] is the comms overhead delay for client i and server j. I make cod[i][j] = Response Time (formula {1}) = 1/ (1/btt[i][j] - acomms[i][j] ) In the below `respr' is 1/btt - tar . I check this isn't zero before reciprocating it */ for(i=0;i<nodes;i++) for(j=0;j<nodes;j++) { respr = 1.0/bcomms[i*nodes+j] - acomms[nodes*i + j]; if(respr<0.0001) respr=0.000000001; cod[nodes*i + j] = 1.0/respr; } /* Now -- to actually work out the over */ /* Find those being used as servers */ for(i=0;i<nodes;i++) serv[i]=0; for(i=0;i<nodes;i++) serv[genotype[i]]=1; nservers=0; for(i=0;i<nodes;i++) if (serv[i]==1) nservers++; /* the array tserv[i] will add up all the transaction rates being processed on server i */ for(i=0;i<nodes;i++) /* for each server */ /* if(serv[i]==1) */ { /* work out the sum of trans rates on it, and highest */ str=0.0; htr=0.0; for(j=0;j<nodes;j++){ ttr = acomms[nodes*j+i]; str+=ttr; if(ttr>htr) htr=ttr; } /* now work out the overall transaction rate using {2} */ tserv[i] = (str-htr)*scr + htr; /* now use this as the transaction rate in formula {1} */ respr = 1.0/btt[i] - tserv[i]; if(respr<0.0001) respr = 0.000000001; tserv[i] = 1.0/respr; } /* now, for each server, find the client in cod with worst time, and add to tserv */ for(i=0;i<nodes;i++) /* if(serv[i]==1) */ { /* find worst client */ htr=0.0; for(j=0;j<nodes;j++) if(cod[j*nodes+i]>htr) htr=cod[j*nodes+i]; tserv[i]+=htr; } /* now find least worst + average of the remainder */ /* worst=0.0; htr=0.0; for(i=0;i<nodes;i++) {if(tserv[i]>worst) worst=tserv[i]; htr+=tserv[i]; } htr-=worst; htr /= (double)(nodes-1) ;*/ /* htr*=0.1; *//* return(-1.0* (worst + htr)); *//****************************************************** HERE Objective 1 is now the value of worst Objective 2 is now the value of htr both are doubles For Illustration, both just printed at the moment.*******************************************************/ shell_sort(tserv, nodes); median = (tserv[nodes/2-1]+tserv[nodes/2])/2.0; worst = tserv[(int)(0.9*nodes)-1]; sec_worst = tserv[(int)(0.8*nodes)-1]; *one = worst; *two = sec_worst; *three = median;// printf("%g %g\n", worst, htr); return 1.0;}double min(double a, double b){ if(a>b) return(b); else return(a);}double max(double a, double b){ if(a>b) return(a); else return(b);}void shell_sort(double *ptr, int count){ double x; int i, j, gap, k; int a[5];
a[0]=9; a[1] = 5; a[2] = 3; a[3] = 2; a[4] = 1; for (k = 0; k < 5; k++) { gap = a[k]; for (i = gap; i < count; ++i) { x = ptr[i]; for (j = i-gap; x < ptr[j] && j >=0; j = j-gap) { ptr[j+gap] = ptr[j]; } ptr[j+gap] = x; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -