Search in sources :

Example 6 with GeneralProblem

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

the class LRTAStarAgentTest method testNormalSearch.

@Test
public void testNormalSearch() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("F"), MapFunctions.createDistanceStepCostFunction(aMap));
    LRTAStarAgent<String, MoveToAction> agent = new LRTAStarAgent<>(problem, MapFunctions.createPerceptToStateFunction(), h);
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==C]->Action[name==moveTo, location==B]->Action[name==moveTo, location==C]->Action[name==moveTo, location==D]->Action[name==moveTo, location==C]->Action[name==moveTo, location==D]->Action[name==moveTo, location==E]->Action[name==moveTo, location==D]->Action[name==moveTo, location==E]->Action[name==moveTo, location==F]->Action[name==NoOp]->", envChanges.toString());
}
Also used : MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MoveToAction(aima.core.environment.map.MoveToAction) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 7 with GeneralProblem

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

the class OnlineDFSAgentTest method testNormalSearch.

@Test
public void testNormalSearch() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("G"), MapFunctions.createDistanceStepCostFunction(aMap));
    OnlineDFSAgent<String, MoveToAction> agent = new OnlineDFSAgent<>(problem, MapFunctions.createPerceptToStateFunction());
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==moveTo, location==B]->Action[name==moveTo, location==A]->Action[name==moveTo, location==C]->Action[name==moveTo, location==A]->Action[name==moveTo, location==C]->Action[name==moveTo, location==A]->Action[name==moveTo, location==B]->Action[name==moveTo, location==D]->Action[name==moveTo, location==B]->Action[name==moveTo, location==E]->Action[name==moveTo, location==B]->Action[name==moveTo, location==E]->Action[name==moveTo, location==B]->Action[name==moveTo, location==D]->Action[name==moveTo, location==F]->Action[name==moveTo, location==D]->Action[name==moveTo, location==G]->Action[name==NoOp]->", envChanges.toString());
}
Also used : OnlineDFSAgent(aima.core.search.online.OnlineDFSAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MoveToAction(aima.core.environment.map.MoveToAction) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 8 with GeneralProblem

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

the class OnlineDFSAgentTest method testAlreadyAtGoal.

@Test
public void testAlreadyAtGoal() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("A"), MapFunctions.createDistanceStepCostFunction(aMap));
    OnlineDFSAgent<String, MoveToAction> agent = new OnlineDFSAgent<>(problem, MapFunctions.createPerceptToStateFunction());
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==NoOp]->", envChanges.toString());
}
Also used : OnlineDFSAgent(aima.core.search.online.OnlineDFSAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MoveToAction(aima.core.environment.map.MoveToAction) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 9 with GeneralProblem

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

the class OnlineDFSAgentTest method testAIMA3eFig4_19.

@Test
public void testAIMA3eFig4_19() {
    aMap = new ExtendableMap();
    aMap.addBidirectionalLink("1,1", "1,2", 1.0);
    aMap.addBidirectionalLink("1,1", "2,1", 1.0);
    aMap.addBidirectionalLink("2,1", "3,1", 1.0);
    aMap.addBidirectionalLink("2,1", "2,2", 1.0);
    aMap.addBidirectionalLink("3,1", "3,2", 1.0);
    aMap.addBidirectionalLink("2,2", "2,3", 1.0);
    aMap.addBidirectionalLink("3,2", "3,3", 1.0);
    aMap.addBidirectionalLink("2,3", "1,3", 1.0);
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("3,3"), MapFunctions.createDistanceStepCostFunction(aMap));
    OnlineDFSAgent<String, MoveToAction> agent = new OnlineDFSAgent<>(problem, MapFunctions.createPerceptToStateFunction());
    me.addAgent(agent, "1,1");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("Action[name==moveTo, location==1,2]->Action[name==moveTo, location==1,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==1,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==2,2]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==2,1]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==3,2]->Action[name==moveTo, location==3,1]->Action[name==moveTo, location==3,2]->Action[name==moveTo, location==3,3]->Action[name==NoOp]->", envChanges.toString());
}
Also used : OnlineDFSAgent(aima.core.search.online.OnlineDFSAgent) MapEnvironment(aima.core.environment.map.MapEnvironment) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) ExtendableMap(aima.core.environment.map.ExtendableMap) MoveToAction(aima.core.environment.map.MoveToAction) GoalTest(aima.core.search.framework.problem.GoalTest) Test(org.junit.Test)

Example 10 with GeneralProblem

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

the class DepthFirstSearchTest method testDepthFirstSuccesfulSearch.

@Test
public void testDepthFirstSuccesfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new DepthFirstSearch<>(new GraphSearch<>());
    List<QueenAction> actions = search.findActions(problem);
    assertCorrectPlacement(actions);
    Assert.assertEquals("113", search.getMetrics().get("nodesExpanded"));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) QueenAction(aima.core.environment.nqueens.QueenAction) DepthFirstSearch(aima.core.search.uninformed.DepthFirstSearch) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Aggregations

GeneralProblem (aima.core.search.framework.problem.GeneralProblem)23 Test (org.junit.Test)20 GoalTest (aima.core.search.framework.problem.GoalTest)12 NQueensBoard (aima.core.environment.nqueens.NQueensBoard)11 NQueensFunctions (aima.core.environment.nqueens.NQueensFunctions)11 QueenAction (aima.core.environment.nqueens.QueenAction)11 MoveToAction (aima.core.environment.map.MoveToAction)10 SearchAgent (aima.core.search.framework.SearchAgent)8 MapEnvironment (aima.core.environment.map.MapEnvironment)7 Action (aima.core.agent.Action)6 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)4 OnlineDFSAgent (aima.core.search.online.OnlineDFSAgent)4 Map (aima.core.environment.map.Map)3 SimplifiedRoadMapOfPartOfRomania (aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania)3 DepthLimitedSearch (aima.core.search.uninformed.DepthLimitedSearch)3 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)3 ExtendableMap (aima.core.environment.map.ExtendableMap)2 Node (aima.core.search.framework.Node)2 Problem (aima.core.search.framework.problem.Problem)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2