Skip to content

Commit 0befd08

Browse files
executeAction of Environment does not return a state anymore(was never
used)
1 parent 5d3c28b commit 0befd08

File tree

9 files changed

+22
-61
lines changed

9 files changed

+22
-61
lines changed

aima-core/src/main/java/aima/core/agent/impl/AbstractEnvironment.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ public abstract class AbstractEnvironment implements Environment,
3838
// PRUBLIC METHODS
3939
//
4040

41+
/** Default implementation returns null. */
42+
public EnvironmentState getCurrentState() {
43+
return null;
44+
}
45+
4146
//
4247
// Methods to be implemented by subclasses.
43-
public abstract EnvironmentState getCurrentState();
4448

45-
public abstract EnvironmentState executeAction(Agent agent, Action action);
49+
public abstract void executeAction(Agent agent, Action action);
4650

4751
public abstract Percept getPerceptSeenBy(Agent anAgent);
4852

aima-core/src/main/java/aima/core/environment/map/MapEnvironment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public EnvironmentState getCurrentState() {
4444
}
4545

4646
@Override
47-
public EnvironmentState executeAction(Agent agent, Action a) {
47+
public void executeAction(Agent agent, Action a) {
4848

4949
if (!a.isNoOp()) {
5050
MoveToAction act = (MoveToAction) a;
@@ -57,8 +57,6 @@ public EnvironmentState executeAction(Agent agent, Action a) {
5757
act.getToLocation(), currTD + distance);
5858
}
5959
}
60-
61-
return state;
6260
}
6361

6462
@Override

aima-core/src/main/java/aima/core/environment/vacuum/NondeterministicVacuumEnvironment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import aima.core.agent.Action;
44
import aima.core.agent.Agent;
5-
import aima.core.agent.EnvironmentState;
65

