CSCI5240 - Combinatorial Search and Optimization with Constraints
Tutorial 11
Today covers
• Asg 10
• Propagator
• Submission Format
Knight’s Tour
move(x, y, n)?x
y
nreturns whether (x, y)
is a legal move on a n*n chessboard
Today covers
• Asg 10
• Propagator
• Submission Format
Propagator
A class to process a constraint to a particular level (of consistency). It checks and “updates” a constraint as needed
Posting a constraint is essentially posting relevant propagators
Propagator of less
less(home, x, y);
rel(home, x, IRT_LE, y);
Propagator
Constraint
Propagator
Propagator
PostingEvents to trigger propagation
Subscription: when particular events of variable happened, the propagator is called
Use IntView
View
x
IntVar x
IntVar s(x)
IntArgs t[0] = x
IntView v(x)
variable implementation
different interfaces
Access or Modifier domain through view
Accessor Modifier
x.in(int)
x.min()
x.max()
x.val()
x.size()
x.assigned()
x.eq(home, int)
x.nq(home, int)
x.le(home, int)
x.lq(home, int)
x.gr(home, int)
x.gq(home, int)
• Int::PC_INT_VAL: a value has been assigned to the variable, that is the variable is bounded
• Int::PC_INT_BND : the minimum (maximum) of the domain of the variable has increased (decreased)
• Int::PC_INT_DOM : the domain of the variable has been modified
Events
Modifying the domain
D(x) = {1, 2, 3, 4}
x.le(home, 4)
D(x) = {1, 2, 3}
Events triggered
D(x) = {2, 3}
D(x) = {2}
x.gr(home, 1)
x.nq(home, 3)Int::PC_INT_VAL
Int::PC_INT_DOMInt::PC_INT_BND
Int::PC_INT_DOMInt::PC_INT_BND
Int::PC_INT_DOMInt::PC_INT_BND
Propagator
Disposal
Cancel the subscriptions
Propagator
Copying
Propagator
not necessary
Propagator
related to a particular consistency level
AC_revise
AC Propagation on less
Domain Reduction
equivalently
Propagation
further propagation needed
propagation failure
x0.le() removes all values in variable x0 that are larger than x1.max()
no more propagations
needed
Used as constraint less
Outside the propagator class Less
now the function less() behaves as a constraint
Write your own propagator• Determine a consistency notion (e.g., AC)
• Link the propagator with events that may make the constraint “inconsistent” (e.g., Int::PC_INT_BND)
• Implement the propagate() function
examine whether a support exists for each domain value
remove unsupported domain values accordingly (x.le(), x.nq(), …)
• Modify those basic necessary components accordingly: constructor, dispose(), copy function, post()
Today covers
• Asg 10
• Propagator
• Submission Format
Submission Format
• Q1
• File: knight.cpp
• Command: ./knight
output all solutions, each in a line
Submission Format• Q2
• File: nqueen.cpp
• Command: ./nqueen -search 1 n (first-fail, mimum-domain-value)
./nqueen -search 2 n (first-fail, median-domain-value)
output the first solution
runtime and numbers of failures are recorded in tables
Submission Format• Q2
• File: nqueen_min.mzn
• Command: mzn-gecode nqueen_min.mzn -D “n=xxx;”
• Output: Output the first solution of the n-Queens problem using the first-fail, minimum-domain-value heuristic
• File: nqueen_med.mzn
• Command: mzn-gecode nqueen_med.mzn -D “n=xxx;”
• Output: Output the first solution of the n-Queens problem using the first-fail, median-domain-value heuristic
Submission Format
• Q2
• File: comparison.txt
contains all tables for comparison
Submission• 2 cpp files, 2 mzn files, and 1 txt file (result comparison)
• Strictly follow the naming rules for filenames, option values and running commands
• Include compiling and linking commands as comments at the bottom of your program file (if applicable)
• Compress all files into one
• Send to [email protected]
• Subject: CSCI5240-Asg9-sid
• Due: Dec 11
Grading• Modelling
Clearness (variables and domains, what do they stand for)
Correctness (size and bounds)
• Programming
Correctness (the constraint specified, running results)
Readability (use comment, delete unused code)
Programming style (good block structure)