Esempio n. 1
0
/*******************************************************************
 void runSimulationA(Simulation sim, int iTimeLimit)
 Purpose:
     Runs a simulation on the event list. Prints a table displaying
     the arrival and departures of travelers
 Parameters:
     I   Simulation simulation
     I   int iTimeLimit
 Returns:
     1. Does not return anything functionally
 Notes:
     1. Uses removeLL function
 *******************************************************************/
void runSimulationA(Simulation sim, int iTimeLimit)
{
    Event event;                            // Creates a local event variable to store current
                                            // nodes event information into (uses in simulation evaluation)
    Server server1 = newServer("Server 1");           // Creates a new server -
                                            //  - contains Server Name, whether it is busy or not, and a widget
    Server server2 = newServer("Server 2");            // creates the second server for our program (refer to server1 comments)
    Queue queue1 = newQueue("Queue 1");                // Creates a new queue
    Queue queue2 = newQueue("Queue 2");                // Creates a new queue
    
    if (sim->bVerbose == TRUE)
        printf("%-4s %-6s %-10s\n", "TIME", "WIDGET", "EVENT");      //table header
    
    while (removeLL(sim->eventList, &event))
    {
        // buffer to stop arrivals after the time limit
        if (event.iEventType == EVT_ARRIVAL && event.iTime > iTimeLimit)
            continue;
        
        sim->iClock = event.iTime;  // advance clock to current event time
        
        // the switch evaluates the eventType
        switch(event.iEventType)
        {
            case EVT_ARRIVAL:
                arrival(sim, &event.widget);
                queueUp(sim, queue1, &event.widget);
                seize(sim, queue1, server1);
                break;
            case EVT_SERVER1_COMPLETE:
                release(sim, queue1, server1, &event.widget);
                queueUp(sim, queue2, &event.widget);
                seize(sim, queue2, server2);
                break;
            case EVT_SERVER2_COMPLETE:
                release(sim, queue2, server2, &event.widget);
                leaveSystem(sim, event.widget);
                break;
            default:
                ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType);
        }
    }
    // prints the averages produced by the simulation
    printStatistics(sim, queue1, queue2);

    // frees servers and queues used in simulation A
    free(server1);
    free(server2);
    free(queue1);
    free(queue2);
}
Esempio n. 2
0
/**************************** runSimulation ************************************
void runSimulation(Simulation sim, int iTimeLimit)
Purpose:
	Goes through a list of events in a Simulation and run them as they are 
	encountered.
Parameters:
	I	Simulation sim		The simulation variable containing the list of 
							events.
	I	int iTimeLimit		A time limit upon which the simulation will terminate 
							if it is reached before all of the events are ran.
Returns:
Notes:
*******************************************************************************/
void runSimulation(Simulation sim, int iTimeLimit)
{	
	//Variables
	Event event;
	Server server1, server2;
	Queue queue1, queue2;
	
	//create servers and queues
	server1 = newServer("Server 1");
	queue1 = newQueue("Queue 1");
	if (sim->cRunType == 'A')
	{
		server2 = newServer("Server 2");
		queue2 = newQueue("Queue 2");	
	}

	//begin simulation
	printHeader(sim);
	while (removeLL(sim->eventList, &event)) 
	{	
		if (event.iTime > iTimeLimit)
		{
			printFooter(sim, queue1, queue2);	
			freeServersAndQueues(sim, server1, server2, queue1, queue2);	
			ErrExit(ERR_BAD_INPUT, "Event time (%d) is out of simulation bounds (%d)\n", 
					event.iTime, iTimeLimit);
		}

		sim->iClock = event.iTime;
		switch (event.iEventType)
		{
			case EVT_ARRIVAL:
				arrival(sim, &event.widget);
				queueUp(sim, &event.widget, queue1);
				seize(sim, queue1, server1);
				break;

			case EVT_SERVER1_COMPLETE:
				release(sim, queue1, server1);
				if (sim->cRunType == 'A') //Alternative A follows up with server 2
				{
					queueUp(sim, &event.widget, queue2);
					seize(sim, queue2, server2);
				}
				else //Alternative B and Current leave after server 1
				{
					leaveSystem(sim, &event.widget);
				}
				break;

			case EVT_SERVER2_COMPLETE:
				release(sim, queue2, server2);
				leaveSystem(sim, &event.widget);
				break;
		
			default:
				ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType);
		}
	}
	
	printFooter(sim, queue1, queue2);	
	freeServersAndQueues(sim, server1, server2, queue1, queue2);	
}