Skip to content

Commit 5b82658

Browse files
committed
Fix OptimizeDPLL defect discovered by Ruediger.
1 parent 7c36d30 commit 5b82658

File tree

3 files changed

+6
-39
lines changed

3 files changed

+6
-39
lines changed

aima-core/src/main/java/aima/core/environment/wumpusworld/HybridWumpusAgent.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import aima.core.agent.EnvironmentViewNotifier;
55
import aima.core.agent.Percept;
66
import aima.core.agent.impl.AbstractAgent;
7-
import aima.core.logic.propositional.inference.DPLLSatisfiable;
87
import aima.core.logic.propositional.inference.OptimizedDPLL;
98
import aima.core.search.framework.SearchForActions;
109
import aima.core.search.framework.problem.GeneralProblem;
@@ -94,8 +93,7 @@ public HybridWumpusAgent(int caveDimensions, AgentPosition start) {
9493
}
9594

9695
public HybridWumpusAgent(int caveDimensions, AgentPosition start, EnvironmentViewNotifier notifier) {
97-
// kb = new WumpusKnowledgeBase(new OptimizedDPLL(), caveDimensions, start); // buggy?
98-
kb = new WumpusKnowledgeBase(new DPLLSatisfiable(), caveDimensions, start);
96+
kb = new WumpusKnowledgeBase(new OptimizedDPLL(), caveDimensions, start);
9997
this.start = start;
10098
this.currentPosition = start;
10199
this.notifier = notifier;
@@ -234,7 +232,7 @@ public List<WumpusAction> planRoute(Set<AgentPosition> goals, Set<Room> allowed)
234232
new AStarSearch<>(new GraphSearch<>(), new ManhattanHeuristicFunction(goals));
235233
Optional<List<WumpusAction>> actions = search.findActions(problem);
236234

237-
return actions.isPresent() ? actions.get() : Collections.EMPTY_LIST;
235+
return actions.isPresent() ? actions.get() : Collections.emptyList();
238236
}
239237

240238
/**

aima-core/src/main/java/aima/core/environment/wumpusworld/WumpusKnowledgeBase.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -146,37 +146,6 @@ public void disableNavSentences() {
146146
}
147147

148148
public AgentPosition askCurrentPosition(int t) {
149-
150-
// There seems to be a bug in OptimizedDPLL (incorrect position computation):
151-
// Call with: WumpusAgentDemo, 2x2 cave, OptimizedDPLL (HybridWumpusAgend-Constructor)
152-
/*
153-
if (t == 4) { // todo
154-
System.out.println("Ask L_3_1_1: " + ask(newSymbol(LOCATION, 3, 1, 1))); // false
155-
System.out.println("Ask L_3_1_2: " + ask(newSymbol(LOCATION, 3, 1, 2))); // true
156-
System.out.println("Ask L_3_2_1: " + ask(newSymbol(LOCATION, 3, 2, 1))); // false
157-
System.out.println("Ask L_3_2_2: " + ask(newSymbol(LOCATION, 3, 2, 2))); // false
158-
System.out.println("Ask North_3: " + ask(newSymbol(FACING_NORTH, 3))); // false
159-
System.out.println("Ask South_3: " + ask(newSymbol(FACING_SOUTH, 3))); // false
160-
System.out.println("Ask East_3: " + ask(newSymbol(FACING_EAST, 3))); // true
161-
System.out.println("Ask West_3: " + ask(newSymbol(FACING_WEST, 3))); // false
162-
163-
System.out.println("Ask L_4_1_1: " + ask(newSymbol(LOCATION, 4, 1, 1)) + " !"); // true (incorrect)
164-
System.out.println("Ask L_4_2_2: " + ask(newSymbol(LOCATION, 4, 2, 2)) + " !"); // true (correct)
165-
System.out.println("Ask North_4: " + ask(newSymbol(FACING_NORTH, 4))); // false
166-
System.out.println("Ask South_4: " + ask(newSymbol(FACING_SOUTH, 4))); // false
167-
System.out.println("Ask East_4: " + ask(newSymbol(FACING_EAST, 4))); // true
168-
System.out.println("Ask West_4: " + ask(newSymbol(FACING_WEST, 4))); // false
169-
170-
System.out.println("Ask L_5_1_1: " + ask(newSymbol(LOCATION, 5, 1, 1))); // false
171-
System.out.println("Ask L_5_1_2: " + ask(newSymbol(LOCATION, 5, 1, 2))); // false
172-
System.out.println("Ask L_5_2_1: " + ask(newSymbol(LOCATION, 5, 2, 1))); // false
173-
System.out.println("Ask L_5_2_2: " + ask(newSymbol(LOCATION, 5, 2, 2))); // false
174-
175-
// L_4_1_1 is only constrained by:
176-
// L_4_1_1 <=> L_3_1_1 & (~FORWARD_3 | Bump_4) | L_3_1_2 & FACING_SOUTH_3 & FORWARD_3 | L_3_2_1 & FACING_WEST_3 & FORWARD_3
177-
}
178-
*/
179-
180149
int locX = -1, locY = -1;
181150
for (int x = 1; x <= getCaveXDimension() && locX == -1; x++) {
182151
for (int y = 1; y <= getCaveYDimension() && locY == -1; y++) {

aima-core/src/main/java/aima/core/logic/propositional/inference/OptimizedDPLL.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ public boolean dpll(Set<Clause> clauses, List<PropositionSymbol> symbols,
8585
// if P is non-null then
8686
if (pAndValue != null) {
8787
// return DPLL(clauses, symbols - P, model U {P = value})
88-
return dpll(clauses, minus(symbols, pAndValue.getFirst()),
89-
model.unionInPlace(pAndValue.getFirst(), pAndValue.getSecond()));
88+
return callDPLL(clauses, minus(symbols, pAndValue.getFirst()), model,
89+
pAndValue.getFirst(), pAndValue.getSecond());
9090
}
9191

9292
// P, value <- FIND-UNIT-CLAUSE(clauses, model)
9393
pAndValue = findUnitClause(clauses, model);
9494
// if P is non-null then
9595
if (pAndValue != null) {
9696
// return DPLL(clauses, symbols - P, model U {P = value})
97-
return dpll(clauses, minus(symbols, pAndValue.getFirst()),
98-
model.unionInPlace(pAndValue.getFirst(), pAndValue.getSecond()));
97+
return callDPLL(clauses, minus(symbols, pAndValue.getFirst()), model,
98+
pAndValue.getFirst(), pAndValue.getSecond());
9999
}
100100

101101
// P <- FIRST(symbols); rest <- REST(symbols)

0 commit comments

Comments
 (0)