Beispiel #1
0
        /// <summary>
        /// Run this example
        /// </summary>
        public static void Run()
        {
            // Make a simulation context
            using (var context = new SimulationContext(isDefaultContextForProcess: true))
            {
                // Add the resources that represent the staff of the call center
                context.Register<Level1CallCenterStaffMember>(new Level1CallCenterStaffMember(){ Capacity = 10 });
                context.Register<Level2CallCenterStaffMember>(new Level2CallCenterStaffMember(){ Capacity = 5 });

                // Add the processes that represent the phone calls to the call center
                IEnumerable<Call> calls = GeneratePhoneCalls(context,
                    numberOfCalls: 500,
                    level1CallTime: 120,
                    level2CallTime: 300,
                    callTimeVariability: 0.5,
                    callStartTimeRange: 14400);

                // instantate a new simulator
                var simulator = new Simulator();

                // run the simulation
                simulator.Simulate();

                // output the statistics
                OutputResults(calls);
            }
        }
Beispiel #2
0
        public void Simulate_Terminated_SimulationEndsAtTerminatedPeriod()
        {
            using (var context = new SimulationContext(isDefaultContextForProcess: true)){
                var processor1Instructions = new List<InstructionBase>(){
                    new WaitInstruction(5),
                    new WaitInstruction(10)
                };

                var processor2Instructions = new List<InstructionBase>(){
                    new WaitInstruction(2),
                    new TerminateSimulationInstruction(),
                    new WaitInstruction(9),
                };

                var processor1 = new InstructionListTestProcess(processor1Instructions);
                var processor2 = new InstructionListTestProcess(processor2Instructions);

                var simulator = new Simulator();

                simulator.Simulate();

                Assert.AreEqual(2, context.TimePeriod);

                Assert.IsNull(processor1Instructions[0].CompletedAtTimePeriod);
                Assert.IsNull(processor1Instructions[1].CompletedAtTimePeriod);
                Assert.AreEqual(2, processor2Instructions[0].CompletedAtTimePeriod);
                Assert.AreEqual(2, processor2Instructions[1].CompletedAtTimePeriod);
                Assert.IsNull(processor2Instructions[2].CompletedAtTimePeriod);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Run the example
        /// </summary>
        public static void Run()
        {
            // Make a simulation context
            using (var context = new SimulationContext(isDefaultContextForProcess: true))
            {
                // instantiate the process responsible for setting alarms
                new AlarmSettingProcess();

                new SleepingProcess();

                // instantate a new simulator
                var simulator = new Simulator();

                // run the simulation
                simulator.Simulate();

                Console.WriteLine("Simulation ended at time period {0}", context.TimePeriod);
            }
        }
        public void Process_EndConditionSpecified_EndConditionMetAtExpectedTime()
        {
            using(var context = new SimulationContext(isDefaultContextForProcess: true)){

                var waitInstruction1 = new WaitInstruction(2);
                var waitInstruction2 = new WaitInstruction(4);
                var waitInstruction3 = new WaitInstruction(4);

                var process = new InstructionListTestProcess(new List<InstructionBase>(){ waitInstruction1, waitInstruction2, waitInstruction3 });
                var endTrigger = new SimulationEndTrigger(()=>context.TimePeriod >= 5);

                var simulator = new Simulator();

                simulator.Simulate();

                Assert.AreEqual(6, context.TimePeriod);

                // the simulation should have ended at th expected time
                Assert.IsTrue(process.SimulationState.IsActive);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Run the example
        /// </summary>
        public static void Run()
        {
            // Make a simulation context
            using (var context = new SimulationContext(isDefaultContextForProcess: true))
            {
                // initialise the model
                var machines = CreateModel(context: context, numberOfJobs: 500);

                // instantate a new simulator
                var simulator = new Simulator();

                // run the simulation
                simulator.Simulate();

                Console.WriteLine("Jobs processed in {0} minutes", context.TimePeriod);

                int index = 1;
                foreach(var machine in machines){
                    Console.WriteLine("Machine {0} processed {1} jobs and had {2} breakdowns.", index, machine.ProcessedCount, machine.BreakdownCount);
                    index++;
                }
            }
        }
Beispiel #6
0
        public static void Run()
        {
            // Make a simulation context
            using (var context = new SimulationContext(isDefaultContextForProcess: true))
            {
                var products = CreateProducts();

                var inventory = CreateWarehouseInventory(products);
                context.Register<WarehouseInventory>(inventory);

                var orders = GenerateOrders(500, products);
                var deliveryPeople = CreateDeliveryPeople(3, orders);

                // instantate a new simulator
                var simulator = new Simulator();

                // run the simulation
                simulator.Simulate();

                // output the statistics
                OutputResults(deliveryPeople);
            }
        }
Beispiel #7
0
        public void Simulate_ResourceContention_SimulationEndsAtExpectedPeriod()
        {
            using (var context = new SimulationContext(isDefaultContextForProcess: true)){

                new TestResource(1);

                var firstAllocation = new AllocateInstruction<TestResource>(1);
                var secondAllocation = new AllocateInstruction<TestResource>(1);
                var firstRelease = new ReleaseInstruction<TestResource>(firstAllocation);
                var secondRelease = new ReleaseInstruction<TestResource>(secondAllocation);

                var processor1Instructions = new List<InstructionBase>(){
                    firstAllocation,
                    new WaitInstruction(5),
                    firstRelease,
                    new WaitInstruction(10)
                };

                var processor2Instructions = new List<InstructionBase>(){
                    secondAllocation,
                    new WaitInstruction(2),
                    secondRelease,
                    new WaitInstruction(9),
                };

                var processor1 = new InstructionListTestProcess(processor1Instructions);
                var processor2 = new InstructionListTestProcess(processor2Instructions);

                var simulator = new Simulator();

                simulator.Simulate();

                // simulation time is extended due to resource contention
                Assert.AreEqual(16, context.TimePeriod);
            }
        }
Beispiel #8
0
        public void Simulate_VariousProcesses_SimulateAsExpected()
        {
            using (var context = new SimulationContext(isDefaultContextForProcess: true)){
                var processor1Instructions = new List<InstructionBase>(){
                    new WaitInstruction(5),
                    new WaitInstruction(10)
                };

                var processor2Instructions = new List<InstructionBase>(){
                    new WaitInstruction(2),
                    new WaitInstruction(12),
                };

                var processor3Instructions = new List<InstructionBase>(){
                    new WaitInstruction(9),
                };

                var processor1 = new InstructionListTestProcess(processor1Instructions);
                var processor2 = new InstructionListTestProcess(processor2Instructions);
                var processor3 = new InstructionListTestProcess(processor3Instructions);

                processor3.SimulationState.IsActive = false;
                processor2Instructions.Add(new ActivateInstruction(processor3));

                var simulator = new Simulator();

                simulator.Simulate();

                Assert.AreEqual(23, context.TimePeriod);

                Assert.AreEqual(5, processor1Instructions[0].CompletedAtTimePeriod);
                Assert.AreEqual(15, processor1Instructions[1].CompletedAtTimePeriod);

                Assert.AreEqual(2, processor2Instructions[0].CompletedAtTimePeriod);
                Assert.AreEqual(14, processor2Instructions[1].CompletedAtTimePeriod);

                Assert.AreEqual(23, processor3Instructions[0].CompletedAtTimePeriod);
            }
        }