Search in sources :

Example 6 with Map

use of aima.core.environment.map.Map in project aima-java by aimacode.

the class GreedyBestFirstSearchTest method testAIMA3eFigure3_23_using_GraphSearch.

@Test
public void testAIMA3eFigure3_23_using_GraphSearch() 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 GraphSearch<>(), 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("4", agent.getInstrumentation().getProperty("queueSize"));
    Assert.assertEquals("5", 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 7 with Map

use of aima.core.environment.map.Map 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 8 with Map

use of aima.core.environment.map.Map in project aima-java by aimacode.

the class ExtendedMapAgentView method paintMap.

/**
	 * Represents roads by lines and locations by name-labeled points.
	 */
protected void paintMap(java.awt.Graphics2D g2) {
    Map envMap = getMapEnv().getMap();
    Map aMap = (agentMap != null) ? agentMap : envMap;
    List<Roadblock> roadblocks = new ArrayList<Roadblock>();
    for (String l1 : envMap.getLocations()) {
        Point2D pt1 = envMap.getPosition(l1);
        List<String> linkedLocs = envMap.getPossibleNextLocations(l1);
        for (String l2 : aMap.getPossibleNextLocations(l1)) if (!linkedLocs.contains(l2))
            linkedLocs.add(l2);
        for (String l2 : linkedLocs) {
            Point2D pt2 = envMap.getPosition(l2);
            g2.setColor(Color.lightGray);
            g2.drawLine(x(pt1), y(pt1), x(pt2), y(pt2));
            boolean blockedInEnv = !envMap.getPossibleNextLocations(l2).contains(l1);
            boolean blockedInAgent = !aMap.getPossibleNextLocations(l2).contains(l1);
            roadblocks.add(new Roadblock(pt1, pt2, blockedInEnv, blockedInAgent));
            if (blockedInEnv && blockedInAgent) {
                boolean blockedInEnvOtherDir = !envMap.getPossibleNextLocations(l1).contains(l2);
                boolean blockedInAgentOtherDir = !aMap.getPossibleNextLocations(l1).contains(l2);
                roadblocks.add(new Roadblock(pt2, pt1, blockedInEnvOtherDir, blockedInAgentOtherDir));
            }
        }
    }
    for (Roadblock block : roadblocks) paintRoadblock(g2, block);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) ArrayList(java.util.ArrayList) Map(aima.core.environment.map.Map)

Example 9 with Map

use of aima.core.environment.map.Map in project aima-java by aimacode.

the class MapAgentView method adjustTransformation.

/**
	 * Adjusts offsets and scale so that the whole map fits on the view without
	 * scrolling.
	 */
private void adjustTransformation() {
    Map map = getMapEnv().getMap();
    List<String> locs = map.getLocations();
    // adjust coordinates relative to the left upper corner of the graph
    // area
    double minX = Double.POSITIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (String loc : locs) {
        Point2D xy = map.getPosition(loc);
        if (xy.getX() < minX)
            minX = xy.getX();
        if (xy.getY() < minY)
            minY = xy.getY();
        if (xy.getX() > maxX)
            maxX = xy.getX();
        if (xy.getY() > maxY)
            maxY = xy.getY();
    }
    this.setBorder(20, 20, 20, 100);
    adjustTransformation(minX, minY, maxX, maxY);
}
Also used : Point2D(aima.core.util.math.geom.shapes.Point2D) Map(aima.core.environment.map.Map)

Example 10 with Map

use of aima.core.environment.map.Map in project aima-java by aimacode.

the class MapAgentView method paintComponent.

/**
	 * Clears the panel, displays the map, the current agent locations, and the
	 * track of the first agent.
	 */
@Override
public void paintComponent(java.awt.Graphics g) {
    super.paintComponent(g);
    if (env != null) {
        Map map = getMapEnv().getMap();
        if (!map.getLocations().isEmpty()) {
            // safety first!
            updateTracks();
            java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
            adjustTransformation();
            paintMap(g2);
            for (Agent a : env.getAgents()) paintTrack(g2, a);
            for (String loc : map.getLocations()) paintLoc(g2, loc);
        }
    }
}
Also used : Agent(aima.core.agent.Agent) Map(aima.core.environment.map.Map)

Aggregations

Map (aima.core.environment.map.Map)11 Point2D (aima.core.util.math.geom.shapes.Point2D)7 MoveToAction (aima.core.environment.map.MoveToAction)3 SimplifiedRoadMapOfPartOfRomania (aima.core.environment.map.SimplifiedRoadMapOfPartOfRomania)3 SearchAgent (aima.core.search.framework.SearchAgent)3 GeneralProblem (aima.core.search.framework.problem.GeneralProblem)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Agent (aima.core.agent.Agent)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2 Node (aima.core.search.framework.Node)1 UniformCostSearch (aima.core.search.uninformed.UniformCostSearch)1 Circle (javafx.scene.shape.Circle)1 Line (javafx.scene.shape.Line)1 Shape (javafx.scene.shape.Shape)1 Font (javafx.scene.text.Font)1 Text (javafx.scene.text.Text)1