예제 #1
0
파일: Event.cs 프로젝트: rNdm74/C-
        public override void Execute(Calender calender, ResourceManager resourceManager, Statistics statistics, RandomNumberGenerator rGen, EntityFactory entitiyFactory, EventFactory eventFactory)
        {
            // Set entities start time at call centre
            CurrentEntity.StartTime = EventTime;

            // Total of the two product queues
            if (resourceManager.IsSpaceInQueues)
            {
                // Set active entites call type
                CurrentEntity.CallType = rGen.GetCallType;

                // Calculate the next event time
                int nextEventTime = CurrentEntity.StartTime + rGen.DelayAtSwitch;

                // Setup next event for active entity switch complete event
                Event processingCompleteEvent = eventFactory.Spawn(EEventType.SWITCH_COMPLETE, nextEventTime, CurrentEntity);

                // Add to calender
                calender.Add(processingCompleteEvent);
            }
            else
            {
                // Entity hangs up at the switch
                Global.BusySignalCount++;
            }

            // Calculate next arrival time
            int nextArrivalTime = EventTime + rGen.TimeBetweenArrivals;

            // Create entity
            Entity nextEntity = entitiyFactory.CreateEntity();

            // Setup next event for entity
            Event nextEvent = eventFactory.Spawn(EEventType.ARRIVAL, nextArrivalTime, nextEntity);

            // Add to the calender
            calender.Add(nextEvent);
        }
예제 #2
0
파일: Simulator.cs 프로젝트: rNdm74/C-
        public Simulator(Statistics statistics)
        {
            this.statistics = statistics;

            calender = new Calender();
            resourceManager = new ResourceManager();
            rGen = new RandomNumberGenerator();
            entityFactory = new EntityFactory();
            eventFactory = new EventFactory();

            // Set global clock
            //Global.Clock = Global.StartSimulationTime;

            // Add EndSim Event
            Event endSimulationEvent = eventFactory.Spawn(EEventType.END_SIMULATION, Global.EndSimulationTime, entityFactory.CreateEntity());
            calender.Add(endSimulationEvent);

            // Create First Arrival Event
            Entity firstCaller = entityFactory.CreateEntity();
            int nextArrivalTime = Global.Clock + rGen.TimeBetweenArrivals;
            Event firstArrivalEvent = eventFactory.Spawn(EEventType.ARRIVAL, nextArrivalTime, firstCaller);
            calender.Add(firstArrivalEvent);
        }
예제 #3
0
파일: Form1.cs 프로젝트: rNdm74/C-
        /// <summary>
        /// Create the simulation
        /// </summary>
        private void InitializeSimulation()
        {
            // Setup subject
            statisticsSubject = new Statistics();

            // Setup observers
            displayObservers = new IDisplay[]
            {
                new Graphical(statisticsSubject, this, pGraphicalDisplay),
                new Text(statisticsSubject, this,  dgvCalender, dgvOtherQueue, dgvCarStereoQueue),
                new Stats(statisticsSubject, this,  dgvStatistics, pbSimulation)
            };

            // Setup simulator
            simulator = new Simulator(statisticsSubject);
        }
예제 #4
0
파일: Display.cs 프로젝트: rNdm74/C-
 public abstract void Update(Calender calender, ResourceManager resourceMananger, Statistics statistics);
예제 #5
0
파일: Display.cs 프로젝트: rNdm74/C-
 /// <summary>
 /// Update the information from the main simulation
 /// </summary>
 public override void Update(Calender calender, ResourceManager resourceMananger, Statistics statistics)
 {
     calenderData = calender.GetEventData();
     otherQueueData = resourceMananger.GetQueueEntityData(ECallType.OTHER);
     carStereoQueueData = resourceMananger.GetQueueEntityData(ECallType.CAR_STEREO);
 }
예제 #6
0
파일: Display.cs 프로젝트: rNdm74/C-
 /// <summary>
 /// Update status bar no information from the main simulation is used
 /// </summary>
 public override void Update(Calender calender, ResourceManager resourceMananger, Statistics statistics)
 {
     if (pBar.InvokeRequired)
     {
         // It's on a different thread, so use Invoke.
         SetCallBack d = new SetCallBack(UpdateProgress);
         mainForm.Invoke(d);
     }
     else
     {
         // It's on the same thread, no need for Invoke
         pBar.Value = Global.Clock;
     }
 }
