Search in sources :

Example 16 with GeneralProblem

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

the class GreedyBestFirstSearchTest method testAIMA3eFigure3_23.

@Test
public void testAIMA3eFigure3_23() throws Exception {
    Map romaniaMap = new SimplifiedRoadMapOfPartOfRomania();
    Problem<String, MoveToAction> problem = new GeneralProblem<>(SimplifiedRoadMapOfPartOfRomania.ARAD, MapFunctions.createActionsFunction(romaniaMap), MapFunctions.createResultFunction(), GoalTest.isEqual(SimplifiedRoadMapOfPartOfRomania.BUCHAREST), MapFunctions.createDistanceStepCostFunction(romaniaMap));
    SearchForActions<String, MoveToAction> search = new GreedyBestFirstSearch<>(new TreeSearch<>(), MapFunctions.createSLDHeuristicFunction(SimplifiedRoadMapOfPartOfRomania.BUCHAREST, romaniaMap));
    SearchAgent<String, MoveToAction> agent = new SearchAgent<>(problem, search);
    Assert.assertEquals("[Action[name==moveTo, location==Sibiu], Action[name==moveTo, location==Fagaras], Action[name==moveTo, location==Bucharest]]", agent.getActions().toString());
    Assert.assertEquals(3, agent.getActions().size());
    Assert.assertEquals("3", agent.getInstrumentation().getProperty("nodesExpanded"));
    Assert.assertEquals("6", agent.getInstrumentation().getProperty("queueSize"));
    Assert.assertEquals("7", agent.getInstrumentation().getProperty("maxQueueSize"));
}
Also used : SimplifiedRoadMapOfPartOfRomania(aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania) SearchAgent(aima.core.search.framework.SearchAgent) GreedyBestFirstSearch(aima.core.search.informed.GreedyBestFirstSearch) 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)

Example 17 with GeneralProblem

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

the class BreadthFirstSearchTest method testBreadthFirstSuccesfulSearch.

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

Example 18 with GeneralProblem

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

the class BreadthFirstSearchTest method testBreadthFirstUnSuccesfulSearch.

@Test
public void testBreadthFirstUnSuccesfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new BreadthFirstSearch<>(new TreeSearch<>());
    SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
    List<Action> actions = agent.getActions();
    Assert.assertEquals(0, actions.size());
    Assert.assertEquals("6", agent.getInstrumentation().getProperty("nodesExpanded"));
    Assert.assertEquals("0", agent.getInstrumentation().getProperty("pathCost"));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) Action(aima.core.agent.Action) QueenAction(aima.core.environment.nqueens.QueenAction) BreadthFirstSearch(aima.core.search.uninformed.BreadthFirstSearch) QueenAction(aima.core.environment.nqueens.QueenAction) SearchAgent(aima.core.search.framework.SearchAgent) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Example 19 with GeneralProblem

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

the class DepthFirstSearchTest method testDepthFirstUnSuccessfulSearch.

@Test
public void testDepthFirstUnSuccessfulSearch() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(3), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    SearchForActions<NQueensBoard, QueenAction> search = new DepthFirstSearch<>(new GraphSearch<>());
    SearchAgent<NQueensBoard, QueenAction> agent = new SearchAgent<>(problem, search);
    List<Action> actions = agent.getActions();
    Assert.assertEquals(0, actions.size());
    Assert.assertEquals("6", agent.getInstrumentation().getProperty("nodesExpanded"));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) Action(aima.core.agent.Action) QueenAction(aima.core.environment.nqueens.QueenAction) QueenAction(aima.core.environment.nqueens.QueenAction) SearchAgent(aima.core.search.framework.SearchAgent) DepthFirstSearch(aima.core.search.uninformed.DepthFirstSearch) NQueensBoard(aima.core.environment.nqueens.NQueensBoard) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) Test(org.junit.Test)

Example 20 with GeneralProblem

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

the class DepthLimitedSearchTest method testCutOff.

@Test
public void testCutOff() throws Exception {
    Problem<NQueensBoard, QueenAction> problem = new GeneralProblem<>(new NQueensBoard(8), NQueensFunctions::getIFActions, NQueensFunctions::getResult, NQueensFunctions::testGoal);
    DepthLimitedSearch<NQueensBoard, QueenAction> search = new DepthLimitedSearch<>(1);
    Node<NQueensBoard, QueenAction> result = search.findNode(problem);
    Assert.assertEquals(true, search.isCutoffNode(result));
}
Also used : NQueensFunctions(aima.core.environment.nqueens.NQueensFunctions) QueenAction(aima.core.environment.nqueens.QueenAction) DepthLimitedSearch(aima.core.search.uninformed.DepthLimitedSearch) 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