Question
Server W is a bottleneck and does many things. Its step 1 takes an average of 10 tu and its step 2 takes an average
Server W is a bottleneck and does many things. Its step 1 takes an average of 10 tu and its step 2 takes
an average of 20 tu. It can only process one widget at a time. While a widget is on step 2, no widgets
can be serviced on step 1. Average arrival rate is every 10 tu. Running the server for 50 widgets, our average wait time has been over 500 tu.
Alternative A. Add a new server (server M) similar to server W to do the same work as server W. Server M does both step 1 and step 2; however, like server W it can only process one widget at a time. Widgets will either queue up for server M (and be processed by server M) or queue up for server W (and be processed by server W). Cost to purchase Server M will be $2M + $20oK maintenance per year. Since we are doubling our server capacity, the executives think this will at least cut both the average wait time and average time in the system in half.
The downtime to reconfigure is expected to be the same for both alternatives so it isn't a factor.
What should we recommend?
Statistics to produce:
0 Average time in system (from arrival to completion at step 2) 0 Average queue time for each server
Input - p4lnput.txt IWidgetNr iStep1tu iStepZtu iArrivaIDelta iWhichServer 1d %d %d %d %d IWidgetNr - identifies a widget going through the system iStep1tu - time units for step 1 for this widget iStepZtu - time units for step 2 for this widget iArrivaIDelta - delta time units before next widget arrives iWhichServer - determines which server to use when given an option: For alternative A : 1 = server M, 2 = server W For alternative B (extra credit): 1: server X, 2 = server Y For current, iWhichServer isn't used.
Part A - 50 points
Provide a simulation of alternative A.
Include a switch (-v) which has no corresponding argument. If -v is specified, this is verbose mode. This causes your program to print all clock times and events as they happen: Arrival, Enter Queue M, Leave Queue M, Seize Server M, Release Server M,
Enter Queue W, Leave Queue W, Seize Server W, Release Server W, Exit System. For some of those events, you should print additional information (time in queue, time in
system). See the sample output below.
When simulating for alternative A, make certain you add iStepltu and iStepZtu for the total processing time for each widget.
Show the statistics specified above.
Run the simulation for 50 widgets. Allow all of the widgets to complete both steps and exit the system.
Sample Output: Simulation for Alternative A Time Widget Event 0 1 Arrived 0 1 Enter Queue M 0 1 Leave Queue M, waited 0 0 1 Seized Server M 13 2 Arrived 13 2 Enter Queue w 13 2 Leave Queue w, waited 0 13 2 Seized Server w 28 3 Arrived 28 3 Enter Queue M 36 1 Released Server M 36 3 Leave Queue M, waited 8 36 3 Seized Server M 36 1 Exit System, in system 36 42 4 Arrived 42 4 Enter Queue w 49 5 Arrived 49 5 Enter Queue M 56 2 Released Server N 56 4 Leave Queue w, waited 14 56 4 Seized Server w 56 2 Exit System, in system 43 67 6 Arrived 67 6 Enter Queue w 77 3 Released Server M 924 Simulation Complete for Alternative A Average Queue Time for Server M = ???? Average Queue Time for Server N = ???? Average Time in System = ?????
* Header File */
/********************************************************************** cs2123p4.h Purpose: Defines constants: max constants error constants event type constants boolean constants Defines typedef for Widget Event (instead of Element) For Linked List NodeLL LinkedListImp LinkedList For Queues QElement NodeQ QueueImp Queue For the Servers ServerImp Server For the Simulation SimulationImp Simulation Protypes Functions provided by student Other functions provided by Larry previously (program 2) Utility functions provided by Larry previously (program 2) Notes:
**********************************************************************/
/*** constants ***/ // Maximum constants
#define MAX_TOKEN 50 // Maximum number of actual characters for a token #define MAX_LINE_SIZE 100 // Maximum number of character per input line #define MAX_ARRIVAL_TIME 600
// Error constants (program exit values) #define ERR_COMMAND_LINE 900 // invalid command line argument #define ERR_ALGORITHM 903 // Error in algorithm - almost anything else #define ERR_BAD_INPUT 503 // Bad input
// Error Messages #define ERR_MISSING_SWITCH "missing switch" #define ERR_EXPECTED_SWITCH "expected switch, found" #define ERR_MISSING_ARGUMENT "missing argument for"
// Event Constants #define EVT_ARRIVAL 1 // when a widget arrives #define EVT_SERVERM_COMPLETE 2 // when a widget completes with server M #define EVT_SERVERW_COMPLETE 3 // when a widget completes with server W #define EVT_SERVERX_COMPLETE 4 // when a widget completes with server X #define EVT_SERVERY_COMPLETE 5 // when a widget completes with server Y // exitUsage control #define USAGE_ONLY 0 // user only requested usage information #define USAGE_ERR -1 // usage error, show message and usage information
// boolean constants #define FALSE 0 #define TRUE 1
/* EOF */ #define REACHED_EOF 1
/*** typedef ***/
// Widget typedef typedef struct { long lWidgetNr; // Identifies a widget int iStep1tu; // Step 1 time units int iStep2tu; // Step 2 time units int iArrivalTime; // Arrival time in tu int iWhichServer; // For the alternatives, this specifies which server } Widget;
// Event typedef typedef struct { int iEventType; // The type of event as an integer: // EVT_ARRIVAL - arrival event // EVT_SERVERM_COMPLETE - servicing by server M is complete // EVT_SERVERW_COMPLETE - servicing by server W is complete // EVT_SERVERX_COMPLETE - servicing by server X is complete // EVT_SERVERY_COMPLETE - servicing by server Y is complete int iTime; // The time the event will occur Widget widget; // The widget involved in the event. } Event;
// typedefs for the Linked Lists used for the event list typedef struct NodeLL { Event event; struct NodeLL *pNext; } NodeLL;
typedef struct { NodeLL *pHead; } LinkedListImp;
typedef LinkedListImp *LinkedList;
// typedefs for the queues
typedef struct { Widget widget; int iEnterQTime; // time widget was inserted in queue } QElement;
typedef struct NodeQ { QElement element; struct NodeQ *pNext; } NodeQ;
typedef struct { NodeQ *pHead; NodeQ *pFoot; long lQueueWaitSum; // Sum of wait times for the queue long lQueueWidgetTotalCount; // Total count of widgets that entered queue char szQName[12]; } QueueImp;
typedef QueueImp *Queue;
// typedefs for server typedef struct { char szServerName[12]; int bBusy; // TRUE - server is busy, FALSE - server is free Widget widget; // Widget the server is currently working } ServerImp; typedef ServerImp *Server;
// typedefs for the Simulation typedef struct { int iClock; // clock time int bVerbose; // When TRUE, this causes printing of event information long lSystemTimeSum; // Sum of times widgets are in the system long lWidgetCount; // The number of widgets processed char cRunType; // A - Alternative A, B - Alternative B, C - Current LinkedList eventList; } SimulationImp; typedef SimulationImp *Simulation;
/********** prototypes ***********/
// linked list functions - you must provide the code for these (see course notes) int removeLL(LinkedList list, Event *pValue); NodeLL *insertOrderedLL(LinkedList list, Event value); NodeLL *searchLL(LinkedList list, int match, NodeLL **ppPrecedes); LinkedList newLinkedList(); NodeLL *allocateNodeLL(LinkedList list, Event value);
// queue functions int removeQ(Queue queue, QElement *pFromQElement); void insertQ(Queue queue, QElement element); NodeQ *allocNodeQ(Queue queue, QElement value); Queue newQueue(char szQueueNm[]);
// simulation functions - you must provide code for this void runSimulation(Simulation simulation, int iTimeLimit);
// functions in most programs, but require modifications void exitUsage(int iArg, char *pszMessage, char *pszDiagnosticInfo);
// Utility routines provided by Larry (copy from program #2) void ErrExit(int iexitRC, char szFmt[], ...); char * getToken(char *pszInputTxt, char szToken[], int iTokenSize);
/*Starting Point*/
void runSimulation(Simulation simulation, int iTimeLimit)
{
generateArrival(sim, 0);
while (removeLL(sim->eventList, &event))
{
sim->iClock = event.iTime; // advance clock
switch(event.eventType);
{
case EVT_ARRIVAL:
arrival(sim, &event.widget);
queueUp(sim, queueTeller, &event.widget);
seize(sim, queueTeller, serverTeller);
break;
case EVT_TELLER_COMPLETE:
release(sim, queueTeller, serverTeller, &event.widget);
leaveSystem(sim, event.widget);
break;
default:
ErrExit(ERR_ALGORITHM, "Unknown event type: %d ", event.iEventType);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started