Skip to content

Commit 05fa84a

Browse files
committed
Bug (lost goal) in GraphPlan fixed.
1 parent 62657fe commit 05fa84a

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* is possible.
3030
*
3131
* @author samagra
32+
* @author Ruediger Lunde
3233
*/
3334
public class GraphPlanAlgorithm {
3435

@@ -96,19 +97,18 @@ private List<List<ActionSchema>> extractSolution(Graph graph, List<Literal> goal
9697
if (nogoods.contains(numLevel))
9798
return null;
9899

99-
int level = (graph.numLevels() - 1) / 2;
100+
List<Literal> goalsCurr = new ArrayList<>(goals);
100101
List<List<ActionSchema>> solution = new ArrayList<>();
101-
Level currLevel = graph.getLevels().get(2 * level);
102-
while (level > 0) {
102+
for (int level = (graph.numLevels() - 1) / 2; level > 0; level--) {
103+
Level currLevel = graph.getLevels().get(2 * level);
103104
List<List<ActionSchema>> setOfPossibleActions = new ArrayList<>();
104105
HashMap<Object, List<Object>> mutexLinks = currLevel.getPrevLevel().getMutexLinks();
105-
for (Literal literal : goals) {
106-
List<ActionSchema> possiBleActionsPerLiteral = new ArrayList<>();
107-
for (Object action :
108-
currLevel.getPrevLinks().get(literal)) {
109-
possiBleActionsPerLiteral.add((ActionSchema) action);
106+
for (Literal literal : goalsCurr) {
107+
List<ActionSchema> possibleActionsPerLiteral = new ArrayList<>();
108+
for (Object action : currLevel.getPrevLinks().get(literal)) {
109+
possibleActionsPerLiteral.add((ActionSchema) action);
110110
}
111-
setOfPossibleActions.add(possiBleActionsPerLiteral);
111+
setOfPossibleActions.add(possibleActionsPerLiteral);
112112
}
113113
List<List<ActionSchema>> allPossibleSubSets = generateCombinations(setOfPossibleActions);
114114
boolean validSet;
@@ -125,24 +125,21 @@ private List<List<ActionSchema>> extractSolution(Graph graph, List<Literal> goal
125125
}
126126
}
127127
if (validSet) {
128+
// This is too simple. Completeness is lost. Search would be required... (RLu)
128129
setToBeTaken = possibleSet;
129130
break;
130131
}
131132
}
132133
if (setToBeTaken == null) {
133-
nogoods.put(level, goals);
134+
nogoods.put(level, goalsCurr);
134135
return null;
135136
}
136-
137-
level--;
138-
currLevel = graph.getLevels().get(2 * level);
139-
goals.clear();
140137
solution.add(setToBeTaken);
138+
goalsCurr.clear();
141139
for (ActionSchema action : setToBeTaken) {
142-
for (Literal literal :
143-
action.getPrecondition()) {
144-
if (!goals.contains(literal)) {
145-
goals.add(literal);
140+
for (Literal literal : action.getPrecondition()) {
141+
if (!goalsCurr.contains(literal)) {
142+
goalsCurr.add(literal);
146143
}
147144
}
148145
}

aima-core/src/test/java/aima/test/core/unit/environment/tictactoe/TicTacToeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void testAlphaBetaDecision() {
162162
.createFor(game);
163163
search.makeDecision(state);
164164
int expandedNodes = search.getMetrics().getInt(MinimaxSearch.METRICS_NODES_EXPANDED);
165-
Assert.assertEquals(30709, expandedNodes);
165+
Assert.assertEquals(18296, expandedNodes);
166166
}
167167

168168
@Test

0 commit comments

Comments
 (0)