Skip to content

Commit 7524db8

Browse files
committed
Minor cleanup.
1 parent d47cddc commit 7524db8

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

aima-core/src/main/java/aima/core/logic/planning/BackwardStateSpaceSearchProblem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ List<ActionSchema> actions(List<Literal> state) {
4646
if (relevant) {
4747
for (Literal literal : action.getPrecondition()) {
4848
Literal cLit = literal.getComplementaryLiteral();
49-
if (!action.getEffect().contains(cLit) && state.contains(cLit)) {
49+
if (state.contains(cLit) && !action.getEffect().contains(cLit)) {
5050
relevant = false; // unchanged precondition contradicts state specification
5151
break;
5252
}

aima-core/src/main/java/aima/core/logic/planning/ForwardStateSpaceSearchProblem.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ else if (!result.contains(literal))
7373

7474
boolean goalTest(List<Literal> state) {
7575
for (Literal literal : pProblem.getGoal())
76-
if (literal.isPositiveLiteral() && !state.contains(literal)
77-
|| literal.isNegativeLiteral() && state.contains(literal.getComplementaryLiteral()))
76+
if (literal.isPositiveLiteral()
77+
? !state.contains(literal)
78+
: state.contains(literal.getComplementaryLiteral()))
7879
return false;
79-
return true;
80+
return true;
8081
}
8182
}

aima-core/src/main/java/aima/core/logic/planning/PlanningProblem.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
* within the domain is defined with the addition of an initial state and a goal. The initial
1717
* state is a conjunction of ground atoms.The goal is just like a
1818
* precondition: a conjunction of literals (positive or negative) that may contain variables, such
19-
* as At(p, SFO ) ∧ Plane(p). Any variables are treated as existentially quantified, so this goal
19+
* as At(p, SFO) ∧ Plane(p). Any variables are treated as existentially quantified, so this goal
2020
* is to have any plane at SFO. The problem is solved when we can find a sequence of actions
2121
* that end in a state s that entails the goal.
2222
*
2323
* @author samagra
24+
* @author Ruediger Lunde
2425
*/
2526
public class PlanningProblem {
26-
private final State initialState; // initialState
27-
private final Set<ActionSchema> actionSchemas; // Planning Domain
28-
private final List<Literal> goal; // goal
27+
private final State initialState;
28+
private final Set<ActionSchema> actionSchemas;
29+
private final List<Literal> goal;
2930

3031
private List<ActionSchema> propositionalisedActionSchemas;
3132

aima-core/src/main/java/aima/core/logic/planning/PlanningProblemFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package aima.core.logic.planning;
22

3+
import aima.core.logic.fol.kb.data.Literal;
34
import aima.core.logic.fol.parsing.ast.Constant;
45
import aima.core.logic.fol.parsing.ast.Term;
56
import aima.core.logic.fol.parsing.ast.Variable;
@@ -40,7 +41,7 @@ public class PlanningProblemFactory {
4041
public static PlanningProblem airCargoTransportProblem() {
4142
State initialState = new State("At(C1,SFO)^At(C2,JFK)^At(P1,SFO)" +
4243
"^At(P2,JFK)^Cargo(C1)^Cargo(C2)^Plane(P1)^Plane(P2)^Airport(JFK)^Airport(SFO)");
43-
State goalState = new State("At(C1,JFK)^At(C2,SFO)");
44+
List<Literal> goal = Utils.parse("At(C1,JFK)^At(C2,SFO)");
4445
Variable c = new Variable("c");
4546
Variable p = new Variable("p");
4647
Variable a = new Variable("a");
@@ -58,7 +59,7 @@ public static PlanningProblem airCargoTransportProblem() {
5859
"At(p,from)^Plane(p)^Airport(from)^Airport(to)",
5960
"~At(p,from)^At(p,to)");
6061

61-
return new PlanningProblem(initialState, goalState.getFluents(), loadAction, unloadAction, flyAction);
62+
return new PlanningProblem(initialState, goal, loadAction, unloadAction, flyAction);
6263
}
6364

6465
/**
@@ -85,7 +86,7 @@ public static PlanningProblem airCargoTransportProblem() {
8586
*/
8687
public static PlanningProblem spareTireProblem() {
8788
State initialState = new State("Tire(Flat)^Tire(Spare)^At(Flat,Axle)^At(Spare,Trunk)");
88-
State goalState = new State("At(Spare,Axle)");
89+
List<Literal> goal = Utils.parse("At(Spare,Axle)");
8990
Variable obj = new Variable("obj");
9091
Variable loc = new Variable("loc");
9192
Variable t = new Variable("t");
@@ -101,7 +102,7 @@ public static PlanningProblem spareTireProblem() {
101102
"",
102103
"~At(Spare,Ground)^~At(Spare,Axle)^~At(Spare,Trunk)" +
103104
"^~At(Flat,Ground)^~At(Flat,Axle)^~At(Flat,Trunk)");
104-
return new PlanningProblem(initialState, goalState.getFluents(), removeAction, putOnAction, leaveOvernightAction);
105+
return new PlanningProblem(initialState, goal, removeAction, putOnAction, leaveOvernightAction);
105106
}
106107

107108
/**
@@ -119,7 +120,7 @@ public static PlanningProblem spareTireProblem() {
119120
*/
120121
public static PlanningProblem goHomeToSFOProblem() {
121122
State initialState = new State("At(Home)");
122-
State goalState = new State("At(SFO)");
123+
List<Literal> goal = Utils.parse("At(SFO)");
123124
ActionSchema driveAction = new ActionSchema("Drive", null,
124125
"At(Home)",
125126
"~At(Home)^At(SFOLongTermParking)");
@@ -129,7 +130,7 @@ public static PlanningProblem goHomeToSFOProblem() {
129130
ActionSchema taxiAction = new ActionSchema("Taxi", null,
130131
"At(Home)",
131132
"~At(Home)^At(SFO)");
132-
return new PlanningProblem(initialState, goalState.getFluents(), driveAction, shuttleAction, taxiAction);
133+
return new PlanningProblem(initialState, goal, driveAction, shuttleAction, taxiAction);
133134

134135
}
135136

aima-core/src/test/java/aima/test/core/unit/logic/planning/PlanningProblemTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package aima.test.core.unit.logic.planning;
22

3+
import aima.core.logic.fol.kb.data.Literal;
34
import aima.core.logic.fol.parsing.ast.Constant;
45
import aima.core.logic.fol.parsing.ast.Term;
56
import aima.core.logic.fol.parsing.ast.Variable;
6-
import aima.core.logic.planning.ActionSchema;
7-
import aima.core.logic.planning.PlanningProblemFactory;
8-
import aima.core.logic.planning.PlanningProblem;
9-
import aima.core.logic.planning.State;
7+
import aima.core.logic.planning.*;
108
import org.junit.Assert;
119
import org.junit.Before;
1210
import org.junit.Test;
@@ -29,7 +27,7 @@ public void setup() {
2927
@Test
3028
public void constructorTest() {
3129
State initState = new State("Tire(Flat)^Tire(Spare)^At(Flat,Axle)^At(Spare,Trunk)");
32-
State goalState = new State("At(Spare,Axle)");
30+
List<Literal> goal = Utils.parse("At(Spare,Axle)");
3331
Variable obj = new Variable("obj");
3432
Variable loc = new Variable("loc");
3533
Variable t = new Variable("t");
@@ -46,7 +44,7 @@ public void constructorTest() {
4644
"~At(Spare,Ground)^~At(Spare,Axle)^~At(Spare,Trunk)" +
4745
"^~At(Flat,Ground)^~At(Flat,Axle)^~At(Flat,Trunk)");
4846
Assert.assertEquals(initState, testProblem.getInitialState());
49-
Assert.assertEquals(goalState, testProblem.getGoal());
47+
Assert.assertEquals(goal, testProblem.getGoal());
5048
Assert.assertEquals(3, testProblem.getActionSchemas().size());
5149
Assert.assertTrue(testProblem.getActionSchemas().contains(removeAction));
5250
Assert.assertTrue(testProblem.getActionSchemas().contains(putOnAction));

0 commit comments

Comments
 (0)