Beispiel #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"]);
        }
Beispiel #2
0
        static void RunAllLevels()
        {
            string[] levels = new string[] {
                //"Levels/LA 1.xml","Levels/LA 2.xml","Levels/LA 3.xml","Levels/LA 4.xml",
                //"Levels/LA 6.xml","Levels/LA 7.xml",
                //"Levels/LA 8.xml","Levels/LoZ 1.xml",
                //"Levels/LoZ 2.xml","Levels/LoZ 3.xml","Levels/LoZ 4.xml","Levels/LoZ 5.xml",
                //"Levels/LoZ 7.xml","Levels/LoZ 8.xml","Levels/LoZ 9.xml","Levels/LoZ2 1.xml",
                //"Levels/LoZ2 2.xml","Levels/LoZ2 4.xml","Levels/LoZ2 5.xml","Levels/LoZ2 6.xml",
                //"Levels/LoZ2 7.xml","Levels/LoZ2 8.xml",
                //"Levels/LoZ2 9.xml",
                "Levels/LttP 1.xml",
                //"Levels/LttP 10.xml",
                //"Levels/LttP 11.xml",
                //"Levels/LttP 2.xml","Levels/LttP 3.xml",
                //"Levels/LttP 4.xml","Levels/LttP 5.xml","Levels/LttP 6.xml","Levels/LttP 7.xml",
                //"Levels/LttP 8.xml","Levels/LttP 9.xml",
            };

            foreach (var level in levels)
            {
                Console.WriteLine(level);
                Dungeon     dungeon = new Dungeon(level);
                SearchAgent path    = dungeon.getOptimalPath(level.Contains("LttP"));
                Console.WriteLine(path.pathToString());
                dungeon.UpdateRooms(path);
                string output = level;
                output = Regex.Replace(output, @"Levels", "Summaries");
                output = Regex.Replace(output, " ", "");
                dungeon.WriteStats(output, path);
            }
        }
Beispiel #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"));
        }
Beispiel #4
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));
        }
Beispiel #5
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));
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var environment = new PuzzleEnvironment <int>(GetEightPuzzleBoard());

            var bfs = new BreadthFirstStrategy <ProblemState <int>, ProblemAction>();

            var ucs = new UniformCostStrategy <ProblemState <int>, ProblemAction>();

            var ucs2 = new UniformCostStrategy2 <ProblemState <int>, ProblemAction>();

            var dfs = new DepthFirstStrategy <ProblemState <int>, ProblemAction>();

            var dls = new DepthLimitedStrategy <ProblemState <int>, ProblemAction>(10);

            var ids = new IterativeDeepeningStrategy <ProblemState <int>, ProblemAction>();

            var greedy = new GreedyBestFirstStrategy <ProblemState <int>, ProblemAction>(
                HeuristicFunctions.StraightLineDistance);

            var astar = new AStarStrategy <ProblemState <int>, ProblemAction>(
                HeuristicFunctions.StraightLineDistance);

            var agent = new SearchAgent <int>(astar);

            RunAgent(environment, agent);
        }
	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.");
		}
	}
    //幅優先探索 basePosition:始点座標 judgePosition:通行可能条件 dMOFunction:各座標に対する処理
    public void DetureMatrixOperate(Vector2Int basePosition, JudgePosition judgePosition, DMOFunction dMOFunction)
    {
        int[,] searchMatrix = new int[mapRange.x, mapRange.y];
        Queue <SearchAgent> searchAgent = new Queue <SearchAgent>();

        searchAgent.Enqueue(new SearchAgent()
        {
            position = basePosition, distance = 1
        });
        searchMatrix[basePosition.x, basePosition.y] = 1;
        while (0 < searchAgent.Count)
        {
            SearchAgent current = searchAgent.Dequeue();
            NextPoint(current.position, (x, y) =>
            {
                if (searchMatrix[x, y] == 0 && judgePosition(new Vector2Int(x, y)) == true)
                {
                    searchAgent.Enqueue(new SearchAgent()
                    {
                        position = new Vector2Int(x, y), distance = current.distance + 1
                    });
                    searchMatrix[x, y] = current.distance + 1;
                }
            });
        }
        MatrixOperate((xcount, ycount) =>
        {
            dMOFunction(xcount, ycount, searchMatrix[xcount, ycount]);
        });
    }
