Exemplo n.º 1
0
        public void testMultiGoalProblem()
        {
            Map     romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
            Problem problem    = new Problem(SimplifiedRoadMapOfPartOfRomania.ARAD,
                                             MapFunctionFactory.getActionsFunction(romaniaMap),
                                             MapFunctionFactory.getResultFunction(), new DualMapGoalTest(
                                                 SimplifiedRoadMapOfPartOfRomania.BUCHAREST,
                                                 SimplifiedRoadMapOfPartOfRomania.HIRSOVA),
                                             new MapStepCostFunction(romaniaMap));

            Search search = new BreadthFirstSearch(new GraphSearch());

            SearchAgent agent = new SearchAgent(problem, search);

            Assert
            .Equals(
                "[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==Fagaras], Action[name==moveTo, location==Bucharest], Action[name==moveTo, location==Urziceni], Action[name==moveTo, location==Hirsova]]",
                agent.getActions().ToString());
            Assert.Equals(5, agent.getActions().Count);
            Assert.Equals("14", agent.getInstrumentation()[
                              "nodesExpanded"]);
            Assert.Equals("1", agent.getInstrumentation()[
                              "queueSize"]);
            Assert.Equals("5", agent.getInstrumentation()[
                              "maxQueueSize"]);
        }
Exemplo n.º 2
0
        public void testAIMA3eFigure3_24()
        {
            Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
            IProblem <string, MoveToAction> problem = new GeneralProblem <string, MoveToAction>(
                SimplifiedRoadMapOfPartOfRomania.ARAD,
                MapFunctions.createActionsFunction(romaniaMap),
                MapFunctions.createResultFunction(),
                SimplifiedRoadMapOfPartOfRomania.BUCHAREST.Equals,
                MapFunctions.createDistanceStepCostFunction(romaniaMap));

            ISearchForActions <string, MoveToAction> search = new AStarSearch <string, MoveToAction>(new TreeSearch <string, MoveToAction>(),
                                                                                                     MapFunctions.createSLDHeuristicFunction(SimplifiedRoadMapOfPartOfRomania.BUCHAREST, romaniaMap));
            SearchAgent <string, MoveToAction> agent = new SearchAgent <string, MoveToAction>(problem, search);

            Assert.AreEqual(
                "[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==RimnicuVilcea], Action[name==moveTo, location==Pitesti], Action[name==moveTo, location==Bucharest]]",
                agent.getActions().ToString());
            Assert.AreEqual(4, agent.getActions().Size());
            Assert.AreEqual("5",
                            agent.getInstrumentation().getProperty("nodesExpanded"));
            Assert.AreEqual("10",
                            agent.getInstrumentation().getProperty("queueSize"));
            Assert.AreEqual("11",
                            agent.getInstrumentation().getProperty("maxQueueSize"));
        }
Exemplo n.º 3
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"));
        }
Exemplo n.º 4
0
        public void testAIMA3eFigure3_15()
        {
            Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
            IProblem <string, MoveToAction> problem = new GeneralProblem <string, MoveToAction>(
                SimplifiedRoadMapOfPartOfRomania.SIBIU,
                MapFunctions.createActionsFunction(romaniaMap),
                MapFunctions.createResultFunction(),
                SimplifiedRoadMapOfPartOfRomania.BUCHAREST.Equals,
                MapFunctions.createDistanceStepCostFunction(romaniaMap));

            ISearchForActions <string, MoveToAction> search
                = new AStarSearch <string, MoveToAction>(
                      new GraphSearch <string, MoveToAction>(),
                      MapFunctions.createSLDHeuristicFunction(
                          SimplifiedRoadMapOfPartOfRomania.BUCHAREST,
                          romaniaMap));
            SearchAgent <string, MoveToAction> agent = new SearchAgent <string, MoveToAction>(problem, search);

            ICollection <MoveToAction> actions = agent.getActions();

            Assert.AreEqual(
                "[Action[name==moveTo, location==RimnicuVilcea], Action[name==moveTo, location==Pitesti], Action[name==moveTo, location==Bucharest]]",
                actions.ToString());
            Assert.AreEqual("278",
                            search.getMetrics().get(QueueSearch <string, MoveToAction> .METRIC_PATH_COST));
        }
	public void testGreedyBestFirstSearch() {
		try {
			// 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 });

			Problem problem = new Problem(board, EightPuzzleFunctionFactory
					.getActionsFunction(), EightPuzzleFunctionFactory
					.getResultFunction(), new EightPuzzleGoalTest());
			Search search = new GreedyBestFirstSearch(new GraphSearch(),
					new ManhattanHeuristicFunction());
			SearchAgent agent = new SearchAgent(problem, search);
			Assert.assertEquals(49, agent.getActions().size());
			Assert.assertEquals("197", agent.getInstrumentation().getProperty(
					"nodesExpanded"));
			Assert.assertEquals("140", agent.getInstrumentation().getProperty(
					"queueSize"));
			Assert.assertEquals("141", agent.getInstrumentation().getProperty(
					"maxQueueSize"));
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail("Exception thrown.");
		}
	}
