4 Reasoning with Constraints

The third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including full text).

4.12 Exercises

  1. 1.

    Consider the crossword puzzle shown in Figure 4.14.

    Words: add, age, aid, aim, air, are, arm, art, bad, bat, bee, boa, dim, ear, eel, eft, lee, oaf
    Figure 4.14: A crossword puzzle to be solved with six words

    You must find six three-letter words: three words read across (1-across, 4-across, 5-across) and three words read down (1-down, 2-down, 3-down). Each word must be chosen from the list of 18 possible words shown. Try to solve it yourself, first by intuition, then by hand using first domain consistency and then arc consistency.

    There are at least two ways to represent the crossword puzzle shown in Figure 4.14 as a constraint satisfaction problem.

    The first is to represent the word positions (1-across, 4-across, etc.) as variables, with the set of words as possible values. The constraints are that the letter is the same where the words intersect.

    The second is to represent the nine squares as variables. The domain of each variable is the set of letters of the alphabet, {a,b,,z}. The constraints are that there is a word in the word list that contains the corresponding letters. For example, the top-left square and the center-top square cannot both have the value a, because there is no word starting with aa.

    1. (a)

      Give an example of pruning due to domain consistency using the first representation (if one exists).

    2. (b)

      Give an example of pruning due to arc consistency using the first representation (if one exists).

    3. (c)

      Are domain consistency plus arc consistency adequate to solve this problem using the first representation? Explain.

    4. (d)

      Give an example of pruning due to domain consistency using the second representation (if one exists).

    5. (e)

      Give an example of pruning due to arc consistency using the second representation (if one exists).

    6. (f)

      Are domain consistency plus arc consistency adequate to solve this problem using the second representation?

    7. (g)

      Which representation leads to a more efficient solution using consistency-based techniques? Give the evidence on which you are basing your answer.

  2. 2.

    Suppose you have a relation v(N,W) that is true if there is a vowel (one of: a, e, i, o, u) as the N-th letter of word W. For example, v(2,cat) is true because there is a vowel (“a”) as the second letter of the word “cat”;v(3,cat) is false, because the third letter of “cat” is “t”, which is not a vowel; and v(5,cat) is also false because there is no fifth letter in “cat”.

    Suppose the domain of N is {1,3,5} and the domain of W is {added, blue, fever, green, stare}.

    1. (a)

      Is the arc N,v arc consistent? If so, explain why. If not, show what element(s) can be removed from a domain to make it arc consistent.

    2. (b)

      Is the arc W,v arc consistent? If so, explain why. If not, show what element(s) can be removed from a domain to make it arc consistent.

  3. 3.

    Consider the crossword puzzles shown in Figure 4.15.

    Figure 4.15: Two crossword puzzles

    The possible words for (a) are:

    ant, big, bus, car, has, book, buys, hold, lane, year, ginger, search, symbol, syntax.

    The available words for (b) are

    at, eta, be, hat, he, her, it, him, on, one, desk, dance, usage, easy, dove, first, else, loses, fuels, help, haste, given, kind, sense, soon, sound, this, think.

    1. (a)

      Draw the constraint graph nodes for the positions (1-across, 2-down, etc.) and words for the domains, after it has been made domain consistent

    2. (b)

      Give an example of pruning due to arc consistency.

    3. (c)

      What are the domains after arc-consistency has halted?

    4. (d)

      Consider the dual representation, in which the squares on the intersection of words are the variables. The domains of the variable contain the letters that could go in these positions. Give the domains after this network has been made arc consistent. Does the result after arc consistency in this representation correspond to the result in part (c)?

    5. (e)

      Show how variable elimination solves the crossword problem. Start from the arc-consistent network from part (c).

    6. (f)

      Does a different elimination ordering affect the efficiency? Explain.

  4. 4.

    Consider the complexity for generalized arc consistency beyond the binary case considered in the text. Suppose there are n variables, c constraints, where each constraint involves k variables, and the domain of each variable is of size d. How many arcs are there? What is the worst-case cost of checking one arc as a function of c, k and d? How many times must an arc be checked? Based on this, what is the time complexity of GAC as a function of c, k and d? What is the space complexity?

  5. 5.

    Consider how stochastic local search can solve Exercise 3. You should use the “stochastic local search” AIspace.org applet or the book’s Python code to answer this question. Start with the arc-consistent network.

    1. (a)

      How well does random walking work?

    2. (b)

      How well does hill climbing work?

    3. (c)

      How well does the combination work?

    4. (d)

      Which (range of) parameter settings works best? What evidence did you use to answer this question?

  6. 6.

    Consider a scheduling problem, where there are five activities to be scheduled in four time slots. Suppose we represent the activities by the variables A, B, C, D, and E, where the domain of each variable is {1,2,3,4} and the constraints are A>D, D>E, CA, C>E, CD, BA, BC, and CD+1.

    [Before you start this, try to find the legal schedule(s) using your own intutions.]

    1. (a)

      Show how backtracking solves this problem. To do this, you should draw the search tree generated to find all answers. Indicate clearly the valid schedule(s). Make sure you choose a reasonable variable ordering.

      To indicate the search tree, write it in text form with each branch on one line. For example, suppose we had variables X, Y, and Z with domains t, f and constraints XY and YZ. The corresponding search tree is written as:

      X=t Y=t failure
          Y=f Z=t solution
              Z=f failure
      X=f Y=t Z=t failure
              Z=f solution
          Y=f failure
      

      [Hint: It may be easier to write a program to generate such a tree for a particular problem than to do it by hand.]

    2. (b)

      Show how arc consistency solves this problem. To do this you must

      • draw the constraint graph;

      • show which elements of a domain are deleted at each step, and which arc is responsible for removing the element;

      • show explicitly the constraint graph after arc consistency has stopped; and

      • show how splitting a domain can be used to sove this problem.

  7. 7.

    Which of the following methods can

    1. (a)

      determine that there is no model, if there is not one

    2. (b)

      find a model if one exists

    3. (c)

      find all models?

    The methods to consider are

    1. (a)

      arc consistency with domain splitting

    2. (b)

      variable elimination

    3. (c)

      stochastic local search

    4. (d)

      genetic algorithms.

  8. 8.

    Modify arc consistency with domain splitting to return all of the models and not just one. Give the algorithm.

  9. 9.

    Give the algorithm for variable elimination to return one of the models rather than all of them. How is finding one easier than finding all?

  10. 10.

    Explain how arc consistency with domain splitting can be used to count the number of models. If domain splitting results in a disconnected graph, how can this be exploited by the algorithm?

  11. 11.

    Modify VE to count the number of models, without enumerating them all. [Hint: You do not need the backward pass, but instead you can pass forward the number of solutions there would be.]

  12. 12.

    Consider the constraint graph of Figure 4.16 with named binary constraints. r1 is a relation on A and B, which we can write as r1(A,B), and similarly for the other relations. Consider solving this network using VE.

    Figure 4.16: Abstract constraint network
    1. (a)

      Suppose you were to eliminate variable A. Which constraints are removed? A constraint is created on which variables? (You can call this r11).

    2. (b)

      Suppose you were to subsequently eliminate B (i.e., after eliminating A). Which relations are removed? A constraint is created on which variables?

  13. 13.

    Pose and solve the crypt-arithmetic problem SEND+MORE=MONEY as a CSP. In a crypt-arithmetic problem, each letter represents a different digit, the leftmost digit cannot be zero (because then it would not be there), and the sum must be correct considering each sequence of letters as a base ten numeral. In this example, you know that Y=(D+E)mod10 and that E=(N+R+((D+E)÷10))mod10, and so on.