Skip to content

Commit cb36f7a

Browse files
Ruediger.LundeRuediger.Lunde
authored andcommitted
Class Map replaced by MapWithSLD
1 parent 110bcf8 commit cb36f7a

17 files changed

Lines changed: 442 additions & 403 deletions

src/aima/gui/applications/search/map/RoutePlanningAgentAppDemo.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import aima.gui.framework.SimpleAgentAppDemo;
99
import aima.search.framework.SearchFactory;
1010
import aima.search.map.AdaptableHeuristicFunction;
11+
import aima.search.map.Map;
1112
import aima.search.map.MapAgent;
1213
import aima.search.map.MapEnvironment;
13-
import aima.search.map.MapWithSLD;
1414
import aima.search.map.Scenario;
1515
import aima.search.map.SimplifiedRoadMapOfAustralia;
16-
import aima.search.map.SimplifiedRoadMapOfRomania;
16+
import aima.search.map.SimplifiedRoadMapOfPartOfRomania;
1717

1818
/**
1919
* Demo example of a route planning agent application with GUI. The main method
@@ -113,21 +113,21 @@ protected static class RoutePlanningAgentController extends
113113
*/
114114
@Override
115115
protected void selectScenarioAndDest(int scenarioIdx, int destIdx) {
116-
MapWithSLD map = new MapWithSLD();
116+
Map map = new Map();
117117
MapEnvironment env = new MapEnvironment(map);
118118
String agentLoc = null;
119119
switch (scenarioIdx) {
120120
case 0:
121-
SimplifiedRoadMapOfRomania.initMap(map);
122-
agentLoc = SimplifiedRoadMapOfRomania.ARAD;
121+
SimplifiedRoadMapOfPartOfRomania.initMap(map);
122+
agentLoc = SimplifiedRoadMapOfPartOfRomania.ARAD;
123123
break;
124124
case 1:
125-
SimplifiedRoadMapOfRomania.initMap(map);
126-
agentLoc = SimplifiedRoadMapOfRomania.LUGOJ;
125+
SimplifiedRoadMapOfPartOfRomania.initMap(map);
126+
agentLoc = SimplifiedRoadMapOfPartOfRomania.LUGOJ;
127127
break;
128128
case 2:
129-
SimplifiedRoadMapOfRomania.initMap(map);
130-
agentLoc = SimplifiedRoadMapOfRomania.FAGARAS;
129+
SimplifiedRoadMapOfPartOfRomania.initMap(map);
130+
agentLoc = SimplifiedRoadMapOfPartOfRomania.FAGARAS;
131131
break;
132132
case 3:
133133
SimplifiedRoadMapOfAustralia.initMap(map);
@@ -144,13 +144,14 @@ protected void selectScenarioAndDest(int scenarioIdx, int destIdx) {
144144
if (scenarioIdx < 3) {
145145
switch (destIdx) {
146146
case 0:
147-
destinations.add(SimplifiedRoadMapOfRomania.BUCHAREST);
147+
destinations
148+
.add(SimplifiedRoadMapOfPartOfRomania.BUCHAREST);
148149
break;
149150
case 1:
150-
destinations.add(SimplifiedRoadMapOfRomania.EFORIE);
151+
destinations.add(SimplifiedRoadMapOfPartOfRomania.EFORIE);
151152
break;
152153
case 2:
153-
destinations.add(SimplifiedRoadMapOfRomania.NEAMT);
154+
destinations.add(SimplifiedRoadMapOfPartOfRomania.NEAMT);
154155
break;
155156
case 3:
156157
destinations.add(map.randomlyGenerateDestination());

src/aima/search/demos/MapDemo.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import aima.search.framework.TreeSearch;
77
import aima.search.informed.AStarEvaluationFunction;
88
import aima.search.informed.RecursiveBestFirstSearch;
9+
import aima.search.map.Map;
910
import aima.search.map.MapAgent;
1011
import aima.search.map.MapEnvironment;
1112
import aima.search.map.SimplifiedRoadMapOfPartOfRomania;
1213
import aima.search.uninformed.BidirectionalSearch;
1314
import aima.search.uninformed.BreadthFirstSearch;
14-
import aima.search.uninformed.UniformCostSearch;
1515
import aima.search.uninformed.DepthFirstSearch;
1616
import aima.search.uninformed.DepthLimitedSearch;
1717
import aima.search.uninformed.IterativeDeepeningSearch;
18+
import aima.search.uninformed.UniformCostSearch;
1819

1920
/**
2021
* @author Ciaran O'Reilly
@@ -39,8 +40,8 @@ private static void newMapDemo() {
3940
private static void mapWithBreadthFirstSearch() {
4041
System.out.println("\nMapDemo BFS -->");
4142

42-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
43-
.getMapOfRomania());
43+
MapEnvironment me = new MapEnvironment(
44+
new SimplifiedRoadMapOfPartOfRomania());
4445
MapAgent ma = new MapAgent(me,
4546
new BreadthFirstSearch(new GraphSearch()), 2);
4647
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
@@ -54,8 +55,8 @@ private static void mapWithUniformCostSearch() {
5455
// of nodes expanded etc... will more than likely differ
5556
System.out.println("\nMapDemo UCS (using a TreeSearch) -->");
5657

57-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
58-
.getMapOfRomania());
58+
MapEnvironment me = new MapEnvironment(
59+
new SimplifiedRoadMapOfPartOfRomania());
5960
MapAgent ma = new MapAgent(me, new UniformCostSearch(new TreeSearch()),
6061
new String[] { SimplifiedRoadMapOfPartOfRomania.BUCHAREST });
6162
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
@@ -64,8 +65,7 @@ private static void mapWithUniformCostSearch() {
6465

6566
System.out.println("\nMapDemo UCS (using a GraphSearch) -->");
6667

67-
me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
68-
.getMapOfRomania());
68+
me = new MapEnvironment(new SimplifiedRoadMapOfPartOfRomania());
6969
ma = new MapAgent(me, new UniformCostSearch(new GraphSearch()),
7070
new String[] { SimplifiedRoadMapOfPartOfRomania.BUCHAREST });
7171
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
@@ -76,8 +76,8 @@ private static void mapWithUniformCostSearch() {
7676
private static void mapWithDepthFirstSearch() {
7777
System.out.println("\nMapDemo DFS -->");
7878

79-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
80-
.getMapOfRomania());
79+
MapEnvironment me = new MapEnvironment(
80+
new SimplifiedRoadMapOfPartOfRomania());
8181
MapAgent ma = new MapAgent(me, new DepthFirstSearch(new GraphSearch()),
8282
2);
8383
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
@@ -88,8 +88,8 @@ private static void mapWithDepthFirstSearch() {
8888
private static void mapWithRecursiveDLS() {
8989
System.out.println("\nMapDemo recursive DLS -->");
9090

91-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
92-
.getMapOfRomania());
91+
MapEnvironment me = new MapEnvironment(
92+
new SimplifiedRoadMapOfPartOfRomania());
9393
MapAgent ma = new MapAgent(me, new DepthLimitedSearch(8), 2);
9494
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
9595
me.registerView(new BasicEnvironmentView());
@@ -99,8 +99,8 @@ private static void mapWithRecursiveDLS() {
9999
private static void mapWithIterativeDeepeningSearch() {
100100
System.out.println("\nMapDemo Iterative DS -->");
101101

102-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
103-
.getMapOfRomania());
102+
MapEnvironment me = new MapEnvironment(
103+
new SimplifiedRoadMapOfPartOfRomania());
104104
MapAgent ma = new MapAgent(me, new IterativeDeepeningSearch(), 2);
105105
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ARAD);
106106
me.registerView(new BasicEnvironmentView());
@@ -110,8 +110,8 @@ private static void mapWithIterativeDeepeningSearch() {
110110
private static void mapWithBidrectionalSearch() {
111111
System.out.println("\nMapDemo Bidirectional Search -->");
112112

113-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
114-
.getMapOfRomania());
113+
MapEnvironment me = new MapEnvironment(
114+
new SimplifiedRoadMapOfPartOfRomania());
115115
MapAgent ma = new MapAgent(me, new BidirectionalSearch(),
116116
new String[] { SimplifiedRoadMapOfPartOfRomania.BUCHAREST });
117117
me.addAgent(ma, SimplifiedRoadMapOfPartOfRomania.ORADEA);
@@ -122,17 +122,17 @@ private static void mapWithBidrectionalSearch() {
122122
private static void mapWithRecursiveBestFirstSearch() {
123123
System.out.println("\nMapDemo RecursiveBestFirstSearch Search -->");
124124

125-
MapEnvironment me = new MapEnvironment(SimplifiedRoadMapOfPartOfRomania
126-
.getMapOfRomania());
125+
MapEnvironment me = new MapEnvironment(
126+
new SimplifiedRoadMapOfPartOfRomania());
127127
MapAgent ma = new MapAgent(me, new RecursiveBestFirstSearch(
128128
new AStarEvaluationFunction()),
129129
new String[] { SimplifiedRoadMapOfPartOfRomania.BUCHAREST });
130130
ma.setHeuristicFunction(new HeuristicFunction() {
131+
Map map = new SimplifiedRoadMapOfPartOfRomania();
132+
131133
public double getHeuristicValue(Object state) {
132-
return SimplifiedRoadMapOfPartOfRomania
133-
.getStraightLineDistancesToBucharest().getDistance(
134-
(String) state,
135-
SimplifiedRoadMapOfPartOfRomania.BUCHAREST);
134+
return map.getStraightLineDistance((String) state,
135+
SimplifiedRoadMapOfPartOfRomania.BUCHAREST);
136136
}
137137
});
138138

src/aima/search/map/AdaptableHeuristicFunction.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,24 @@
33
import aima.search.framework.HeuristicFunction;
44

55
/**
6-
* This class extends heuristic functions in two ways:
7-
* It maintains a goal and a map to estimate distance to goal for states
8-
* in routing and tour problems, and it provides a method to adapt to
9-
* different goals.
6+
* This class extends heuristic functions in two ways: It maintains a goal and a
7+
* map to estimate distance to goal for states in routing and tour problems, and
8+
* it provides a method to adapt to different goals.
9+
*
1010
* @author R. Lunde
1111
*/
1212
public abstract class AdaptableHeuristicFunction implements HeuristicFunction,
1313
Cloneable {
1414
/** The Current Goal. */
1515
protected Object goal;
1616
/** The map to be used for distance to goal estimates. */
17-
protected MapWithSLD map;
18-
17+
protected Map map;
18+
1919
/**
20-
* Creates a clone and stores goal and map in the
21-
* corresponding attributes. This method MUST be called
22-
* before using the heuristic!
20+
* Creates a clone and stores goal and map in the corresponding attributes.
21+
* This method MUST be called before using the heuristic!
2322
*/
24-
public AdaptableHeuristicFunction getAdaptation(Object goal,
25-
MapWithSLD map) {
23+
public AdaptableHeuristicFunction getAdaptation(Object goal, Map map) {
2624
AdaptableHeuristicFunction result = null;
2725
try {
2826
result = (AdaptableHeuristicFunction) this.clone();
@@ -33,7 +31,7 @@ public AdaptableHeuristicFunction getAdaptation(Object goal,
3331
}
3432
return result;
3533
}
36-
34+
3735
// when subclassing: Don't forget to implement the most important method
3836
// double getHeuristicValue(Object state)
3937
}

0 commit comments

Comments
 (0)