Exemplo n.º 6
0
        public void Resolve()
        {
            rubickCube.Apply();
            Problem problem = new Problem(rubickCube,
                                          new RubickSuccessorFunction(),
                                          new RubickGoalTest(),
                                          new RubickHeuristicFunction());
            Search search = new IterativeDeepeningSearch();
            //Search search = new AStarSearch(new GraphSearch());
            SearchAgent agent      = new SearchAgent(problem, search);
            int         iterations = -1;
            ArrayList   actions    = agent.getActions();
            Hashtable   info       = agent.getInstrumentation();

            for (int i = 0; i < actions.Count; i++)
            {
                RubickMovementTypes move = (RubickMovementTypes)Enum.Parse(typeof(RubickMovementTypes), (string)actions[i]);
                rubickCube.Transform(move);
            }
            //aStarSearchTree.Search(rubickCube);
            //if (aStarSearchTree.result != null)
            //{
            //    rubickCube = aStarSearchTree.result;
            //    iterations = aStarSearchTree.iterations;
            //}
            DispatchEvent(new RubickCubeResolvedOutputEvent((RubickColorMatrix)rubickCube.Clone(), iterations));
        }
Exemplo n.º 7
0
        static void nQueensHillClimbingSearch()
        {
            System.Console.WriteLine("\nNQueensDemo HillClimbing  -->");
            try
            {
                IProblem <NQueensBoard, QueenAction>
                problem = NQueensFunctions.createCompleteStateFormulationProblem(
                    boardSize,
                    NQueensBoard.Config.QUEENS_IN_FIRST_ROW);
                HillClimbingSearch <NQueensBoard, QueenAction>
                search = new HillClimbingSearch <NQueensBoard, QueenAction>(
                    NQueensFunctions.createAttackingPairsHeuristicFunction());
                SearchAgent <NQueensBoard, QueenAction>
                agent = new SearchAgent <NQueensBoard, QueenAction>(problem, search);

                System.Console.WriteLine();
                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;
            }
        }
Exemplo n.º 8
0
	public void testAStarSearch() {
		// added to narrow down bug report filed by L.N.Sudarshan of
		// Thoughtworks and Xin Lu of UCI
		try {
			// 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 });

			Problem problem = new Problem(board, EightPuzzleFunctionFactory
					.getActionsFunction(), EightPuzzleFunctionFactory
					.getResultFunction(), new EightPuzzleGoalTest());
			Search search = new AStarSearch(new GraphSearch(),
					new ManhattanHeuristicFunction());
			SearchAgent agent = new SearchAgent(problem, search);
			Assert.assertEquals(23, agent.getActions().size());
			Assert.assertEquals("926", agent.getInstrumentation().getProperty(
					"nodesExpanded"));
			Assert.assertEquals("534", agent.getInstrumentation().getProperty(
					"queueSize"));
			Assert.assertEquals("535", agent.getInstrumentation().getProperty(
					"maxQueueSize"));
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail("Exception thrown");
		}
	}
Exemplo n.º 9
0
        private void btnBreadthFirst_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "NQueensDemo BFS -->" + System.Environment.NewLine;
            Problem     problem = new Problem(new NQueensBoard(8), new NQueensSuccessorFunction(), new NQueensGoalTest());
            Search      search  = new BreadthFirstSearch(new TreeSearch());
            SearchAgent agent2  = new SearchAgent(problem, search);

            printActions(agent2.getActions());
            printInstrumentation(agent2.getInstrumentation());
        }
Exemplo n.º 10
0
        private void btnRecursiveDLS_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "NQueensDemo recursive DLS -->" + System.Environment.NewLine;

            Problem     problem = new Problem(new NQueensBoard(8), new NQueensSuccessorFunction(), new NQueensGoalTest());
            Search      search  = new DepthLimitedSearch(8);
            SearchAgent agent   = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 11
0
        private void btnHillClimbing_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "NQueensDemo HillClimbing -->" + System.Environment.NewLine;

            Problem     problem = new Problem(new NQueensBoard(8), new NQueensSuccessorFunction(), new NQueensGoalTest(), new QueensToBePlacedHeuristic());
            Search      search  = new HillClimbingSearch();
            SearchAgent agent   = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 12
