コード例 #1
0
        public void Complete_ResourcesAllocated_ResourcesDeallocated()
        {
            using (var context = new SimulationContext(isDefaultContextForProcess:true)){

                int resouceCapacity = 5;
                var testResourceSet1 = new TestResource(resouceCapacity) { Code = "First", Priority = 10 };
                context.Register<TestResource>(testResourceSet1);

                var allocateInstruction = new AllocateInstruction<TestResource>(resouceCapacity);
                allocateInstruction.Complete(context);

                Assert.AreEqual(resouceCapacity, testResourceSet1.Allocated);
                Assert.AreEqual(testResourceSet1.Allocated, allocateInstruction
                   .Allocations
                   .First(al=>al.Key == testResourceSet1)
                   .Value);

                var releaseInstruction = new ReleaseInstruction<TestResource>(allocateInstruction);

                long? nextTimePeriodCheck;
                bool canComplete = releaseInstruction.CanComplete(context, out nextTimePeriodCheck);

                Assert.IsTrue(canComplete);
                Assert.IsNull(nextTimePeriodCheck);

                releaseInstruction.Complete(context);

                Assert.AreEqual(0, testResourceSet1.Allocated);
                Assert.IsTrue(allocateInstruction.IsReleased);
            }
        }
コード例 #2
0
        public void Complete_ResourcesAllocated_ResourcesDeallocated()
        {
            using (var context = new SimulationContext())
            {
                int resouceCapacity  = 5;
                var testResourceSet1 = new TestResource(context, resouceCapacity)
                {
                    Code = "First", Priority = 10
                };
                context.Register <TestResource>(testResourceSet1);

                var allocateInstruction = new AllocateInstruction <TestResource>(resouceCapacity);
                allocateInstruction.Complete(context);

                Assert.AreEqual(resouceCapacity, testResourceSet1.Allocated);
                Assert.AreEqual(testResourceSet1.Allocated, allocateInstruction
                                .Allocations
                                .First(al => al.Key == testResourceSet1)
                                .Value);

                var releaseInstruction = new ReleaseInstruction <TestResource>(allocateInstruction);

                long?nextTimePeriodCheck;
                bool canComplete = releaseInstruction.CanComplete(context, out nextTimePeriodCheck);

                Assert.IsTrue(canComplete);
                Assert.IsNull(nextTimePeriodCheck);

                releaseInstruction.Complete(context);

                Assert.AreEqual(0, testResourceSet1.Allocated);
                Assert.IsTrue(allocateInstruction.IsReleased);
            }
        }
コード例 #3
0
ファイル: SimulatorFixture.cs プロジェクト: jhorv/NSimulate
        public void Simulate_ResourceContention_SimulationEndsAtExpectedPeriod()
        {
            using (var context = new SimulationContext())
            {
                new TestResource(context, 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(context, processor1Instructions);
                var processor2 = new InstructionListTestProcess(context, processor2Instructions);

                var simulator = new Simulator(context);

                simulator.Simulate();

                // simulation time is extended due to resource contention
                Assert.AreEqual(16, context.TimePeriod);
            }
        }
コード例 #4
0
ファイル: SimulatorFixture.cs プロジェクト: PhillP/NSimulate
        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);
            }
        }