book image Knowledge Representation, Reasoning, and the Design of Intelligent Agents

Knowledge Representation, Reasoning, and the Design of Intelligent Agents
The Answer-Set Programming Approach

by Michael Gelfond and Yulia Kahl
Cambridge University Press

Welcome!
The goal of this site is to provide additional resources for those using the book.
Questions can be sent to Yulia Kahl at ygkahl@gmail.com.
Last modified: June 3, 2020. Additions are marked with New!


Contents


Course Slides

The following are slides I created for my class on Artificial Intelligence. Since I had other topics to cover, the slides are only for select chapters and are not comprehensive; however, they do cover a fair amount of material and may be of use.
-- Yulia Kahl


Tips


Programs from the Book

Download all here

Chapter 4

family.lp -- Section 4.1.1
basic family relationships
orphans.lp -- Section 4.1.2
defining orphans
ancestors.lp -- Section 4.1.3
defining ancestors
ec.lp -- Section 4.2
representing an electrical circuit
hierarchy.lp -- Section 4.3
representing a basic inheritance hierarchy

Chapter 5

uncaring.lp -- Section 5.1
uncaring John -- basic defauts and their exceptions
cowardly.lp -- Section 5.1.2
cowardly students -- more defaults with weak and strong exceptions
course_catalog_1.lp -- Section 5.2
representing null values with value 'staff'
course_catalog_2.lp -- Section 5.2
representing null values with disjunction
orphans2.lp -- Section 5.3
priorities between defaults
blue_deep.lp -- Section 5.4.1
inheritance hierarchy with defaults
darling.lp -- Section 5.4.2
redefining membership using defaults
tweety.lp -- Section 5.4.3
illustration of the specificity principle as applied to an inheritance hierarchy with multiple defaults and exceptions

Chapter 6

hamgraph.lp -- Section 6.1
finds Hamiltonian cycles
sudoku.lp -- Section 6.2.1
solves a Sudoku puzzle
sudokudlv.lp -- Section 6.2.1
sudoku.lp in DLV syntax
mystery.lp -- Section 6.2.2
solves a murder puzzle

Chapter 8

blocks1.lp -- Section 8.1
only for experimentation
blocks2.lp -- Section 8.1
only for experimentation
blocks3.lp -- Section 8.1
final version
bc.lp -- Section 8.5.1
briefcase domain translated from AL system description
bw.lp -- Section 8.5.2
blocks world domain translated from AL system description
twoarms.lp -- Section 8.5.3
blocks world with concurrent actions

Chapter 9 (and Appendices D.1 and D.2)

bwplan_choice.lp -- Section 9.1
bw.lp + simple planning module using choice rule + example initial situation + example goal
where bw.txt is the AL system description of the blocks-world domain translated into ASP (see Ch. 8)
bwplan_disjunction.lp -- Section 9.1
same as bwplan_choice.lp but the simple planning module uses a disjunctive rule instead of a choice rule
ignite.lp -- Section 9.2.2 & Appendix D.1
finds a plan for igniting a burner through a series of pipes and valves
crossing.lp -- Section 9.2.3 & Appendix D.2
finds a plan for solving the missionaries and cannibals problem
heuristics.lp -- Section 9.3
bwplan_choice.lp + new initial state, new goal state + heuristics
twoarmsplan.lp -- Section 9.4
planner for blocks world with concurrent actions
crbwplan.lp -- Section 9.5
CR-Prolog planner for blocks world

Chapter 10 (and Appendix D.3)

circuit.lp -- Section 10.3 & Appendix D.3
finds possible explanations for a broken circuit

Chapter 12

derivatives.pl -- Section 12.2.3
Prolog program that computes derivatives of polynomials

SPARC Versions of Book Programs

Download all SPARC programs here

Chapter 4:

s_family.sp
s_orphans.sp
s_ancestors.sp
s_ec.sp
s_hierarchy.sp

Chapter 5:

s_uncaring.sp
s_course_catalog_1.sp
s_course_catalog_2.sp
s_cowardly.sp
s_orphans2.sp
s_blue_deep.sp
s_darling.sp
s_tweety.sp

Chapter 6:

s_hamgraph.sp
s_sudoku.sp
s_mystery.sp

Chapter 8:

s_blocks1.sp
s_blocks2.sp
s_blocks3.sp
s_bc.sp
s_bw.sp
s_twoarms.sp

Chapter 9:

s_bwplan.sp
s_ignite.sp
s_crossing.sp
s_heuristics.sp

Chapter 10:

s_circuit.sp

Solvers and Other Useful Software

For clingo, gringo, and clasp visit the Potassco site at http://potassco.sourceforge.net/.

