public void InitNodes() { var nodeHandler = new GraphNodeHandler(); var matrix = Enumerable.Range(0, 2).Select(i => new[] { i / 2, i % 2 }).ToArray(); nodeHandler.InitNodes(out var doneNodes, out var nodes, matrix); }
public void GetMinimalCostNodeTests() { var nodeHandler = new GraphNodeHandler(); var nodes = new List <Node> { new Node(null, null, 3, 1), new Node(null, null, 4, 1), new Node(null, null, 1, 1), }; var doneNodes = new List <Node>(); Assert.AreEqual(nodes[2], nodeHandler.GetMinimalCostNode(nodes, doneNodes)); }
public void SetStartNodeTest() { var nodeHandler = new GraphNodeHandler(); var positions = new List <int[]> { new[] { 1, 1 }, new[] { 1, 2 }, new[] { 1, 3 } }; var nodes = new List <Node> { new Node(positions[2], null, 3, 1), new Node(positions[1], null, 4, 1), new Node(positions[0], null, 1, 1), }; nodeHandler.SetStartNode(nodes, positions[0]); Assert.AreEqual(0, nodes[2].Cost); }
public void GetShortestPathTests() { var nodeHandler = new GraphNodeHandler(); var positions = new List <int[]> { new[] { 1, 1 }, new[] { 1, 2 }, new[] { 1, 3 } }; var nodes = new List <Node> { new Node(positions[2], null, 3, 1), new Node(positions[1], null, 4, 1), new Node(positions[0], null, 1, 1), }; nodes[1].Parent = nodes[0]; nodes[2].Parent = nodes[1]; var shortestPath = nodeHandler.GetShortestPath(nodes, nodes[0].Position, nodes[2].Position); Assert.IsTrue(positions.SequenceEqual(shortestPath)); }
public Dijkstra(GraphNodeHandler nodeHandler, GraphCostCalculator costCalculator) : base(nodeHandler, costCalculator) { }