-
Notifications
You must be signed in to change notification settings - Fork 797
/
MapAgentDemo.java
44 lines (38 loc) · 1.68 KB
/
MapAgentDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package aima.gui.demo.agent;
import aima.core.agent.Agent;
import aima.core.agent.EnvironmentListener;
import aima.core.agent.impl.DynamicPercept;
import aima.core.agent.impl.SimpleEnvironmentView;
import aima.core.environment.map.*;
import aima.core.search.framework.SearchForActions;
import aima.core.search.framework.qsearch.GraphSearch;
import aima.core.search.framework.qsearch.TreeSearch;
import aima.core.search.informed.AStarSearch;
import aima.core.search.uninformed.DepthFirstSearch;
import aima.core.search.uninformed.UniformCostSearch;
/**
* Demonstrates how different kinds of search algorithms perform in a route finding scenario.
* @author Ruediger Lunde
*/
public class MapAgentDemo {
public static void main(String[] args) {
ExtendableMap map = new ExtendableMap();
SimplifiedRoadMapOfRomania.initMap(map);
MapEnvironment env = new MapEnvironment(map);
EnvironmentListener<Object, Object> envView = new SimpleEnvironmentView();
env.addEnvironmentListener(envView);
String agentLoc = SimplifiedRoadMapOfRomania.ARAD;
String destination = SimplifiedRoadMapOfRomania.BUCHAREST;
SearchForActions<String, MoveToAction> search;
// search = new DepthFirstSearch<>(new GraphSearch<>());
// search = new UniformCostSearch<>(new TreeSearch<>());
// search = new UniformCostSearch<>(new GraphSearch<>());
search = new AStarSearch<>(new GraphSearch<>(), MapFunctions.createSLDHeuristicFunction(destination, map));
Agent<DynamicPercept, MoveToAction> agent;
agent = new SimpleMapAgent(map, search, destination);
// agent = new MapAgent(map, search, destination);
env.addAgent(agent, agentLoc);
env.stepUntilDone();
envView.notify(search.getMetrics().toString());
}
}