76
/**
87
* Create the erratic vacuum world from page 134, AIMA3e. In the erratic vacuum
@@ -38,13 +37,9 @@ public NondeterministicVacuumEnvironment(LocationState locAState, LocationState
3837

3938
/**
4039
* Execute the agent action
41-
*
42-
* @param a
43-
* @param agentAction
44-
* @return the environment state after the action is executed.
4540
*/
4641
@Override
47-
public EnvironmentState executeAction(Agent a, Action agentAction) {
42+
public void executeAction(Agent a, Action agentAction) {
4843
if (ACTION_MOVE_RIGHT == agentAction) {
4944
envState.setAgentLocation(a, LOCATION_B);
5045
updatePerformanceMeasure(a, -1);
@@ -72,6 +67,5 @@ else if (VacuumEnvironment.LocationState.Clean == envState.getLocationState(envS
7267
} else if (agentAction.isNoOp()) {
7368
isDone = true;
7469
}
75-
return envState;
7670
}
7771
}

aima-core/src/main/java/aima/core/environment/vacuum/VacuumEnvironment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public EnvironmentState getCurrentState() {
7171
}
7272

7373
@Override
74-
public EnvironmentState executeAction(Agent a, Action agentAction) {
74+
public void executeAction(Agent a, Action agentAction) {
7575

7676
if (ACTION_MOVE_RIGHT == agentAction) {
7777
envState.setAgentLocation(a, LOCATION_B);
@@ -91,8 +91,6 @@ public EnvironmentState executeAction(Agent a, Action agentAction) {
9191
// the agent generates a NoOp.
9292
isDone = true;
9393
}
94-
95-
return envState;
9694
}
9795

9896
@Override

aima-core/src/main/java/aima/core/environment/xyenv/XYEnvironment.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public EnvironmentState getCurrentState() {
3636
return envState;
3737
}
3838

39+
/** Does nothing (don't ask me why...). */
3940
@Override
40-
public EnvironmentState executeAction(Agent a, Action action) {
41-
return envState;
41+
public void executeAction(Agent a, Action action) {
4242
}
4343

4444
@Override
@@ -50,8 +50,7 @@ public void addObjectToLocation(EnvironmentObject eo, XYLocation loc) {
5050
moveObjectToAbsoluteLocation(eo, loc);
5151
}
5252

53-
public void moveObjectToAbsoluteLocation(EnvironmentObject eo,
54-
XYLocation loc) {
53+
public void moveObjectToAbsoluteLocation(EnvironmentObject eo, XYLocation loc) {
5554
// Ensure the object is not already at a location
5655
envState.moveObjectToAbsoluteLocation(eo, loc);
5756

@@ -119,14 +118,12 @@ public XYEnvironmentState(int width, int height) {
119118
this.height = height;
120119
for (int h = 1; h <= height; h++) {
121120
for (int w = 1; w <= width; w++) {
122-
objsAtLocation.put(new XYLocation(h, w),
123-
new LinkedHashSet<EnvironmentObject>());
121+
objsAtLocation.put(new XYLocation(h, w), new LinkedHashSet<EnvironmentObject>());
124122
}
125123
}
126124
}
127125

128-
public void moveObjectToAbsoluteLocation(EnvironmentObject eo,
129-
XYLocation loc) {
126+
public void moveObjectToAbsoluteLocation(EnvironmentObject eo, XYLocation loc) {
130127
// Ensure is not already at another location
131128
for (Set<EnvironmentObject> eos : objsAtLocation.values()) {
132129
if (eos.remove(eo)) {
@@ -180,13 +177,9 @@ public String toString() {
180177
//
181178
// PRIVATE METHODS
182179
//
183-
private boolean withinRadius(int radius, XYLocation agentLocation,
184-
XYLocation objectLocation) {
185-
int xdifference = agentLocation.getXCoOrdinate()
186-
- objectLocation.getXCoOrdinate();
187-
int ydifference = agentLocation.getYCoOrdinate()
188-
- objectLocation.getYCoOrdinate();
189-
return Math.sqrt((xdifference * xdifference)
190-
+ (ydifference * ydifference)) <= radius;
180+
private boolean withinRadius(int radius, XYLocation agentLocation, XYLocation objectLocation) {
181+
int xdifference = agentLocation.getXCoOrdinate() - objectLocation.getXCoOrdinate();
182+
int ydifference = agentLocation.getYCoOrdinate() - objectLocation.getYCoOrdinate();
183+
return Math.sqrt((xdifference * xdifference) + (ydifference * ydifference)) <= radius;
191184
}
192185
}

aima-core/src/main/java/aima/core/learning/reinforcement/example/CellWorldEnvironment.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public EnvironmentState getCurrentState() {
8282
}
8383

8484
@Override
85-
public EnvironmentState executeAction(Agent agent, Action action) {
85+
public void executeAction(Agent agent, Action action) {
8686
if (!action.isNoOp()) {
8787
Cell<Double> s = currentState.getAgentLocation(agent);
8888
double probabilityChoice = r.nextDouble();
@@ -103,8 +103,6 @@ public EnvironmentState executeAction(Agent agent, Action action) {
103103
throw new IllegalStateException("Failed to simulate the action="+action+" correctly from s="+s);
104104
}
105105
}
106-
107-
return currentState;
108106
}
109107

110108
@Override

aima-gui/src/main/java/aima/gui/swing/demo/search/csp/CSPEnvironment.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import aima.core.agent.Action;
44
import aima.core.agent.Agent;
5-
import aima.core.agent.EnvironmentState;
65
import aima.core.agent.Percept;
76
import aima.core.agent.impl.AbstractEnvironment;
87
import aima.core.search.csp.Assignment;
@@ -32,7 +31,7 @@ public Assignment getAssignment() {
3231

3332
/** Executes the provided action and returns null. */
3433
@Override
35-
public EnvironmentState executeAction(Agent agent, Action action) {
34+
public void executeAction(Agent agent, Action action) {
3635
if (action instanceof StateChangeAction) {
3736
StateChangeAction a = (StateChangeAction) action;
3837
if (a.updateCSP())
@@ -42,13 +41,6 @@ public EnvironmentState executeAction(Agent agent, Action action) {
4241
if (agent == null)
4342
updateEnvironmentViewsAgentActed(agent, action);
4443
}
45-
return null;
46-
}
47-
48-
/** Returns null. */
49-
@Override
50-
public EnvironmentState getCurrentState() {
51-
return null;
5244
}
5345

5446
/** Returns null. */

aima-gui/src/main/java/aima/gui/swing/demo/search/games/EightPuzzleApp.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import aima.core.agent.Action;
1717
import aima.core.agent.Agent;
1818
import aima.core.agent.Environment;
19-
import aima.core.agent.EnvironmentState;
2019
import aima.core.agent.Percept;
2120
import aima.core.agent.impl.AbstractEnvironment;
2221
import aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem;
@@ -361,7 +360,7 @@ protected EightPuzzleBoard getBoard() {
361360

362361
/** Executes the provided action and returns null. */
363362
@Override
364-
public EnvironmentState executeAction(Agent agent, Action action) {
363+
public void executeAction(Agent agent, Action action) {
365364
if (action == EightPuzzleBoard.UP)
366365
board.moveGapUp();
367366
else if (action == EightPuzzleBoard.DOWN)
@@ -372,13 +371,6 @@ else if (action == EightPuzzleBoard.RIGHT)
372371
board.moveGapRight();
373372
if (agent == null)
374373
updateEnvironmentViewsAgentActed(agent, action);
375-
return null;
376-
}
377-
378-
/** Returns null. */
379-
@Override
380-
public EnvironmentState getCurrentState() {
381-
return null;
382374
}
383375

384376
/** Returns null. */

aima-gui/src/main/java/aima/gui/swing/demo/search/games/NQueensApp.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import aima.core.agent.Action;
1717
import aima.core.agent.Agent;
1818
import aima.core.agent.Environment;
19-
import aima.core.agent.EnvironmentState;
2019
import aima.core.agent.Percept;
2120
import aima.core.agent.impl.AbstractEnvironment;
2221
import aima.core.environment.nqueens.AttackingPairsHeuristic;
@@ -370,7 +369,7 @@ public NQueensBoard getBoard() {
370369
* Executes the provided action and returns null.
371370
*/
372371
@Override
373-
public EnvironmentState executeAction(Agent agent, Action action) {
372+
public void executeAction(Agent agent, Action action) {
374373
if (action instanceof QueenAction) {
375374
QueenAction act = (QueenAction) action;
376375
XYLocation loc = new XYLocation(act.getX(), act.getY());
@@ -383,13 +382,6 @@ else if (act.getName() == QueenAction.MOVE_QUEEN)
383382
if (agent == null)
384383
updateEnvironmentViewsAgentActed(agent, action);
385384
}
386-
return null;
387-
}
388-
389-
/** Returns null. */
390-
@Override
391-
public EnvironmentState getCurrentState() {
392-
return null;
393385
}
394386

395387
/** Returns null. */

0 commit comments

Comments
 (0)