mahoney@cs code$ pwd /var/www/cs/htdocs/courses/fall2007/ai/code/AIMA_lisp/code mahoney@cs code$ clisp -M "aima" i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo 8oooo `-__|__-' 8 8 8 8 8 | 8 o 8 8 o 8 8 ------+------ ooooo 8oooooo ooo8ooo ooooo 8 Copyright (c) Bruno Haible, Michael Stoll 1992, 1993 Copyright (c) Bruno Haible, Marcus Daniels 1994-1997 Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998 Copyright (c) Bruno Haible, Sam Steingold 1999-2000 Copyright (c) Sam Steingold, Bruno Haible 2001-2006 [1]> (test 'all) Testing System AGENTS ;;; Test agents in the vacuum and wumpus worlds. ;;; Here is how to run an environment, in this case the vacuum world. ;;; We specify the maximum number of steps, but that is optional: > (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :MAX-STEPS 10)) At Time step 0: |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | * | * | | * | | # | |----|----|----|----|----|----|----|----| 4 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 3 | # | | | | | | | # | |----|----|----|----|----|----|----|----| 2 | # | | * | | | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1> | * | | | | | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 At Time step 1: Agent [1 = -1] perceives (NIL NIL HOME) and does (TURN LEFT) |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | * | * | | * | | # | |----|----|----|----|----|----|----|----| 4 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 3 | # | | | | | | | # | |----|----|----|----|----|----|----|----| 2 | # | | * | | | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1^ | * | | | | | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 At Time step 2: Agent [1 = -2] perceives (NIL NIL HOME) and does (TURN LEFT) |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | * | * | | * | | # | |----|----|----|----|----|----|----|----| 4 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 3 | # | | | | | | | # | |----|----|----|----|----|----|----|----| 2 | # | | * | | | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1< | * | | | | | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 At Time step 3: Agent [1 = -3] perceives (NIL NIL HOME) and does SHUT-OFF |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | * | * | | * | | # | |----|----|----|----|----|----|----|----| 4 | # | | | | | | * | # | |----|----|----|----|----|----|----|----| 3 | # | | | | | | | # | |----|----|----|----|----|----|----|----| 2 | # | | * | | | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1 | * | | | | | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 # ;;; You can turn off the display (with :stream nil), and just see the results: > (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :STREAM NIL)) # ;;; You can customize several things, such as the agent(s) in the world. ;;; By default, a vacuum-world has a random-agent; we can change that to ;;; a slightly smarter agent with the :ASPEC (Agent SPECification) keyword: > (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :STREAM NIL :ASPEC '(REACTIVE-VACUUM-AGENT))) # ;;; We can change the probability of dirt in each cell using the :CSPEC ;;; keyword (Custom SPECification). It allows a complex language for ;;; specifying objects and where they go. > (RUN-ENVIRONMENT (MAKE-VACUUM-WORLD :CSPEC '((AT ALL (P 0.9 DIRT))) :MAX-STEPS 10)) At Time step 0: |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | | * | * | * | * | # | |----|----|----|----|----|----|----|----| 4 | # | | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 3 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 2 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1> | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 At Time step 1: Agent [1 = -1] perceives (NIL NIL HOME) and does SHUT-OFF |----|----|----|----|----|----|----|----| 7 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 6 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 5 | # | * | | * | * | * | * | # | |----|----|----|----|----|----|----|----| 4 | # | | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 3 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 2 | # | * | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 1 | # | 1 | * | * | * | * | * | # | |----|----|----|----|----|----|----|----| 0 | # | # | # | # | # | # | # | # | |----|----|----|----|----|----|----|----| 0 1 2 3 4 5 6 7 # ;;; Finally, we can compare 2 or more agents over a number of trials: > (AGENT-TRIALS 'MAKE-VACUUM-WORLD '(REACTIVE-VACUUM-AGENT RANDOM-VACUUM-AGENT) :N 10) 35.10 average for REACTIVE-VACUUM-AGENT -484.00 average for RANDOM-VACUUM-AGENT (35.1 -484.0) ;;; Now for the wumpus world > (RUN-ENVIRONMENT (MAKE-WUMPUS-WORLD :MAX-STEPS 10)) At Time step 0: |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | 1> | | | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 1: Agent [1 = -1] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | 1> | | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 2: Agent [1 = -2] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | 1> | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 3: Agent [1 = -3] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | | 1> | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 4: Agent [1 = -4] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | | 1> | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 5: Agent [1 = -5] perceives (NIL NIL NIL BUMP NIL) and does (TURN RIGHT) |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | | 1V | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 6: Agent [1 = -6] perceives (NIL NIL NIL NIL NIL) and does (TURN RIGHT) |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | | 1< | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 7: Agent [1 = -7] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | | 1< | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 8: Agent [1 = -8] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | 1< | | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 9: Agent [1 = -9] perceives (NIL NIL NIL NIL NIL) and does (TURN LEFT) |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | 1V | | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 At Time step 10: Agent [1 = -10] perceives (NIL NIL NIL NIL NIL) and does FORWARD |----|----|----|----|----|----| 5 | # | # | # | # | # | # | |----|----|----|----|----|----| 4 | # | $ | O | | W> | # | |----|----|----|----|----|----| 3 | # | | O | | | # | |----|----|----|----|----|----| 2 | # | | | | | # | |----|----|----|----|----|----| 1 | # | | 1V | | | # | |----|----|----|----|----|----| 0 | # | # | # | # | # | # | |----|----|----|----|----|----| 0 1 2 3 4 5 # 0 errors on system AGENTS Testing System SEARCH ;;; Test the code for Solving Problems by Searching ;;; Start with a trivial version of the missionaries and cannibals puzzle. > (SETQ P1 (MAKE-CANNIBAL-PROBLEM :INITIAL-STATE (MAKE-CANNIBAL-STATE :M1 2 :C1 1))) # ;;; We search for a solution node: > (SETQ RESULT (BREADTH-FIRST-SEARCH P1)) # ;;; We can get information out of that solution: > (SOLUTION-ACTIONS RESULT) ((2 0 1) (-1 0 -1) (1 1 1)) > (SOLUTION-NODES RESULT) (# # # #) ;;; Or we can use SOLVE to print the results nicely. By default, SOLVE uses A*-search, but you can give it another algorithm as the second arg. > (SOLVE P1) Action State ====== ===== (2 1 1 0 0 0) (1 1 1) (1 0 0 1 1 1) (-1 0 -1) (2 0 1 0 1 0) (2 0 1) (0 0 0 2 1 1) ====== ===== Total of 7 nodes expanded. # ;;; For the full 3 missionary and 3 cannibal problem, breadth-first-search ;;; is very inefficient. Better to use something that handles repeated states, ;;; like A*-search or no-duplicates-breadth-first-search: > (SOLVE (MAKE-CANNIBAL-PROBLEM) 'A*-SEARCH) Action State ====== ===== (3 3 1 0 0 0) (1 1 1) (2 2 0 1 1 1) (-1 0 -1) (3 2 1 0 1 0) (0 2 1) (3 0 0 0 3 1) (0 -1 -1) (3 1 1 0 2 0) (2 0 1) (1 1 0 2 2 1) (-1 -1 -1) (2 2 1 1 1 0) (2 0 1) (0 2 0 3 1 1) (0 -1 -1) (0 3 1 3 0 0) (0 2 1) (0 1 0 3 2 1) (0 -1 -1) (0 2 1 3 1 0) (0 2 1) (0 0 0 3 3 1) ====== ===== Total of 14 nodes expanded. # > (SOLVE (MAKE-CANNIBAL-PROBLEM) 'NO-DUPLICATES-BREADTH-FIRST-SEARCH) Action State ====== ===== (3 3 1 0 0 0) (1 1 1) (2 2 0 1 1 1) (-1 0 -1) (3 2 1 0 1 0) (0 2 1) (3 0 0 0 3 1) (0 -1 -1) (3 1 1 0 2 0) (2 0 1) (1 1 0 2 2 1) (-1 -1 -1) (2 2 1 1 1 0) (2 0 1) (0 2 0 3 1 1) (0 -1 -1) (0 3 1 3 0 0) (0 2 1) (0 1 0 3 2 1) (0 -1 -1) (0 2 1 3 1 0) (0 2 1) (0 0 0 3 3 1) ====== ===== Total of 14 nodes expanded. # ;;; Here is how to get a problem-solving agent to find the solution, ;;; and then go ahead and execute the actions that comprise the solution. > (RUN-ENVIRONMENT (PROBLEM->ENVIRONMENT P1)) At Time step 0: # At Time step 1: Agent [AGENT-BODY> = 0] perceives (2 1 1 0 0 0) and does (1 1 1) # At Time step 2: Agent [AGENT-BODY> = 0] perceives (1 0 0 1 1 1) and does (-1 0 -1) # At Time step 3: Agent [AGENT-BODY> = 1] perceives (2 0 1 0 1 0) and does (2 0 1) # # ;;; Now we look at the route-finding domain. ;;; First, solve the Arad-to-Bucharest problem with A*-search: > (SOLVE (MAKE-ROMANIAN-PROBLEM :INITIAL-STATE 'ARAD :GOAL 'BUCHAREST)) Action State ====== ===== ARAD SIBIU SIBIU RIMNICU RIMNICU PITESTI PITESTI BUCHAREST BUCHAREST ====== ===== Total of 5 nodes expanded. # ;;; Now turn it around: > (SOLVE (MAKE-ROMANIAN-PROBLEM :GOAL 'ARAD :INITIAL-STATE 'BUCHAREST)) Action State ====== ===== BUCHAREST PITESTI PITESTI RIMNICU RIMNICU SIBIU SIBIU ARAD ARAD ====== ===== Total of 4 nodes expanded. # ;;; Let's just see the actions: > (SOLUTION-ACTIONS (A*-SEARCH (MAKE-ROMANIAN-PROBLEM))) (SIBIU RIMNICU PITESTI BUCHAREST) ;;; Now on a random map: > (SOLVE (MAKE-ROUTE-FINDING-PROBLEM)) Action State ====== ===== A B B ====== ===== Total of 1 node expanded. # ;;; Here's how to compare several algorithms. > (SETQ SEARCHERS '(A*-SEARCH NO-CYCLES-DEPTH-FIRST-SEARCH NO-DUPLICATES-BREADTH-FIRST-SEARCH)) (A*-SEARCH NO-CYCLES-DEPTH-FIRST-SEARCH NO-DUPLICATES-BREADTH-FIRST-SEARCH) > (COMPARE-SEARCH-ALGORITHMS #'MAKE-ROUTE-FINDING-PROBLEM SEARCHERS) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 10 93.0 2.4 3.4 A*-SEARCH 10 179.0 3.7 26.6 NO-CYCLES-DEPTH-FIRST-SEARCH 10 109.1 2.0 6.2 NO-DUPLICATES-BREADTH-FIRST-SEARCH NIL > (COMPARE-SEARCH-ALGORITHMS #'MAKE-ROMANIAN-PROBLEM SEARCHERS :N 1) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 1 418.0 4.0 5.0 A*-SEARCH 1 607.0 5.0 5.0 NO-CYCLES-DEPTH-FIRST-SEARCH 1 450.0 3.0 11.0 NO-DUPLICATES-BREADTH-FIRST-SEARCH NIL > (COMPARE-SEARCH-ALGORITHMS #'MAKE-CANNIBAL-PROBLEM '(NO-RETURNS-BREADTH-FIRST-SEARCH A*-SEARCH NO-DUPLICATES-BREADTH-FIRST-SEARCH) :N 1) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 1 11.0 11.0 55.0 NO-RETURNS-BREADTH-FIRST-SEARCH 1 11.0 11.0 14.0 A*-SEARCH 1 11.0 11.0 14.0 NO-DUPLICATES-BREADTH-FIRST-SEARCH NIL > (COMPARE-SEARCH-ALGORITHMS #'MAKE-ROMANIAN-PROBLEM '(TREE-A*-SEARCH A*-SEARCH TREE-IDA*-SEARCH) :N 1) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 1 418.0 4.0 5.0 TREE-A*-SEARCH 1 418.0 4.0 5.0 A*-SEARCH 1 418.0 4.0 20.0 TREE-IDA*-SEARCH NIL ;;; We'll look at the iterative improvement algorithms on a harder map problem. > (SETQ SEARCHERS '(A*-SEARCH HILL-CLIMBING-SEARCH SIMULATED-ANNEALING-SEARCH)) (A*-SEARCH HILL-CLIMBING-SEARCH SIMULATED-ANNEALING-SEARCH) > (COMPARE-SEARCH-ALGORITHMS #'(LAMBDA NIL (MAKE-ROMANIAN-PROBLEM :GOAL 'IASI)) SEARCHERS :N 1) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 1 737.0 7.0 14.0 A*-SEARCH 0 0.0 0.0 3.0 HILL-CLIMBING-SEARCH 0 0.0 0.0 8.0 SIMULATED-ANNEALING-SEARCH NIL ;;; Let's take a look at the 8-puzzle: > (SOLVE (MAKE-8-PUZZLE-PROBLEM)) Action State ====== ===== 208503308 ^ 208555724 > 208555292 V 208378388 < 208798292 ^ 208837604 < 208837620 V 208836892 > 208801900 V 175367044 < 196624684 ^ 199808956 > 199768132 > 199348228 V 27397540 < 218716300 < 244225468 ^ 247940452 > 247893796 ====== ===== Total of 233 nodes expanded. # > (COMPARE-SEARCH-ALGORITHMS 'MAKE-8-PUZZLE-PROBLEM '(A*-SEARCH) :N 2) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 2 21.0 21.0 332.0 A*-SEARCH NIL ;;; And the path-planning problem among polygonal obstacles: > (SOLVE (MAKE-PATH-PLANNING-PROBLEM :SCENE *SCENE-4.17*)) Action State ====== ===== # (39 10) # (47 -35) # (22 -19) # (60 -33) # (59 -5) # (14 -5) # ====== ===== Total of 7 nodes expanded. #> ;;; Now the 8-queens problem > (SOLVE (MAKE-NQUEENS-PROBLEM) 'CSP-BACKTRACKING-SEARCH) Action State ====== ===== # (0 . 7) # (1 . 3) # (2 . 0) # (3 . 2) # (4 . 5) # (5 . 1) # (6 . 6) # (7 . 4) # ====== ===== Total of 113 nodes expanded. #> > (COMPARE-SEARCH-ALGORITHMS 'MAKE-NQUEENS-PROBLEM '(CSP-BACKTRACKING-SEARCH CSP-FORWARD-CHECKING-SEARCH) :N 1) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 1 8.0 8.0 113.0 CSP-BACKTRACKING-SEARCH 1 8.0 8.0 53.0 CSP-FORWARD-CHECKING-SEARCH NIL ;;; Here is the Travelling Salesperson Problem (TSP). > (SOLVE (MAKE-TSP-PROBLEM)) Action State ====== ===== ((F) (E D C B A)) E ((E F) (D C B A)) B ((B E F) (D C A)) A ((A B E F) (D C)) D ((D A B E F) (C)) C ((C D A B E F) NIL) F ((F C D A B E F) NIL) ====== ===== Total of 8 nodes expanded. # > (COMPARE-SEARCH-ALGORITHMS 'MAKE-TSP-PROBLEM '(A*-SEARCH GREEDY-SEARCH UNIFORM-COST-SEARCH) :N 5) Solved Cost Length Nodes Algorithm ====== ====== ====== ======= ========= 5 316.0 6.0 20.6 A*-SEARCH 5 341.0 6.0 6.0 GREEDY-SEARCH 5 446.0 6.0 326.0 UNIFORM-COST-SEARCH NIL ;;; Now we test the environments for 2-player and 3-player games: > (RUN-GAME (MAKE-TTT-GAME)) |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 X to move: X moved to (0 0). |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | X | - | - | |---|---|---| 0 1 2 O to move: O moved to (1 0). |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | X | O | - | |---|---|---| 0 1 2 X to move: X moved to (1 2). |---|---|---| 2 | - | X | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | X | O | - | |---|---|---| 0 1 2 O to move: O moved to (2 2). |---|---|---| 2 | - | X | O | |---|---|---| 1 | - | - | - | |---|---|---| 0 | X | O | - | |---|---|---| 0 1 2 X to move: X moved to (2 1). |---|---|---| 2 | - | X | O | |---|---|---| 1 | - | - | X | |---|---|---| 0 | X | O | - | |---|---|---| 0 1 2 O to move: O moved to (2 0). |---|---|---| 2 | - | X | O | |---|---|---| 1 | - | - | X | |---|---|---| 0 | X | O | O | |---|---|---| 0 1 2 X to move: X moved to (1 1). |---|---|---| 2 | - | X | O | |---|---|---| 1 | - | X | X | |---|---|---| 0 | X | O | O | |---|---|---| 0 1 2 O to move: O moved to (0 1). |---|---|---| 2 | - | X | O | |---|---|---| 1 | O | X | X | |---|---|---| 0 | X | O | O | |---|---|---| 0 1 2 X to move: X moved to (0 2). |---|---|---| 2 | X | X | O | |---|---|---| 1 | O | X | X | |---|---|---| 0 | X | O | O | |---|---|---| 0 1 2 O to move: # > (RUN-GAME (MAKE-COGNAC-GAME :PLAYERS '(X O @))) |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 X to move: X moved to (1 0). |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | - | X | - | |---|---|---| 0 1 2 O to move: O moved to (1 1). |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | X | - | |---|---|---| 0 1 2 @ to move: @ moved to (2 0). |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | X | @ | |---|---|---| 0 1 2 X to move: X moved to (1 2). |---|---|---| 2 | - | X | - | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | X | @ | |---|---|---| 0 1 2 O to move: O moved to (2 1). |---|---|---| 2 | - | X | - | |---|---|---| 1 | - | O | O | |---|---|---| 0 | - | X | @ | |---|---|---| 0 1 2 @ to move: @ moved to (2 2). |---|---|---| 2 | - | X | @ | |---|---|---| 1 | - | O | O | |---|---|---| 0 | - | X | @ | |---|---|---| 0 1 2 X to move: X moved to (0 0). |---|---|---| 2 | - | X | @ | |---|---|---| 1 | - | O | O | |---|---|---| 0 | X | X | @ | |---|---|---| 0 1 2 O to move: O moved to (0 1). |---|---|---| 2 | - | X | @ | |---|---|---| 1 | O | O | O | |---|---|---| 0 | X | X | @ | |---|---|---| 0 1 2 @ to move: # ;;; Now we see that 2x2 tic-tac-toe is a win for the first player, X. > (RUN-GAME (MAKE-TTT-GAME :N 2) :AGENTS '(ALPHA-BETA-TTT-AGENT ALPHA-BETA-TTT-AGENT)) |---|---| 1 | - | - | |---|---| 0 | - | - | |---|---| 0 1 X to move: X moved to (1 1). |---|---| 1 | - | X | |---|---| 0 | - | - | |---|---| 0 1 O to move: O moved to (1 0). |---|---| 1 | - | X | |---|---| 0 | - | O | |---|---| 0 1 X to move: X moved to (0 1). |---|---| 1 | X | X | |---|---| 0 | - | O | |---|---| 0 1 O to move: # ;;; In a full 3x3 game, alpha-beta search (playing O) often wins. > (RUN-GAME (MAKE-TTT-GAME) :AGENTS '(RANDOM-GAME-AGENT ALPHA-BETA-TTT-AGENT)) |---|---|---| 2 | - | - | - | |---|---|---| 1 | - | - | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 X to move: X moved to (2 2). |---|---|---| 2 | - | - | X | |---|---|---| 1 | - | - | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 O to move: O moved to (1 1). |---|---|---| 2 | - | - | X | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 X to move: X moved to (0 2). |---|---|---| 2 | X | - | X | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 O to move: O moved to (1 2). |---|---|---| 2 | X | O | X | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | - | - | |---|---|---| 0 1 2 X to move: X moved to (2 0). |---|---|---| 2 | X | O | X | |---|---|---| 1 | - | O | - | |---|---|---| 0 | - | - | X | |---|---|---| 0 1 2 O to move: O moved to (2 1). |---|---|---| 2 | X | O | X | |---|---|---| 1 | - | O | O | |---|---|---| 0 | - | - | X | |---|---|---| 0 1 2 X to move: X moved to (1 0). |---|---|---| 2 | X | O | X | |---|---|---| 1 | - | O | O | |---|---|---| 0 | - | X | X | |---|---|---| 0 1 2 O to move: O moved to (0 1). |---|---|---| 2 | X | O | X | |---|---|---| 1 | O | O | O | |---|---|---| 0 | - | X | X | |---|---|---| 0 1 2 X to move: # 0 errors on system SEARCH Testing System LOGIC ;;; Some simple examples in Propositional Logic ;;; First, just test the infix reader. > (LOGIC "P=>Q <=> ~Q=>~P") (<=> (=> P Q) (=> (NOT Q) (NOT P))) ;;; Print a truth table, as on [p 169]. > (TRUTH-TABLE "(P | H) ^ ~H => P") ----------------------------------------------------------- P H P | H ~ H (P | H) ^ (~ H) ((P | H) ^ (~ H)) => P ----------------------------------------------------------- F F F T F T T F T T T T F T T F F T T T T F F T ----------------------------------------------------------- NIL ;;; Some simple examples > (VALIDITY "P=>Q <=> ~Q=>~P") VALID > (VALIDITY "SillyQuestion") SATISFIABLE > (VALIDITY "~SillyQuestion") SATISFIABLE > (VALIDITY "ToBe or not ToBe") VALID > (VALIDITY "ToBe and not ToBe") UNSATISFIABLE > (VALIDITY "((S => W1|W2|W3|W4) ^ S ^ (~W1^~W2^~W3)) => W4") VALID > (VALIDITY "Ok ^ (Ok <=> ~W^~P) => ~W") VALID > (SETF KB (MAKE-PROP-KB)) # > (TELL KB "S => W1|W2|W3|W4") T > (TELL KB "S") T > (TELL KB "~W1") T > (TELL KB "~W2") T > (ASK KB "W4") NIL > (TELL KB "~W3") T > (ASK KB "W4") T > (TELL KB "Ok <=> ~W ^ ~P") T > (TELL KB "Ok") T > (ASK KB "W") NIL > (ASK KB "~W") T > (TELL KB "ToBe and ~ToBe") T > (ASK KB "SillyQuestion") T ;;; A look at Normal forms (conjunctive, implicative, and Horn). > (->CNF '(<=> P Q)) (AND (OR P (NOT Q)) (OR (NOT P) Q)) > (->INF '(<=> P Q)) (AND (=> Q P) (=> P Q)) > (->HORN '(<=> P Q)) (AND (=> Q P) (=> P Q)) > (->CNF '(=> (NOT P) R)) (OR R P) > (->INF '(=> (NOT P) R)) (=> TRUE (OR R P)) ;;; Use the KB to solve the `Wumpus at [1,3]' problem [p 174-176]. ;;; This builds a KB with 12 propositional symbols -- about the max. ;;; you can do without starting to slow down. > (SETQ KB1 (MAKE-PROP-KB)) # ;;; The initial state of knowledge > (TELL KB1 "~S11 ^ ~S21 ^S12 ^ ~B11 ^ B21 ^ ~B12") T ;;; Rules R1 through R4 > (TELL KB1 "~S11 => ~W11 ^ ~W12 ^ ~W21") T > (TELL KB1 "~S21 => ~W11 ^ ~W21 ^ ~W22 ^ ~W31") T > (TELL KB1 "~S12 => ~W11 ^ ~W12 ^ ~W22 ^ ~W13") T > (TELL KB1 "S12 => W13 | W12 | W22 | W11") T ;;; Now the query -- this may take a while. > (ASK KB1 "W13") T ;;; Now a quick demo of the Horn Logic backward chainer. > (SETF KB2 (MAKE-HORN-KB)) # ;;; Now we define the Member predicate. > (TELL KB2 "Member(x,Cons(x,y))") NIL > (TELL KB2 "Member(x,rest) => Member(x,Cons(y,rest))") NIL > (ASK-EACH KB2 "Member(x,Cons(1,Cons(2,Cons(3,Nil))))" #'PRINT) (($Y.553 CONS 2 (CONS 3 |Nil|)) ($X.552 . 1) ($X . $X.552)) (($Y.558 CONS 3 |Nil|) ($X.557 . 2) ($X.554 . $X.557) ($REST.556 CONS 2 (CONS 3 |Nil|)) ($Y.555 . 1) ($X . $X.554)) (($Y.563 . |Nil|) ($X.562 . 3) ($X.559 . $X.562) ($REST.561 CONS 3 |Nil|) ($Y.560 . 2) ($X.554 . $X.559) ($REST.556 CONS 2 (CONS 3 |Nil|)) ($Y.555 . 1) ($X . $X.554)) NIL > (ASK-PATTERNS KB2 "Member(x,Cons(1,Cons(2,Cons(3,Nil))))" "x") (1 2 3) > (ASK-PATTERN KB2 "Member(x,Cons(1,Cons(2,Cons(3,Nil)))) & x=2" "x") 2 > (ASK-PATTERNS KB2 "s = Cons(1,Cons(2,Nil)) & Member(x,s) & Member(y,s)" '($X $Y)) ((1 1) (1 2) (2 1) (2 2)) ;;; A family relationships knowledge base and problem. > (TELL KB2 '(MOTHER GERDA PETER)) NIL > (TELL KB2 '(FATHER TORSTEN PETER)) NIL > (TELL KB2 '(FATHER PETER ISABELLA)) NIL > (TELL KB2 '(FATHER PETER JULIET)) NIL > (TELL KB2 '(=> (MOTHER $X $Y) (PARENT $X $Y))) NIL > (TELL KB2 '(=> (FATHER $X $Y) (PARENT $X $Y))) NIL > (TELL KB2 '(=> (AND (PARENT $G $P) (PARENT $P $C)) (GRAND-PARENT $G $C))) NIL > (ASK-PATTERNS KB2 '(GRAND-PARENT $X $Y)) ((GRAND-PARENT GERDA ISABELLA) (GRAND-PARENT GERDA JULIET) (GRAND-PARENT TORSTEN ISABELLA) (GRAND-PARENT TORSTEN JULIET)) ;;; Now the 'Criminal' problem from [p 271-272]. > (SETF KB3 (MAKE-HORN-KB)) # > (TELL KB3 "American(x) ^ Weapon(y) ^ Nation(z) ^ Hostile(z) ^ Sells(x,z,y) => Criminal(x)") NIL > (TELL KB3 "Owns(Nono,M1)") NIL > (TELL KB3 "Missle(M1)") NIL > (TELL KB3 "Owns(Nono,x) ^ Missle(x) => Sells(West,Nono,x)") NIL > (TELL KB3 "Missle(x) => Weapon(x)") NIL > (TELL KB3 "Enemy(x,America) => Hostile(x)") NIL > (TELL KB3 "American(West)") NIL > (TELL KB3 "Nation(Nono)") NIL > (TELL KB3 "Enemy(Nono,America)") NIL > (TELL KB3 "Nation(America)") NIL > (ASK KB3 "Criminal(West)") T > (ASK-PATTERN KB3 "Criminal(x)" "x") WEST 0 errors on system LOGIC Testing System PLANNING 0 errors on system PLANNING Testing System UNCERTAINTY ;;; Test code for reasoning with uncertainty. Currently, just MDPs. ;;; Given the MDP (Markov Decision Process) for the 4x3 grid from Ch.s 17, 20, ;;; create an agent, and an environment corresponding to the MDP. > (SETQ AGENT (MAKE-MDP-AGENT :MDP *4X3-MDP* :ALGORITHM 'VALUE-ITERATION-POLICY)) [NIL = 0] > (SETQ ENV (MAKE-MDP-ENVIRONMENT :MDP *4X3-MDP* :AGENTS (LIST AGENT))) # ;;; Now run the agent in the environment. ;;; If all goes well, we get to the (4 3) terminal square. > (RUN-ENVIRONMENT ENV) At Time step 0: # At Time step 1: Agent [1 = -0.04] perceives ((1 1) -0.04 NIL) and does UP # At Time step 2: Agent [1 = -0.08] perceives ((1 1) -0.04 NIL) and does UP # At Time step 3: Agent [1 = -0.12] perceives ((1 2) -0.04 NIL) and does UP # At Time step 4: Agent [1 = -0.16] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 5: Agent [1 = -0.19999999] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 6: Agent [1 = -0.23999998] perceives ((3 3) -0.04 NIL) and does RIGHT # At Time step 7: Agent [1 = 0.76] perceives ((4 3) 1 T) and does DOWN # # 0 errors on system UNCERTAINTY Testing System LEARNING > (SETQ P *RESTAURANT-BOOLEAN-PROBLEM*) # > (SETQ E (LEARNING-PROBLEM-EXAMPLES P) G (LEARNING-PROBLEM-GOALS P)) ((WILLWAIT 1 0)) > (SETQ H (DECISION-LIST-LEARNING 4 P)) ((0 ((PATRONS 1 0) . 0)) (1 ((BAR 1 0) . 0) ((ALTERNATE 1 0) . 0)) (1 ((FRI/SAT 1 0) . 0) ((ALTERNATE 1 0) . 0)) (0 ((ALTERNATE 1 0) . 0)) (0 ((HUNGRY 1 0) . 0)) (1 ((FRI/SAT 1 0) . 1) ((BAR 1 0) . 0)) (0 ((PATRONS 1 0) . 1) ((BAR 1 0) . 0)) (1 ((BAR 1 0) . 0)) (1 ((RESERVATION 1 0) . 0)) (0) (0)) > (ACCURACY H #'DLPREDICT E G) 1.0 > (SETQ P *RESTAURANT-MULTIVALUED-PROBLEM*) # > (SETQ E (LEARNING-PROBLEM-EXAMPLES P) G (LEARNING-PROBLEM-GOALS P)) ((WILLWAIT YES NO)) > (SETQ H (DECISION-TREE-LEARNING P)) ((PATRONS NONE SOME FULL) (FULL (HUNGRY YES NO) (NO . NO) (YES (TYPE FRENCH ITALIAN THAI BURGER) (BURGER . YES) (THAI (FRI/SAT YES NO) (NO . NO) (YES . YES)) (ITALIAN . NO) (FRENCH . YES))) (SOME . YES) (NONE . NO)) > (ACCURACY H #'DTPREDICT E G) 1.0 > (SETQ P *MAJORITY-BOOLEAN-PROBLEM*) # > (SETQ E (LEARNING-PROBLEM-EXAMPLES P) A (LEARNING-PROBLEM-ATTRIBUTES P) G (LEARNING-PROBLEM-GOALS P)) ((G1 0 1)) > (SETQ H (NN-LEARNING P (MAKE-PERCEPTRON 11 1) #'PERCEPTRON-UPDATE)) ((#S(UNIT :PARENTS (0 1 2 3 4 5 6 7 8 9 10 11) :CHILDREN NIL :WEIGHTS (2.4555497 0.40535638 0.5929339 0.45184746 0.5059462 0.36152416 0.60977346 0.35713696 0.5029692 0.44402066 0.44361803 0.27438447) :G # :DG NIL :A 0 :IN -0.082589805 :GRADIENT 0))) > (ACCURACY H #'(LAMBDA (E1 H1) (NN-OUTPUT E1 H1 A G)) E G) 1.0 > (SETQ P *RESTAURANT-REAL12-PROBLEM*) # > (SETQ E (LEARNING-PROBLEM-EXAMPLES P) A (LEARNING-PROBLEM-ATTRIBUTES P) G (LEARNING-PROBLEM-GOALS P)) ((WILLWAIT 1 0)) > (SETQ H (NN-LEARNING P (MAKE-CONNECTED-NN '(10 4 1)) #'BACKPROP-UPDATE)) ((#S(UNIT :PARENTS (0 1 2 3 4 5 6 7 8 9 10) :CHILDREN (1) :WEIGHTS (0.70670617 0.5395565 1.1241872 1.5089221 -1.594226 0.055378713 0.91806716 0.012949398 -0.19064291 -0.009884756 1.7385197) :G # :DG # :A 0.8577068 :IN 1.7963722 :GRADIENT 0.12204585) #S(UNIT :PARENTS (0 1 2 3 4 5 6 7 8 9 10) :CHILDREN (1) :WEIGHTS (-0.19062807 -0.9816312 0.34351867 0.2461764 1.615181 0.51929224 -1.8934634 -0.24386598 -1.405498 -1.2645328 -1.2564315) :G # :DG # :A 0.78666675 :IN 1.3049493 :GRADIENT 0.16782217) #S(UNIT :PARENTS (0 1 2 3 4 5 6 7 8 9 10) :CHILDREN (1) :WEIGHTS (1.2629097 -1.3740617 2.7876792 2.4048836 2.408191 1.0014293 1.0787929 -2.7804623 3.0536792 -0.87113494 -4.033219) :G # :DG # :A 0.9810831 :IN 3.9486024 :GRADIENT 0.018559055) #S(UNIT :PARENTS (0 1 2 3 4 5 6 7 8 9 10) :CHILDREN (1) :WEIGHTS (0.12006151 0.63415706 -0.16871245 -0.004713215 0.4199728 0.35066494 0.43083704 -0.45257133 0.43460086 -0.06654046 -0.24793041) :G # :DG # :A 0.72856265 :IN 0.9873424 :GRADIENT 0.1977591)) (#S(UNIT :PARENTS (0 1 2 3 4) :CHILDREN NIL :WEIGHTS (2.7894208 -4.22417 3.2617662 6.207698 -1.006933) :G # :DG # :A 0.8190696 :IN 1.5100565 :GRADIENT 0.14819458))) > (ACCURACY H #'(LAMBDA (E1 H1) (NN-OUTPUT E1 H1 A G)) E G #'RMS-ERROR) 0.8820836 > (SETQ A (MAKE-MDP-AGENT :NAME 'LM :PROGRAM (MAKE-PASSIVE-LMS-LEARNER))) [LM = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-PASSIVE-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [LM = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 2: Agent [LM = 0] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 3: Agent [LM = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 4: Agent [LM = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 5: Agent [LM = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 6: Agent [LM = 0] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 7: Agent [LM = 0] perceives ((3 1) 0 NIL) and does NO-OP # At Time step 8: Agent [LM = 0] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 9: Agent [LM = 0] perceives ((3 1) 0 NIL) and does NO-OP # At Time step 10: Agent [LM = 0] perceives ((4 1) 0 NIL) and does NO-OP # At Time step 11: Agent [LM = -1] perceives ((4 2) -1 T) and does NO-OP # At Time step 12: Agent [LM = -1] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 13: Agent [LM = -1] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 14: Agent [LM = -1] perceives ((3 1) 0 NIL) and does NO-OP # At Time step 15: Agent [LM = -1] perceives ((4 1) 0 NIL) and does NO-OP # At Time step 16: Agent [LM = -1] perceives ((3 1) 0 NIL) and does NO-OP # At Time step 17: Agent [LM = -1] perceives ((3 2) 0 NIL) and does NO-OP # At Time step 18: Agent [LM = -2] perceives ((4 2) -1 T) and does NO-OP # # > (SETQ A (MAKE-MDP-AGENT :NAME 'TD :PROGRAM (MAKE-PASSIVE-TD-LEARNER))) [TD = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-PASSIVE-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 2: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 3: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 4: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 5: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 6: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 7: Agent [TD = 0] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 8: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 9: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 10: Agent [TD = 0] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 11: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 12: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 13: Agent [TD = 0] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 14: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 15: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 16: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 17: Agent [TD = 0] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 18: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 19: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 20: Agent [TD = 0] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 21: Agent [TD = 0] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 22: Agent [TD = 0] perceives ((2 1) 0 NIL) and does NO-OP # At Time step 23: Agent [TD = 0] perceives ((3 1) 0 NIL) and does NO-OP # At Time step 24: Agent [TD = 0] perceives ((3 2) 0 NIL) and does NO-OP # At Time step 25: Agent [TD = 0] perceives ((3 3) 0 NIL) and does NO-OP # At Time step 26: Agent [TD = 1] perceives ((4 3) 1 T) and does NO-OP # At Time step 27: Agent [TD = 1] perceives ((1 1) 0 NIL) and does NO-OP # At Time step 28: Agent [TD = 1] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 29: Agent [TD = 1] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 30: Agent [TD = 1] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 31: Agent [TD = 1] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 32: Agent [TD = 1] perceives ((1 2) 0 NIL) and does NO-OP # At Time step 33: Agent [TD = 1] perceives ((1 3) 0 NIL) and does NO-OP # At Time step 34: Agent [TD = 1] perceives ((2 3) 0 NIL) and does NO-OP # At Time step 35: Agent [TD = 1] perceives ((3 3) 0 NIL) and does NO-OP # At Time step 36: Agent [TD = 1] perceives ((3 2) 0 NIL) and does NO-OP # At Time step 37: Agent [TD = 0] perceives ((4 2) -1 T) and does NO-OP # # > (SETQ A (MAKE-MDP-AGENT :NAME 'MA :PROGRAM (MAKE-MAXIMIZING-ADP-LEARNER '(LEFT RIGHT UP DOWN)))) [MA = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [MA = -0.04] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 2: Agent [MA = -0.08] perceives ((1 1) -0.04 NIL) and does UP # At Time step 3: Agent [MA = -0.12] perceives ((2 1) -0.04 NIL) and does UP # At Time step 4: Agent [MA = -0.16] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 5: Agent [MA = -0.19999999] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 6: Agent [MA = -0.23999998] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 7: Agent [MA = -0.27999997] perceives ((3 1) -0.04 NIL) and does UP # At Time step 8: Agent [MA = -0.31999996] perceives ((3 2) -0.04 NIL) and does RIGHT # At Time step 9: Agent [MA = -1.3199999] perceives ((4 2) -1 T) and does UP # At Time step 10: Agent [MA = -1.3599999] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 11: Agent [MA = -1.3999999] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 12: Agent [MA = -1.4399998] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 13: Agent [MA = -1.4799998] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 14: Agent [MA = -1.5199997] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 15: Agent [MA = -1.5599997] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 16: Agent [MA = -1.5999997] perceives ((3 2) -0.04 NIL) and does RIGHT # At Time step 17: Agent [MA = -1.6399996] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 18: Agent [MA = -1.6799996] perceives ((3 2) -0.04 NIL) and does UP # At Time step 19: Agent [MA = -1.7199996] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 20: Agent [MA = -1.7599995] perceives ((3 3) -0.04 NIL) and does RIGHT # At Time step 21: Agent [MA = -0.7599995] perceives ((4 3) 1 T) and does LEFT # # > (SETQ A (MAKE-MDP-AGENT :NAME 'QI :PROGRAM (MAKE-MAXIMIZING-QI-LEARNER '(LEFT RIGHT UP DOWN)))) [QI = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [QI = -0.04] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 2: Agent [QI = -0.08] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 3: Agent [QI = -0.12] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 4: Agent [QI = -0.16] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 5: Agent [QI = -0.19999999] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 6: Agent [QI = -0.23999998] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 7: Agent [QI = -0.27999997] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 8: Agent [QI = -0.31999996] perceives ((2 1) -0.04 NIL) and does UP # At Time step 9: Agent [QI = -0.35999995] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 10: Agent [QI = -0.39999995] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 11: Agent [QI = -0.43999994] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 12: Agent [QI = -0.47999993] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 13: Agent [QI = -0.5199999] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 14: Agent [QI = -0.55999994] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 15: Agent [QI = -0.59999996] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 16: Agent [QI = -0.64] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 17: Agent [QI = -0.68] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 18: Agent [QI = -0.72] perceives ((3 1) -0.04 NIL) and does UP # At Time step 19: Agent [QI = -0.76000005] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 20: Agent [QI = -0.8000001] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 21: Agent [QI = -0.8400001] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 22: Agent [QI = -1.8400002] perceives ((4 2) -1 T) and does RIGHT # At Time step 23: Agent [QI = -1.8800001] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 24: Agent [QI = -1.9200001] perceives ((1 1) -0.04 NIL) and does UP # At Time step 25: Agent [QI = -1.96] perceives ((1 2) -0.04 NIL) and does UP # At Time step 26: Agent [QI = -2.0] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 27: Agent [QI = -2.04] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 28: Agent [QI = -2.08] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 29: Agent [QI = -2.12] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 30: Agent [QI = -2.1599998] perceives ((1 3) -0.04 NIL) and does UP # At Time step 31: Agent [QI = -2.1999998] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 32: Agent [QI = -2.2399998] perceives ((2 3) -0.04 NIL) and does UP # At Time step 33: Agent [QI = -2.2799997] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 34: Agent [QI = -2.3199997] perceives ((3 3) -0.04 NIL) and does UP # At Time step 35: Agent [QI = -2.3599997] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 36: Agent [QI = -2.3999996] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 37: Agent [QI = -2.4399996] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 38: Agent [QI = -2.4799995] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 39: Agent [QI = -2.5199995] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 40: Agent [QI = -2.5599995] perceives ((3 2) -0.04 NIL) and does RIGHT # At Time step 41: Agent [QI = -3.5599995] perceives ((4 2) -1 T) and does DOWN # # > (SETQ A (MAKE-MDP-AGENT :NAME 'EA :PROGRAM (MAKE-EXPLORING-ADP-LEARNER '(LEFT RIGHT UP DOWN)))) [EA = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [EA = -0.04] perceives ((1 1) -0.04 NIL) and does UP # At Time step 2: Agent [EA = -0.08] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 3: Agent [EA = -0.12] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 4: Agent [EA = -0.16] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 5: Agent [EA = -0.19999999] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 6: Agent [EA = -0.23999998] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 7: Agent [EA = -0.27999997] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 8: Agent [EA = -0.31999996] perceives ((4 1) -0.04 NIL) and does RIGHT # At Time step 9: Agent [EA = -0.35999995] perceives ((4 1) -0.04 NIL) and does UP # At Time step 10: Agent [EA = -1.3599999] perceives ((4 2) -1 T) and does LEFT # At Time step 11: Agent [EA = -1.3999999] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 12: Agent [EA = -1.4399998] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 13: Agent [EA = -1.4799998] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 14: Agent [EA = -1.5199997] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 15: Agent [EA = -1.5599997] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 16: Agent [EA = -1.5999997] perceives ((2 1) -0.04 NIL) and does UP # At Time step 17: Agent [EA = -1.6399996] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 18: Agent [EA = -1.6799996] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 19: Agent [EA = -1.7199996] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 20: Agent [EA = -1.7599995] perceives ((1 1) -0.04 NIL) and does UP # At Time step 21: Agent [EA = -1.7999995] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 22: Agent [EA = -1.8399994] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 23: Agent [EA = -1.8799994] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 24: Agent [EA = -1.9199994] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 25: Agent [EA = -1.9599993] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 26: Agent [EA = -1.9999993] perceives ((2 1) -0.04 NIL) and does UP # At Time step 27: Agent [EA = -2.0399992] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 28: Agent [EA = -2.0799992] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 29: Agent [EA = -2.1199992] perceives ((3 3) -0.04 NIL) and does UP # At Time step 30: Agent [EA = -2.1599991] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 31: Agent [EA = -2.199999] perceives ((3 2) -0.04 NIL) and does UP # At Time step 32: Agent [EA = -2.239999] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 33: Agent [EA = -2.279999] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 34: Agent [EA = -2.319999] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 35: Agent [EA = -2.359999] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 36: Agent [EA = -2.399999] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 37: Agent [EA = -2.4399989] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 38: Agent [EA = -2.4799988] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 39: Agent [EA = -2.5199988] perceives ((3 2) -0.04 NIL) and does UP # At Time step 40: Agent [EA = -2.5599988] perceives ((3 3) -0.04 NIL) and does UP # At Time step 41: Agent [EA = -2.5999987] perceives ((3 3) -0.04 NIL) and does UP # At Time step 42: Agent [EA = -2.6399987] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 43: Agent [EA = -2.6799986] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 44: Agent [EA = -2.7199986] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 45: Agent [EA = -2.7599986] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 46: Agent [EA = -2.7999985] perceives ((3 1) -0.04 NIL) and does DOWN # At Time step 47: Agent [EA = -2.8399985] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 48: Agent [EA = -2.8799984] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 49: Agent [EA = -2.9199984] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 50: Agent [EA = -2.9599984] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 51: Agent [EA = -2.9999983] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 52: Agent [EA = -3.0399983] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 53: Agent [EA = -3.0799983] perceives ((1 1) -0.04 NIL) and does UP # At Time step 54: Agent [EA = -3.1199982] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 55: Agent [EA = -3.1599982] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 56: Agent [EA = -3.1999981] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 57: Agent [EA = -3.239998] perceives ((1 1) -0.04 NIL) and does UP # At Time step 58: Agent [EA = -3.279998] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 59: Agent [EA = -3.319998] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 60: Agent [EA = -3.359998] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 61: Agent [EA = -3.399998] perceives ((1 2) -0.04 NIL) and does UP # At Time step 62: Agent [EA = -3.439998] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 63: Agent [EA = -3.4799979] perceives ((1 2) -0.04 NIL) and does UP # At Time step 64: Agent [EA = -3.5199978] perceives ((1 2) -0.04 NIL) and does UP # At Time step 65: Agent [EA = -3.5599978] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 66: Agent [EA = -3.5999978] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 67: Agent [EA = -3.6399977] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 68: Agent [EA = -3.6799977] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 69: Agent [EA = -3.7199976] perceives ((1 2) -0.04 NIL) and does UP # At Time step 70: Agent [EA = -3.7599976] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 71: Agent [EA = -3.7999976] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 72: Agent [EA = -3.8399975] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 73: Agent [EA = -3.8799975] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 74: Agent [EA = -3.9199975] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 75: Agent [EA = -3.9599974] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 76: Agent [EA = -3.9999974] perceives ((2 3) -0.04 NIL) and does UP # At Time step 77: Agent [EA = -4.0399976] perceives ((2 3) -0.04 NIL) and does UP # At Time step 78: Agent [EA = -4.0799975] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 79: Agent [EA = -4.1199975] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 80: Agent [EA = -4.1599975] perceives ((2 3) -0.04 NIL) and does UP # At Time step 81: Agent [EA = -4.1999974] perceives ((2 3) -0.04 NIL) and does UP # At Time step 82: Agent [EA = -4.2399974] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 83: Agent [EA = -4.2799973] perceives ((3 3) -0.04 NIL) and does UP # At Time step 84: Agent [EA = -4.3199973] perceives ((3 3) -0.04 NIL) and does UP # At Time step 85: Agent [EA = -4.3599973] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 86: Agent [EA = -4.399997] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 87: Agent [EA = -4.439997] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 88: Agent [EA = -4.479997] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 89: Agent [EA = -4.519997] perceives ((2 3) -0.04 NIL) and does UP # At Time step 90: Agent [EA = -4.559997] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 91: Agent [EA = -4.599997] perceives ((3 3) -0.04 NIL) and does DOWN # At Time step 92: Agent [EA = -4.639997] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 93: Agent [EA = -4.679997] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 94: Agent [EA = -4.719997] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 95: Agent [EA = -4.759997] perceives ((3 1) -0.04 NIL) and does UP # At Time step 96: Agent [EA = -4.799997] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 97: Agent [EA = -4.839997] perceives ((3 3) -0.04 NIL) and does LEFT # At Time step 98: Agent [EA = -4.879997] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 99: Agent [EA = -4.9199967] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 100: Agent [EA = -4.9599967] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 101: Agent [EA = -4.9999967] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 102: Agent [EA = -5.0399966] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 103: Agent [EA = -5.0799966] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 104: Agent [EA = -5.1199965] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 105: Agent [EA = -5.1599965] perceives ((1 1) -0.04 NIL) and does UP # At Time step 106: Agent [EA = -5.1999965] perceives ((1 2) -0.04 NIL) and does UP # At Time step 107: Agent [EA = -5.2399964] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 108: Agent [EA = -5.2799964] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 109: Agent [EA = -5.3199964] perceives ((1 2) -0.04 NIL) and does UP # At Time step 110: Agent [EA = -5.3599963] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 111: Agent [EA = -5.3999963] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 112: Agent [EA = -5.4399962] perceives ((1 2) -0.04 NIL) and does UP # At Time step 113: Agent [EA = -5.479996] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 114: Agent [EA = -5.519996] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 115: Agent [EA = -5.559996] perceives ((1 2) -0.04 NIL) and does UP # At Time step 116: Agent [EA = -5.599996] perceives ((1 2) -0.04 NIL) and does UP # At Time step 117: Agent [EA = -5.639996] perceives ((1 3) -0.04 NIL) and does UP # At Time step 118: Agent [EA = -5.679996] perceives ((1 3) -0.04 NIL) and does UP # At Time step 119: Agent [EA = -5.719996] perceives ((1 3) -0.04 NIL) and does UP # At Time step 120: Agent [EA = -5.759996] perceives ((1 3) -0.04 NIL) and does UP # At Time step 121: Agent [EA = -5.799996] perceives ((1 3) -0.04 NIL) and does UP # At Time step 122: Agent [EA = -5.839996] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 123: Agent [EA = -5.879996] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 124: Agent [EA = -5.919996] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 125: Agent [EA = -5.9599957] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 126: Agent [EA = -5.9999957] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 127: Agent [EA = -6.0399957] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 128: Agent [EA = -6.0799956] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 129: Agent [EA = -6.1199956] perceives ((3 3) -0.04 NIL) and does RIGHT # At Time step 130: Agent [EA = -5.1199956] perceives ((4 3) 1 T) and does RIGHT # # > (SETQ A (MAKE-MDP-AGENT :NAME 'TQ :PROGRAM (MAKE-EXPLORING-TDQ-LEARNER '(LEFT RIGHT UP DOWN)))) [TQ = 0] > (SETQ E (MAKE-MDP-ENVIRONMENT :MDP *4X3-MDP* :AGENTS (LIST A) :EPOCHS-LEFT 2)) # > (RUN-ENVIRONMENT E) At Time step 0: # At Time step 1: Agent [TQ = -0.04] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 2: Agent [TQ = -0.08] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 3: Agent [TQ = -0.12] perceives ((1 1) -0.04 NIL) and does UP # At Time step 4: Agent [TQ = -0.16] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 5: Agent [TQ = -0.19999999] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 6: Agent [TQ = -0.23999998] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 7: Agent [TQ = -0.27999997] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 8: Agent [TQ = -0.31999996] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 9: Agent [TQ = -0.35999995] perceives ((1 3) -0.04 NIL) and does LEFT # At Time step 10: Agent [TQ = -0.39999995] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 11: Agent [TQ = -0.43999994] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 12: Agent [TQ = -0.47999993] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 13: Agent [TQ = -0.5199999] perceives ((1 3) -0.04 NIL) and does UP # At Time step 14: Agent [TQ = -0.55999994] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 15: Agent [TQ = -0.59999996] perceives ((2 3) -0.04 NIL) and does UP # At Time step 16: Agent [TQ = -0.64] perceives ((2 3) -0.04 NIL) and does UP # At Time step 17: Agent [TQ = -0.68] perceives ((2 3) -0.04 NIL) and does DOWN # At Time step 18: Agent [TQ = -0.72] perceives ((2 3) -0.04 NIL) and does LEFT # At Time step 19: Agent [TQ = -0.76000005] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 20: Agent [TQ = -0.8000001] perceives ((1 2) -0.04 NIL) and does UP # At Time step 21: Agent [TQ = -0.8400001] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 22: Agent [TQ = -0.8800001] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 23: Agent [TQ = -0.92000014] perceives ((1 1) -0.04 NIL) and does UP # At Time step 24: Agent [TQ = -0.96000016] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 25: Agent [TQ = -1.0000001] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 26: Agent [TQ = -1.0400001] perceives ((3 1) -0.04 NIL) and does DOWN # At Time step 27: Agent [TQ = -1.08] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 28: Agent [TQ = -1.12] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 29: Agent [TQ = -1.16] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 30: Agent [TQ = -1.1999999] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 31: Agent [TQ = -1.2399999] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 32: Agent [TQ = -1.2799999] perceives ((3 1) -0.04 NIL) and does UP # At Time step 33: Agent [TQ = -1.3199998] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 34: Agent [TQ = -1.3599998] perceives ((3 2) -0.04 NIL) and does LEFT # At Time step 35: Agent [TQ = -1.3999997] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 36: Agent [TQ = -1.4399997] perceives ((3 1) -0.04 NIL) and does UP # At Time step 37: Agent [TQ = -1.4799997] perceives ((3 2) -0.04 NIL) and does DOWN # At Time step 38: Agent [TQ = -1.5199996] perceives ((3 1) -0.04 NIL) and does DOWN # At Time step 39: Agent [TQ = -1.5599996] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 40: Agent [TQ = -1.5999995] perceives ((2 1) -0.04 NIL) and does UP # At Time step 41: Agent [TQ = -1.6399995] perceives ((3 1) -0.04 NIL) and does DOWN # At Time step 42: Agent [TQ = -1.6799995] perceives ((4 1) -0.04 NIL) and does LEFT # At Time step 43: Agent [TQ = -1.7199994] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 44: Agent [TQ = -1.7599994] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 45: Agent [TQ = -1.7999994] perceives ((3 1) -0.04 NIL) and does DOWN # At Time step 46: Agent [TQ = -1.8399993] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 47: Agent [TQ = -1.8799993] perceives ((4 1) -0.04 NIL) and does RIGHT # At Time step 48: Agent [TQ = -1.9199992] perceives ((4 1) -0.04 NIL) and does DOWN # At Time step 49: Agent [TQ = -1.9599992] perceives ((4 1) -0.04 NIL) and does DOWN # At Time step 50: Agent [TQ = -1.9999992] perceives ((4 1) -0.04 NIL) and does UP # At Time step 51: Agent [TQ = -2.999999] perceives ((4 2) -1 T) and does DOWN # At Time step 52: Agent [TQ = -3.039999] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 53: Agent [TQ = -3.079999] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 54: Agent [TQ = -3.119999] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 55: Agent [TQ = -3.159999] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 56: Agent [TQ = -3.1999989] perceives ((1 1) -0.04 NIL) and does UP # At Time step 57: Agent [TQ = -3.2399988] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 58: Agent [TQ = -3.2799988] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 59: Agent [TQ = -3.3199987] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 60: Agent [TQ = -3.3599987] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 61: Agent [TQ = -3.3999987] perceives ((2 1) -0.04 NIL) and does UP # At Time step 62: Agent [TQ = -3.4399986] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 63: Agent [TQ = -3.4799986] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 64: Agent [TQ = -3.5199986] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 65: Agent [TQ = -3.5599985] perceives ((1 1) -0.04 NIL) and does UP # At Time step 66: Agent [TQ = -3.5999985] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 67: Agent [TQ = -3.6399984] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 68: Agent [TQ = -3.6799984] perceives ((2 1) -0.04 NIL) and does UP # At Time step 69: Agent [TQ = -3.7199984] perceives ((2 1) -0.04 NIL) and does UP # At Time step 70: Agent [TQ = -3.7599983] perceives ((2 1) -0.04 NIL) and does DOWN # At Time step 71: Agent [TQ = -3.7999983] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 72: Agent [TQ = -3.8399982] perceives ((3 1) -0.04 NIL) and does RIGHT # At Time step 73: Agent [TQ = -3.8799982] perceives ((3 1) -0.04 NIL) and does LEFT # At Time step 74: Agent [TQ = -3.9199982] perceives ((2 1) -0.04 NIL) and does RIGHT # At Time step 75: Agent [TQ = -3.9599981] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 76: Agent [TQ = -3.999998] perceives ((1 1) -0.04 NIL) and does UP # At Time step 77: Agent [TQ = -4.039998] perceives ((1 2) -0.04 NIL) and does UP # At Time step 78: Agent [TQ = -4.079998] perceives ((1 3) -0.04 NIL) and does RIGHT # At Time step 79: Agent [TQ = -4.119998] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 80: Agent [TQ = -4.159998] perceives ((1 1) -0.04 NIL) and does RIGHT # At Time step 81: Agent [TQ = -4.199998] perceives ((2 1) -0.04 NIL) and does LEFT # At Time step 82: Agent [TQ = -4.239998] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 83: Agent [TQ = -4.279998] perceives ((1 1) -0.04 NIL) and does UP # At Time step 84: Agent [TQ = -4.319998] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 85: Agent [TQ = -4.3599977] perceives ((1 3) -0.04 NIL) and does DOWN # At Time step 86: Agent [TQ = -4.3999977] perceives ((1 2) -0.04 NIL) and does LEFT # At Time step 87: Agent [TQ = -4.4399977] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 88: Agent [TQ = -4.4799976] perceives ((1 1) -0.04 NIL) and does UP # At Time step 89: Agent [TQ = -4.5199976] perceives ((1 2) -0.04 NIL) and does DOWN # At Time step 90: Agent [TQ = -4.5599976] perceives ((1 1) -0.04 NIL) and does UP # At Time step 91: Agent [TQ = -4.5999975] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 92: Agent [TQ = -4.6399975] perceives ((1 1) -0.04 NIL) and does LEFT # At Time step 93: Agent [TQ = -4.6799974] perceives ((1 1) -0.04 NIL) and does DOWN # At Time step 94: Agent [TQ = -4.7199974] perceives ((1 1) -0.04 NIL) and does UP # At Time step 95: Agent [TQ = -4.7599974] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 96: Agent [TQ = -4.7999973] perceives ((1 2) -0.04 NIL) and does RIGHT # At Time step 97: Agent [TQ = -4.8399973] perceives ((1 2) -0.04 NIL) and does UP # At Time step 98: Agent [TQ = -4.8799973] perceives ((1 3) -0.04 NIL) and does UP # At Time step 99: Agent [TQ = -4.919997] perceives ((2 3) -0.04 NIL) and does RIGHT # At Time step 100: Agent [TQ = -4.959997] perceives ((3 3) -0.04 NIL) and does UP # At Time step 101: Agent [TQ = -4.999997] perceives ((3 3) -0.04 NIL) and does RIGHT # At Time step 102: Agent [TQ = -5.039997] perceives ((3 3) -0.04 NIL) and does RIGHT # At Time step 103: Agent [TQ = -4.039997] perceives ((4 3) 1 T) and does RIGHT # # 0 errors on system LEARNING Testing System LANGUAGE ;;; Test the chart parser on some grammars. ;;; First the simple E0 grammar from page 665. > (CHART-PARSES '(I SMELL A STENCH) *E0*) ((S (NP (PRONOUN I)) (VP (VP (VERB SMELL)) (NP (ARTICLE A) (NOUN STENCH))))) > (CHART-PARSES '(THE GOLD IS IN 2 2) *E0*) ((S (NP (ARTICLE THE) (NOUN GOLD)) (VP (VP (VERB IS)) (PP (PREPOSITION IN) (NP (DIGIT 2) (DIGIT 2)))))) ;;; Now the E1 grammar to show how pronoun case is handled. ;;; It is grammatical to use 'I' as a subject, but not 'me'. > (CHART-PARSES '(I SHOT THE WUMPUS) *E1*) ((S ((NP SUBJECTIVE) ((PRONOUN SUBJECTIVE) I)) (VP (VERB SHOT) ((NP $CASE.688) (ARTICLE THE) (NOUN WUMPUS))))) > (CHART-PARSES '(ME SHOT THE WUMPUS) *E1*) NIL ;;; The E0 grammar allows anything (including 'me') as a subject: > (CHART-PARSES '(ME SHOT THE WUMPUS) *E0*) ((S (NP (PRONOUN ME)) (VP (VP (VERB SHOT)) (NP (ARTICLE THE) (NOUN WUMPUS))))) ;;; Now for a longer sentence > (CHART-PARSES '(I SEE THE WUMPUS IN 2 3 AND IT IS SMELLY) *E1*) ((S (S ((NP SUBJECTIVE) ((PRONOUN SUBJECTIVE) I)) (VP (VERB SEE) ((NP $CASE.704) ((NP $CASE.706) (ARTICLE THE) (NOUN WUMPUS)) (PP (PREPOSITION IN) ((NP $CASE.711) (DIGIT 2) (DIGIT 3)))))) (CONJUNCTION AND) (S ((NP $CASE.720) ((PRONOUN $CASE) IT)) (VP (VERB IS) (ADJECTIVE SMELLY))))) ;;; An example from the simple arithmetic grammar. > (CHART-PARSES '([ 1 + 2 ] * 3 0) *ARITHMETIC-GRAMMAR*) (((EXP (* (+ 1 2) (+ (* 10 3) 0))) ((EXP (+ 1 2)) ([ [) ((EXP (+ 1 2)) ((EXP 1) ((NUMBER 1) ((DIGIT 1) 1))) ((OPERATOR +) +) ((EXP 2) ((NUMBER 2) ((DIGIT 2) 2)))) (] ])) ((OPERATOR *) *) ((EXP (+ (* 10 3) 0)) ((NUMBER (+ (* 10 3) 0)) ((NUMBER 3) ((DIGIT 3) 3)) ((DIGIT 0) 0))))) ;;; The function MEANINGS picks out just the semantics > (MEANINGS '([ 1 + 2 ] * 3 0) *ARITHMETIC-GRAMMAR*) ((* (+ 1 2) (+ (* 10 3) 0))) ;;; Note that strings can be ambiguous, yielding two or more parses. > (MEANINGS '(1 + 2 * 3) *ARITHMETIC-GRAMMAR*) ((* (+ 1 2) 3) (+ 1 (* 2 3))) > (CHART-PARSES '(1 + 2 * 3) *ARITHMETIC-GRAMMAR*) (((EXP (* (+ 1 2) 3)) ((EXP (+ 1 2)) ((EXP 1) ((NUMBER 1) ((DIGIT 1) 1))) ((OPERATOR +) +) ((EXP 2) ((NUMBER 2) ((DIGIT 2) 2)))) ((OPERATOR *) *) ((EXP 3) ((NUMBER 3) ((DIGIT 3) 3)))) ((EXP (+ 1 (* 2 3))) ((EXP 1) ((NUMBER 1) ((DIGIT 1) 1))) ((OPERATOR +) +) ((EXP (* 2 3)) ((EXP 2) ((NUMBER 2) ((DIGIT 2) 2))) ((OPERATOR *) *) ((EXP 3) ((NUMBER 3) ((DIGIT 3) 3)))))) > (CHART-PARSES '(I SHOT THE WUMPUS THAT STINKS) *E2*) (((S ((SHOT (THE $X.873 (AND (WUMPUS $X.873) (STINKS $X.873)))) I)) ((NP I) ((PRONOUN I) I)) ((VP (SHOT (THE $X.873 (AND (WUMPUS $X.873) (STINKS $X.873))))) ((VP SHOT) ((VERB SHOT) SHOT)) ((NP (THE $X.873 (AND (WUMPUS $X.873) (STINKS $X.873)))) ((NP (THE $X.880 (WUMPUS $X.880))) ((ARTICLE THE) THE) ((NOUN WUMPUS) WUMPUS)) ((RELCLAUSE STINKS) (THAT THAT) ((VP STINKS) ((VERB STINKS) STINKS))))))) > (MEANINGS '(I SHOOT THE WUMPUS THAT STINKS AND I GRAB THE GOLD) *E2*) ((AND ((SHOOT (THE $X.971 (AND (WUMPUS $X.971) (STINKS $X.971)))) I) ((GRAB (THE $X.1076 (GOLD $X.1076))) I))) 0 errors on system LANGUAGE 0 [2]> (quit) Bye. mahoney@cs code$