コード例 #1
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));
        }
コード例 #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"));
        }
コード例 #3
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"]);
        }