Search in sources :

Example 1 with GoalTest

use of aima.core.search.framework.problem.GoalTest in project aima-java by aimacode.

the class SolutionTesterTest method testMultiGoalProblem.

@Test
public void testMultiGoalProblem() throws Exception {
    Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
    Problem<String, MoveToAction> problem = new GeneralProblem<String, MoveToAction>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.<String>isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST).or(GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.HIRSOVA)), MapFunctions.createDistanceStepCostFunction(romaniaMap)) {

        @Override
        public boolean testSolution(Node<String, MoveToAction> node) {
            return testGoal(node.getState()) && node.getPathCost() > 550;
        // accept paths to goal only if their costs are above 550
        }
    };
    SearchForActions<String, MoveToAction> search = new UniformCostSearch<>(new GraphSearch<>());
    SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
    Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==RimnicuVilcea], Action[name==moveTo, location==Pitesti], Action[name==moveTo, location==Bucharest], Action[name==moveTo, location==Urziceni], Action[name==moveTo, location==Hirsova]]", agent.getActions().toString());
    Assert.assertEquals(6, agent.getActions().size());
    Assert.assertEquals("15", agent.getInstrumentation().getProperty("nodesExpanded"));
    Assert.assertEquals("1", agent.getInstrumentation().getProperty("queueSize"));
    Assert.assertEquals("5", agent.getInstrumentation().getProperty("maxQueueSize"));
}
Also used : UniformCostSearch(aima.core.search.uninformed.UniformCostSearch) SimplifiedRoadMapOfPartOfRomania(aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania) SearchAgent(aima.core.search.framework.SearchAgent) Node(aima.core.search.framework.Node) Map(aima.core.environment.map.Map) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Aggregations

Map (aima.core.environment.map.Map)1 MoveToAction (aima.core.environment.map.MoveToAction)1 SimplifiedRoadMapOfPartOfRomania (aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania)1 Node (aima.core.search.framework.Node)1 SearchAgent (aima.core.search.framework.SearchAgent)1 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)1 GoalTest (aima.core.search.framework.problem.GoalTest)1 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)1 Test (org.junit.Test)1