예제 #1
0
        public void HasPathTest()
        {
            Node[] net = new[] {
                new Node(0)
                {
                    NearestNodes = new[] { 9 }, IsActive = true
                },
                new Node(1)
                {
                    NearestNodes = new[] { 5, 4, 2, 3 }, IsActive = true
                },
                new Node(2)
                {
                    NearestNodes = new[] { 1, 5, 4 }, IsActive = true
                },
                new Node(3)
                {
                    NearestNodes = new[] { 1, 4, 8 }, IsActive = true
                },
                new Node(4)
                {
                    NearestNodes = new[] { 2, 3, 1 }, IsActive = true
                },
                new Node(5)
                {
                    NearestNodes = new[] { 2, 1 }, IsActive = true
                },
                new Node(6)
                {
                    NearestNodes = new[] { 8 }, IsActive = true
                },
                new Node(7)
                {
                    NearestNodes = new[] { 8, 1 }, IsActive = true
                },
                new Node(8)
                {
                    NearestNodes = new[] { 3, 6, 7 }, IsActive = true
                },
                new Node(9)
                {
                    NearestNodes = new[] { 0 }, IsActive = true
                }
            };

            Assert.AreEqual(true, GrafCalculator.HasPath(net, 5, 7));
            Assert.AreEqual(true, GrafCalculator.HasPath(net, 1, 6));
            Assert.AreEqual(true, GrafCalculator.HasPath(net, 6, 1));
            Assert.AreEqual(true, GrafCalculator.HasPath(net, 3, 5));
            Assert.AreEqual(false, GrafCalculator.HasPath(net, 0, 1));
            Assert.AreEqual(false, GrafCalculator.HasPath(net, 7, 9));
        }
        private void Process()
        {
            var  inactivCount = 0;
            bool hasPath      = GrafCalculator.HasPath(_connections, A, B);
            var  step         = 0;

            while ((inactivCount < _connections.Length) && (hasPath))
            {
                inactivCount = (int)(_calculationTask.PofInfective * (_netMap.Sum(node => node.NearestNodes.Length) / 2));
                Inactivate(_connections, inactivCount);
                hasPath = GrafCalculator.HasPath(_connections, A, B);
                step++;
            }
            _percalationResult.Add(step);
        }
예제 #3
0
        private void Process()
        {
            var  inactivCount = 0;
            bool hasPath      = GrafCalculator.HasPath(NetMap, A, B);
            var  step         = 0;

            while ((inactivCount < NetMap.Length) && (hasPath))
            {
                ClaerNet();
                inactivCount = (int)(_calculationTask.PofInfective * step * NetMap.Length);
                Inactivate(NetMap, inactivCount);
                hasPath = GrafCalculator.HasPath(NetMap, A, B);
                step++;
            }
            _percalationResult.Add(step);
        }
        private void Process()
        {
            var hasPath = GrafCalculator.HasPath(_connections, _a, _b);

            _percalationResult.Add(hasPath ? 1 : 0);
        }