For DLV and ASPIDE, visit http://www.dlvsystem.com/.

SPARC can be found at https://github.com/iensen/sparc/wiki.

A nice Online Sparc Tool can be found at http://wave.ttu.edu.
For a quick start, simply cut and paste programs to replace the sample code in the main window. Enter a query and press "Submit" to get an answer or simply click on "Get Answer Sets" to get all answer sets of your program.

CRModels is at http://www.mbal.tk/crmodels/.

MKAtoms is at http://www.mbal.tk/mkatoms/.

Additional resources can be found at the Texas Tech Knowledge Representation Lab site
at http://www.depts.ttu.edu/cs/research/krlab/.


Additional Exercises with Solutions

EXERCISES ASP SOLUTIONS SPARC SOLUTIONS
ex02.pdf   (Ch. 2) soln_ex02.pdf The answer sets are the same.
This file has the SPARC code for the mini programs: s_ex02.txt
New!
These exercises illustrate the definition of the answer to a query.
They are not implementation-specific, but rather test knowledge of the defintion.
answersToQueriesEx.pdf   (Ch. 2)
answersToQueriesExSolutions.pdf Same as ASP.
ex_local_cwa.txt   (Ch. 4) local_cwa.lp s_local_cwa.sp
ex_cars.txt   (Section 5.5) cars.cr   (CR-Prolog) s_cars.sp
ex_loops.txt   (Ch. 6) loops.lp s_loops.sp
ex_clique.txt  (Ch. 6) clique.lp s_clique.sp
ex_max_clique.txt  (Ch. 6) max_clique.cr   (CR-Prolog) s_max_clique.sp
ex_morphing_vehicles.txt   (Ch. 8) morphing_vehicles.lp s_morphing_vehicles.sp

Errata

Special thanks to Elham Hojati and Yuliya Lierler for finding some of these.
LOCATION ERROR FIX
New!
p. 20 — Definition 2.2.2
The first two bullets fo Definition 2.2.2 (Answer to a Query) are not correct. The first two bullets should be replaced with the following definition of a ground query:

The answer to a ground query is "yes" if it is true in all answer sets, "no" if it is false in all answer sets, and "unknown" otherwise. (This applies to all ground queries, whether conjunctive, disjunctive, or singleton.)

For examples, please see the solutions to answersToQueriesEx answersToQueriesExSolutions.pdf

(Further references to answers to a query in the book, including examples and solver implementation, are unaffected by this change. They are correct, as the error was only in the way the definition was written.)

p. 173 — line 3 {occurs(ai): 0 ≤ i ≤ k} {occurs(aj, i): 0 ≤ j ≤ k}
p. 173 In showing the translation of preconditions, we did not make a note about the case where the preconditions are statics. Since in this case we are not concerned about showing their change over time, we should not use holds. Simply write the statics as they are. For example: given a rule "a causes l if s, f" where s is a static and f is a fluent, the translation is

h(l,I+1) :- s,

            holds(f,I),

            occurs(a,I),

            I < n.

Blocks world In the original description of the blocks world, we fail to flush out an implicit rule; namely, that a given block must have a location. The effect of this is not felt until we suggest in Section 8.5.3 that we can remove rule 7 from p. 180
impossible put(B1,B) if on(B2,B)
because it is an overspecification. With this rule gone, it becomes possible for a block to be nowhere.
Subsequent references and examples already ignore the removal of the rule, so the text makes sense except for the actual example on overspecification on p. 184.
p. 185, Figure 8.9 States in which f holds do not have loops showing what happens when action a is executed. Add loops labeled by the letter a to the three states in which f holds as there is nothing preventing the exectution of action a in those states.
p. 194 — next to last line (i) For any 0 < i ≤ k, occurs(ai, i-1) in S (i) For any 0 < i ≤ k, occurs(ai, i) in S
p. 199 — line 26 fluent(defined, wrong_config(B)) fluent(defined, wrong_config)
p. 223 — line 24 E2 would be the only possible explanation E1 would be the only possible explanation
p. 241 — next-to-last line a(t̅)=y1 or ... or a(t̅)=yn ← body, not intervene(a(t̅)) a(t̅,y1) or ... or a(t̅,yn) ← body, not intervene(a(t̅))
p. 246 — line 29 W1 is 1/24 W is 1/24
p. 250 — last line draw(T):{C:available(C,T)} random(draw(T):{C:available(C,T)})
p. 258 In the list of 6 pr-atoms in the top half of the page, the first two only have a vertical bar in them, not a causal stroke. Use a causal stroke instead of a vertical bar.