Пример #1
0
int main()  /* Main function. */
{
    /* Open input and output files. */
    infile  = fopen("mm1.in",  "r");
    outfile = fopen("mm1.out", "w");

    /* Specify the number of events for the timing function. */
    num_events = 2;

    /* Read input parameters. */
    fscanf(infile, "%f %f %d", &mean_interarrival, &mean_service,
           &num_delays_required);

    /* Write report heading and input parameters. */
    fprintf(outfile, "Single-server queueing system\n\n");
    fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n",mean_interarrival);
    fprintf(outfile, "Mean service time%16.3f minutes\n\n", mean_service);
    fprintf(outfile, "Number of customers%14d\n\n", num_delays_required);

    /* Initialize the simulation. */
    initialize();

    /* Run the simulation while more delays are still needed. */
    while (num_custs_delayed < num_delays_required) {
        /* Determine the next event. */
        timing();

        /* Update time-average statistical accumulators. */
        update_time_avg_stats();

        /* Invoke the appropriate event function. */
        switch (next_event_type) {
            case 1:
                arrive();
                break;
            case 2:
                depart();
                break;
        }
    }

    /* Invoke the report generator and end the simulation. */
    report();

    fclose(infile);
    fclose(outfile);

    return 0;
}
Пример #2
0
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
main()  /* Main function. */
{
    /* Open input and output files. */

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

    /* Specify the number of events for the timing function. */

    num_events = 3;

    /* Read input parameters. */

    fscanf(infile, "%f %f %f", &mean_interarrival, &mean_service, &time_end);

    /* Write report heading and input parameters. */

    fprintf(outfile, "Single-server queueing system with fixed run");
    fprintf(outfile, " length\n\n");
    fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n",
            mean_interarrival);
    fprintf(outfile, "Mean service time%16.3f minutes\n\n", mean_service);
    fprintf(outfile, "Length of the simulation%9.3f minutes\n\n", time_end);

    /* Initialize the simulation. */

    initialize();

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

    do
    {
        /* Determine the next event. */

        timing();

        /* Update time-average statistical accumulators. */

        update_time_avg_stats();

        /* Invoke the appropriate event function. */

        switch (next_event_type)
        {
            case 1:
                arrive();
                break;
            case 2:
                depart();
                break;
            case 3:
                report();
                break;
        }

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

    } while (next_event_type != 3);

    fclose(infile);
    fclose(outfile);

    return 0;
}
Пример #4
0
 /**
  * Depart from sosi node.
  */
 void depart()
 {
     depart(INT_MAX, 0);
 }
Пример #5
0
int main(int argc, char **argv){
    
    char *infilename = "mm1.in";
    char *outfilename = "mm1.out";
    
    //Read Exec options (実行オプションの読み込み)
    int option;
    while( (option = getopt(argc, argv,"i:o:th"))!=-1 ){
		switch(option){
			case 'i':
				infilename = optarg;
				break;
      case 'o':
				outfilename = optarg;
				break;
      case 't':
				limit_time_mode = true;
				break;
			case 'h':
			default:
				usage(argv[0]);
				return 0;
				break;
		}
	}
    
    /*Open input and output file(入力ファイルと出力ファイルを開く)*/
    infile  =   fopen(infilename,"r");
    outfile  =   fopen(outfilename,"w");
    
    /*Specify the number of events for the timing function(イベント数を定義)*/
    //Customer Number Limit Mode
    if(!limit_time_mode) num_events = 2;//到着(Arrival Event)と出発(Departure Event)
    //Time Limit Mode
    else num_events = 3;//到着(Arrival Event)と出発(Departure  Event)と終了(Simulation End  Event)
    
    /*Read input parameter.(パラメータの読み込み)*/
    if(!limit_time_mode) {//Customer Number Limit Mode
        fscanf(infile,"%f %f %d",&mean_interarrival,&mean_service,&num_deleyed_required);
        printf("input %f %f %d\n",mean_interarrival,mean_service,num_deleyed_required);
    }else{//Time Limit Mode
        fscanf(infile,"%f %f %f",&mean_interarrival,&mean_service,&time_end);
        printf("input %f %f %f\n",mean_interarrival,mean_service,time_end);
    }
    
    if(!limit_time_mode) printf("Exec Limit Costomer Number Mode\n");
    else printf("Exec Limit Time Mode\n");
    
    /*Write Report heading and input parameter.(入力されたパラメータを書き出し)*/
    fprintf(outfile,"Single-server queueing system \n");
    fprintf(outfile,"Mean interarrival time Limit %11.3f minutes \n",mean_interarrival);
    fprintf(outfile,"Mean service time Limit %16.3f minutes \n",mean_service);
    
    if(!limit_time_mode) fprintf(outfile,"Number of customers %14d \n",num_deleyed_required);
    else fprintf(outfile,"Length of the Simulation %9.3f minute \n",time_end);
    
    
    printf("mean interarrival %f \n",mean_interarrival);
    printf("mean service %f \n",mean_service);
    
    /*Initialize the simulation.(シミュレーションの初期化)*/
    initialize();
        
    bool sim_run=true;
    //int arrival_id=0,dep_id=0;
    while(sim_run){
        /*Determine the next event.(次のイベントを定義)*/
        timing();
        
        /*Update time-average statistical accumulators(のべ時間の更新)*/
        update_time_avg_status();
        
        /*Invoke the appropriate event function.(イベントの実行)*/
        switch(next_event_type){
            case 1:
                arrival_id++;
                printf("[%10.3f] Customer %d is Arrival\n",sim_clock,arrival_id);
                arrival();//Arrival Event(到着イベント)
                break;
            case 2:
                dep_id++;
                printf("[%10.3f] Customer %d is Departure\n",sim_clock,dep_id);
                depart();//Departure Event(出発イベント)
                break;
            case 3://for Limit Time Mode
                /*Invoke the report generator and end the simulation.(レポートを出力してシミュレーションを修了)*/
                report();
                break;
        }
        if(!limit_time_mode){//Limit Customer Number Mode
            /*Quit the simulation when more delays are not needed.(もう客が来なくてもいいならシミュレーションを終わる)*/
            if(num_custs_delayed > num_deleyed_required) sim_run=false;
        }else{//Limit Time Mode
            /*Quit the simulation when time to simulation end.(シミュレーションの終了時間になったらシミュレーションを終わる)*/
            if(next_event_type==3) sim_run=false;
        }
    }
    
    /*Invoke the report generator and end the simulation.(レポートを出力してシミュレーションを修了)*/
    if(!limit_time_mode) report();//Limit Customer Number Mode
    
    fclose(infile);
    fclose(outfile);
    
    return 0;
}