Пример #1
0
        public void AStarSearchLP()
        {
            int[] puzzle_start            = { 2, 3, 8, 1, 6, 7, 5, 4, 0 };
            LloydPuzzleSituation sitStart = new LloydPuzzleSituation(puzzle_start);

            int[] puzzle_ziel              = { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
            LloydPuzzleSituation sitEnd    = new LloydPuzzleSituation(puzzle_ziel);
            TreeNode             nodeStart = new TreeNode(sitStart);
            TreeNode             nodeEnd   = new TreeNode(sitEnd);
            LloydPuzzleProblem   problem   = new LloydPuzzleProblem(nodeStart, nodeEnd, false);

            var searchMethod = new AStarFirstSearch(problem);

            searchMethod.Run();
            Assert.True(problem.FoundSolution);
            TreeNode currentNode = problem.Destination as TreeNode;

            int counter = 0;

            while (currentNode != null)
            {
                ((LloydPuzzleSituation)currentNode.Data).Show();
                currentNode = currentNode.Parent;
                counter++;
            }

            Assert.Equal(15, counter);

            Assert.Equal(63, searchMethod.InspectedNodes);
        }
Пример #2
0
        public void AStarSearchQ()
        {
            QueenProblem problem      = new QueenProblem(8);
            var          searchMethod = new AStarFirstSearch(problem);
            DateTime     date         = DateTime.Now;

            searchMethod.Run();
            TreeNode currentNode = problem.Destination as TreeNode;

            int counter = 0;

            while (currentNode != null)
            {
                currentNode = currentNode.Parent;
                counter++;
            }

            Assert.Equal(9, counter);
            Assert.Equal(83, searchMethod.InspectedNodes);
        }