#include #include #include typedef struct known_struct { int id; int rank; int best_rank; int best_overall_rank; int score; float bw[6]; } Known; int id_count = 0; int idmap[100000]; // Used to map the ids to values 0,1,2,... total # of ids float maxgc = 0.0, maxgc3 = 0.0, maxdi = 0.0, maxln = 0.0; char *filename; FILE *in, *out; Known known_cases[9]; int calculate_ranks(float w1, float w2, float w3, float w4, float w5, float w6); void radix(int array[], int pos); int main (int argc, char **argv) { int i; float arg2; float w1 = 0.0, w2 = 0.0, w3 = 0.0, w4 = 0.0, w5 = 0.0, w6 = 0.0; float bw1 = 0.0, bw2 = 0.0, bw3 = 0.0, bw4 = 0.0, bw5 = 0.0, bw6 = 0.0; int best_total_rank = 1000000000; int total_rank = 0; char output_filename[100]; if(argc < 3) { printf("Usage: %s summary.non-processed.co-localized.txt weight_1\n",argv[0]); exit(0); } strcpy(output_filename, "rankings.txt."); strcat(output_filename,argv[2]); arg2 = atof(argv[2]); // These must be initialized in order so that // they can be searched for in the sorted scores // in the most efficient manner. known_cases[0].id = 535; known_cases[1].id = 2141; known_cases[2].id = 4734; known_cases[3].id = 8798; known_cases[4].id = 8894; known_cases[5].id = 11041; known_cases[6].id = 11753; known_cases[7].id = 11923; known_cases[8].id = 13690; for(i=0; i<9; i++) { known_cases[i].best_rank = 100000000; } filename = argv[1]; if((in = fopen (filename,"r")) == NULL) { printf("%s could not be opened for reading.\n",filename); } char *line; if((line = malloc(sizeof(char) * 200)) == NULL) { printf("Could not allocate memory\n"); exit(0); } while(!feof(in)) { int id, st, fs; float ln, di, gl, pi, pg, gc, g3; char nm[20], pr[20]; line = fgets(line,200,in); if(line != NULL) { sscanf(line, "%d %s %s %f %f %f %f %d %d %f %f %f", &id,&nm,&pr,&ln,&pi,&pg,&di,&st,&fs,&gc,&g3,&gl); idmap[id] = id_count; id_count++; if(gc > maxgc) { maxgc = gc; } if(g3 > maxgc3) { maxgc3 = g3; } if(di > maxdi) { maxdi = di; } if(ln > maxln) { maxln = ln; } } } fclose(in); if((out = fopen(output_filename,"w")) == NULL) printf("%s could not be opened for writing.\n", output_filename); fprintf(out,"idcount = %d\n",id_count); w1=arg2; for(w2=0.0; w2<=1-w1; w2+=.02) { for(w3=0.0; w3<=1-w1-w2; w3+=.02) { for(w4=0.0; w4<=1-w1-w2-w3; w4+=.02) { for(w5=0.0; w5<=1-w1-w2-w3-w4; w5+=.02) { w6=1-w1-w2-w3-w4-w5; if(w1+w2+w3+w4+w5 >= 1.0) { w6 = 0.0; } total_rank = calculate_ranks(w1,w2,w3,w4,w5,w6); if(total_rank < best_total_rank) { bw1 = w1; bw2 = w2; bw3 = w3; bw4 = w4; bw5 = w5; bw6 = w6; best_total_rank = total_rank; for(i=0; i<9; i++) { known_cases[i].best_overall_rank = known_cases[i].rank; } } } } } } fprintf(out,"bw1 = %.2f\tbw2 = %.2f\tbw3 = %.2f\tbw4 = %.2f\tbw5 = %.2f\tbw6 = %.2f\n", bw1, bw2, bw3, bw4, bw5, bw6); fprintf(out,"best_total_rank = %d\n\n", best_total_rank); for(i=0; i<9; i++) { fprintf(out,"id: %d \tbest_overall_rank= %d\tbest_rank= %d\tweights= %.2f %.2f %.2f %.2f %.2f %.2f\n", known_cases[i].id,known_cases[i].best_overall_rank,known_cases[i].best_rank, known_cases[i].bw[0], known_cases[i].bw[1], known_cases[i].bw[2], known_cases[i].bw[3], known_cases[i].bw[4], known_cases[i].bw[5]); } fclose(out); return 0; } int calculate_ranks(float w1, float w2, float w3, float w4, float w5, float w6) { int i=0, j=0, max_score=0, known_pos=0, total_rank=0; int scores[100000]; char *line; if((line = malloc(sizeof(char) * 200)) == NULL) { printf("Could not allocate memory\n"); exit(0); } if((in = fopen (filename,"r")) == NULL) { printf("%s could not be opened for reading.\n",filename); } while(!feof(in)) { int id, st, fs, count = 0; float ln, di, gl, pi, pg, gc, g3, score; char nm[20], pr[20]; line = fgets(line,200,in); if(line != NULL) { sscanf(line, "%d %s %s %f %f %f %f %d %d %f %f %f", &id,&nm,&pr,&ln,&pi,&pg,&di,&st,&fs,&gc,&g3,&gl); score = (w1*pi + w2*(ln/gl)*100 + w3*(gc/maxgc)*100 + w4*(g3/maxgc3)*100 + w5*(100 - (di/maxdi)) + w6*(ln/maxln)*100)/.001; scores[idmap[id]] = (int) score; // Turning the score into a sortable integer // that will give me accuracy in sorting // to the nearest one hundredth. (i.e. 100.00 --> 10000, 52.16 --> 5216) if(scores[idmap[id]]%10 >= 5) { scores[idmap[id]] += 5; } scores[idmap[id]] = scores[idmap[id]]/10; if(scores[idmap[id]] > max_score) { max_score = scores[idmap[id]]; } if(id == known_cases[known_pos].id) { printf("%s", line); printf("Score for %d: %d\n\n", id, scores[idmap[id]]); known_cases[known_pos].score = scores[idmap[id]]; known_pos++; } } } fclose(in); radix(scores,1); radix(scores,10); radix(scores,100); radix(scores,1000); if(max_score > 1000) { radix(scores,10000); } for(i=0; i<9; i++) { for(j=0; j= pos) { num = (array[i]/pos)%10; } else { num = 0; } bins[num][counters[num]] = i; counters[num]++; } for(i=0; i<10; i++) { for(j=0; j