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);
        }
示例#2
0
        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));
        }
示例#3
0
        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);
        }
示例#4
0
        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));
        }
示例#5
0
 public Dijkstra(GraphNodeHandler nodeHandler, GraphCostCalculator costCalculator) : base(nodeHandler, costCalculator)
 {
 }