33import aima .core .agent .Action ;
44import aima .core .agent .EnvironmentViewNotifier ;
55import aima .core .agent .Percept ;
6+ import aima .core .logic .propositional .inference .DPLL ;
7+ import aima .core .logic .propositional .inference .DPLLSatisfiable ;
68import aima .core .search .framework .SearchForActions ;
79import aima .core .search .framework .problem .GeneralProblem ;
810import aima .core .search .framework .problem .Problem ;
@@ -75,18 +77,18 @@ public class EfficientHybridWumpusAgent extends HybridWumpusAgent {
7577 private Set <Room > visitedRooms = new HashSet <>();
7678
7779 public EfficientHybridWumpusAgent () {
78- // i.e. default is a 4x4 world as depicted in figure 7.2
79- this (4 , new AgentPosition (1 , 1 , AgentPosition .Orientation .FACING_NORTH ));
80+ this (4 , 4 , new AgentPosition (1 , 1 , AgentPosition .Orientation .FACING_NORTH ));
8081 }
8182
82- public EfficientHybridWumpusAgent (int caveDimensions , AgentPosition start ) {
83- this (caveDimensions , start , null );
83+ public EfficientHybridWumpusAgent (int caveXDim , int caveYDim , AgentPosition start ) {
84+ this (caveXDim , caveYDim , start , new DPLLSatisfiable () , null );
8485 }
8586
86- public EfficientHybridWumpusAgent (int caveDimensions , AgentPosition start , EnvironmentViewNotifier notifier ) {
87- super (caveDimensions , start , notifier );
88- getKB ().disableNavSentences ();
89- modelCave = new WumpusCave (caveDimensions , caveDimensions );
87+ public EfficientHybridWumpusAgent (int caveXDim , int caveYDim , AgentPosition start , DPLL satSolver ,
88+ EnvironmentViewNotifier notifier ) {
89+ super (caveXDim , caveYDim , start , satSolver , notifier );
90+ getKB ().disableNavSentences (); // Optimization: Verbosity of produced sentences is reduced.
91+ modelCave = new WumpusCave (caveXDim , caveYDim );
9092 visitedRooms .add (currentPosition .getRoom ());
9193 }
9294
@@ -105,16 +107,15 @@ public Action execute(Percept percept) {
105107 // TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
106108 getKB ().makePerceptSentence ((WumpusPercept ) percept , t );
107109 // TELL the KB the temporal "physics" sentences for time t
108- getKB ().tellTemporalPhysicsSentences (t );
110+ // Optimization: The agent is aware of it's position - the KB can profit from that!
111+ getKB ().tellTemporalPhysicsSentences (t , currentPosition );
109112
110113 Set <Room > safe = null ;
111114 Set <Room > unvisited = null ;
112115
113116 // Speed optimization: Do not ask anything during plan execution (different from pseudo-code)
114117 if (plan .isEmpty ()) {
115- notifyViews ("Reasoning (t=" + t + ", Percept=" + percept + ", Pos=" + currentPosition +
116- ", KB.size=" + getKB ().size () + ", KB.sym.size=" + getKB ().getSymbols ().size () +
117- ", KB.cnf.size=" + getKB ().asCNF ().size () + ") ..." );
118+ notifyViews ("Reasoning (t=" + t + ", Percept=" + percept + ", Pos=" + currentPosition + ") ..." );
118119
119120 // safe <- {[x, y] : ASK(KB, OK<sup>t</sup><sub>x,y</sub>) = true}
120121 safe = getKB ().askSafeRooms (t );
@@ -172,10 +173,8 @@ public Action execute(Percept percept) {
172173 getKB ().makeActionSentence (action , t );
173174 // t <- t+1
174175 t = t + 1 ;
175-
176176 updateAgentPosition (action );
177177 visitedRooms .add (currentPosition .getRoom ());
178- getKB ().makePositionSentence (currentPosition , t );
179178 // return action
180179 return action ;
181180 }
@@ -192,7 +191,6 @@ public Action execute(Percept percept) {
192191 * goal from the current position.
193192 */
194193 public List <WumpusAction > planRoute (Set <AgentPosition > goals , Set <Room > allowed ) {
195-
196194 modelCave .setAllowed (allowed );
197195 Problem <AgentPosition , WumpusAction > problem = new GeneralProblem <>(currentPosition ,
198196 WumpusFunctions .createActionsFunction (modelCave ),
@@ -201,7 +199,7 @@ public List<WumpusAction> planRoute(Set<AgentPosition> goals, Set<Room> allowed)
201199 new AStarSearch <>(new GraphSearch <>(), new ManhattanHeuristicFunction (goals ));
202200 Optional <List <WumpusAction >> actions = search .findActions (problem );
203201
204- return actions .isPresent () ? actions .get () : Collections .EMPTY_LIST ;
202+ return actions .isPresent () ? actions .get () : Collections .emptyList () ;
205203 }
206204
207205 /**
0 commit comments