Chapter 5 - Satisfying constraints Flashcards

1
Q

Generate and test

A

a value is generated for a variable and then tested to see if the value is the desired one.
“Root” of constraint satisfaction problems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Constraint satisfaction problems are made up of 3 elements:

A
  1. number of variables for which value are to be found
  2. each variable gets a value from some finite domain
  3. there are constraints to be satisfied among subsets of variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A “solution” is…

A

an assignment of a value to each variable such that all the constraints are satisfied

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Steps to solve a constraint satisfaction problem…

A
  1. generate values
  2. test to see if all constraints are satisfied
  3. backtrack as necessary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Example of constraint satisfaction problem:

solution(Variable1,Variable2,. . .,VariableN):-

domain1(Variable1),…domainN(VariableN),

constraint1(Variable,…,Variable),…
constraintM(Variable,…,Variable).

A

Map coloring:

solution(A,B,C,D,E) :-

color(A), color(B), color(C), color(D), color(E),

+ A=B, + A=C, + A=D, + A=E, + B=C, + C=D, + D=E.

color(red).
color(white).
color(blue).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the predicate write(argument) do?

A

It is used in KB to personalize the output.
When a query will be called (the head of the if-statement in the KB), the output will be given according to what was specified in the write() predicate in the body of the if-statement. (see page 90 of the Lbook for example)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

nl

A

new line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Anonymus variable

A

used in problems where the goal is not finding the value, but ensuring there is one.

Example:

child(_, Sue) –> does Sue have a child?
Not important WHICH child, important is she has a child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

uniq() predicate

A

takes n arguments and ensures that they are all different from each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

num() predicate

A

can test or generate the numbers from X to Y that are unique

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Try to explain what happens in figure 5.5 at page 93 of the book - Sudoku problem-

A

How does this solution predicate work? It needs to generate sixteen values. It starts by using uniq(R11,R12,R13,R14) to generate four distinct values for the variables of row 1. Then it does the same for rows 2, 3, and 4. At this point, all sixteen variables have values. It then tests uniq(R11,R21,R31,R41), which is for the variables of column 1. If these four values are distinct, it continues and tests the distinctness of columns 2, 3, and 4; if they are not distinct, the test fails, and it backtracks to generate new values for the variables in row 4 or 3 or 2 or perhaps all the way back to row 1, as necessary. Once all the column tests succeed, the solution predicate tests uniq(R11,R12,R21,R22), which is for the variables of the NW quadrant. If these four values are distinct, it tests the quadrants NE, SW, and SE in turn; if they are not distinct, it again backtracks all the way to the rows and tries to generate new values.If all the column and quadrant tests are successful, a solution has been found, and the program is done.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Number in Prolog

A

sequence of one or more digits: they can appear anywhere a constant can appear.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Arithmetic realtions in Prolog:

A
less than: <
greater than: >
less than or equal to: <=
greater than or equal to >=
equal =:=
equal : Variable is E
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Must variables in arithmetic relations be already instantiated?

A

Yes, unless we are using the “is” operation: in that case, we have to make sure that the query is in the following format:
- LHS: variables with a term such as X = 4 and the variable we want to calculate, say Y, WITH NO VALUE IN THE LHS: additionally, the “Y is..”
RHS; arithmetic expression, that defines Y, such as X + 4

Example:
(Y=2, X is) (Y+4.)
X=6, Y=2
Yes

NB: the parentheses are not part of the code, they were put there by me to highlight the LHS and RHS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Is

q(Y), p(Y+4, Z) a legal query?

A

No, because Y+4 is not a legal term

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is

q(Y), X is Y+4, p(X, Z) a legal query?

A

Yes, because all predicates have legal terms as arguments.

17
Q

How can we minimize the guesswork in constraint satisfaction problems?

A
  1. if a value is fully determined by other values, then avoid guessing the value and later testing if it is correct.
  2. avoid placing independent guesses between the generation and the testing of other values
18
Q

Example of point 1 of how to minimize constraint satisfaction problems:

A

Suppose there are two predicates uniq2 and uniq3 that can test or generate two or three distinct values, respectively. Then instead of writing this:

uniq3(A,B,C), % Guess at A,B,C.
B is (A+C) mod 10 % Then test if B is ok.

write this:

uniq2(A,C), % Guess at A and C.
B is (A+C) mod 10, % Calculate B once.
uniq3(A,B,C) % Test that all values are unique.

19
Q

Example of point 2 of how to minimize constraint satisfaction problems:

A

dig(A), dig(B), % Guess at A and B.
dig(C), dig(D), % Guess at C and D.
A>B % Test for A and B.

write this:
dig(A), dig(B), % Guess at A and B.
A>B, % Test for A and B.
dig(C), dig(D) % Guess at C and D.

This minimization applies to the map coloring problem.

20
Q

Challenge in satisfaction constraint problems: how can we express the constraint?

A

One way to go about this is to imagine that there are hidden variables that are not mentioned, but whose values need to be taken into account.