Ejemplo n.º 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;
}
Ejemplo n.º 2
0
main()  /* Main function. */
{
    int i, num_policies;

    /* Open input and output files. */

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

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

    num_events = 4;

    /* Read input parameters. */

    fscanf(infile, "%d %d %d %d %f %f %f %f %f %f %f",
           &initial_inv_level, &num_months, &num_policies, &num_values_demand,
           &mean_interdemand, &setup_cost, &incremental_cost, &holding_cost,
           &shortage_cost, &minlag, &maxlag);
    for (i = 1; i <= num_values_demand; ++i)
        fscanf(infile, "%f", &prob_distrib_demand[i]);

    /* Write report heading and input parameters. */

    fprintf(outfile, "Single-product inventory system\n\n");
    fprintf(outfile, "Initial inventory level%24d items\n\n",
            initial_inv_level);
    fprintf(outfile, "Number of demand sizes%25d\n\n", num_values_demand);
    fprintf(outfile, "Distribution function of demand sizes  ");
    for (i = 1; i <= num_values_demand; ++i)
        fprintf(outfile, "%8.3f", prob_distrib_demand[i]);
    fprintf(outfile, "\n\nMean interdemand time%26.2f\n\n", mean_interdemand);
    fprintf(outfile, "Delivery lag range%29.2f to%10.2f months\n\n", minlag,
            maxlag);
    fprintf(outfile, "Length of the simulation%23d months\n\n", num_months);
    fprintf(outfile, "K =%6.1f   i =%6.1f   h =%6.1f   pi =%6.1f\n\n",
            setup_cost, incremental_cost, holding_cost, shortage_cost);
    fprintf(outfile, "Number of policies%29d\n\n", num_policies);
    fprintf(outfile, "                 Average        Average");
    fprintf(outfile, "        Average        Average\n");
    fprintf(outfile, "  Policy       total cost    ordering cost");
    fprintf(outfile, "  holding cost   shortage cost");

    /* Run the simulation varying the inventory policy. */

    for (i = 1; i <= num_policies; ++i) {

        /* Read the inventory policy, and initialize the simulation. */

        fscanf(infile, "%d %d", &smalls, &bigs);
        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:
                    order_arrival();
                    break;
                case 2:
                    demand();
                    break;
                case 4:
                    evaluate();
                    break;
                case 3:
                    report();
                    break;
            }

        /* If the event just executed was not the end-simulation event (type 3),
           continue simulating.  Otherwise, end the simulation for the current
           (s,S) pair and go on to the next pair (if any). */

        } while (next_event_type != 3);
    }

    /* End the simulations. */

    fclose(infile);
    fclose(outfile);

    return 0;
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
int main()  /* Main function. */
{
    /* Open input and output files. */

    infile  = fopen("tandem.in",  "r");
    outfile = fopen("tandem.out", "w");
	debugfile = fopen("debug.out", "w");

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

    num_events = 5;

    /* Read input parameters. */

    fscanf(infile, "%f %f %f %f", &mean_interarrival, &mean_service[0],
           &mean_service[1], &time_end);

    /* Write report heading and input parameters. */

    fprintf(outfile, "Tandem-server queueing system\n\n");
    fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n",
            mean_interarrival);
    fprintf(outfile, "SRVR1 mean service time%16.3f minutes\n\n", mean_service[0]);
	fprintf(outfile, "SRVR2 mean service time%16.3f minutes\n\n", mean_service[1]);
    fprintf(outfile, "Length of the simulation%16.3f minutes\n\n", time_end);

    int replications = 10;

    /* Run simulation ten times total */
    for (int i = 0; i < replications; i++) {
      /* Initialize the simulation. */
	
      initialize();

      /* Run the simulation until the end time is reached */
      do {
        /* Determine the next event. */
        timing();

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

		/* FIXME log loop information to debug file */
		fprintf(debugfile, "\nCALL:%d    TIME:%f\n", next_event_type, sim_time);
    	fprintf(debugfile, "#Q1 :%d    #Q2 :%d\n", num_in_q[0], num_in_q[1]);
    	fprintf(debugfile, "SRV1:%d    SRV2:%d\n",
                server_status[0], server_status[1]);


        /* Invoke the appropriate event function. */
        switch (next_event_type) 
        {
            case 1:
                queue1_arrival();
                break;
            case 2:
                queue1_departure();
                break;
            case 3:
                queue2_arrival();
                break;
            case 4:
                queue2_departure();
                break;
            case 5:
                report();
                break;
        }
	  /* If the event just executed was not the end-simulation event, then continue */
	  } while (next_event_type != 5);
	}

    fclose(infile);
    fclose(outfile);

    return 0;
}
Ejemplo n.º 5
0
int main()  /* Main function. */
{
    /* Open input and output files. */

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

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

    num_events = 5;

    /* Read input parameters. */

    fscanf(infile, "%f %f %f %d", &mean_interarrival, &service_time1, &service_time2, &time_limit);
           

    /* Write report heading and input parameters. */

    fprintf(outfile, "Double-server queueing system with transit time\n\n");
    fprintf(outfile, "Mean interarrival time%11.3f minutes\n\n",
            mean_interarrival);
    fprintf(outfile, "Mean service time for server 1%16.3f minutes\n\n", service_time1);
    fprintf(outfile, "Mean service time for server 2%16.3f minutes\n\n", service_time2);
    fprintf(outfile, "Time limit%14d\n\n", time_limit);

    /* Initialize the simulation. */

for(int i = 0; i < 10; i++) {    
	initialize();

		int running = 1;
		while(running) {
			/* 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:
					arrive1();
					break;
				case 2:
					depart1();
					break;
				case 3:
					arrive2();
					break;
				case 4:
					depart2();
					break;
				case 5:
					finish();
					running = 0;
					break;
			}
		}

    
}

    fclose(infile);
    fclose(outfile);

    return 0;
}