Picat Constraint Programming with CP 3 — Questions and Answers
Question 1: Which predicate in Picat's CP module finds a solution that minimizes a given objective expression?
- solve_min(Vars, Obj)
- minimize(Obj, Vars)
- solve([min(Obj)], Vars) (Correct answer)
- optimal(Vars, Obj)
Correct answer: solve([min(Obj)], Vars)
Passing `min(Obj)` as a solve option instructs the CP solver to use branch-and-bound to minimize the objective Obj.
Question 2: What is the purpose of `element/3` in Picat's CP module?
- It accesses the Nth element of a list where N is a CP variable (Correct answer)
- It creates a list of N constrained variables
- It enforces that a value appears exactly once in a list
- It returns the domain size of a variable
Correct answer: It accesses the Nth element of a list where N is a CP variable
`element(Index, List, Value)` constrains Value to equal List[Index] when Index is a CP variable, enabling indexed access in models.
Question 3: In a Picat CP model, what does posting `X #= Y + Z` when Y and Z are already instantiated do?
- It raises an error because X must be declared first
- It unifies X with the sum of Y and Z via constraint propagation (Correct answer)
- It creates a new variable representing Y + Z
- It fails silently if X's domain does not contain the sum
Correct answer: It unifies X with the sum of Y and Z via constraint propagation
When Y and Z are ground, propagation immediately determines X's value, effectively unifying X with Y+Z within the constraint store.
Question 4: Which built-in in Picat CP is used to obtain the current lower bound of a variable's domain?
- fd_min(Var, Lo) (Correct answer)
- min_domain(Var, Lo)
- domain_min(Var, Lo)
- lo(Var)
Correct answer: fd_min(Var, Lo)
`fd_min(Var, Lo)` unifies Lo with the minimum value currently in Var's finite domain.
Question 5: What does the `cumulative/4` global constraint model in Picat CP?
- Sequencing tasks with deadlines on a single machine
- Resource allocation where tasks use capacity over time (Correct answer)
- Partitioning variables into groups of equal sum
- Enforcing monotonic ordering of a variable sequence
Correct answer: Resource allocation where tasks use capacity over time
`cumulative(Starts, Durations, Resources, Limit)` ensures that at no point in time does the total resource consumption exceed Limit.
Question 6: In Picat, how do you express that variable X must be different from the integer constant 3?
- X #\= 3 (Correct answer)
- X != 3
- not(X #= 3)
- X #<> 3
Correct answer: X #\= 3
`X #\= 3` is the disequality constraint operator for finite-domain variables in Picat's CP module.
Question 7: What search strategy does `[up]` specify when passed to `solve` in Picat's CP module?
- Assigns values starting from the upper bound of each variable's domain
- Performs search upward through the constraint hierarchy
- Orders variables by ascending domain size before labeling
- Tries the largest value first during value selection (Correct answer)
Correct answer: Tries the largest value first during value selection
The `up` value-ordering option makes the solver try the largest value in the domain first at each choice point.
Which predicate in Picat's CP module finds a solution that minimizes a given objective expression?