コード例 #1
0
ファイル: practica4.c プロジェクト: Mithrandir0x/so2
int main(int argc, char **argv)
{
  char option;
  int op;
  RBTree *tree = NULL;

  while ( 1 )
  {
    show_menu(tree);

    printf("Indiqui la opcio: ");
    scanf("%c", &option);
    flush();
    
    printf("option: [%c]\n", option);

    switch ( option )
    {
      case '1':
        clean_up(tree);
        tree = import_database();
        break;
      case '2':
        save_database(tree);
        break;
      case '3':
        clean_up(tree);
        tree = malloc(sizeof(RBTree));
        op = load_database(tree);
        if ( op == PRS_FILE_NOT_FOUND ) {
          free(tree);
          tree = NULL;
        }
        break;
      case '4':
        generate_statistics(tree);
        break;
      case '5':
        clean_up(tree);
        exit(0);
        break;
      default:
        printf("\nOption not recognised.\n");
        break;
    }
  }

  return 0;
}
コード例 #2
0
ファイル: simulation.c プロジェクト: DWTSI/CargoSimulator2015
int main() {

    FILE *plane_list,
         *storm_list,
         *output_log_verbose,
         *output_log,
         *output_log_read,
         *verification_log,
         *statistics_log;

    //int sim_length = TIME_YEAR;

    init_simlib();

    /* Set the log list to be ordered by event time */
    list_rank[LIST_LOG] = EVENT_TIME;

    /* Set the in-port residence time list to be ordered by plane id */
    list_rank[LIST_PLANE_PORT_TIME] = PLANE_ID;

    list_rank[LIST_AVG_PLANES_RUNWAY] = EVENT_TIME;
    list_rank[LIST_AVG_PLANES_DEBERTH] = EVENT_TIME;

    /* Set max attributes in a list to 9, for simlog */
    maxatr = 10;

    storm_state = STORM_OFF;
    taxi_state  = TAXI_IDLE;

    int i;
    for (i=0; i<NUMBER_OF_BERTHS; i++) {
        berths[i].state = BERTH_FREE;
        berths[i].time_unoccupied_last = 0;
        berths[i].time_unoccupied = 0;
        berths[i].time_loading = 0;
        berths[i].time_loading_last = 0;
        berths[i].time_occupied = 0;
        berths[i].time_occupied_last = 0;
    }

    stats.taxi_time_idle = 0;
    stats.taxi_time_idle_last = 0;
    stats.taxi_time_travelling = 0;
    stats.taxi_time_travelling_last = 0;
    stats.taxi_time_berthing_deberthing = 0;
    stats.taxi_time_berthing_deberthing_last = 0;

    /* initialize timest */
    timest(0.0, 0);

    /* Load the input paramters for times and such */
    FILE *input = fopen("config.ini", "r");
    verification_log = fopen("verification.log", "w");
    load_input_file(input, verification_log);
    fclose(input);

    /* initialize berths array to specified size */
    //berths = (struct berth *)malloc(sizeof(struct berth)*G.num_berths);

    /* Generate the plane and storm list */
    generate_input_files();

    /* Schedule the plane landing and storm events using the input lists*/
    plane_list = fopen("plane_list.dat", "r");
    storm_list = fopen("storm_list.dat", "r");
    schedule_input_list(plane_list);
    schedule_input_list(storm_list);
    fclose(plane_list);
    fclose(storm_list);

    plane_list = fopen("plane_list.dat", "r");
    storm_list = fopen("storm_list.dat", "r");
    verify_actors(storm_list, plane_list, verification_log);
    fclose(plane_list);
    fclose(storm_list);

    while(list_size[LIST_EVENT] != 0) {

        timing();

        /* If sim time passes a year, exit the simulation. */
        if ((int)sim_time>=G.sim_length) {//TIME_YEAR) {
            if (taxi_state == TAXI_IDLE)
                stats.taxi_time_idle += G.sim_length - stats.taxi_time_idle_last;
            if (taxi_state == TAXI_TRAVELLING_BERTHS || taxi_state == TAXI_TRAVELLING_RUNWAY)
                stats.taxi_time_travelling += G.sim_length - stats.taxi_time_travelling_last;
            if (taxi_state == TAXI_BERTHING || taxi_state == TAXI_DEBERTHING)
                stats.taxi_time_berthing_deberthing += G.sim_length - stats.taxi_time_berthing_deberthing_last;

            /*  Because the stats.taxi_time_travelling isn't quite getting all of the time
                but I know that the idle and berthing/deberthing times are correct,
                I'm cheating and using those to figure out the travelling time. */
            stats.taxi_time_travelling = G.sim_length - stats.taxi_time_idle - stats.taxi_time_berthing_deberthing;
            break;
        }

        /*
        printf("%.1f  %.1f  %s  %s\n", sim_time/60,
                                       stats.taxi_time_berthing_deberthing/60.0f,
                                       strings_event[(int)transfer[EVENT_TYPE]],
                                       strings_taxi[taxi_state]);
                                       */

        /* Main event handler switch */
        switch(next_event_type) {

            case EVENT_LAND1:
            case EVENT_LAND2:
            case EVENT_LAND3:
                plane_land(next_event_type, transfer[EVENT_PLANE_ID]);
                break;
            case EVENT_STORM_START:
                storm_start();
                break;
            case EVENT_STORM_END:
                storm_end();
                break;
            case EVENT_BERTH:
                berth(transfer[BERTH_NUMBER]);
                break;
            case EVENT_DEBERTH:
                deberth(transfer[BERTH_NUMBER]);
                break;
            case EVENT_FINISH_LOADING:
                finish_loading(transfer[BERTH_NUMBER]);
                break;
            case EVENT_BERTH_FINISH:
                berth_finish(transfer[BERTH_NUMBER]);
                break;
            case EVENT_DEBERTH_FINISH:
                deberth_finish(transfer[BERTH_NUMBER]);
                break;
            case EVENT_TAXI_RETURNS_IDLE:
                taxi_returns();
                break;
        }

        if (sim_time == 129705)
            printf("%d\n", taxi_state == TAXI_IDLE);

        /* Taxi handler */
        switch (taxi_state) {
            case TAXI_IDLE:
                taxi_idle();
                break;
            case TAXI_TRAVELLING_RUNWAY:
                taxi_travelling_runway();
                break;
            case TAXI_TRAVELLING_BERTHS:
                taxi_travelling_berths();
                break;
            case TAXI_BERTHING:
                taxi_berthing();
                break;
            case TAXI_DEBERTHING:
                taxi_deberthing();
                break;
        }
    }// end simulation loop

    printf("Log list size: %d\n", list_size[LIST_LOG]);

    output_log_verbose = fopen("output_log_verbose.csv", "w");
    save_log_file_verbose(output_log_verbose);
    fclose(output_log_verbose);

    output_log = fopen("output_log.csv", "w");
    save_log_file(output_log);
    fclose(output_log);
    /*
    output_log = fopen("output_log.csv", "w");
    //verify_output(output_log, verification_log);
    fclose(output_log);
    fclose(verification_log);
    */
    statistics_log = fopen("statistics.log", "w");
    generate_statistics(statistics_log);
    fclose(statistics_log);

    /*  Clean up files  */
    remove("plane_list.dat");
    remove("storm_list.dat");
    remove("storm_list.csv");
}