Beispiel #1
0
        /// <summary>
        /// Executes the simulation
        /// </summary>
        /// <param name="delay">The time to pause between each event process</param>
        public void RunSimulation(uint delay)
        {
            // Create the active event variable
            Event activeEvent = null;

            //do while the active event is not the end simulation event
            do
            {
                //Retrieve the next event
                activeEvent = calendar.NextEvent();

                clock = activeEvent.EventTime;
                EventProcessArgs epa           = processArgsFactory.CreateProcessArgsFor(activeEvent);
                List <Event>     spawnedEvents = activeEvent.Process(epa);

                //Loop through all the spawned events and add them to the calendar
                foreach (Event e in spawnedEvents)
                {
                    calendar.AddEvent(e);
                }

                OnEventOccured(activeEvent);

                Thread.Sleep((int)delay);
            } while (!(activeEvent is EndReplicationEvent));
        }
        /// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the CompleteServiceProcessArgs class</param>
        /// <returns>A list of events that processing this event spawned</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given args is null</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given args is not the correct EventProcessArgs child type</exception>
        public override List <Event> Process(EventProcessArgs args)
        {
            //If the given args is not null
            if (args != null)
            {
                // Attempt to cast the args to the correct EventProcessArgs child type
                CompletedServiceProcessArgs pArgs = args as CompletedServiceProcessArgs;

                //If the cast worked
                if (pArgs != null)
                {
                    //Create the list of Events to return
                    List <Event> spawnedEvents = new List <Event>();

                    //Set this events entities finish time
                    entity.FinishTime = eventTime;

                    //GetProcessableProductTypes the salesrep that was assigned this entity
                    SalesRepresentative salesrep = entity.ProcessedBy;
                    //remove the salesRep's currentlly processing
                    salesrep.CurrentlyProcessing = null;

                    //Get a new call from the queue manager
                    Call nextCall = pArgs.QueueManager.GetCallForRepType(salesrep.RepType);

                    //If the above method returned a call
                    if (nextCall != null)
                    {
                        nextCall.BeganProcessing = eventTime;
                        //Assign them to each other
                        nextCall.ProcessedBy         = salesrep;
                        salesrep.CurrentlyProcessing = nextCall;

                        //Get the next calls product type
                        ProductType ncProductType = nextCall.ProductType;

                        //create the processing complete event
                        DateTime processingTime = eventTime;
                        double   timespanInMins = NormalDistributor.Roll() * ncProductType.ProcessingDelayMultiplier;
                        processingTime = processingTime.AddMinutes(timespanInMins);
                        Event processComplete = pArgs.EventFactory.CreateEvent(EEventType.CompletedService, processingTime, nextCall);
                        spawnedEvents.Add(processComplete);
                    }
                    //else No calls waiting in queue

                    //Return the list of spawned events
                    return(spawnedEvents);
                }
                else // The given args could not be cast to the correct type
                {
                    throw new ArgumentOutOfRangeException("args", "Attempted to pass invalid args to CompletedServiceEvent.Process");
                }
            }
            else // The given args was null
            {
                throw new ArgumentNullException("args", "Attempted to pass null args to CompletedServiceEvent.Process");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the SwitchCompleteProcessArgs</param>
        /// <returns>A list of events that processing this event spawned</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given args is null or not of the correct type</exception>
        /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given args is not the correct EventProcessArgs child type</exception>
        public override List <Event> Process(EventProcessArgs args)
        {
            // If the given args is not null
            if (args != null)
            {
                // Attempt to cast the args to the correct EventProcessArgs child type
                SwitchCompleteProcessArgs pArgs = args as SwitchCompleteProcessArgs;

                //If the cast worked
                if (pArgs != null)
                {
                    //Create the list of events to return
                    List <Event> spawnedEvents = new List <Event>();

                    //GetProcessableProductTypes the product type from the entity
                    ProductType entityProductType = entity.ProductType;
                    //GetProcessableProductTypes a sales representative from the Simulations SalesManager if one is available
                    SalesRepresentative salesRep = pArgs.SalesManager.GetRepresentativeForProductType(entityProductType);
                    //If a SalesRepresentative was returned above, assign the entity to it
                    if (salesRep != null)
                    {
                        entity.BeganProcessing       = eventTime;
                        salesRep.CurrentlyProcessing = entity;
                        entity.ProcessedBy           = salesRep;
                        //create the processing complete event
                        DateTime processingTime = eventTime;
                        double   timespanInMins = NormalDistributor.Roll() * entityProductType.ProcessingDelayMultiplier;
                        processingTime = processingTime.AddMinutes(timespanInMins);
                        Event processComplete = args.EventFactory.CreateEvent(EEventType.CompletedService, processingTime, entity);
                        spawnedEvents.Add(processComplete);
                    }
                    else //No representative was available
                    {
                        //Set the enitities begin wait
                        entity.BeginWait = eventTime;
                        //Add the call to the queue
                        args.QueueManager.AddToQueue(entity);
                    }

                    //Return the list of events spawned as a result of this
                    return(spawnedEvents);
                }
                else // The given args could not be cast to the correct type
                {
                    throw new ArgumentOutOfRangeException("args", "Attempted to pass invalid args to SwitchCompletedEvent.Process");
                }
            }
            else // The given args was null
            {
                throw new ArgumentNullException("args", "Attempted to pass null EventProcessArgs to SwitchCompletedEvent.Process");
            }
        }
        /// <summary>
        /// Creates and returns an the correct EventProcessArgs child class for the given event type
        /// </summary>
        /// <param name="e">The event to create the EventProcessArgs for</param>
        /// <returns>An instance of an EventProcessArgs child classes</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given Event is null</exception>
        public EventProcessArgs CreateProcessArgsFor(Event e)
        {
            //Check that e is not null
            if (e != null)
            {
                // Create the EventProcessArgs return variable
                EventProcessArgs epa = null;

                // Check if e is a CallArriveEvent
                if (e is CallArriveEvent)
                {
                    epa = CreateCallArriveArgs();
                }
                else // e is not a CallArrive
                {
                    // Check if e is a SwitchCompleteEvent
                    if (e is SwitchCompletedEvent)
                    {
                        epa = CreateSwitchCompleteArgs();
                    }
                    else // e is not a SwitchCompleteEvent
                    {
                        // Check if e is a CompletedServiceEvent
                        if (e is CompletedServiceEvent)
                        {
                            epa = CreateCompleteServiceArgs();
                        }
                        else // e is not a CompletedServiceEvent
                        {
                            // Check if e is an EndReplicationEvent
                            if (e is EndReplicationEvent)
                            {
                                epa = CreateEndReplicationArgs();
                            }
                            // else leave epa null
                        }
                    }
                }

                return(epa);
            }
            else // e is null
            {
                throw new ArgumentNullException("e", "Attempted to pass null Event to ProcessArgsFactory.CreateProcessArgsFor");
            }
        }
Beispiel #5
0
 /// <summary>
 /// Processes the event
 /// </summary>
 /// <param name="args">An instance of the Simulator class</param>
 /// <returns>A List of Events spawned by the processing of this one</returns>
 public abstract List <Event> Process(EventProcessArgs args);
        /// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the CallArriveProcessArgs class</param>
        /// <returns>A list of events that processing this event spawned</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given args is null</exception>
        /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given args is not the correct EventProcessArgs child type</exception>
        public override List <Event> Process(EventProcessArgs args)
        {
            // if the given args is not null
            if (args != null)
            {
                // Attempt to cast the args to the correct EventProcessArgs child type
                CallArriveProcessArgs pArgs = args as CallArriveProcessArgs;

                //If the cast worked
                if (pArgs != null)
                {
                    //Create the list of events to return
                    List <Event> spawnedEvents = new List <Event>();

                    //Set up the call
                    entity.StartTime   = eventTime;
                    entity.ProductType = ChooseProductType(pArgs.ProductTypes);

                    //Check if there are to many calls waiting for this product type
                    if (args.QueueManager.IsQueueTooLong(entity.ProductType) == false)
                    {
                        //Calculate the time of the new SwitchCompletedEvent
                        DateTime switchCompleteTime = eventTime;
                        int      roll           = NormalDistributor.Roll();
                        double   timespanInMins = roll * pArgs.SwitchDelayMultiplier;
                        //Add the minutes to the switchCompleteTime
                        switchCompleteTime = switchCompleteTime.AddMinutes(timespanInMins);
                        //Use the event factory to create a switch complete event
                        Event switchComplete = args.EventFactory.CreateEvent(EEventType.SwitchCompleted, switchCompleteTime, entity);
                        spawnedEvents.Add(switchComplete);
                        hangUp = false;
                    }
                    else
                    {
                        hangUp = true;
                    }

                    //Create the next CallArrive event
                    DateTime nextCallArriveTime    = eventTime;
                    int      rollNewCall           = NormalDistributor.Roll();
                    double   timespanInMinsNewCall = rollNewCall * pArgs.CallArriveMultiplier;
                    nextCallArriveTime = nextCallArriveTime.AddMinutes(timespanInMinsNewCall);
                    //GetProcessableProductTypes a new blank call for the next event
                    Call newCall = pArgs.CallFactory.CreateCall();
                    //Use the event factory to create a call arrive event
                    Event callArrive = args.EventFactory.CreateEvent(EEventType.CallArrive, nextCallArriveTime, newCall);
                    spawnedEvents.Add(callArrive);

                    //Return all spawned events
                    return(spawnedEvents);
                }
                else // The given args could not be cast to the correct type
                {
                    throw new ArgumentOutOfRangeException("args", "Attempted to pass invalid args to CallArriveEvent.Process");
                }
            }
            else // The given args are null
            {
                throw new ArgumentNullException("args", "Attempted to pass null CallArriveProcessArgs to CallArriveEvent.Process");
            }
        }
Beispiel #7
0
 /// <summary>
 /// Does nothing
 /// </summary>
 /// <returns>An empty List of events</returns>
 public override List <Event> Process(EventProcessArgs args)
 {
     //Create and return the empty list
     return(new List <Event>());
 }