Esempio n. 1
0
        public void GetNodesBidirectional_ThirdNodeHaveOneDirection_FirstAndSecondHaveLinkToThird()
        {
            var databaseAccessLayer = new DatabaseAccessLayer();
            var firstNode           = new Node()
            {
                id = 1, adjacentNodes = new byte[1] {
                    2
                }
            };
            var secondNode = new Node()
            {
                id = 2, adjacentNodes = new byte[1] {
                    1
                }
            };
            var thirdNode = new Node()
            {
                id = 3, adjacentNodes = new byte[2] {
                    1, 2
                }
            };
            var nodesList = new List <Node> {
                firstNode, secondNode, thirdNode
            };

            databaseAccessLayer.GetNodesBidirectional(nodesList);

            Assert.AreEqual(firstNode.adjacentNodes.Last(), thirdNode.id);
            Assert.AreEqual(secondNode.adjacentNodes.Last(), thirdNode.id);
        }
Esempio n. 2
0
        /// <summary>
        /// Find Shortest path in graph, inside of databse. Currently use modified BFS alg.
        /// </summary>
        /// <param name="firstNodeId">Start node to search from</param>
        /// <param name="secondNodeId">Final node of path</param>
        public List <Node> FindShortestPath(int firstNodeId, int secondNodeId)
        {
            var         databaseAccessLayer = new DatabaseAccessLayer();
            List <Node> nodesUniList        = databaseAccessLayer.GetNodes();
            List <Node> nodesBiList         = databaseAccessLayer.GetNodesBidirectional(nodesUniList);
            var         breathSearchFirst   = new BreathSearchFirst();
            List <Node> resultNodes         = breathSearchFirst.FindShortestPath(nodesBiList, firstNodeId, secondNodeId);

            return(resultNodes);
        }
Esempio n. 3
0
        public void GetNodesBidirectional_OneDirection_BothDirectionLink()
        {
            var databaseAccessLayer = new DatabaseAccessLayer();
            var firstNode           = new Node()
            {
                id = 1, adjacentNodes = new byte[1] {
                    2
                }
            };
            var secondNode = new Node()
            {
                id = 2
            };
            var nodesList = new List <Node> {
                firstNode, secondNode
            };

            databaseAccessLayer.GetNodesBidirectional(nodesList);

            Assert.AreEqual(firstNode.adjacentNodes.First(), secondNode.id);
            Assert.AreEqual(secondNode.adjacentNodes.First(), firstNode.id);
        }