Skip to content

Commit dfb949a

Browse files
Ruediger.LundeRuediger.Lunde
authored andcommitted
Method stepUntilNoOp of environment renamed to stepUntilDone.
Agent constant DIE removed. (It was discussed to rename DIE to DONE and make the environment responsible for killing agents. But it seems quite hard to get consistent library state after that, see e.g. the vacuum agents.)
1 parent 869adac commit dfb949a

20 files changed

+61
-65
lines changed

src/aima/basic/Agent.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
*/
1515
public abstract class Agent extends ObjectWithDynamicAttributes {
1616

17-
/**
18-
* Name of an action which indicates, the Agent is unwilling to generate any
19-
* more goals and should therefore DIE. This indicates final success.
20-
*/
21-
public static final String DIE = "DIE";
2217
// Used to define No Operations/Action is to be performed.
2318
public static final String NO_OP = "NoOP";
2419

src/aima/basic/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void step(int n) {
8080
}
8181
}
8282

83-
public void stepUntilNoOp() {
83+
public void stepUntilDone() {
8484
while (!(this.isDone())) {
8585
step();
8686
}

src/aima/basic/ObjectWithDynamicAttributes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public void setAttribute(Object key, Object value) {
1818
public Object getAttribute(Object key) {
1919
return attributes.get(key);
2020
}
21+
22+
public void removeAttribute(Object key) {
23+
attributes.remove(key);
24+
}
2125

2226
public Iterator<Object> getSortedAttributeKeys() {
2327
// Want to guarantee the keys are returned back ordered

src/aima/basic/vaccum/ReflexAgentWithStateProgram.java

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

33
import java.util.Set;
44

5+
import aima.basic.Agent;
56
import aima.basic.AgentProgram;
67
import aima.basic.ObjectWithDynamicAttributes;
78
import aima.basic.Percept;
@@ -29,9 +30,6 @@
2930
*
3031
*/
3132
public abstract class ReflexAgentWithStateProgram extends AgentProgram {
32-
// Used to define No Operations/Action is to be performed.
33-
public static final String NO_OP = "NoOP";
34-
3533
//
3634
// static state, a description of the current world state
3735
private ObjectWithDynamicAttributes state = null;
@@ -96,6 +94,6 @@ protected Rule ruleMatch(ObjectWithDynamicAttributes envState,
9694
}
9795

9896
protected String ruleAction(Rule r) {
99-
return null == r ? NO_OP : r.getAction();
97+
return null == r ? Agent.NO_OP : r.getAction();
10098
}
10199
}

src/aima/basic/vaccum/ReflexVaccumAgentWithState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static Set<Rule> getRuleSet() {
5858
.add(new Rule(new ANDCondition(new EQUALCondition(
5959
"statusLocationA", "Clean"), new EQUALCondition(
6060
"statusLocationB", "Clean")),
61-
ReflexAgentWithStateProgram.NO_OP));
61+
Agent.NO_OP));
6262
rules
6363
.add(new Rule(new EQUALCondition("currentStatus", "Dirty"),
6464
"Suck"));

src/aima/basic/vaccum/TrivialVaccumEnvironment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public void executeAction(Agent a, String agentAction) {
6868
setLocationStatus(getAgentLocation(a), "Clean");
6969
setAgentPerformance(a, getAgentperformance(a) + 10);
7070
}
71-
72-
} else if (agentAction.equals("NoOP")) {
71+
72+
} else if (agentAction.equals(Agent.NO_OP)) {
73+
// this is a bit unfair, but it simplifies testing...
7374
a.die();
7475

7576
}

src/aima/gui/applications/VacuumAppDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void prepareAgent() {
191191
public void runAgent() {
192192
VacuumModel vmodel = (VacuumModel) model;
193193
frame.logMessage("<simulation-log>");
194-
vmodel.getEnv().stepUntilNoOp();
194+
vmodel.getEnv().stepUntilDone();
195195
frame.logMessage("Performance: " +
196196
vmodel.getEnv().getAgentperformance(vmodel.getAgent()));
197197
frame.logMessage("</simulation-log>");

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ public void runAgent() {
7070
.getAttribute(DynAttributeNames.AGENT_STATUS);
7171
Double travelDistance = (Double) agent
7272
.getAttribute(DynAttributeNames.AGENT_TRAVEL_DISTANCE);
73-
StringBuffer statusMsg = new StringBuffer("Task ");
73+
StringBuffer statusMsg = new StringBuffer();
7474
if (status != null)
75-
statusMsg.append(status);
75+
statusMsg.append("Agent status: " + status);
7676
else
77-
statusMsg.append("completed");
77+
statusMsg.append("Task completed");
7878
if (travelDistance != null)
79-
statusMsg.append("; travel distance " + travelDistance);
79+
statusMsg.append("; travel distance: " + travelDistance);
8080
statusMsg.append(".");
8181
frame.setStatus(statusMsg.toString());
8282
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public MapAgentFrame() {
5151
//////////////////////////////////////////////////////////
5252
// inner classes
5353

54-
5554
/**
5655
* Agent view for map and tour agent applications. This
5756
* view requires the used model to be of type

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ public void clearTourHistory() {
4242
* Reacts on environment changes and updates the tour history. The command
4343
* string is always send to all registered model change listeners. If the
4444
* command is a location name (with attached position info) or
45-
* {@link aima.basic.Agent#NO_OP} or {@link aima.basic.Agent#DIE}, the
45+
* {@link aima.basic.Agent#NO_OP} or {@link aima.basic.Agent#DONE}, the
4646
* agent's current location is added to the tour history and all listeners
4747
* are informed about the change.
4848
*/
4949
@Override
5050
public void envChanged(String command) {
5151
for (AgentAppModel.ModelChangedListener listener : listeners)
5252
listener.logMessage(command);
53-
if (getLocCoords(command) != null || command.equals(Agent.NO_OP)
54-
|| command.equals(Agent.DIE)) {
53+
if (getLocCoords(command) != null || command.equals(Agent.NO_OP)) {
5554
String loc = (String) getAgent().getAttribute(
5655
DynAttributeNames.AGENT_LOCATION);
5756
tourHistory.add(loc);

0 commit comments

Comments
 (0)