예제 #1
0
void simulate()
{
	printf("Blood bank inventory management simulation.\n");
	if ((infile = fopen("bloodbank.in", "r")) == NULL) {
		printf("Can't find the file: bloodbank.in\n");
		exit(1);
	}
	if ((outfile = fopen("bloodbank.out", "w")) == NULL) {
		printf("Can't create the file: bloodbank.out\n");
		exit(1);
	}
	readInput();

	init_simlib();

	// Schedule first event

	event_schedule(sim_time + 0, EVENT_BLOOD_ARRIVAL); //first arrival from camp at beginning
	event_schedule(sim_time + 0, EVENT_BLOOD_DONATION); //first donation at beginning
	event_schedule(sim_time + 1, EVENT_BLOOD_DEMAND); //first demand next day


	event_schedule(max_sim_time, EVENT_END_SIMULATION);

	eventLoop();
	report();

	fclose(infile);
	fclose(outfile);
}
예제 #2
0
파일: jobshop.c 프로젝트: gunnarrb/isal
int
main ()				/* Main function. */
{
    /* Open input and output files. */

    infile = fopen ("jobshop.in", "r");
    outfile = fopen ("jobshop.out", "w");

    /* Read input parameters. */

    fscanf (infile, "%d %d %lg %lg", &num_stations, &num_job_types, &mean_interarrival, &length_simulation);
    for (j = 1; j <= num_stations; ++j)
        fscanf (infile, "%d", &num_machines[j]);
    for (i = 1; i <= num_job_types; ++i)
        fscanf (infile, "%d", &num_tasks[i]);
    for (i = 1; i <= num_job_types; ++i)
    {
        for (j = 1; j <= num_tasks[i]; ++j)
            fscanf (infile, "%d", &route[i][j]);
        for (j = 1; j <= num_tasks[i]; ++j)
            fscanf (infile, "%lg", &mean_service[i][j]);
    }
    for (i = 1; i <= num_job_types; ++i)
        fscanf (infile, "%lg", &prob_distrib_job_type[i]);

    /* Write report heading and input parameters. */

    fprintf (outfile, "Job-shop model\n\n");
    fprintf (outfile, "Number of work stations%21d\n\n", num_stations);
    fprintf (outfile, "Number of machines in each station     ");
    for (j = 1; j <= num_stations; ++j)
        fprintf (outfile, "%5d", num_machines[j]);
    fprintf (outfile, "\n\nNumber of job types%25d\n\n", num_job_types);
    fprintf (outfile, "Number of tasks for each job type      ");
    for (i = 1; i <= num_job_types; ++i)
        fprintf (outfile, "%5d", num_tasks[i]);
    fprintf (outfile, "\n\nDistribution function of job types  ");
    for (i = 1; i <= num_job_types; ++i)
        fprintf (outfile, "%8.3f", prob_distrib_job_type[i]);
    fprintf (outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n", mean_interarrival);
    fprintf (outfile, "Length of the simulation%20.1f eight-hour days\n\n\n", length_simulation);
    fprintf (outfile, "Job type     Work stations on route");
    for (i = 1; i <= num_job_types; ++i)
    {
        fprintf (outfile, "\n\n%4d        ", i);
        for (j = 1; j <= num_tasks[i]; ++j)
            fprintf (outfile, "%5d", route[i][j]);
    }
    fprintf (outfile, "\n\n\nJob type     ");
    fprintf (outfile, "Mean service time (in hours) for successive tasks");
    for (i = 1; i <= num_job_types; ++i)
    {
        fprintf (outfile, "\n\n%4d    ", i);
        for (j = 1; j <= num_tasks[i]; ++j)
            fprintf (outfile, "%9.2f", mean_service[i][j]);
    }

    /* Initialize rndlib */
    init_twister();

    /* Initialize all machines in all stations to the idle state. */

    for (j = 1; j <= num_stations; ++j)
        num_machines_busy[j] = 0;

    /* Initialize simlib */

    init_simlib ();

    /* Set maxatr = max(maximum number of attributes per record, 4) */

    maxatr = 4;			/* NEVER SET maxatr TO BE SMALLER THAN 4. */

    /* Schedule the arrival of the first job. */

    event_schedule (expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL);

    /* Schedule the end of the simulation.  (This is needed for consistency of
       units.) */

    event_schedule (8 * length_simulation, EVENT_END_SIMULATION);

    /* Run the simulation until it terminates after an end-simulation event
       (type EVENT_END_SIMULATION) occurs. */

    do
    {

        /* Determine the next event. */

        timing ();

        /* Invoke the appropriate event function. */

        switch (next_event_type)
        {
        case EVENT_ARRIVAL:
            arrive (1);
            break;
        case EVENT_DEPARTURE:
            depart ();
            break;
        case EVENT_END_SIMULATION:
            report ();
            break;
        }

        /* If the event just executed was not the end-simulation event (type
           EVENT_END_SIMULATION), continue simulating.  Otherwise, end the
           simulation. */

    }
    while (next_event_type != EVENT_END_SIMULATION);

    fclose (infile);
    fclose (outfile);

    return 0;
}
예제 #3
0
int main(int argc, char* argv[])
{
	if (argc != 4 && argc != 5) {
		printf("Wrong number of arguments.\n");
		return 1;
	}

	// seed RNG
	time_t seconds = time(NULL);
	srand(seconds);

	//debug
	num_dirty_meters = 0;
	num_clean_meters = 0;

	num_user_meters = atoi(argv[1]);
	num_inspector_meters = atoi(argv[2]);
	prob_dirty_meter = atof(argv[3]);
	prob_meter_flip = 0.0;

	if (argc == 5) {
		prob_meter_flip = atof(argv[4]);
	}

	init_simlib();

	maxatr = 4;

	init_model();

	int should_run = 1;
	while (should_run) {
		timing();

		switch (next_event_type) {
			case EVENT_BEGIN_INSPECTION:
				handleInspection();
				break;
			case EVENT_CLEAN_RESULT:
				handleResult(next_event_type);
				break;
			case EVENT_DIRTY_RESULT:
				handleResult(next_event_type);
				break;
			case EVENT_CLEAN_INSPECTOR:
				handleResult(next_event_type);
				break;
			case EVENT_DIRTY_INSPECTOR:
				handleResult(next_event_type);
				break;
			case EVENT_END_SIMULATION:
				should_run = 0;
				break;
			default:
				printf("Unrecognized Event Type\n");
				return 1;
		}
	}

	report();


	return 0;
}
int main()  /* Main function. */
{
    printf("Masukkan batas atas job 1 (default: 10): \n");
    scanf("%d", &batasatasjob1);
    printf("\n\nMasukkan batas atas job 2 (default: 40): \n");
    scanf("%d", &batasatasjob2);

    /* Open input and output files. */

    infile  = fopen("tscomp-tugas.in",  "r");
    outfile = fopen("tscomp-tugas.out", "w");

    /* Read input parameters. */

    fscanf(infile, "%d %d %d %d %f %f %f %f",
           &min_terms, &max_terms, &incr_terms, &num_responses_required,
           &mean_think, &mean_service, &quantum, &swap);

    /* Write report heading and input parameters. */

    fprintf(outfile, "Time-shared computer model\n\n");
    fprintf(outfile, "Number of terminals%9d to%4d by %4d\n\n",
            min_terms, max_terms, incr_terms);
    fprintf(outfile, "Mean think time  %11.3f seconds\n\n", mean_think);
    fprintf(outfile, "Mean service time%11.3f seconds\n\n", mean_service);
    fprintf(outfile, "Quantum          %11.3f seconds\n\n", quantum);
    fprintf(outfile, "Swap time        %11.3f seconds\n\n", swap);
    fprintf(outfile, "Number of jobs processed%12d\n\n\n",
            num_responses_required);
    fprintf(outfile, "Number of      Average         Average");
    fprintf(outfile, "       Utilization      CPU-num/\n");
    fprintf(outfile, "terminals   response time  number in queue     of CPU          JOB-type");

    /* Run the simulation varying the number of terminals. */

    for (num_terms = min_terms; num_terms <= max_terms;
         num_terms += incr_terms) {

        /* Initialize simlib */

        init_simlib();

        /* Set maxatr = max(maximum number of attributes per record, 4) */

        maxatr = 4;  /* NEVER SET maxatr TO BE SMALLER THAN 4. */

        /* Initialize the non-simlib statistical counter. */

        num_responses = 0;

        /* Schedule the first arrival to the CPU from each terminal. */

        for (term = 1; term <= num_terms; ++term)
            event_schedule(expon(mean_think, STREAM_THINK), EVENT_ARRIVAL);

        /* Run the simulation until it terminates after an end-simulation event
           (type EVENT_END_SIMULATION) occurs. */

        do {

            /* Determine the next event. */

            timing();

            /* Invoke the appropriate event function. */

            switch (next_event_type) {
                case EVENT_ARRIVAL:
                    arrive();
                    break;
                case EVENT_END_CPU_1_RUN:
                    end_CPU_run(LIST_CPU_1);
                    break;
                case EVENT_END_CPU_2_RUN:
                    end_CPU_run(LIST_CPU_2);
                    break;
                case EVENT_END_CPU_3_RUN:
                    end_CPU_run(LIST_CPU_3);
                    break;
                case EVENT_END_SIMULATION:
                    report();
                    break;
            }

        /* If the event just executed was not the end-simulation event (type
           EVENT_END_SIMULATION), continue simulating.  Otherwise, end the
           simulation. */

        } while (next_event_type != EVENT_END_SIMULATION);
    }

    fclose(infile);
    fclose(outfile);

    printf("\n\nOutput hasil eksekusi program dapat dilihat pada tscomp-tugas.out\n");

    return 0;
}
예제 #5
0
파일: isal.c 프로젝트: gunnarrb/isal
int main()
{
    // load datafiles
    parse_input("adal_inntak.in","velar_og_bidradir.in");
	
    // initialize arrays and variables
    if((fail_list = malloc(sizeof(breakdown)*NUM_MACHINES+1))==NULL) {
	printf("Allocation Error\n");
	exit(1);
    }
   
    for (failure_nr = min_no_failures; failure_nr<= max_no_failures; failure_nr++) {
	stream = (unsigned int)time(NULL) % 100;   
		
	memset( is_machine_busy,0, NUM_MACHINES +1 );
	memset( machine_broken,0, NUM_MACHINES +1);
	memset( queue_max_lengths,0, NUM_MACHINES +1);
	memset( fail_list,0, sizeof(breakdown)*(NUM_MACHINES+1));
	fail_index = 0;
	skaut_throughput = 0;
	sampst_delays = number_of_machines +1;
	throughput_time = number_of_machines +2;
		
	skaut_id = 1;
	skaut_throughput = 0;
		
		
	// Initialize rndlib
	init_twister();
		
	// Initialize simlib
	init_simlib();
		
	maxatr = 6; // how many attributes do we need?
		
	/* Schedule first wagen arrival */
	event_schedule( 10.0, EVENT_WAGEN_UNLOAD_ARRIVAL );
		
	/* Schedule end of warmup time */
	event_schedule( end_warmup_time, EVENT_END_WARMUP );
	event_schedule(end_warmup_time, EVENT_GENERATE_FAILURES );	
	/* Schedule simulation termination */
	event_schedule(end_simulation_time , EVENT_END_SIMULATION );
		
	next_event_type = 0;
		
        
	while (next_event_type != EVENT_END_SIMULATION) {
			
	    timing();
			
	    switch (next_event_type) {
	    case EVENT_WAGEN_UNLOAD_ARRIVAL:
		wagen_unload_arrival();
		break;
	    case EVENT_SKAUT_ARRIVAL:
		skaut_arrival();
		break;
	    case EVENT_SKAUT_DEPARTURE:
		skaut_departure();
		break;
	    case EVENT_MACHINE_FAILURE:
		machine_failure();
		break;
	    case EVENT_MACHINE_FIXED:
		machine_fixed();
		break;
	    case EVENT_END_WARMUP:
		end_warmup();
		break;
	    case EVENT_END_SIMULATION:
		report();
		break;
	    case EVENT_GENERATE_FAILURES:
		create_machine_fail_events();
		break;
					
	    }
	}
		
    }
}
예제 #6
0
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");
}