Search in sources :

Example 1 with LRTAStarAgent

use of aima.core.search.online.LRTAStarAgent 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 2 with LRTAStarAgent

use of aima.core.search.online.LRTAStarAgent in project aima-java by aimacode.

the class LRTAStarAgentTest method testNoPath.

@Test
public void testNoPath() {
    MapEnvironment me = new MapEnvironment(aMap);
    OnlineSearchProblem<String, MoveToAction> problem = new GeneralProblem<>(null, MapFunctions.createActionsFunction(aMap), null, GoalTest.isEqual("G"), MapFunctions.createDistanceStepCostFunction(aMap));
    LRTAStarAgent<String, MoveToAction> agent = new LRTAStarAgent<>(problem, MapFunctions.createPerceptToStateFunction(), h);
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    // Note: Will search forever if no path is possible,
    // Therefore restrict the number of steps to something
    // reasonablbe, against which to test.
    me.step(14);
    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==moveTo, location==E]->", 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 3 with LRTAStarAgent

use of aima.core.search.online.LRTAStarAgent in project aima-java by aimacode.

the class LRTAStarAgentTest 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));
    LRTAStarAgent<String, MoveToAction> agent = new LRTAStarAgent<>(problem, MapFunctions.createPerceptToStateFunction(), h);
    me.addAgent(agent, "A");
    me.addEnvironmentView(new TestEnvironmentView());
    me.stepUntilDone();
    Assert.assertEquals("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 4 with LRTAStarAgent

use of aima.core.search.online.LRTAStarAgent in project aima-java by aimacode.

the class OsmAgentController method initAgents.

/** Creates new agents and adds them to the current environment. */
protected void initAgents(MessageLogger logger) {
    List<MapNode> markers = map.getOsmMap().getMarkers();
    if (markers.size() < 2) {
        logger.log("Error: Please set two markers with mouse-left.");
        return;
    }
    String[] locs = new String[markers.size()];
    for (int i = 0; i < markers.size(); i++) {
        MapNode node = markers.get(i);
        Point2D pt = new Point2D(node.getLon(), node.getLat());
        locs[i] = map.getNearestLocation(pt);
    }
    MapAgentFrame.SelectionState state = frame.getSelection();
    heuristic = createHeuristic(state.getIndex(MapAgentFrame.HEURISTIC_SEL), locs[1]);
    search = SearchFactory.getInstance().createSearch(state.getIndex(MapAgentFrame.SEARCH_SEL), state.getIndex(MapAgentFrame.Q_SEARCH_IMPL_SEL), heuristic);
    Agent agent = null;
    switch(state.getIndex(MapAgentFrame.AGENT_SEL)) {
        case 0:
            agent = new SimpleMapAgent(map, env, search, new String[] { locs[1] });
            break;
        case 1:
            Problem<String, MoveToAction> p = new BidirectionalMapProblem(map, null, locs[1]);
            OnlineSearchProblem<String, MoveToAction> osp = new GeneralProblem<>(null, p::getActions, null, p::testGoal, p::getStepCosts);
            agent = new LRTAStarAgent<>(osp, MapFunctions.createPerceptToStateFunction(), s -> heuristic.applyAsDouble(new Node<>(s)));
            break;
    }
    env.addAgent(agent, locs[0]);
}
Also used : DecimalFormat(java.text.DecimalFormat) MessageLogger(aima.gui.swing.framework.MessageLogger) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) MapAdapter(aimax.osm.routing.MapAdapter) SearchForActions(aima.core.search.framework.SearchForActions) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame) ArrayList(java.util.ArrayList) Point2D(aima.core.util.math.geom.shapes.Point2D) AgentAppController(aima.gui.swing.framework.AgentAppController) List(java.util.List) Node(aima.core.search.framework.Node) OnlineSearchProblem(aima.core.search.framework.problem.OnlineSearchProblem) MapWayAttFilter(aimax.osm.data.MapWayAttFilter) ToDoubleFunction(java.util.function.ToDoubleFunction) MapNode(aimax.osm.data.entities.MapNode) Agent(aima.core.agent.Agent) SimulationThread(aima.gui.swing.framework.SimulationThread) aima.core.environment.map(aima.core.environment.map) Problem(aima.core.search.framework.problem.Problem) SearchFactory(aima.gui.util.SearchFactory) LRTAStarAgent(aima.core.search.online.LRTAStarAgent) Agent(aima.core.agent.Agent) MapNode(aimax.osm.data.entities.MapNode) aima.core.environment.map(aima.core.environment.map) Point2D(aima.core.util.math.geom.shapes.Point2D) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) MapAgentFrame(aima.gui.swing.applications.agent.map.MapAgentFrame)

Aggregations

GeneralProblem (aima.core.search.framework.problem.GeneralProblem)4 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)4 MapEnvironment (aima.core.environment.map.MapEnvironment)3 MoveToAction (aima.core.environment.map.MoveToAction)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 Test (org.junit.Test)3 Agent (aima.core.agent.Agent)1 aima.core.environment.map (aima.core.environment.map)1 Node (aima.core.search.framework.Node)1 SearchForActions (aima.core.search.framework.SearchForActions)1 OnlineSearchProblem (aima.core.search.framework.problem.OnlineSearchProblem)1 Problem (aima.core.search.framework.problem.Problem)1 Point2D (aima.core.util.math.geom.shapes.Point2D)1 MapAgentFrame (aima.gui.swing.applications.agent.map.MapAgentFrame)1 AgentAppController (aima.gui.swing.framework.AgentAppController)1 MessageLogger (aima.gui.swing.framework.MessageLogger)1 SimulationThread (aima.gui.swing.framework.SimulationThread)1 SearchFactory (aima.gui.util.SearchFactory)1 MapWayAttFilter (aimax.osm.data.MapWayAttFilter)1 MapNode (aimax.osm.data.entities.MapNode)1