Exemplo n.º 1
0
/* Function to load the main menu for the program. */
int menu(event_ptr event) {
    int option;

    do {
        printf("\nPress enter to continue.\n");
        getchar(); /* Consumes \n. */
        getchar(); /* Pauses program until enter is entered. */

        printf("\n===================================== MAIN MENU =====================================");
        printf("\n|                                                                                   |");
        printf("\n| 1: Query competitor for current location/status.                                  |");
        printf("\n| 2: Display how many competitors have not started yet.                             |");
        printf("\n| 3: Display how many competitors are out on the courses.                           |");
        printf("\n| 4: Display how many competitors have completed their course successfully.         |");
        printf("\n| 5: Manually supply time at which a competitor had reached a time checkpoint.      |");
        printf("\n| 6: Read in a file of times at which competitors have reached time checkpoints.    |");
        printf("\n| 7: Display the result times for the successfully completed.                       |");
        printf("\n| 8: Display the competitors who have been excluded.                                |");
        printf("\n| 9: Exit program.                                                                  |");
        printf("\n|                                                                                   |");
        printf("\n=====================================================================================");

        printf("\n\nPlease select from one of the options above (number): ");
        scanf("%d", &option);

        switch (option) {
            case 1:
                query_location(event);
                break;
            case 2:
                print_not_started(event);
                break;
            case 3:
                print_out_on_course(event);
                break;
            case 4:
                print_finished(event);
                break;
            case 5:
                update_competitor(event);
                break;
            case 6:
                read_times_file(event);
                break;
            case 7:
                print_results(event);
                break;
            case 8:
                print_excluded(event);
                break;
            case 9:
                break;
            default:
                printf("\nPlease enter in a valid option.");
        }
    } while (option != 9);

    return SUCCESS;
}
Exemplo n.º 2
0
int main (int argc, char * argv [])
{

  int j = 1;
  algorithm = -1;
  if(argc != 5)
    {
      print_usage();
    }

	
  // process command line arguments
  while (j < argc) {
    if (strcmp ("-alg", argv [j]) == 0) {
      j++;
      if (j >= argc)
	print_usage ();
      algorithm = atoi (argv [j]);
      j++;
    } else if (strcmp ("-file", argv [j]) == 0) {
      j++;
      if (j >= argc)
	print_usage ();
      filename = argv [j];
      j++;
    }
    else{
      j++;
    }
  }
  if((algorithm == -1) || (filename==NULL))
    {
      print_usage();
    }

  //we'll always assume a basic quanta is 100 time units
  int time_step = 100;
  //int curr_time = 0;
  // create the system emulation of processes from the file
  Processes *proc = proc_create(filename);
/*
  int zero = 0;
  int done = 0;
  int blocked = 0;
  int arrival = 0;
  int proc_arrival = 0;
  int count = 0;
  ////////////////////////////////////////////////////////////////////////////////////////////////
    while(count < 10)
    {
      count++;
      DEBUGPRINTF("ran test while\n");
      int returnVal = 0;
      if(returnVal == -1 || blocked == 1)
	{
	  returnVal = proc_norun_check_arrival(proc, time_step, curr_time, &arrival, &proc_arrival);
	  curr_time += returnVal;
	}
      else
	{
	  int returnVal = run_proc(proc, 0, time_step, &blocked, &done, curr_time, &zero, &zero);
	  curr_time += returnVal;
	}
      
      proc_print(proc);
      DEBUGPRINTF("Current Time = %d\n", curr_time);
      ////////////////////////////////////////////////////////////////////////////////////////////////
    }
  */
  //setup first job
  // int returnVal = runFCFS(proc, &time_step);
  // You may assume that there is a job 0 which arrived at time 0 and is ready to go


  // Here is the bulk of your work.  You will need to run until you've finished running all the
  // incoming processes.  (You may assume that when you have finished all the jobs you know about, you are
  // done.  Arrival times will always be early enough to ensure future processes have arrived before
  // you have finished previous ones.)

  //0 Shortest remaining time
  //1 First Come First Serve
  //2 Round Robin
  //3 Multi-level Queue
  switch(algorithm)
    {
    case 0: 
      runSRT(proc,time_step);
      break;
    case 1:
      runFCFS(proc,time_step);
      break;
    case 2:
      runRR(proc,time_step);
      break;
    case 3:
      runMLQ(proc,time_step);
      break;
    default:
      printf("Please enter valid scheduling argument. \"%d\" is not a valid option\n", algorithm);
      break;
    }
  
  

  print_finished();

  proc_destroy(proc);
  free(proc);
  proc=NULL;
  return 0;
}