0
        public List <string> PrintActions(SearchAgent agent)
        {
            var toReturn = new List <String>();
            var actions  = agent.getActions().toArray();

            foreach (aima.core.agent.Action action in actions)
            {
                toReturn.Add(action.ToString());
            }
            return(toReturn);
        }
Exemplo n.º 13
0
        private void btnIDLS_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "EightPuzzleDemo Iterative DLS-->" + System.Environment.NewLine;
            Problem problem = new Problem(random1,
                                          new EightPuzzleSuccessorFunction(),
                                          new EightPuzzleGoalTest());
            Search      search = new IterativeDeepeningSearch();
            SearchAgent agent  = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 14
0
        private void btnIterativeDeeping_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "NQueensDemo Iterative DS -->" + System.Environment.NewLine;

            Problem     problem = new Problem(new NQueensBoard(8), new NQueensSuccessorFunction(), new NQueensGoalTest());
            Search      search  = new IterativeDeepeningSearch();
            SearchAgent agent   = new SearchAgent(problem, search);


            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 15
0
        private void btnGreedyBestFirstMan_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "EightPuzzleDemo Greedy Best First Search (ManhattanHeursitic)-->" + System.Environment.NewLine;
            Problem problem = new Problem(boardWithThreeMoveSolution,
                                          new EightPuzzleSuccessorFunction(),
                                          new EightPuzzleGoalTest(), new ManhattanHeuristicFunction());
            Search      search = new GreedyBestFirstSearch(new GraphSearch());
            SearchAgent agent  = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 16
0
        private void btnSimulatedAnnealing_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "EightPuzzleDemo Simulated Annealing  Search -->" + System.Environment.NewLine;
            Problem problem = new Problem(random1,
                                          new EightPuzzleSuccessorFunction(),
                                          new EightPuzzleGoalTest(), new ManhattanHeuristicFunction());
            Search      search = new SimulatedAnnealingSearch();
            SearchAgent agent  = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 17
0
        private void btnAStar_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text = "EightPuzzleDemo AStar Search (MisplacedTileHeursitic)-->" + System.Environment.NewLine;

            Problem problem = new Problem(random1,
                                          new EightPuzzleSuccessorFunction(),
                                          new EightPuzzleGoalTest(),
                                          new MisplacedTilleHeuristicFunction());
            Search      search = new AStarSearch(new GraphSearch());
            SearchAgent agent  = new SearchAgent(problem, search);

            printActions(agent.getActions());
            printInstrumentation(agent.getInstrumentation());
        }
