csci5240 - combinatorial search and optimization with...
TRANSCRIPT
![Page 1: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/1.jpg)
CSCI5240 - Combinatorial Search and Optimization with Constraints
Tutorial 11
![Page 2: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/2.jpg)
Today covers
• Asg 10
• Propagator
• Submission Format
![Page 3: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/3.jpg)
Knight’s Tour
move(x, y, n)?x
y
nreturns whether (x, y)
is a legal move on a n*n chessboard
![Page 4: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/4.jpg)
Today covers
• Asg 10
• Propagator
• Submission Format
![Page 5: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/5.jpg)
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
![Page 6: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/6.jpg)
Propagator of less
less(home, x, y);
rel(home, x, IRT_LE, y);
Propagator
Constraint
![Page 7: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/7.jpg)
Propagator
![Page 8: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/8.jpg)
Propagator
![Page 9: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/9.jpg)
PostingEvents to trigger propagation
Subscription: when particular events of variable happened, the propagator is called
Use IntView
![Page 10: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/10.jpg)
View
x
IntVar x
IntVar s(x)
IntArgs t[0] = x
IntView v(x)
variable implementation
different interfaces
![Page 11: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/11.jpg)
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)
![Page 12: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/12.jpg)
• 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
![Page 13: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/13.jpg)
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
![Page 14: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/14.jpg)
Propagator
![Page 15: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/15.jpg)
Disposal
Cancel the subscriptions
![Page 16: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/16.jpg)
Propagator
![Page 17: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/17.jpg)
Copying
![Page 18: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/18.jpg)
Propagator
not necessary
![Page 19: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/19.jpg)
Propagator
related to a particular consistency level
![Page 20: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/20.jpg)
AC_revise
![Page 21: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/21.jpg)
AC Propagation on less
Domain Reduction
equivalently
![Page 22: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/22.jpg)
Propagation
further propagation needed
propagation failure
x0.le() removes all values in variable x0 that are larger than x1.max()
no more propagations
needed
![Page 23: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/23.jpg)
Used as constraint less
Outside the propagator class Less
now the function less() behaves as a constraint
![Page 24: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/24.jpg)
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()
![Page 25: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/25.jpg)
Today covers
• Asg 10
• Propagator
• Submission Format
![Page 26: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/26.jpg)
Submission Format
• Q1
• File: knight.cpp
• Command: ./knight
output all solutions, each in a line
![Page 27: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/27.jpg)
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
![Page 28: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/28.jpg)
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
![Page 29: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/29.jpg)
Submission Format
• Q2
• File: comparison.txt
contains all tables for comparison
![Page 30: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/30.jpg)
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
![Page 31: CSCI5240 - Combinatorial Search and Optimization with ...jlee/courses/csc5240/tutorials/16F/2016CSCI... · Propagator A class to process a constraint to a particular level (of consistency)](https://reader034.vdocuments.net/reader034/viewer/2022051722/5a9d50a17f8b9abd058bc5d9/html5/thumbnails/31.jpg)
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)