Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	Pior1 = createQueue (10);
	Pior2 = createQueue (10);
	Pior3 = createQueue (10);
	Pior4 = createQueue (10);
	
    int i = 0;
    int algorithm = FCFS;
    int quantum = 1;

    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-q") == 0) {
            i++;
            quantum = atoi(argv[i]);
        } else if (strcmp(argv[i], "-a") == 0) {
            i++;
            if (strcmp(argv[i], "FCFS") == 0) {
                algorithm = FCFS;
            } else if (strcmp(argv[i], "PS") == 0) {
                algorithm = PS;
            } else if (strcmp(argv[i], "MLFQ") == 0) {
                algorithm = MLFQ;
            } else if (strcmp(argv[i], "STRIDE") == 0) {
                algorithm = STRIDE;
            }
        }
    }
         
    read_task_data();

    if (num_tasks == 0) {
        fprintf(stderr,"%s: no tasks for the simulation\n", argv[0]);
        exit(1);
    }

    init_simulation_data(algorithm);
    run_simulation(algorithm, quantum);
    compute_and_print_stats();

    exit(0);
}
int main(int argc, char* argv[]) {
  FILE* F;
  GFF_Set *gff_real=NULL, *gff_pred=NULL;
  char c;
  List *real_fname_list = NULL, *pred_fname_list = NULL, 
    *feat_list = NULL, *seq_len_list = NULL, *l = NULL;
  int nfile, i, j;
  char *prefix = NULL;
  int tot_tp = 0, tot_fp = 0, tot_nreal_pos = 0, tot_npred_pos = 0, 
    tot_seqlen = 0, tot_ncr = 0, tot_npca = 0, tot_nola = 0, tot_nme = 0, 
    tot_npcp = 0, tot_nolp = 0, tot_nwe = 0, tot_nexons_real = 0, 
    tot_nexons_pred = 0, dump_exons = 0, nnc = -1, tot_nnc = -1, 
    nc_threshold = 0;

  while ((c = (char)getopt(argc, argv, "r:p:f:l:d:n:h")) != -1) {
    switch(c) {
    case 'r':
      real_fname_list = get_arg_list(optarg);
      break;
    case 'p':
      pred_fname_list = get_arg_list(optarg);
      break;
    case 'l':
      l = get_arg_list(optarg);
      /* convert to ints */
      seq_len_list = lst_new_int(lst_size(l));
      for (i = 0; i < lst_size(l); i++) {
        int tmp;
        if (str_as_int((String*)lst_get_ptr(l, i), 
                       &tmp) != 0) {
          die("ERROR: Bad integer in <seq_len_list>.\n"); 
        }
        lst_push_int(seq_len_list, tmp);
      }
      break;
    case 'f':
      feat_list = get_arg_list(optarg);
      break;
    case 'd':
      dump_exons = 1;
      prefix = optarg;
      break;
    case 'n':
      nnc = tot_nnc = 0;
      nc_threshold = get_arg_int(optarg);
      break;
    case 'h':
      print_usage();
      exit(0);
    case '?':
      die("Unrecognized option.  Try \"eval_predictions -h\" for help.\n");
    }
  }

  set_seed(-1);

  if (feat_list == NULL) {
    feat_list = lst_new_ptr(1);
    lst_push_ptr(feat_list, str_new_charstr(GFF_CDS_TYPE));
  }
  
  if (real_fname_list == NULL || pred_fname_list == NULL || 
      seq_len_list == NULL) {
    die("ERROR: Must specify -r, -p, and -l.  Try \"eval_predictions -h\" for help.\n");
  }

  if (lst_size(real_fname_list) != lst_size(pred_fname_list)) {
    die("ERROR: Must specify lists of equal length for real and predicted filenames.\n\n.");
  }

  if (lst_size(seq_len_list) == 1 && lst_size(real_fname_list) > 1)
    for (i = 1; i < lst_size(real_fname_list); i++)
      lst_push_int(seq_len_list, lst_get_int(seq_len_list, 0));
  else if (lst_size(seq_len_list) != lst_size(real_fname_list))
    die("ERROR: List of sequence lengths does not match lists of real and predicted filenames.\n");

  /* print header */
  printf("%-25s %-25s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s %7s", "Real_fname", "Pred_fname", "Sn", "Sp", "AC", "CC", "ESn", "ESp", "CRa", "PCa", "OLa", "ME", "CRp", "PCp", "OLp", "WE");
  if (nnc != -1) printf(" %7s %7s %7s %7s", "NCa", "NCp", "CR+NCa", "CR+NCp");
  printf("\n");

  for (nfile = 0; nfile < lst_size(real_fname_list); nfile++) {
    int tp, fp, nexons_real, nexons_pred, nwe, nme, ncr, npca, 
      npcp, nola, nolp, nreal_pos, npred_pos, len_real, len_pred, seqlen,
      already_counted_real;
    String *real_fname, *pred_fname;
    GFF_Feature *feat_real, *feat_pred=NULL;

    real_fname = (String*)lst_get_ptr(real_fname_list, nfile);
    F = phast_fopen(real_fname->chars, "r");
    if ((gff_real = gff_read_set(F)) == NULL) {
      die("ERROR: Unable to read file \"%s\".\n", 
	  real_fname->chars);
    }
    phast_fclose(F);

    pred_fname = (String*)lst_get_ptr(pred_fname_list, nfile);
    F = phast_fopen(pred_fname->chars, "r");
    if ((gff_pred = gff_read_set(F)) == NULL) {
      die("ERROR: Unable to read file \"%s\".\n", 
	  pred_fname->chars);
    }
    phast_fclose(F);

    seqlen = lst_get_int(seq_len_list, nfile);

    /* sort ungrouped -- only cds exons will be considered, and each
       one will be considered individually */
    gff_ungroup(gff_real); 
    gff_ungroup(gff_pred);
    gff_sort(gff_real);
    gff_sort(gff_pred);

    nexons_real = nexons_pred = nwe = nme = ncr = npca = npcp = nola = 
      nolp = tp = fp = nreal_pos = npred_pos = 0;
    if (nnc != -1) nnc = 0;
    i = j = 0;
    already_counted_real = 0;
    while (i < lst_size(gff_real->features)) {
      feat_real = (GFF_Feature*)lst_get_ptr(gff_real->features, i);
      if (!is_exon(feat_real, feat_list)) { i++; continue; }

      len_real = feat_real->end - feat_real->start + 1;

      if (!already_counted_real) {
        nexons_real++;
        nreal_pos += len_real;
      }

      /* look at all predicted exons up to and overlapping this real exon */
      while (j < lst_size(gff_pred->features)) {
        feat_pred = (GFF_Feature*)lst_get_ptr(gff_pred->features, j);
        if (!is_exon(feat_pred, feat_list)) {
          j++;
          continue;
        }
        else if (feat_pred->start > feat_real->end) {
          if (!already_counted_real) {
            nme++;
            if (dump_exons) dump(prefix, feat_real, NULL, ME, -1);
          }
          break;
        }

        /* otherwise we have a predicted exon to count (start of pred
           <= end of real) */
        nexons_pred++;
        len_pred = feat_pred->end - feat_pred->start + 1;
        npred_pos += len_pred;
        j++;                    /* we'll be done with this prediction
                                   one way or another; next time
                                   through look at a new one */

        if (feat_pred->end < feat_real->start) { /* WE */
          nwe++;
          fp += len_pred;
          if (dump_exons) dump(prefix, NULL, feat_pred, WE, 0);
        }
        else if (feat_pred->start == feat_real->start && /* CR */
                 feat_pred->end == feat_real->end) {
          ncr++;
          tp += len_pred;
          if (dump_exons) dump(prefix, feat_real, feat_pred, CR, 1);
          break;
        }
        else if (feat_pred->start == feat_real->start || /* PC */
                 feat_pred->end == feat_real->end) {
          pred_type type;
          npca++;
          npcp++;
          if (nnc != -1 && 
              max(abs(feat_pred->start - feat_real->start), 
                  abs(feat_pred->end - feat_real->end)) <= nc_threshold) {
            nnc++; 
            type = NC;
          }
          else type = PC;
          if (len_pred < len_real) 
            tp += len_pred;
          else {
            tp += len_real;
            fp += (len_pred - len_real);
          }
          if (dump_exons) dump(prefix, feat_real, feat_pred, type, 
                               min(1, (double)len_real/len_pred));
          break;
        }
        else {                  /* OL */
          int overlap_size;
          pred_type type;
          nola++;
          nolp++;
          if (nnc != -1 && 
              max(abs(feat_pred->start - feat_real->start), 
                  abs(feat_pred->end - feat_real->end)) <= nc_threshold) {
            nnc++; 
            type = NC;
          }
          else type = PC;

          overlap_size = min(feat_pred->end, feat_real->end) - 
            max(feat_pred->start, feat_real->start) + 1;
          tp += overlap_size;
          fp += len_pred - overlap_size;
          if (dump_exons) dump(prefix, feat_real, feat_pred, type,
                               (double)overlap_size/len_pred);
          break;
        }
        /* NOTE: I'm ignoring the possibility that a predicted exon
           could be a PC and/or OL with respect to multiple real
           exons.  The effect on the exon-level stats will be fairly
           minor (at worst a predicted exon is scored as an OL when it
           should be scored as an PC, and a real exon is erroneously
           counted as a ME), but the effect on the nucleotide-level Sn
           and Sp could conceivably be significant.  */
      }

      /* if we have counted at least one prediction (and thus failed
         to reach the end of the list), but the last prediction did
         not extend as far as the end of the real exon, then delay
         moving on to the next real exon */
      if (j < lst_size(gff_pred->features) && feat_pred->end < feat_real->end) 
          already_counted_real = 1;
      else {
        /* if we reached the end of the list of predictions, then it
           must not have contained any exons, and the real exon in
           question is a ME (if it hasn't already been counted) */
        if (j == lst_size(gff_pred->features) && !already_counted_real) 
          nme++; 

        i++;
        already_counted_real = 0;
      }
    }
    
    /* any remaining predictions must be wrong */
    for (; j < lst_size(gff_pred->features); j++) {
      if (is_exon((GFF_Feature*)lst_get_ptr(gff_pred->features, j), 
                  feat_list)) {
        nexons_pred++;
        nwe++;
      }
    }

    compute_and_print_stats(stdout, real_fname, pred_fname, 
                            tp, fp, nreal_pos, npred_pos, seqlen, ncr, 
                            npca, nola, nme, npcp, nolp, nwe, 
                            nexons_real, nexons_pred, nnc);

    tot_tp += tp;
    tot_fp += fp;
    tot_nreal_pos += nreal_pos;
    tot_npred_pos += npred_pos;
    tot_seqlen += seqlen;
    tot_ncr += ncr;
    tot_npca += npca;
    tot_nola += nola;
    tot_nme += nme;
    tot_npcp += npcp;
    tot_nolp += nolp;
    tot_nwe += nwe;
    tot_nexons_real += nexons_real;
    tot_nexons_pred += nexons_pred;
    if (nnc != -1) tot_nnc += nnc;

    if (dump_exons && SUMF != NULL)
      fprintf(SUMF, "# Total number of bases in real exons: %d\n", nreal_pos);

    gff_free_set(gff_real);
    gff_free_set(gff_pred);
  }

  if (lst_size(real_fname_list) > 1)
    compute_and_print_stats(stdout, str_new_charstr("TOTAL"), str_new_charstr(""), 
                            tot_tp, tot_fp, tot_nreal_pos, tot_npred_pos, 
                            tot_seqlen, tot_ncr, tot_npca, tot_nola, tot_nme, 
                            tot_npcp, tot_nolp, tot_nwe, tot_nexons_real, 
                            tot_nexons_pred, tot_nnc);

  return 0;
}
Ejemplo n.º 3
0
void priority_scheduling()
{

    int current_task = 0;
    int current_tick = 0;
	int highest_priority = 0;
	int lowest_time = 999;
	int i;
	
	
	for (i=0;i<num_tasks;i++){
		
		if (tasks[i].priority > highest_priority&&tasks[i].finish_time == 0){
			
			highest_priority = tasks[i].priority;
		}
		
	}
	for (i=0;i<num_tasks;i++){
		
		if(tasks[i].priority == highest_priority&&tasks[i].finish_time == 0){
			
			if (tasks[i].arrival_time <= lowest_time&&tasks[i].finish_time == 0){
				
					lowest_time = tasks[i].arrival_time;
			
		}
		}
		}
		
		
	
		
		for (i=0;i<num_tasks;i++){
			
			if(tasks[i].priority == highest_priority && lowest_time == tasks[i].arrival_time &&tasks[i].finish_time == 0){
				tasks[i].schedulings +=1;
				
				
				for(;;){
				current_tick +=1;
				tasks[i].cpu_cycles +=1;
				
			
				
					if (tasks[i].cpu_cycles >= tasks[i].length) {
            float quantum_fragment = tasks[i].cpu_cycles -
                tasks[current_task].length;
            tasks[i].cpu_cycles = tasks[i].length;
            tasks[i].finish_time = current_tick - quantum_fragment;
            tasks[i].schedulings = 1;
            i++;
            if (i > num_tasks) {
				
                break;
            }
            tasks[i].cpu_cycles += quantum_fragment;
            count++;
            if (count==num_tasks)
            {
				compute_and_print_stats();
				exit(0);
				
			}
            priority_scheduling();
        }
				
				
				}
				
			}
			
		}

}	
Ejemplo n.º 4
0
void stride_scheduling(int quantum)
{
	
  	
  	total_priority = 0;
  	global_tickets = 10000;
  	/*  divide tickets by piority */
  	
  	int i,p;
   	for ( p =0; p<num_tasks; p++){
		if (tasks[p].stride <= current_pass && tasks[p].finish_time == 0)	
	     total_priority += tasks[p].priority;
	    
			
       }
       
       if (total_priority == 0){
		   compute_and_print_stats();
		   exit(0);
	   }
  	for ( i =0; i<num_tasks; i++){ 
		
		 
		tasks[i].stride = tasks[i].priority * tasks[i].schedulings;
		 /*printf("Stride: %d %d \n", tasks[i].stride, current_pass);*/
		 
	
		 
		
		 if (global_tickets - tasks[i].tickets <=0){
			/* printf ("Not enough tickets \n");*/
		 break;
	 }
	 
	 
	 
			if (tasks[i].stride > current_pass || tasks[i].finish_time != 0)
			{
				tasks[i].tickets = 0;
		     
		     tasks[i].upperbound = 0;
			 global_tickets-= tasks[i].tickets;
			 tasks[i].lowerbound= 0;
			 current_pass++;
			}
		 
		 else{
			/* printf("Total Priority : %d\n", total_priority);*/
			 tasks[i].tickets = tasks[i].priority *(10000/total_priority);
		     
		     tasks[i].upperbound = global_tickets;
			 global_tickets-= tasks[i].tickets;
			 tasks[i].lowerbound= global_tickets+1;
			/* printf(" Upper; %d Lower  %d\n", tasks[i].upperbound, tasks[i].lowerbound);*/
		 
	 }
 }
		 
		 

		
	
		srand ( time(NULL) );
		int r = rand() % (10000 - global_tickets + 2);
		r = 10000 - r; 
		
		int j;
		 for (j =0; j<num_tasks; j++)
		 
		 {
			 
			 if (tasks[j].upperbound >= r && r >= tasks[j].lowerbound)
			 
			 {
				 /*task runs*/
				
				 
				 
				 if (tasks[j].length - quantum - tasks[j].cpu_cycles<=0 )
				 
				 {
					/* printf("Running task %d:\n\n" , j);*/
					 int  p = tasks[j].length- tasks[j].cpu_cycles;
				    tasks[j].cpu_cycles += p;
				    tasks[j].schedulings +=1; 
				    current_tick += p;
				    tasks[j].finish_time = current_tick;
				   /* printf("finish time %f current tick %d  schedulings %d\n" , tasks[j].finish_time, current_tick, tasks[j].schedulings);*/
				    
				   /* printf("TASK %d FINSIHED \\n\n\n", j);*/
				   current_pass++;
				   usleep(10000);
			     }
				 
				else {
					/*printf("Running task %d:\n" , j);*/
				   tasks[j].cpu_cycles += quantum;
				   current_tick+= quantum;
				   tasks[j].schedulings += 1; 
				  /* printf("Cycles %f current tick %d  schedulings %d\n" , tasks[j].cpu_cycles, current_tick, tasks[j].schedulings);*/
				   current_pass++;
				    usleep(10000);
				   
				 }
				 
			 }
			 
			 
		 }
		 		
		
		 stride_scheduling(quantum);
		
	
	  
		 printf("STRIDE SCHEDULING appears here\n");
    exit(1);
	
}