Beispiel #9
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;
            }
        }
Beispiel #10
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");
		}
	}
Beispiel #11
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"));
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            JiraApi.Instance.JiraAuthorize();

            using (SearchAgent agent = new SearchAgent(JiraApi.Instance))
            {
                var data = agent.Search("project = WEB AND issuetype = Bug AND status = \"To Do\" AND \"Epic Link\" = WEB-3826 ORDER BY priority DESC");
            }
        }
Beispiel #13
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());
        }
Beispiel #14
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());
        }
Beispiel #15
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);
        }
Beispiel #16
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());
        }
Beispiel #17
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());
        }
Beispiel #18
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());
        }
Beispiel #19
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());
        }
Beispiel #20
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());
        }
Beispiel #21
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());
        }
Beispiel #22
0
        public Dictionary <string, string> PrintInstrumentation(SearchAgent agent)
        {
            var      toReturn        = new Dictionary <String, String>();
            var      instrumentation = agent.getInstrumentation();
            Iterator terator         = instrumentation.keySet().iterator();

            while (terator.hasNext())
            {
                string key      = (string)terator.next();
                string property = instrumentation.getProperty(key);
                toReturn[key] = property;
            }

            return(toReturn);
        }
Beispiel #23
0
    private void OnTriggerEnter(Collider other)
    {
        SearchAgent searchAgent = other.GetComponent <SearchAgent>();

        if (searchAgent && (searchAgent.waypoint == this || searchAgent.waypoint == null))
        {
            searchAgent.waypoint = m_nextWaypoint;
        }
        StateAgent stateAgent = other.GetComponent <StateAgent>();

        if (stateAgent && (stateAgent.waypoint == this || stateAgent.waypoint == null))
        {
            stateAgent.waypoint = m_nextWaypoint;
        }
    }
Beispiel #24
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;
     }
 }
 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;
     }
 }
Beispiel #26
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");
		}
	}
Beispiel #28
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;
     } 
 }
Beispiel #29
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;
     }
 }
Beispiel #30
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"));
        }
Beispiel #31
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;
     }
 }
Beispiel #32
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;
     }
 }
Beispiel #33
0
    private List<Vector2> GetRouteTo(Vector3 target)
    {
        List<Vector2> ret = new List<Vector2>();
        //Create the problem and the agent
        Problem prob = new Problem(heroList.First().Position, target, matrix, guiManagerInstance.GetComponent<GuiManager>());
        SearchAgent agent = new SearchAgent(prob);
        //Get the selected 
        Node goalNode = null;
        switch (alg)
        {
            case AlgorithmsEnum.DFS:
                goalNode = agent.DFGS();
                break;
            case AlgorithmsEnum.BFS:
                goalNode = agent.BFGS();
                break;
            case AlgorithmsEnum.UCS:
                goalNode = agent.UCGS();
                break;
            case AlgorithmsEnum.AStar:
                goalNode = agent.AstarGS();
                break;
            default:
               goalNode = agent.DFGS();
                break;
        }
        var nodeRoute = goalNode.Path();
        nodeRoute.Reverse();
        foreach (var node in nodeRoute)
        {
            if (node.Action.HasValue)
            { 
                ret.Add(node.Action.Value);
                var pos = node.State.GetPosition();
                guiManagerInstance.GetComponent<GuiManager>().MarkMoveCell(new Vector3(pos.x, pos.y));
            }
        }

        return ret;
    }
Beispiel #34
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);
        }