001 package aima.basic.vaccum; 002 003 import java.util.Hashtable; 004 import java.util.Map; 005 006 import aima.basic.Agent; 007 import aima.basic.Percept; 008 import aima.basic.PerceptSequence; 009 010 /** 011 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 2.3, page 34. 012 * 013 * Figure 2.3 Partial tabulation of a simple agent function for the vacuum-cleaner world 014 * shown in Figure 2.2. 015 */ 016 017 /** 018 * @author Ciaran O'Reilly 019 * 020 */ 021 public class TableDrivenVaccumAgent extends Agent { 022 023 public TableDrivenVaccumAgent() { 024 super(new TableDrivenAgentProgram(getPerceptSequenceActions())); 025 } 026 027 // 028 // PRIVATE METHODS 029 // 030 private static Map<PerceptSequence, String> getPerceptSequenceActions() { 031 Map<PerceptSequence, String> perceptSequenceActions = new Hashtable<PerceptSequence, String>(); 032 033 PerceptSequence ps; 034 // 035 // Level 1: 4 states 036 ps = new PerceptSequence( 037 new Percept("location", "A", "status", "Clean")); 038 perceptSequenceActions.put(ps, "Right"); 039 ps = new PerceptSequence( 040 new Percept("location", "A", "status", "Dirty")); 041 perceptSequenceActions.put(ps, "Suck"); 042 ps = new PerceptSequence( 043 new Percept("location", "B", "status", "Clean")); 044 perceptSequenceActions.put(ps, "Left"); 045 ps = new PerceptSequence( 046 new Percept("location", "B", "status", "Dirty")); 047 perceptSequenceActions.put(ps, "Suck"); 048 049 // 050 // Level 2: 4x4 states 051 ps = new PerceptSequence( 052 new Percept("location", "A", "status", "Clean"), new Percept( 053 "location", "A", "status", "Clean")); 054 perceptSequenceActions.put(ps, "Right"); 055 ps = new PerceptSequence( 056 new Percept("location", "A", "status", "Clean"), new Percept( 057 "location", "A", "status", "Dirty")); 058 perceptSequenceActions.put(ps, "Suck"); 059 ps = new PerceptSequence( 060 new Percept("location", "A", "status", "Clean"), new Percept( 061 "location", "B", "status", "Clean")); 062 perceptSequenceActions.put(ps, "Left"); 063 ps = new PerceptSequence( 064 new Percept("location", "A", "status", "Clean"), new Percept( 065 "location", "B", "status", "Dirty")); 066 perceptSequenceActions.put(ps, "Suck"); 067 // 068 ps = new PerceptSequence( 069 new Percept("location", "A", "status", "Dirty"), new Percept( 070 "location", "A", "status", "Clean")); 071 perceptSequenceActions.put(ps, "Right"); 072 ps = new PerceptSequence( 073 new Percept("location", "A", "status", "Dirty"), new Percept( 074 "location", "A", "status", "Dirty")); 075 perceptSequenceActions.put(ps, "Suck"); 076 ps = new PerceptSequence( 077 new Percept("location", "A", "status", "Dirty"), new Percept( 078 "location", "B", "status", "Clean")); 079 perceptSequenceActions.put(ps, "Left"); 080 ps = new PerceptSequence( 081 new Percept("location", "A", "status", "Dirty"), new Percept( 082 "location", "B", "status", "Dirty")); 083 perceptSequenceActions.put(ps, "Suck"); 084 // 085 ps = new PerceptSequence( 086 new Percept("location", "B", "status", "Clean"), new Percept( 087 "location", "A", "status", "Clean")); 088 perceptSequenceActions.put(ps, "Right"); 089 ps = new PerceptSequence( 090 new Percept("location", "B", "status", "Clean"), new Percept( 091 "location", "A", "status", "Dirty")); 092 perceptSequenceActions.put(ps, "Suck"); 093 ps = new PerceptSequence( 094 new Percept("location", "B", "status", "Clean"), new Percept( 095 "location", "B", "status", "Clean")); 096 perceptSequenceActions.put(ps, "Left"); 097 ps = new PerceptSequence( 098 new Percept("location", "B", "status", "Clean"), new Percept( 099 "location", "B", "status", "Dirty")); 100 perceptSequenceActions.put(ps, "Suck"); 101 // 102 ps = new PerceptSequence( 103 new Percept("location", "B", "status", "Dirty"), new Percept( 104 "location", "A", "status", "Clean")); 105 perceptSequenceActions.put(ps, "Right"); 106 ps = new PerceptSequence( 107 new Percept("location", "B", "status", "Dirty"), new Percept( 108 "location", "A", "status", "Dirty")); 109 perceptSequenceActions.put(ps, "Suck"); 110 ps = new PerceptSequence( 111 new Percept("location", "B", "status", "Dirty"), new Percept( 112 "location", "B", "status", "Clean")); 113 perceptSequenceActions.put(ps, "Left"); 114 ps = new PerceptSequence( 115 new Percept("location", "B", "status", "Dirty"), new Percept( 116 "location", "B", "status", "Dirty")); 117 perceptSequenceActions.put(ps, "Suck"); 118 119 // 120 // Level 3: 4x4x4 states 121 ps = new PerceptSequence( 122 new Percept("location", "A", "status", "Clean"), new Percept( 123 "location", "A", "status", "Clean"), new Percept( 124 "location", "A", "status", "Clean")); 125 perceptSequenceActions.put(ps, "Right"); 126 ps = new PerceptSequence( 127 new Percept("location", "A", "status", "Clean"), new Percept( 128 "location", "A", "status", "Clean"), new Percept( 129 "location", "A", "status", "Dirty")); 130 perceptSequenceActions.put(ps, "Suck"); 131 ps = new PerceptSequence( 132 new Percept("location", "A", "status", "Clean"), new Percept( 133 "location", "A", "status", "Clean"), new Percept( 134 "location", "B", "status", "Clean")); 135 perceptSequenceActions.put(ps, "Left"); 136 ps = new PerceptSequence( 137 new Percept("location", "A", "status", "Clean"), new Percept( 138 "location", "A", "status", "Clean"), new Percept( 139 "location", "B", "status", "Dirty")); 140 perceptSequenceActions.put(ps, "Suck"); 141 // 142 ps = new PerceptSequence( 143 new Percept("location", "A", "status", "Clean"), new Percept( 144 "location", "A", "status", "Dirty"), new Percept( 145 "location", "A", "status", "Clean")); 146 perceptSequenceActions.put(ps, "Right"); 147 ps = new PerceptSequence( 148 new Percept("location", "A", "status", "Clean"), new Percept( 149 "location", "A", "status", "Dirty"), new Percept( 150 "location", "A", "status", "Dirty")); 151 perceptSequenceActions.put(ps, "Suck"); 152 ps = new PerceptSequence( 153 new Percept("location", "A", "status", "Clean"), new Percept( 154 "location", "A", "status", "Dirty"), new Percept( 155 "location", "B", "status", "Clean")); 156 perceptSequenceActions.put(ps, "Left"); 157 ps = new PerceptSequence( 158 new Percept("location", "A", "status", "Clean"), new Percept( 159 "location", "A", "status", "Dirty"), new Percept( 160 "location", "B", "status", "Dirty")); 161 perceptSequenceActions.put(ps, "Suck"); 162 // 163 ps = new PerceptSequence( 164 new Percept("location", "A", "status", "Clean"), new Percept( 165 "location", "B", "status", "Clean"), new Percept( 166 "location", "A", "status", "Clean")); 167 perceptSequenceActions.put(ps, "Right"); 168 ps = new PerceptSequence( 169 new Percept("location", "A", "status", "Clean"), new Percept( 170 "location", "B", "status", "Clean"), new Percept( 171 "location", "A", "status", "Dirty")); 172 perceptSequenceActions.put(ps, "Suck"); 173 ps = new PerceptSequence( 174 new Percept("location", "A", "status", "Clean"), new Percept( 175 "location", "B", "status", "Clean"), new Percept( 176 "location", "B", "status", "Clean")); 177 perceptSequenceActions.put(ps, "Left"); 178 ps = new PerceptSequence( 179 new Percept("location", "A", "status", "Clean"), new Percept( 180 "location", "B", "status", "Clean"), new Percept( 181 "location", "B", "status", "Dirty")); 182 perceptSequenceActions.put(ps, "Suck"); 183 // 184 ps = new PerceptSequence( 185 new Percept("location", "A", "status", "Clean"), new Percept( 186 "location", "B", "status", "Dirty"), new Percept( 187 "location", "A", "status", "Clean")); 188 perceptSequenceActions.put(ps, "Right"); 189 ps = new PerceptSequence( 190 new Percept("location", "A", "status", "Clean"), new Percept( 191 "location", "B", "status", "Dirty"), new Percept( 192 "location", "A", "status", "Dirty")); 193 perceptSequenceActions.put(ps, "Suck"); 194 ps = new PerceptSequence( 195 new Percept("location", "A", "status", "Clean"), new Percept( 196 "location", "B", "status", "Dirty"), new Percept( 197 "location", "B", "status", "Clean")); 198 perceptSequenceActions.put(ps, "Left"); 199 ps = new PerceptSequence( 200 new Percept("location", "A", "status", "Clean"), new Percept( 201 "location", "B", "status", "Dirty"), new Percept( 202 "location", "B", "status", "Dirty")); 203 perceptSequenceActions.put(ps, "Suck"); 204 // 205 ps = new PerceptSequence( 206 new Percept("location", "A", "status", "Dirty"), new Percept( 207 "location", "A", "status", "Clean"), new Percept( 208 "location", "A", "status", "Clean")); 209 perceptSequenceActions.put(ps, "Right"); 210 ps = new PerceptSequence( 211 new Percept("location", "A", "status", "Dirty"), new Percept( 212 "location", "A", "status", "Clean"), new Percept( 213 "location", "A", "status", "Dirty")); 214 perceptSequenceActions.put(ps, "Suck"); 215 ps = new PerceptSequence( 216 new Percept("location", "A", "status", "Dirty"), new Percept( 217 "location", "A", "status", "Clean"), new Percept( 218 "location", "B", "status", "Clean")); 219 perceptSequenceActions.put(ps, "Left"); 220 ps = new PerceptSequence( 221 new Percept("location", "A", "status", "Dirty"), new Percept( 222 "location", "A", "status", "Clean"), new Percept( 223 "location", "B", "status", "Dirty")); 224 perceptSequenceActions.put(ps, "Suck"); 225 // 226 ps = new PerceptSequence( 227 new Percept("location", "A", "status", "Dirty"), new Percept( 228 "location", "A", "status", "Dirty"), new Percept( 229 "location", "A", "status", "Clean")); 230 perceptSequenceActions.put(ps, "Right"); 231 ps = new PerceptSequence( 232 new Percept("location", "A", "status", "Dirty"), new Percept( 233 "location", "A", "status", "Dirty"), new Percept( 234 "location", "A", "status", "Dirty")); 235 perceptSequenceActions.put(ps, "Suck"); 236 ps = new PerceptSequence( 237 new Percept("location", "A", "status", "Dirty"), new Percept( 238 "location", "A", "status", "Dirty"), new Percept( 239 "location", "B", "status", "Clean")); 240 perceptSequenceActions.put(ps, "Left"); 241 ps = new PerceptSequence( 242 new Percept("location", "A", "status", "Dirty"), new Percept( 243 "location", "A", "status", "Dirty"), new Percept( 244 "location", "B", "status", "Dirty")); 245 perceptSequenceActions.put(ps, "Suck"); 246 // 247 ps = new PerceptSequence( 248 new Percept("location", "A", "status", "Dirty"), new Percept( 249 "location", "B", "status", "Clean"), new Percept( 250 "location", "A", "status", "Clean")); 251 perceptSequenceActions.put(ps, "Right"); 252 ps = new PerceptSequence( 253 new Percept("location", "A", "status", "Dirty"), new Percept( 254 "location", "B", "status", "Clean"), new Percept( 255 "location", "A", "status", "Dirty")); 256 perceptSequenceActions.put(ps, "Suck"); 257 ps = new PerceptSequence( 258 new Percept("location", "A", "status", "Dirty"), new Percept( 259 "location", "B", "status", "Clean"), new Percept( 260 "location", "B", "status", "Clean")); 261 perceptSequenceActions.put(ps, "Left"); 262 ps = new PerceptSequence( 263 new Percept("location", "A", "status", "Dirty"), new Percept( 264 "location", "B", "status", "Clean"), new Percept( 265 "location", "B", "status", "Dirty")); 266 perceptSequenceActions.put(ps, "Suck"); 267 // 268 ps = new PerceptSequence( 269 new Percept("location", "A", "status", "Dirty"), new Percept( 270 "location", "B", "status", "Dirty"), new Percept( 271 "location", "A", "status", "Clean")); 272 perceptSequenceActions.put(ps, "Right"); 273 ps = new PerceptSequence( 274 new Percept("location", "A", "status", "Dirty"), new Percept( 275 "location", "B", "status", "Dirty"), new Percept( 276 "location", "A", "status", "Dirty")); 277 perceptSequenceActions.put(ps, "Suck"); 278 ps = new PerceptSequence( 279 new Percept("location", "A", "status", "Dirty"), new Percept( 280 "location", "B", "status", "Dirty"), new Percept( 281 "location", "B", "status", "Clean")); 282 perceptSequenceActions.put(ps, "Left"); 283 ps = new PerceptSequence( 284 new Percept("location", "A", "status", "Dirty"), new Percept( 285 "location", "B", "status", "Dirty"), new Percept( 286 "location", "B", "status", "Dirty")); 287 perceptSequenceActions.put(ps, "Suck"); 288 // 289 ps = new PerceptSequence( 290 new Percept("location", "B", "status", "Clean"), new Percept( 291 "location", "A", "status", "Clean"), new Percept( 292 "location", "A", "status", "Clean")); 293 perceptSequenceActions.put(ps, "Right"); 294 ps = new PerceptSequence( 295 new Percept("location", "B", "status", "Clean"), new Percept( 296 "location", "A", "status", "Clean"), new Percept( 297 "location", "A", "status", "Dirty")); 298 perceptSequenceActions.put(ps, "Suck"); 299 ps = new PerceptSequence( 300 new Percept("location", "B", "status", "Clean"), new Percept( 301 "location", "A", "status", "Clean"), new Percept( 302 "location", "B", "status", "Clean")); 303 perceptSequenceActions.put(ps, "Left"); 304 ps = new PerceptSequence( 305 new Percept("location", "B", "status", "Clean"), new Percept( 306 "location", "A", "status", "Clean"), new Percept( 307 "location", "B", "status", "Dirty")); 308 perceptSequenceActions.put(ps, "Suck"); 309 // 310 ps = new PerceptSequence( 311 new Percept("location", "B", "status", "Clean"), new Percept( 312 "location", "A", "status", "Dirty"), new Percept( 313 "location", "A", "status", "Clean")); 314 perceptSequenceActions.put(ps, "Right"); 315 ps = new PerceptSequence( 316 new Percept("location", "B", "status", "Clean"), new Percept( 317 "location", "A", "status", "Dirty"), new Percept( 318 "location", "A", "status", "Dirty")); 319 perceptSequenceActions.put(ps, "Suck"); 320 ps = new PerceptSequence( 321 new Percept("location", "B", "status", "Clean"), new Percept( 322 "location", "A", "status", "Dirty"), new Percept( 323 "location", "B", "status", "Clean")); 324 perceptSequenceActions.put(ps, "Left"); 325 ps = new PerceptSequence( 326 new Percept("location", "B", "status", "Clean"), new Percept( 327 "location", "A", "status", "Dirty"), new Percept( 328 "location", "B", "status", "Dirty")); 329 perceptSequenceActions.put(ps, "Suck"); 330 // 331 ps = new PerceptSequence( 332 new Percept("location", "B", "status", "Clean"), new Percept( 333 "location", "B", "status", "Clean"), new Percept( 334 "location", "A", "status", "Clean")); 335 perceptSequenceActions.put(ps, "Right"); 336 ps = new PerceptSequence( 337 new Percept("location", "B", "status", "Clean"), new Percept( 338 "location", "B", "status", "Clean"), new Percept( 339 "location", "A", "status", "Dirty")); 340 perceptSequenceActions.put(ps, "Suck"); 341 ps = new PerceptSequence( 342 new Percept("location", "B", "status", "Clean"), new Percept( 343 "location", "B", "status", "Clean"), new Percept( 344 "location", "B", "status", "Clean")); 345 perceptSequenceActions.put(ps, "Left"); 346 ps = new PerceptSequence( 347 new Percept("location", "B", "status", "Clean"), new Percept( 348 "location", "B", "status", "Clean"), new Percept( 349 "location", "B", "status", "Dirty")); 350 perceptSequenceActions.put(ps, "Suck"); 351 // 352 ps = new PerceptSequence( 353 new Percept("location", "B", "status", "Clean"), new Percept( 354 "location", "B", "status", "Dirty"), new Percept( 355 "location", "A", "status", "Clean")); 356 perceptSequenceActions.put(ps, "Right"); 357 ps = new PerceptSequence( 358 new Percept("location", "B", "status", "Clean"), new Percept( 359 "location", "B", "status", "Dirty"), new Percept( 360 "location", "A", "status", "Dirty")); 361 perceptSequenceActions.put(ps, "Suck"); 362 ps = new PerceptSequence( 363 new Percept("location", "B", "status", "Clean"), new Percept( 364 "location", "B", "status", "Dirty"), new Percept( 365 "location", "B", "status", "Clean")); 366 perceptSequenceActions.put(ps, "Left"); 367 ps = new PerceptSequence( 368 new Percept("location", "B", "status", "Clean"), new Percept( 369 "location", "B", "status", "Dirty"), new Percept( 370 "location", "B", "status", "Dirty")); 371 perceptSequenceActions.put(ps, "Suck"); 372 // 373 ps = new PerceptSequence( 374 new Percept("location", "B", "status", "Dirty"), new Percept( 375 "location", "A", "status", "Clean"), new Percept( 376 "location", "A", "status", "Clean")); 377 perceptSequenceActions.put(ps, "Right"); 378 ps = new PerceptSequence( 379 new Percept("location", "B", "status", "Dirty"), new Percept( 380 "location", "A", "status", "Clean"), new Percept( 381 "location", "A", "status", "Dirty")); 382 perceptSequenceActions.put(ps, "Suck"); 383 ps = new PerceptSequence( 384 new Percept("location", "B", "status", "Dirty"), new Percept( 385 "location", "A", "status", "Clean"), new Percept( 386 "location", "B", "status", "Clean")); 387 perceptSequenceActions.put(ps, "Left"); 388 ps = new PerceptSequence( 389 new Percept("location", "B", "status", "Dirty"), new Percept( 390 "location", "A", "status", "Clean"), new Percept( 391 "location", "B", "status", "Dirty")); 392 perceptSequenceActions.put(ps, "Suck"); 393 // 394 ps = new PerceptSequence( 395 new Percept("location", "B", "status", "Dirty"), new Percept( 396 "location", "A", "status", "Dirty"), new Percept( 397 "location", "A", "status", "Clean")); 398 perceptSequenceActions.put(ps, "Right"); 399 ps = new PerceptSequence( 400 new Percept("location", "B", "status", "Dirty"), new Percept( 401 "location", "A", "status", "Dirty"), new Percept( 402 "location", "A", "status", "Dirty")); 403 perceptSequenceActions.put(ps, "Suck"); 404 ps = new PerceptSequence( 405 new Percept("location", "B", "status", "Dirty"), new Percept( 406 "location", "A", "status", "Dirty"), new Percept( 407 "location", "B", "status", "Clean")); 408 perceptSequenceActions.put(ps, "Left"); 409 ps = new PerceptSequence( 410 new Percept("location", "B", "status", "Dirty"), new Percept( 411 "location", "A", "status", "Dirty"), new Percept( 412 "location", "B", "status", "Dirty")); 413 perceptSequenceActions.put(ps, "Suck"); 414 // 415 ps = new PerceptSequence( 416 new Percept("location", "B", "status", "Dirty"), new Percept( 417 "location", "B", "status", "Clean"), new Percept( 418 "location", "A", "status", "Clean")); 419 perceptSequenceActions.put(ps, "Right"); 420 ps = new PerceptSequence( 421 new Percept("location", "B", "status", "Dirty"), new Percept( 422 "location", "B", "status", "Clean"), new Percept( 423 "location", "A", "status", "Dirty")); 424 perceptSequenceActions.put(ps, "Suck"); 425 ps = new PerceptSequence( 426 new Percept("location", "B", "status", "Dirty"), new Percept( 427 "location", "B", "status", "Clean"), new Percept( 428 "location", "B", "status", "Clean")); 429 perceptSequenceActions.put(ps, "Left"); 430 ps = new PerceptSequence( 431 new Percept("location", "B", "status", "Dirty"), new Percept( 432 "location", "B", "status", "Clean"), new Percept( 433 "location", "B", "status", "Dirty")); 434 perceptSequenceActions.put(ps, "Suck"); 435 // 436 ps = new PerceptSequence( 437 new Percept("location", "B", "status", "Dirty"), new Percept( 438 "location", "B", "status", "Dirty"), new Percept( 439 "location", "A", "status", "Clean")); 440 perceptSequenceActions.put(ps, "Right"); 441 ps = new PerceptSequence( 442 new Percept("location", "B", "status", "Dirty"), new Percept( 443 "location", "B", "status", "Dirty"), new Percept( 444 "location", "A", "status", "Dirty")); 445 perceptSequenceActions.put(ps, "Suck"); 446 ps = new PerceptSequence( 447 new Percept("location", "B", "status", "Dirty"), new Percept( 448 "location", "B", "status", "Dirty"), new Percept( 449 "location", "B", "status", "Clean")); 450 perceptSequenceActions.put(ps, "Left"); 451 ps = new PerceptSequence( 452 new Percept("location", "B", "status", "Dirty"), new Percept( 453 "location", "B", "status", "Dirty"), new Percept( 454 "location", "B", "status", "Dirty")); 455 perceptSequenceActions.put(ps, "Suck"); 456 457 // 458 // Level 4: 4x4x4x4 states 459 // ... 460 461 return perceptSequenceActions; 462 } 463 }