aima-lisp tests license

Common Lisp code for the book Artificial Intelligence: A Modern Approach.

This was the original code base of the book (1995), written for its earlier editions (the last version is from 2002); the algorithms of the 4th edition have since been added next to the original code.

Installation

Clone the repository where ASDF looks for systems (e.g., ~/common-lisp/), or register aima.asd by hand, then load the system aima and run its tests; with SBCL:

git clone --recurse-submodules https://github.com/aimacode/aima-lisp.git
cd aima-lisp
sbcl --non-interactive \
  --eval '(require "asdf")' \
  --eval '(asdf:load-asd (truename "aima.asd"))' \
  --eval '(asdf:test-system "aima")'

(asdf:load-system "aima") loads every subsystem into CL-USER. Without ASDF, (load "aima.lisp") followed by (aima-load 'all) does the same, (aima-load 'search) loads a single subsystem, and (test 'all) runs the test examples. The user guide and the overview document the code.

Index of algorithms

One row per algorithm, in the order of the book, with the same rows in every aimacode repository. Figure is the figure of the 4th edition, or “(3e)” after the figure of an algorithm whose pseudocode is only in the 3rd edition; § gives the section of the 4th edition for an algorithm described in the text, and — marks an algorithm that is not in the book. The names link to the pseudocode in aima-pseudocode.

Figure Name (in 4th edition) Code Tests
2.7 TABLE-DRIVEN-AGENT make-table-driven-agent-program test-agents.lisp
2.8 REFLEX-VACUUM-AGENT reactive-vacuum-agent test-agents.lisp
2.10 SIMPLE-REFLEX-AGENT make-simple-reflex-agent-program test-agents.lisp
2.12 MODEL-BASED-REFLEX-AGENT make-model-based-reflex-agent-program test-agents.lisp
§2.1 Table-Driven-Vacuum-Agent *two-square-vacuum-table* test-agents.lisp
§2.4.2 Random-Agent-Program make-random-agent-program test-agents.lisp
§2.4.2 Random-Vacuum-Agent random-vacuum-agent test-agents.lisp
§2.4.3 Model-Based-Vacuum-Agent make-model-based-vacuum-program test-agents.lisp
— Environment-Simulator run-environment test-agents.lisp
3.7 BEST-FIRST-SEARCH best-first-search test-search.lisp
3.9 BREADTH-FIRST-SEARCH breadth-first-search test-search.lisp
3.9 UNIFORM-COST-SEARCH uniform-cost-search test-search.lisp
3.12 DEPTH-LIMITED-SEARCH depth-limited-search test-search.lisp
3.12 ITERATIVE-DEEPENING-SEARCH iterative-deepening-search test-search.lisp
3.14 BIBF-SEARCH bibf-search test-search.lisp
3.22 RECURSIVE-BEST-FIRST-SEARCH recursive-best-first-search test-search.lisp
3.1 (3e) SIMPLE-PROBLEM-SOLVING-AGENT problem-solving-agent test-search.lisp
3.7 (3e) TREE-SEARCH general-search test-search.lisp
3.7 (3e) GRAPH-SEARCH graph-search, breadth-first-graph-search, depth-first-graph-search test-search.lisp
§3.1 Romania *romania-map* test-search.lisp
§3.2.1 Eight-Puzzle *8-puzzle-goal* test-search.lisp
§3.2.1 N-Queens-Problem make-nqueens-problem test-search.lisp
§3.2.2 Traveling-Salesman-Problem make-tsp-problem test-search.lisp
§3.4.3 Depth-First-Search depth-first-search test-search.lisp
§3.4.5 Bidirectional-Search bidirectional-search test-search.lisp
§3.5.1 Greedy-Best-First-Search greedy-search test-search.lisp
§3.5.2 A*-Search A*-search test-search.lisp
§3.5.5 SMA* sma*-search test-search.lisp
§3.5.5 Iterative-Deepening-A*-Search tree-ida*-search test-search.lisp
— Pour-Problem pour-problem test-search.lisp
— Grid-Problem grid-problem test-search.lisp
4.2 HILL-CLIMBING hill-climbing-search test-search.lisp
4.4 SIMULATED-ANNEALING simulated-annealing-search test-search.lisp
4.7 GENETIC-ALGORITHM genetic-algorithm test-search.lisp
4.10 AND-OR-GRAPH-SEARCH and-or-graph-search test-search.lisp
4.20 ONLINE-DFS-AGENT make-online-dfs-agent-program test-search.lisp
4.23 LRTA*-AGENT make-lrta*-agent-program test-search.lisp
§4.1.1 Stochastic-Hill-Climbing stochastic-hill-climbing-search test-search.lisp
§4.1.1 First-Choice-Hill-Climbing first-choice-hill-climbing-search test-search.lisp
§4.1.1 Random-Restart-Hill-Climbing random-restart-search test-search.lisp
§4.1.3 Local-Beam-Search local-beam-search test-search.lisp
§4.3.1 Erratic-Vacuum-World erratic-vacuum-problem test-search.lisp
§4.5.1 Online-Search-Problem online-graph-problem test-search.lisp
§4.5.3 One-Dimensional-State-Space make-one-dim-state-space-problem test-search.lisp
— Peak-Finding-Problem peak-finding-problem test-search.lisp
5.3 MINIMAX-SEARCH minimax-decision test-search.lisp
5.7 ALPHA-BETA-SEARCH alpha-beta-decision test-search.lisp
5.11 MONTE-CARLO-TREE-SEARCH monte-carlo-tree-search test-search.lisp
§5.3.2 Alpha-Beta-Cutoff-Search alpha-beta-cutoff-decision test-search.lisp
§5.3.2 Iterative-Deepening-Alpha-Beta iterative-deepening-alpha-beta-decision test-search.lisp
§5.5 Expectiminimax expectiminimax-decision test-search.lisp
— Random-Player random-game-agent test-search.lisp
— Play-Game run-game test-search.lisp
— Tic-Tac-Toe make-ttt-game test-search.lisp
6.3 AC-3 ac-3 test-search.lisp
6.5 BACKTRACKING-SEARCH csp-backtracking-search test-search.lisp
6.9 MIN-CONFLICTS min-conflicts test-search.lisp
6.11 TREE-CSP-SOLVER tree-csp-solver test-search.lisp
§6.1.1 Map-Coloring-CSP make-map-coloring-csp test-search.lisp
§6.1.3 Cryptarithmetic make-two-two-four-csp test-search.lisp
§6.2.6 Sudoku make-sudoku-csp test-search.lisp
§6.3.1 Variable-And-Value-Ordering mrv, lcv test-search.lisp
§6.3.2 Forward-Checking forward-checking test-search.lisp
§6.3.2 Maintaining-Arc-Consistency mac test-search.lisp
§6.4 N-Queens-CSP make-queens-csp test-search.lisp
§6 Zebra make-zebra-csp test-search.lisp
— AC-3b ac-3b test-search.lisp
— AC-4 ac-4 test-search.lisp
— Arc-Heuristics no-arc-heuristic, dom-j-up test-search.lisp
— N-ary-CSP make-nary-csp test-search.lisp
— GAC-Domain-Splitting ac-solver, gac test-search.lisp
— AC-Search-Solver ac-search-solver test-search.lisp
— GAC-Heuristics no-heuristic, sat-up test-search.lisp
— Crossword make-crossword-csp test-search.lisp
— Kakuro make-kakuro-csp test-search.lisp
7.1 KB-AGENT make-kb-agent-program test-logic.lisp
7.10 TT-ENTAILS validity test-logic.lisp
7.13 PL-RESOLUTION pl-resolution test-logic.lisp
7.15 PL-FC-ENTAILS? pl-fc-entails test-logic.lisp
7.17 DPLL-SATISFIABLE? dpll-satisfiable test-logic.lisp
7.18 WALKSAT walksat test-logic.lisp
7.20 HYBRID-WUMPUS-AGENT hybrid-wumpus-agent test-logic.lisp
7.22 SATPLAN satplan test-logic.lisp
§7.5.2 Convert-to-CNF ->cnf test-logic.lisp
— DPLL-Branching-Heuristics moms, momsf, posit, zm, dlis, dlcs, jw, jw2 test-logic.lisp
— CDCL cdcl-satisfiable test-logic.lisp
— Restart-Strategies no-restart, luby, glucose test-logic.lisp
— Map-Coloring-SAT make-map-coloring-sat test-logic.lisp
9.1 UNIFY unify test-logic.lisp
9.3 FOL-FC-ASK fol-fc-ask test-logic.lisp
9.6 FOL-BC-ASK back-chain-each test-logic.lisp
9.8 APPEND prolog-append test-logic.lisp
§9.1 Subst subst-bindings test-logic.lisp
§9.5.1 Convert-to-CNF-FOL ->minimal-cnf test-logic.lisp
§9.5.2 FOL-Resolution fol-resolution test-logic.lisp
§9.5.5 Demodulation demodulate test-logic.lisp
§9.5.5 Paramodulation paramodulate test-logic.lisp
§9.5.6 Subsumption fol-subsumes? test-logic.lisp
— Unify-MM unify-mm test-logic.lisp
11.1 AIR-CARGO-TRANSPORT-PROBLEM make-air-cargo-problem test-planning.lisp
11.2 SPARE-TIRE-PROBLEM make-spare-tire-problem test-planning.lisp
11.4 BLOCKS-WORLD make-blocks-world-problem test-planning.lisp
11.7 REFINEMENT-HIGH-LEVEL-ACTIONS *go-to-sfo-hierarchy* test-planning.lisp
11.8 HIERARCHICAL-SEARCH hierarchical-search test-planning.lisp
11.11 ANGELIC-SEARCH angelic-search test-planning.lisp
11.13 JOB-SHOP-SCHEDULING-PROBLEM make-car-assembly-problem test-planning.lisp
10.7 (3e) HAVE-CAKE-AND-EAT-CAKE-TOO-PROBLEM make-have-cake-problem test-planning.lisp
10.9 (3e) GRAPHPLAN graphplan test-planning.lisp
§11.1.3 Three-Block-Tower make-blocks-world-problem test-planning.lisp
§11.2.1 Forward-State-Space-Search forward-planning test-planning.lisp
§11.2.2 Backward-State-Space-Search backward-planning test-planning.lisp
§11.2.4 Partial-Order-Planner partial-order-planner test-planning.lisp
§11.3 Planning-Heuristics h-cost test-planning.lisp
§11 Planning-Graph graphplan-expand test-planning.lisp
— SATPlan-Planning sat-planning test-planning.lisp
— CSPlan csp-planning test-planning.lisp
— Linearize linearize-plan test-planning.lisp
12.1 DT-AGENT make-dt-agent-program test-uncertainty.lisp
§12.3 Enumerate-Joint-Ask enumerate-joint-ask test-uncertainty.lisp
13.11 ENUMERATION-ASK enumeration-ask test-uncertainty.lisp
13.13 ELIMINATION-ASK elimination-ask test-uncertainty.lisp
13.16 PRIOR-SAMPLE prior-sample test-uncertainty.lisp
13.17 REJECTION-SAMPLING rejection-sampling test-uncertainty.lisp
13.18 LIKELIHOOD-WEIGHTING likelihood-weighting test-uncertainty.lisp
13.20 GIBBS-ASK gibbs-ask test-uncertainty.lisp
§13.2.3 Hybrid-Bayesian-Network hybrid-bayes-net, hybrid-bn-probability test-uncertainty.lisp
— Read-BIF read-bif test-uncertainty.lisp
14.4 FORWARD-BACKWARD forward-backward test-uncertainty.lisp
14.6 FIXED-LAG-SMOOTHING make-fixed-lag-smoother test-uncertainty.lisp
14.17 PARTICLE-FILTERING particle-filtering test-uncertainty.lisp
§14.2.3 Viterbi hmm-viterbi test-uncertainty.lisp
§14.4 Kalman-Filter kalman-filter test-uncertainty.lisp
§14.5.3 DBN-Unrolling dbn-unroll test-uncertainty.lisp
15.5 OUPM generate-citation-world test-uncertainty.lisp
15.6 NET-VISA generate-seismic-world test-uncertainty.lisp
15.9 RADAR generate-radar-world test-uncertainty.lisp
15.11 GENERATE-IMAGE generate-image test-uncertainty.lisp
15.15 GENERATE-MARKOV-LETTERS generate-markov-letters test-uncertainty.lisp
16.9 INFORMATION-GATHERING-AGENT make-information-gathering-agent test-uncertainty.lisp
§16.5 Decision-Network decision-network, decision-network-best-action test-uncertainty.lisp
17.6 VALUE-ITERATION value-iteration test-uncertainty.lisp
17.9 POLICY-ITERATION policy-iteration test-uncertainty.lisp
17.16 POMDP-VALUE-ITERATION pomdp-value-iteration test-uncertainty.lisp
§17.1 Sequential-Decision-Environment *4x3-mdp* test-learning.lisp
§17.2.2 Policy-Evaluation value-determination test-uncertainty.lisp
§17.5.2 Dynamic-Decision-Network ddn-lookahead test-uncertainty.lisp
18.1 DOUBLES-TENNIS-PROBLEM make-doubles-tennis-problem test-multiagent.lisp
§18.2.1 Dominant-Strategy dominant-strategy, dominates? test-multiagent.lisp
§18.2.1 Iterated-Dominance iterated-dominance test-multiagent.lisp
§18.2.1 Pure-Nash-Equilibria pure-nash-equilibria test-multiagent.lisp
§18.2.1 Zero-Sum-Game solve-zero-sum-game test-multiagent.lisp
§18.3.2 Shapley-Value shapley-value test-multiagent.lisp
§18.3.2 Core in-core? test-multiagent.lisp
§18.4.1 Contract-Net-Protocol contract-net test-multiagent.lisp
§18.4.2 Vickrey-Auction vickrey-auction test-multiagent.lisp
§18.4.3 Voting plurality-winner, borda-winner, condorcet-winner test-multiagent.lisp
§18.4.4 Alternating-Offers-Bargaining alternating-offers-bargaining test-multiagent.lisp
19.5 LEARN-DECISION-TREE decision-tree-learning test-learning.lisp
19.8 MODEL-SELECTION model-selection test-learning.lisp
19.11 DECISION-LIST-LEARNING decision-list-learning test-learning.lisp
19.25 ADABOOST adaboost test-learning.lisp
19.2 (3e) CURRENT-BEST-LEARNING current-best-learning test-learning.lisp
19.3 (3e) VERSION-SPACE-LEARNING version-space-learning test-learning.lisp
19.8 (3e) MINIMAL-CONSISTENT-DET minimal-consistent-det test-learning.lisp
19.12 (3e) FOIL foil test-learning.lisp
§19.2.1 Restaurant-Data *restaurant-boolean-problem* test-learning.lisp
§19.6.1 Linear-Regression linear-regression-learning, univariate-linear-regression test-learning.lisp
§19.6.4 Perceptron-Learning perceptron-learning test-learning.lisp
§19.6.5 Logistic-Regression logistic-regression-learning test-learning.lisp
§19.7.1 K-Nearest-Neighbors nearest-neighbors-learning test-learning.lisp
§19.7.5 Support-Vector-Machine svm-learning test-learning.lisp
§19.8 Ensemble-Learning ensemble-learning test-learning.lisp
§19.8.2 Random-Forest random-forest-learning test-learning.lisp
§19.8.6 Weighted-Majority weighted-majority test-learning.lisp
§19 Learning-Curve learning-curve test-learning.lisp
— Support-Vector-Regression svr-learning test-learning.lisp
— Weighted-Replicate weighted-replicate test-learning.lisp
§20.2.2 Naive-Bayes naive-bayes-learning test-learning.lisp
§20.3.1 EM-Gaussian-Mixture em-gaussian-mixture, k-means test-learning.lisp
§20.3.2 EM-Bayes-Net-Hidden-Variable naive-bayes-em test-learning.lisp
§20.3.3 Baum-Welch baum-welch test-learning.lisp
— Gaussian-Naive-Bayes gaussian-naive-bayes-learning test-learning.lisp
18.24 (3e) BACK-PROP-LEARNING backprop-learning test-learning.lisp
§21.1 Dense-Network make-connected-nn test-learning.lisp
§21.3 Convolution-Pooling-Batch-Normalization convolution-1d, max-pooling-1d, batch-normalize test-learning.lisp
§21.4 Stochastic-Gradient-Descent stochastic-gradient-descent test-learning.lisp
§21.4 Adam-Optimizer adam test-learning.lisp
§21.6 Recurrent-Neural-Network rnn-learning, make-simple-rnn test-learning.lisp
§21.7.1 Autoencoder autoencoder-learning test-learning.lisp
22.2 PASSIVE-ADP-AGENT make-passive-adp-learner test-learning.lisp
22.4 PASSIVE-TD-AGENT make-passive-td-learner test-learning.lisp
22.8 Q-LEARNING-AGENT make-exploring-tdq-learner test-learning.lisp
§22.2.1 Direct-Utility-Estimation make-passive-lms-learner test-learning.lisp
§22.3.1 Exploratory-ADP-Agent make-exploring-adp-learner test-learning.lisp
§22.3.3 SARSA-Agent make-exploring-sarsa-learner test-learning.lisp
23.5 CYK-PARSE cyk-parse test-language.lisp
23.8 SENTENCE-TREE *sentence-tree* test-language.lisp
22.1 (3e) HITS hits test-language.lisp
§23.1 Viterbi-Segmentation viterbi-segment test-language.lisp
§23.1.2 N-Gram-Models make-ngram-model test-language.lisp
§23.1.3 N-Gram-Char-Model make-ngram-char-model test-language.lisp
§23.3 Chart-Parse chart-parse test-language.lisp
§23.3 Parsing-As-Search astar-search-parsing, beam-search-parsing test-language.lisp
§23 IR-System make-ir-system test-language.lisp
— Shift-Decoder shift-decode, shift-encode test-language.lisp
— Permutation-Decoder permutation-decode test-language.lisp
§25.3.1 Edge-Detection gradient-edge-detector, laplacian-edge-detector test-perception.lisp
§25.3.3 Optical-Flow sum-squared-difference test-perception.lisp
§25.3.4 Segmentation group-contour-detection, image-to-graph test-perception.lisp
§25.5 ROI-Pooling pool-rois, pool-roi test-perception.lisp
§25 Histogram-Of-Oriented-Gradients hog test-perception.lisp
26.6 MONTE-CARLO-LOCALIZATION monte-carlo-localization test-robotics.lisp
29.1 (3e) POWERS-OF-2 make-powers-of-2 test-utilities.lisp

Data structures

Figure Name (in 4th edition) Code Tests
§2 Agent agent test-agents.lisp
§2 Environment environment test-uncertainty.lisp
§2 XY-Environment grid-environment test-agents.lisp
§2 Vacuum-World two-square-vacuum-world test-agents.lisp
§3 Problem problem test-search.lisp
§3 Node node test-search.lisp
§3 Queue make-empty-queue, enqueue-by-priority test-utilities.lisp
§5 Stochastic-Game chance-game-tree test-search.lisp
§5 Game game test-search.lisp
§6 CSP csp test-search.lisp
§7 Wumpus-World wumpus-world test-agents.lisp
§7 KB tell, ask, retract test-logic.lisp
§7 Propositional-Logic-Sentence ->prefix test-logic.lisp
§11 Planning-Problem planning-problem, action-schema test-planning.lisp
§12 Probability-Distribution prob-dist test-uncertainty.lisp
§13 Bayesian-Network bayes-net test-uncertainty.lisp
§14 Hidden-Markov-Model hmm test-uncertainty.lisp
§14 Dynamic-Bayesian-Network dynamic-bayes-net test-uncertainty.lisp
§17 Markov-Decision-Process mdp test-uncertainty.lisp
§19 Data-Set learning-problem test-learning.lisp
§20 Counting-Probability-Distribution make-counting-distribution, counting-probability test-learning.lisp
§23 Grammar grammar test-language.lisp
§23 Probabilistic-Grammar pcfg test-language.lisp

Other code in this repository

Name Code Tests
FOL KB queried by resolution fol-kb test-logic.lisp
Shopping world shopping-world test-logic.lisp
Q-iteration q-iteration test-learning.lisp
Missionaries and cannibals cannibal-problem test-search.lisp
Path planning among polygonal obstacles make-path-planning-problem test-search.lisp
Binary search trees create-sorted-tree test-utilities.lisp

Contributing

Every change must keep the test examples passing ((asdf:test-system "aima"), run by CI on every push and pull request); please open one pull request per change.

Authors

In order of the lines they wrote in the current files: Donato Meoli, Peter Norvig; see also all the contributors.

Other aimacode projects

aima-python · aima-java · aima-csharp · aima-scala · aima-julia · aima-javascript · aima-pseudocode · aima-exercises · aima-data · aima-glossary