Exemplo n.º 18
0
 static void eightPuzzleDLSDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo recursive DLS (9) -->");
     try
     {
         IProblem <EightPuzzleBoard, IAction>          problem = new BidirectionalEightPuzzleProblem(boardWithThreeMoveSolution);
         ISearchForActions <EightPuzzleBoard, IAction> search  = new DepthLimitedSearch <EightPuzzleBoard, IAction>(9);
         SearchAgent <EightPuzzleBoard, IAction>       agent   = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 19
0
 static void eightPuzzleIDLSDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo Iterative DLS -->");
     try
     {
         IProblem <EightPuzzleBoard, IAction>          problem = new BidirectionalEightPuzzleProblem(random1);
         ISearchForActions <EightPuzzleBoard, IAction> search  = new IterativeDeepeningSearch <EightPuzzleBoard, IAction>();
         SearchAgent <EightPuzzleBoard, IAction>       agent   = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 20
0
 static void eightPuzzleAStarDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo AStar Search (MisplacedTileHeursitic)-->");
     try
     {
         IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(random1);
         ISearchForActions <EightPuzzleBoard, IAction>
         search = new AStarSearch <EightPuzzleBoard, IAction>(
             new GraphSearch <EightPuzzleBoard, IAction>(), EightPuzzleFunctions.createMisplacedTileHeuristicFunction());
         SearchAgent <EightPuzzleBoard, IAction> agent = new SearchAgent <EightPuzzleBoard, IAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
	public void testIterativeDeepeningSearch() {
		try {
			Problem problem = new Problem(new NQueensBoard(8),
					NQueensFunctionFactory.getIActionsFunction(),
					NQueensFunctionFactory.getResultFunction(),
					new NQueensGoalTest());
			Search search = new IterativeDeepeningSearch();
			SearchAgent agent = new SearchAgent(problem, search);
			List<Action> actions = agent.getActions();
			assertCorrectPlacement(actions);
			Assert.assertEquals("3656", agent.getInstrumentation().getProperty(
					"nodesExpanded"));

		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail("Exception should not occur");
		}
	}
Exemplo n.º 22
0
 static void nQueensWithRecursiveDLS()
 {
     System.Console.WriteLine("\nNQueensDemo recursive DLS -->");
     try
     {
         IProblem<NQueensBoard, QueenAction> problem =
                 NQueensFunctions.createIncrementalFormulationProblem(boardSize);
         ISearchForActions<NQueensBoard, QueenAction> 
             search = new DepthLimitedSearch<NQueensBoard, QueenAction>(boardSize);
         SearchAgent<NQueensBoard, QueenAction> 
             agent = new SearchAgent<NQueensBoard, QueenAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     } 
 }
Exemplo n.º 23
0
 static void nQueensWithBreadthFirstSearch()
 {
     try
     {
         System.Console.WriteLine("\nNQueensDemo BFS -->");
         IProblem <NQueensBoard, QueenAction> problem =
             NQueensFunctions.createIncrementalFormulationProblem(boardSize);
         ISearchForActions <NQueensBoard, QueenAction>
         search = new BreadthFirstSearch <NQueensBoard, QueenAction>(new TreeSearch <NQueensBoard, QueenAction>());
         SearchAgent <NQueensBoard, QueenAction>
         agent = new SearchAgent <NQueensBoard, QueenAction>(problem, search);
         printActions(agent.getActions());
         printInstrumentation(agent.getInstrumentation());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 24
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"));
        }
Exemplo n.º 25
0
 static void eightPuzzleGreedyBestFirstManhattanDemo()
 {
     System.Console.WriteLine("\nEightPuzzleDemo Greedy Best First Search (ManhattanHeursitic)-->");
     try
     {
         IProblem <EightPuzzleBoard, IAction> problem = new BidirectionalEightPuzzleProblem(boardWithThreeMoveSolution);
         ISearchForActions <EightPuzzleBoard, IAction>
         search = new GreedyBestFirstSearch <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;
     }
 }
Exemplo n.º 26
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;
     }
 }
Exemplo n.º 27
0
        /**
         * Returns a sequence of actions using A* Search.
         *
         * @param current
         *            the agent's current position
         * @param goals
         *            a set of squares; try to plan a route to one of them
         * @param allowed
         *            a set of squares that can form part of the route
         *
         * @return the best sequence of actions that the agent have to do to reach a
         *         goal from the current position.
         */
        public ICollection <IAction> planRoute(AgentPosition current, ISet <Room> goals, ISet <Room> allowed)
        {
            // Every square represent 4 possible positions for the agent, it could
            // be in different orientations. For every square in allowed and goals
            // sets we add 4 squares.
            ISet <AgentPosition> allowedPositions = CollectionFactory.CreateSet <AgentPosition>();

            foreach (Room allowedRoom in allowed)
            {
                int x = allowedRoom.getX();
                int y = allowedRoom.getY();

                allowedPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_WEST));
                allowedPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_EAST));
                allowedPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_NORTH));
                allowedPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_SOUTH));
            }
            ISet <AgentPosition> goalPositions = CollectionFactory.CreateSet <AgentPosition>();

            foreach (Room goalRoom in goals)
            {
                int x = goalRoom.getX();
                int y = goalRoom.getY();

                goalPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_WEST));
                goalPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_EAST));
                goalPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_NORTH));
                goalPositions.Add(new AgentPosition(x, y, AgentPosition.Orientation.FACING_SOUTH));
            }

            WumpusCave cave = new WumpusCave(kb.getCaveXDimension(), kb.getCaveYDimension(), allowedPositions);

            GoalTest <AgentPosition> goalTest = goalPositions.Contains;

            IProblem <AgentPosition, IAction> problem = new GeneralProblem <AgentPosition, IAction>(current,
                                                                                                    WumpusFunctionFunctions.createActionsFunction(cave),
                                                                                                    WumpusFunctionFunctions.createResultFunction(), goalTest);

            IToDoubleFunction <Node <AgentPosition, IAction> > h = new ManhattanHeuristicFunction(goals);

            ISearchForActions <AgentPosition, IAction> search = new AStarSearch <AgentPosition, IAction>(
                new GraphSearch <AgentPosition, IAction>(), h);
            SearchAgent <AgentPosition, IAction> agent;
            ICollection <IAction> actions = null;

            try
            {
                agent   = new SearchAgent <AgentPosition, IAction>(problem, search);
                actions = agent.getActions();
                // Search agent can return a NoOp if already at goal,
                // in the context of this agent we will just return
                // no actions.
                if (actions.Size() == 1 && actions.Get(0).IsNoOp())
                {
                    actions = CollectionFactory.CreateQueue <IAction>();
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(actions);
        }