Constraint Programming with CP Flashcards
7 cards from real Picat practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Constraint Programming with CP flashcards as text
In Picat CP, what does the `among/4` global constraint enforce?
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.
Which solve option in Picat CP enables randomized restarts to escape local search traps?
Answer: [rand_val]
`rand_val` is a value-selection heuristic that picks values randomly, helping escape symmetric or structured dead ends.
When modeling the N-Queens problem in Picat CP, which two all_different constraints are typically combined?
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.
What does `fd_size(Var, Size)` return in Picat's CP module?
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.
In Picat CP, what does posting `X #>= Y # B` accomplish (assuming B is a 0/1 variable)?
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.
Which Picat CP predicate retrieves all solutions to a constraint problem as a list?
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.
What is the effect of the `[max]` value-ordering option in Picat CP's solve predicate?
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.