Пример #1
0
        public void testAStarSearch()
        {
            // added to narrow down bug report filed by L.N.Sudarshan of
            // Thoughtworks and Xin Lu of UCI

            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
            // {2,0,5,6,4,8,3,7,1});
            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
            // {0,8,7,6,5,4,3,2,1});
            EightPuzzleBoard board = new EightPuzzleBoard(new int[]
                                                          { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
            //EightPuzzleBoard board = new EightPuzzleBoard(new int[]
            //{ 1, 0, 2, 3, 4, 5, 6, 7, 8 });

            IProblem <EightPuzzleBoard, IAction>          problem = new BidirectionalEightPuzzleProblem(board);
            ISearchForActions <EightPuzzleBoard, IAction> search
                = new AStarSearch <EightPuzzleBoard, IAction>(
                      new GraphSearch <EightPuzzleBoard, IAction>(),
                      EightPuzzleFunctions.createManhattanHeuristicFunction());
            SearchAgent <EightPuzzleBoard, IAction> agent
                = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);

            Assert.AreEqual(23, agent.getActions().Size());
            Assert.AreEqual("1133", // "926" GraphSearchReduced Frontier
                            agent.getInstrumentation().getProperty("nodesExpanded"));
            Assert.AreEqual("676",  // "534" GraphSearchReduced Frontier
                            agent.getInstrumentation().getProperty("queueSize"));
            Assert.AreEqual("677",  // "535" GraphSearchReduced Frontier
                            agent.getInstrumentation().getProperty("maxQueueSize"));
        }
Пример #2
0
 static void eightPuzzleAStarManhattanDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo AStar Search (ManhattanHeursitic)-->");
     try
     {
         IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(random1);
         ISearchForActions <EightPuzzleBoard, IAction>
         search = new AStarSearch <EightPuzzleBoard, IAction>(
             new GraphSearch <EightPuzzleBoard, IAction>(),
             EightPuzzleFunctions.createManhattanHeuristicFunction());
         SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #3
0
        public void testGreedyBestFirstSearchReducedFrontier()
        {
            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
            // {2,0,5,6,4,8,3,7,1});
            // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
            // {0,8,7,6,5,4,3,2,1});
            EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });

            IProblem<EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(board);
            QueueBasedSearch<EightPuzzleBoard, IAction> search = new GreedyBestFirstSearch<EightPuzzleBoard, IAction>
                    (new GraphSearchReducedFrontier<EightPuzzleBoard, IAction>(), EightPuzzleFunctions.createManhattanHeuristicFunction());

            SearchAgent<EightPuzzleBoard, IAction> agent = new SearchAgent<EightPuzzleBoard, IAction>(problem, search);
            Assert.AreEqual(49, agent.getActions().Size());
            Assert.AreEqual("197", agent.getInstrumentation().getProperty("nodesExpanded"));
            Assert.AreEqual("140", agent.getInstrumentation().getProperty("queueSize"));
            Assert.AreEqual("141", agent.getInstrumentation().getProperty("maxQueueSize"));

        }
Пример #4
0
 static void eightPuzzleSimulatedAnnealingDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo Simulated Annealing  Search -->");
     try
     {
         IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(random1);
         SimulatedAnnealingSearch <EightPuzzleBoard, IAction>
         search = new SimulatedAnnealingSearch <EightPuzzleBoard, IAction>(
             EightPuzzleFunctions.createManhattanHeuristicFunction());
         SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);
         printActions(agent.getActions());
         System.Console.WriteLine("Search Outcome=" + search.getOutcome());
         System.Console.WriteLine("Final State=\n" + search.getLastSearchState());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }