public void FindShortestPath_PathExists_PathFound() { var firstNode = new Node() { id = 1, adjacentNodes = new byte[1] { 2 } }; var secondNode = new Node() { id = 2, adjacentNodes = new byte[1] { 3 } }; var thirdNode = new Node() { id = 3, adjacentNodes = new byte[2] { 1, 2 } }; var nodesList = new List <Node> { firstNode, secondNode, thirdNode }; var breathSearchFirst = new BreathSearchFirst(); var resultNodes = breathSearchFirst.FindShortestPath(nodesList, firstNode.id, thirdNode.id); Assert.AreEqual(resultNodes[0].id, thirdNode.id); Assert.AreEqual(resultNodes[1].id, secondNode.id); Assert.AreEqual(resultNodes[2].id, firstNode.id); }
/// <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); }