예제 #7
0
파일: Display.cs 프로젝트: rNdm74/C-
 /// <summary>
 /// Update the information from the main simulation
 /// </summary>
 public override void Update(Calender calender, ResourceManager resourceMananger, Statistics statistics)
 {
     gDisplay.Update(calender, resourceMananger, statistics);
 }
예제 #8
0
파일: Event.cs 프로젝트: rNdm74/C-
 public override void Execute(Calender calender, ResourceManager resourceManager, Statistics statistics, RandomNumberGenerator rGen, EntityFactory entitiyFactory, EventFactory eventFactory)
 {
 }
예제 #9
0
파일: Event.cs 프로젝트: rNdm74/C-
        // ResourceManager
        public override void Execute(Calender calender, ResourceManager resourceManager, Statistics statistics, RandomNumberGenerator rGen, EntityFactory entitiyFactory, EventFactory eventFactory)
        {
            // Check to see if rep is available
            Resource resource = resourceManager.NextAvailableResource(CurrentEntity.CallType);

            // if available rep
            if (resource != null)
            {
                // Resource is now busy
                resource.IsFree = false;

                // Entity is assigned a resource
                CurrentEntity.AssignResource = resource;

                // Set the time the enitity starts being processed
                CurrentEntity.StartProcessingTime = Global.Clock;

                // Compute its process time
                int nextEventTime = EventTime + rGen.NextEventTime(CurrentEntity.CallType);

                // Spawn Processing Complete Event
                Event nextEvent = eventFactory.Spawn(EEventType.PROCESSING_COMPLETE, nextEventTime, CurrentEntity);

                // Add to calender
                calender.Add(nextEvent);
            }
            else
            {
                // Set begin wait time
                CurrentEntity.BeginWait = EventTime;

                // Add entity to resource queue
                resourceManager.AddToQueue(CurrentEntity);
            }
        }
예제 #10
0
파일: Event.cs 프로젝트: rNdm74/C-
        public override void Execute(Calender calender, ResourceManager resourceManager, Statistics statistics, RandomNumberGenerator rGen, EntityFactory entitiyFactory, EventFactory eventFactory)
        {
            // Set entities time they finish in the system
            CurrentEntity.EndTime = EventTime;

            // Update statistics of enitiy leaving system
            statistics.UpdateEntityStatistics(CurrentEntity);

            // (active entity Rep) is now free, look at queue
            Resource resource = CurrentEntity.AssignResource;

            // if Queue is empty
            if (resourceManager.IsQueueEmpty(resource.CallType))
            {
                // Set busy flag to false
                resource.IsFree = true;
            }
            else
            {
                // Remove entity at head of queue
                Entity nextEntityInQueue = resourceManager.GetFirstInQueue(resource.CallType);

                // Set the time the enitity starts being processed
                nextEntityInQueue.StartProcessingTime = Global.Clock;

                // Resource is now busy
                resource.IsFree = false;

                // Assign the entity a resource
                nextEntityInQueue.AssignResource = resource;

                // Compute its process time
                int nextEventTime = EventTime + rGen.NextEventTime(resource.CallType);

                // Spawn next event
                Event nextEvent = eventFactory.Spawn(EEventType.PROCESSING_COMPLETE, nextEventTime, nextEntityInQueue);

                // Add to calender
                calender.Add(nextEvent);
            }
        }
예제 #11
0
        /// <summary>
        /// Keeps the simulation information current for Calender, Other and CarStereo Queue 
        /// </summary>
        public void Update(Calender calender, ResourceManager resourceMananger, Statistics statistics)
        {
            // Clear the lists
            Arrival.Clear();
            SwitchComplete.Clear();
            QueueOther.Clear();
            QueueCarStereo.Clear();
            ResourceOther.Clear();
            ResourceCarStereo.Clear();

            // Update the lists
            updateDisplayDataList(resourceMananger.GetQueueEntityData(ECallType.OTHER));
            updateDisplayDataList(resourceMananger.GetQueueEntityData(ECallType.CAR_STEREO));
            updateDisplayDataList(calender.GetEventData());
        }