Picat Constraint Programming with CP 2 — Questions and Answers
Question 1: In Picat's CP module, which predicate is used to declare a list of decision variables with a shared domain?
- new_list(Vars, N)
- Vars :: [Low..High] (Correct answer)
- Vars in Low..High
- domain(Vars, Low, High)
Correct answer: Vars :: [Low..High]
The `::` operator with a list on the left and a domain expression on the right constrains all variables in the list to that domain.
Question 2: What does the `indomain` predicate do when called on a CP variable during search in Picat?
- It removes the smallest value from the variable's domain
- It assigns the variable each value in its domain on backtracking (Correct answer)
- It returns the current domain as a list
- It propagates constraints across the variable's domain
Correct answer: It assigns the variable each value in its domain on backtracking
`indomain(Var)` non-deterministically instantiates Var to successive values in its domain, supporting backtracking search.
Question 3: Which global constraint in Picat's CP module enforces that no two variables take the same value?
- no_duplicates/1
- distinct/1
- all_different/1 (Correct answer)
- unique/1
Correct answer: all_different/1
`all_different(List)` posts a constraint ensuring every pair of variables in the list has distinct values.
Question 4: In Picat CP, what is the correct way to post a constraint that X is strictly less than Y?
- X #< Y (Correct answer)
- X < Y
- less(X, Y)
- X @< Y
Correct answer: X #< Y
Arithmetic constraints on CP variables use the `#` prefix operators such as `#<`, `#>`, `#=`, and `#\=`.
Question 5: What does `solve(Vars)` do in Picat's CP module?
- Optimizes the sum of Vars using branch-and-bound
- Labels all variables in Vars with default search options (Correct answer)
- Verifies that all constraints on Vars are satisfied
- Removes failed values from each variable's domain
Correct answer: Labels all variables in Vars with default search options
`solve(Vars)` triggers constraint propagation and labeling for the given variable list using default strategies.
Question 6: Which labeling option in Picat's CP `solve` tells the solver to choose the variable with the smallest remaining domain first?
- [ff] (Correct answer)
- [min]
- [ffc]
- [leftmost]
Correct answer: [ff]
`ff` (fail-first) selects the variable with the fewest remaining domain values, reducing early branching failures.
Question 7: In Picat CP, what is reification of a constraint?
- Converting a constraint to a boolean variable that is 1 iff the constraint holds (Correct answer)
- Propagating a constraint across all variables simultaneously
- Removing redundant constraints from the store
- Transforming a global constraint into primitive ones
Correct answer: Converting a constraint to a boolean variable that is 1 iff the constraint holds
Reification links a boolean (0/1) CP variable to a constraint so the variable equals 1 exactly when the constraint is satisfied.
In Picat's CP module, which predicate is used to declare a list of decision variables with a shared domain?