Picat Constraint Programming with CP 5 — Questions and Answers
Question 1: In Picat CP, what does the `among/4` global constraint enforce?
- That a variable lies within a given interval
- That between Low and High variables in a list take values from a given set (Correct answer)
- That exactly N variables in a list are equal to each other
- That a value appears at most High times across all variables
Correct answer: That between Low and High variables in a list take values from a given set
`among(Low, High, Vars, Values)` constrains that the number of variables in Vars whose values belong to Values is between Low and High.
Question 2: Which solve option in Picat CP enables randomized restarts to escape local search traps?
- [rand_val] (Correct answer)
- [restart]
- [random]
- [shuffle]
Correct answer: [rand_val]
`rand_val` is a value-selection heuristic that picks values randomly, helping escape symmetric or structured dead ends.
Question 3: When modeling the N-Queens problem in Picat CP, which two all_different constraints are typically combined?
- all_different on rows and all_different on columns
- all_different on columns and all_different on diagonals
- all_different on diagonals and all_different on rows
- all_different on column positions and all_different on both diagonals (Correct answer)
Correct answer: all_different on column positions and all_different on both diagonals
Queens must differ in column positions and on both the positive and negative diagonals, requiring three all_different constraints in total.
Question 4: What does `fd_size(Var, Size)` return in Picat's CP module?
- The memory size of the constraint store for Var
- The number of values currently in Var's domain (Correct answer)
- The distance between Var's minimum and maximum bounds
- The number of constraints posted on Var
Correct answer: The number of values currently in Var's domain
`fd_size(Var, Size)` unifies Size with the cardinality of Var's current finite domain.
Question 5: In Picat CP, what does posting `X #>= Y #<=> B` accomplish (assuming B is a 0/1 variable)?
- It enforces X >= Y and ignores B
- It sets B to 1 if X >= Y, and to 0 otherwise (Correct answer)
- It fails unless B is already instantiated to 1
- It constrains X to be at least Y when B equals 1
Correct answer: It sets B to 1 if X >= Y, and to 0 otherwise
The `#<=>` operator creates a reified constraint, making B equal 1 exactly when the constraint X #>= Y is satisfied.
Question 6: Which Picat CP predicate retrieves all solutions to a constraint problem as a list?
- findall_solutions(Vars, List)
- solve_all(Options, Vars, List)
- all_solutions(Vars, List)
- findall(Vars, solve(Vars), List) (Correct answer)
Correct answer: findall(Vars, solve(Vars), List)
Standard `findall(Template, Goal, List)` is used with `solve(Vars)` as the goal to collect all satisfying assignments into a list.
Question 7: What is the effect of the `[max]` value-ordering option in Picat CP's solve predicate?
- It selects the variable with the maximum domain size first
- It picks the largest value in the chosen variable's domain first (Correct answer)
- It sorts all domains in descending order before search
- It assigns the global maximum bound to each variable first
Correct answer: It picks the largest value in the chosen variable's domain first
The `max` value-ordering option makes the labeling procedure try the largest value in a variable's domain at each choice point.
In Picat CP, what does the `among/4` global constraint enforce?