SlideShare a Scribd company logo
CP2014: Teaching CP
Context 
• Final Year 
• 120 credits (1 credit approx 10 hours) 
• 30 credit project 
• 4 modules in semester 1 
• 4 modules in semester 2 
• A module is 10 credits 
• 1 compulsory module on Prof Issues 
• Students select 4 modules from 8 in each semester 
• There is competition between staff for students 
• Students make choice after 2nd week 
• First lectures have to be as attractive as possible 
• CP(M) 
• 30 lectures 
• 1 short assessed exercise (5%) 
• 1 long(ish) assessed exercise (15%) 
• Exam (80%) 
• Students are motivated by “marks” ☹
How 
not 
to 
do 
it
Lecture 
1 Course 
outline
Variables 
and 
constraints, 
and 
Lecture 
2 
how 
to 
represent 
them
Backtracking 
search, 
Lectures 
3 
to 
5 
implementation
Lecture 
6 A 
bit 
on 
heuristics
A 
wee 
bit 
of 
theory 
(levels 
Lecture 
7 
of 
consistency 
etc)
A 
tiny 
wee 
bit 
more 
theory 
(dual 
Lecture 
8 
and 
hidden 
variables)
Ready 
to 
write 
our 
Week 
4 
1st 
constraint 
program
Wooooosh!
… 
how 
I 
do 
it 
now
Lecture 
1
Lecture 
1 
Stolen: BMS, TW, JCB
Lecture 
1 
Handed out on paper, given 8 minutes, discussion …
Lecture 
2 
Just 
do 
it!
Lecture 
2 How many dominos are there?
How many dominos are there? 
How many pairs of numbers are there of the form 
0 ≤ x ≤ y ≤ 6 
Lecture 
2
Lecture 
2
Compile & Run 
Lecture 
2
Lecture 
2
Stolen: BMS 
Lecture 
2
Lecture 
2
Compile & Run 
Lecture 
2
An exam question from AF2 
Lecture 
2
Lecture 
2
Compile & Run 
Lecture 
2
1st 
observations 
& 
questions 
• How do you know “How not to do it”? 
• Why are you using choco (jchoco I call it)? 
• Do you steal everything? 
• do you tell the students you deal in stolen goods? 
• have you no sense of shame? 
• You get students to use technology they don’t understand! 
• We would NEVER EVER do that! 
• You write code in the lecture? Edit compile AND run? 
• what if something goes wrong? You’d look stupid, right? 
• You put all of the code on the web?
CPM!
search
Opening up the hood: part 1, search 
So how does CP work? 
BT: Chronological BackTracking 
! 
Thrashing! 
! 
FC: forward checking 
! 
Thrashing! 
! 
CBJ: Conflict-directed BackJumping 
! 
Thrashing!
consistency
Opening up the hood: part 2, arc-consistency 
So how does CP work? 
Arc-consistency 
Definition (aka 2-consistency) 
Covered 1-2-3-Consistency 
! 
Algorithms 
AC3 
AC4/6/2001 
AC5 
Is AC a decision procedure?
modelling
We modelled some problems 
number partitioning 
jobshop scheduling 
magic square 
n-queens 
bin packing 
knight’s tour 
Ramsey number 
Orthogonal Latin Squares 
Crystal Maze 
graph colouring 
m-queens 
Talent Scheduling 
Crossword Puzzle
What are the decision variables? 
Are there any symmetries? 
Is there a variable/value ordering heuristic? 
Is there another model? 
We modelled some problems 
How does search go? 
Redundant constraints? 
Dual or Hidden Variable encoding?
phase transition phenomena
Where are the hard problems? 
Constrainedness? Who cares? 
In optimisation, as a heuristic, in solving problems
heuristics
Variable and value ordering heuristics 
Static, topological properties 
! 
Fail-first, and it’s realisation 
! 
Constrainedness 
! 
Dual viewpoint heuristics 
! 
Promise 
! 
Regret 
! 
Domain Specific (example JSSP slack-based, Warnsdorff)
specialised constraints
specialised constraints 
• max 
• sub-tour elimination 
• Knight’s tour 
• … 
• the glass box
local search
Local search (aka neighbourhood search) Search again 
HC, SA, TS, GLS, GA, ACO, … 
Why we need them 
!! 
Problems in using them 
incompleteness, move operators, 
evaluation/fitness functions, 
tuning parameters, 
! 
Problems in using them in CP 
aka meta-heuristics
Limited Discrepancy Search Search again 
lds 
• motivation for LDS 
• when might we use it? 
• when should we not use it?
change of representation
change of representation 
dual and hidden variable encoding
Levels of consistency
• Node Consistency (NC) 
• Arc-consistency (AC) 
• Path Consistency (PC) 
• Generalised arc-consistency (GAC) 
• Bounds consistency 
• Inverse Path Consistency (IPC aka PIC) 
• Singleton Arc-consistency (SAC) 
• … and others 
consistency
Mechanics of choco
Mechanics of choco
Mechanics of choco
CP for a design problem 
Using CP as an intelligent data base 
! 
Not solving a problem, but using CP as an “active” representation 
! 
Explanations via quickXplain
theory 
• csp <v,c,d> and it’s complexity 
• search (bt, fc, cbj, …) 
• thrashing 
• arc-consistency 
• levels of consistency 
• heuristics 
• local search & lds 
• dual & hidden variables 
• sat 
• phase transition phenomena & constrainedness 
summary
practice 
number partitioning 
jobshop scheduling 
magic square 
Crystal Maze 
Talent Scheduling Orthogonal Latin Squares 
n-queens 
bin packing 
knight’s tour 
graph colouring 
summary Modelling & Solving Problems
practice 
summary Modelling & Solving Problems 
• variables (enumerated/bound/setsVar) and their domains 
• constraints (neq, allDiff, ifOnlyIf, …) 
• decision variables 
• what propagation might take place 
• size of the encoding/model (how it scales with problem size) 
• heuristics (dynamic/static, variable/value) 
• size of the search/state space 
• how search goes (example was knight’s tour) 
• alternative models (dual? hidden? values as variables?) 
• optimisation (with maximise/minimise, seqn of decision problems) 
• dealing with conflicts (soft constraints & penalties) 
• symmetry breaking (ramsey, bin packing, …) 
• redundant constraints (magic square, MOLS …) 
• what will make problems hard to solve and what will make them easy?
Rhythm 
Once 
we 
are 
up 
to 
speed, 
an 
ideal 
week 
goes 
like 
this 
!• 
lecture 
on 
new 
theory 
• a 
new 
problem 
• Model 
and 
solve 
• “Performance 
CP” 
• Consider 
alternative 
models 
• Symmetry 
breaking 
• When 
do 
problems 
get 
hard
Where are the really hard problems
Where are the really hard problems 
The 
usual 
stuff 
int 
x 
= 
3; 
int 
y 
= 
5; 
int 
z 
= 
Math.max(x,y);
Where are the really hard problems 
The 
usual 
stuff 
int 
x 
= 
3; 
int 
y 
= 
5; 
int 
z 
= 
Math.max(x,y); 
Our 
stuff 
Model 
model 
= 
new 
CPModel(); 
IntegerVariable 
x 
= 
makeIntVar(“x”,0,3); 
IntegerVariable 
y 
= 
makeIntVar(“y”,0,5); 
IntegerVariable 
z 
= 
makeIntVar(“z”,0,4); 
model.addConstraint(eq(z,max(x,y)));
Where are the really hard problems 
The 
usual 
stuff 
int 
x 
= 
3; 
int 
y 
= 
5; 
int 
z 
= 
Math.max(x,y); 
Our 
stuff 
Model 
model 
= 
new 
CPModel(); 
IntegerVariable 
x 
= 
makeIntVar(“x”,0,3); 
IntegerVariable 
y 
= 
makeIntVar(“y”,0,5); 
IntegerVariable 
z 
= 
makeIntVar(“z”,0,4); 
model.addConstraint(eq(z,max(x,y))); 
Breaking 
the 
mental 
model 
of 
variables 
in 
a 
programming 
language
Where are the really hard problems 
The 
usual 
stuff 
int 
x 
= 
3; 
int 
y 
= 
5; 
int 
z 
= 
Math.max(x,y); 
Our 
stuff 
Model 
model 
= 
new 
CPModel(); 
IntegerVariable 
x 
= 
makeIntVar(“x”,0,3); 
IntegerVariable 
y 
= 
makeIntVar(“y”,0,5); 
IntegerVariable 
z 
= 
makeIntVar(“z”,0,4); 
model.addConstraint(eq(z,max(x,y))); 
• Post 
x 
> 
0 
and 
propagate 
• Post 
z 
> 
0 
and 
propagate 
• Post 
z 
< 
3 
and 
propagate
Where are the really hard problems 
Almost 
anything 
to 
do 
with 
implication 
is 
mind 
blowing 
(or 
maybe 
I 
am 
a 
bad 
teacher)
arrays Where are the really hard problems
arrays Where are the really hard problems 
Pick 
off 
the 
ith 
row: 
easy
arrays Where are the really hard problems 
Pick 
off 
the 
diagonal: 
easy
arrays Where are the really hard problems 
Pick 
off 
the 
ith 
column: 
hard
arrays Where are the really hard problems 
Pick 
off 
the 
diagonal: 
hard
Where are the really hard problems 
Code 
comprehension
Code 
comprehension Where are the really hard problems 
Given 
n, 
what 
does 
f1 
return? 
Suggest 
a 
name 
for 
f1.
Code 
comprehension Where are the really hard problems 
Given 
n 
and 
r, 
what 
does 
f2 
return? 
Suggest 
a 
name 
for 
f2?
Assessed 
exercises
Assessed 
exercises 
• 1st 
exercise 
is 
sudoku 
(5%) 
• To 
get 
them 
to 
download 
and 
use 
choco
1D Sudoku!
Read in 9 rows of 9 numbers 
Jeez. If I knew it was this hard 
I never would have attempted it
The floggings will 
continue until morale 
improves
Assessed 
exercises 
Exercise 
2 
(15%) 
has 
been 
!• 
Car 
sequencing 
• Talent 
scheduling 
• Meeting 
Scheduling 
• Maximum 
Clique
Assessed 
exercises 
Exercise 
2 
(15%) 
has 
been 
!• 
Car 
sequencing 
• Talent 
scheduling 
• Meeting 
Scheduling 
• Maximum 
Clique 
I 
think 
that 
was 
the 
best
So?
Jump in!
Steal
You can’t teach it all
The hard bits might not 
be where you expect them to be.
Have fun
… and remember, 
your students are not just your students 
CP(M) 
CP(M) 
CP(M) 
CP(M)
Teaching Constraint Programming,  Patrick Prosser

More Related Content

Similar to Teaching Constraint Programming, Patrick Prosser

ai4.ppt
ai4.pptai4.ppt
ai4.ppt
atul404633
 
Multimodal Learning Analytics
Multimodal Learning AnalyticsMultimodal Learning Analytics
Multimodal Learning Analytics
Xavier Ochoa
 
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
ssuser448ad3
 
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
ssuserec53e73
 
MLlecture1.ppt
MLlecture1.pptMLlecture1.ppt
MLlecture1.ppt
butest
 
MLlecture1.ppt
MLlecture1.pptMLlecture1.ppt
MLlecture1.ppt
butest
 
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
Kazutoshi Umemoto
 
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
HOlink
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
huguk
 
Deep learning - a primer
Deep learning - a primerDeep learning - a primer
Deep learning - a primer
Uwe Friedrichsen
 
Deep learning - a primer
Deep learning - a primerDeep learning - a primer
Deep learning - a primer
Shirin Elsinghorst
 
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
AmirMohamedNabilSale
 
General Tips for participating Kaggle Competitions
General Tips for participating Kaggle CompetitionsGeneral Tips for participating Kaggle Competitions
General Tips for participating Kaggle Competitions
Mark Peng
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
Mike Acton
 
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hakky St
 
Coaching teams in creative problem solving
Coaching teams in creative problem solvingCoaching teams in creative problem solving
Coaching teams in creative problem solving
Flowa Oy
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
Masahiro Sakai
 
OR Ndejje Univ (1).pptx
OR Ndejje Univ (1).pptxOR Ndejje Univ (1).pptx
OR Ndejje Univ (1).pptx
ChandigaRichard1
 
Introduction to ML.NET
Introduction to ML.NETIntroduction to ML.NET
Introduction to ML.NET
Marco Parenzan
 

Similar to Teaching Constraint Programming, Patrick Prosser (20)

ai4.ppt
ai4.pptai4.ppt
ai4.ppt
 
Multimodal Learning Analytics
Multimodal Learning AnalyticsMultimodal Learning Analytics
Multimodal Learning Analytics
 
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
 
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
 
ai4.ppt
ai4.pptai4.ppt
ai4.ppt
 
MLlecture1.ppt
MLlecture1.pptMLlecture1.ppt
MLlecture1.ppt
 
MLlecture1.ppt
MLlecture1.pptMLlecture1.ppt
MLlecture1.ppt
 
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
Toward Recommendation for Upskilling: Modeling Skill Improvement and Item Dif...
 
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
Monte Carlo on a Blackpool Budget - Paul Brierly - HOlink2016
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
 
Deep learning - a primer
Deep learning - a primerDeep learning - a primer
Deep learning - a primer
 
Deep learning - a primer
Deep learning - a primerDeep learning - a primer
Deep learning - a primer
 
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
9.b-CMPS 403-F20-Session 9-Intro to ML II.pdf
 
General Tips for participating Kaggle Competitions
General Tips for participating Kaggle CompetitionsGeneral Tips for participating Kaggle Competitions
General Tips for participating Kaggle Competitions
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
Hands-On Machine Learning with Scikit-Learn and TensorFlow - Chapter8
 
Coaching teams in creative problem solving
Coaching teams in creative problem solvingCoaching teams in creative problem solving
Coaching teams in creative problem solving
 
Writing a SAT solver as a hobby project
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
 
OR Ndejje Univ (1).pptx
OR Ndejje Univ (1).pptxOR Ndejje Univ (1).pptx
OR Ndejje Univ (1).pptx
 
Introduction to ML.NET
Introduction to ML.NETIntroduction to ML.NET
Introduction to ML.NET
 

Recently uploaded

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 

Recently uploaded (20)

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 

Teaching Constraint Programming, Patrick Prosser

  • 2.
  • 3.
  • 4.
  • 5. Context • Final Year • 120 credits (1 credit approx 10 hours) • 30 credit project • 4 modules in semester 1 • 4 modules in semester 2 • A module is 10 credits • 1 compulsory module on Prof Issues • Students select 4 modules from 8 in each semester • There is competition between staff for students • Students make choice after 2nd week • First lectures have to be as attractive as possible • CP(M) • 30 lectures • 1 short assessed exercise (5%) • 1 long(ish) assessed exercise (15%) • Exam (80%) • Students are motivated by “marks” ☹
  • 6. How not to do it
  • 8. Variables and constraints, and Lecture 2 how to represent them
  • 9. Backtracking search, Lectures 3 to 5 implementation
  • 10. Lecture 6 A bit on heuristics
  • 11. A wee bit of theory (levels Lecture 7 of consistency etc)
  • 12. A tiny wee bit more theory (dual Lecture 8 and hidden variables)
  • 13. Ready to write our Week 4 1st constraint program
  • 15. … how I do it now
  • 17. Lecture 1 Stolen: BMS, TW, JCB
  • 18. Lecture 1 Handed out on paper, given 8 minutes, discussion …
  • 19. Lecture 2 Just do it!
  • 20. Lecture 2 How many dominos are there?
  • 21. How many dominos are there? How many pairs of numbers are there of the form 0 ≤ x ≤ y ≤ 6 Lecture 2
  • 23. Compile & Run Lecture 2
  • 27. Compile & Run Lecture 2
  • 28. An exam question from AF2 Lecture 2
  • 30. Compile & Run Lecture 2
  • 31. 1st observations & questions • How do you know “How not to do it”? • Why are you using choco (jchoco I call it)? • Do you steal everything? • do you tell the students you deal in stolen goods? • have you no sense of shame? • You get students to use technology they don’t understand! • We would NEVER EVER do that! • You write code in the lecture? Edit compile AND run? • what if something goes wrong? You’d look stupid, right? • You put all of the code on the web?
  • 32. CPM!
  • 33.
  • 35.
  • 36. Opening up the hood: part 1, search So how does CP work? BT: Chronological BackTracking ! Thrashing! ! FC: forward checking ! Thrashing! ! CBJ: Conflict-directed BackJumping ! Thrashing!
  • 38.
  • 39. Opening up the hood: part 2, arc-consistency So how does CP work? Arc-consistency Definition (aka 2-consistency) Covered 1-2-3-Consistency ! Algorithms AC3 AC4/6/2001 AC5 Is AC a decision procedure?
  • 41. We modelled some problems number partitioning jobshop scheduling magic square n-queens bin packing knight’s tour Ramsey number Orthogonal Latin Squares Crystal Maze graph colouring m-queens Talent Scheduling Crossword Puzzle
  • 42. What are the decision variables? Are there any symmetries? Is there a variable/value ordering heuristic? Is there another model? We modelled some problems How does search go? Redundant constraints? Dual or Hidden Variable encoding?
  • 44. Where are the hard problems? Constrainedness? Who cares? In optimisation, as a heuristic, in solving problems
  • 46. Variable and value ordering heuristics Static, topological properties ! Fail-first, and it’s realisation ! Constrainedness ! Dual viewpoint heuristics ! Promise ! Regret ! Domain Specific (example JSSP slack-based, Warnsdorff)
  • 48. specialised constraints • max • sub-tour elimination • Knight’s tour • … • the glass box
  • 50. Local search (aka neighbourhood search) Search again HC, SA, TS, GLS, GA, ACO, … Why we need them !! Problems in using them incompleteness, move operators, evaluation/fitness functions, tuning parameters, ! Problems in using them in CP aka meta-heuristics
  • 51. Limited Discrepancy Search Search again lds • motivation for LDS • when might we use it? • when should we not use it?
  • 53. change of representation dual and hidden variable encoding
  • 55. • Node Consistency (NC) • Arc-consistency (AC) • Path Consistency (PC) • Generalised arc-consistency (GAC) • Bounds consistency • Inverse Path Consistency (IPC aka PIC) • Singleton Arc-consistency (SAC) • … and others consistency
  • 59. CP for a design problem Using CP as an intelligent data base ! Not solving a problem, but using CP as an “active” representation ! Explanations via quickXplain
  • 60. theory • csp <v,c,d> and it’s complexity • search (bt, fc, cbj, …) • thrashing • arc-consistency • levels of consistency • heuristics • local search & lds • dual & hidden variables • sat • phase transition phenomena & constrainedness summary
  • 61. practice number partitioning jobshop scheduling magic square Crystal Maze Talent Scheduling Orthogonal Latin Squares n-queens bin packing knight’s tour graph colouring summary Modelling & Solving Problems
  • 62. practice summary Modelling & Solving Problems • variables (enumerated/bound/setsVar) and their domains • constraints (neq, allDiff, ifOnlyIf, …) • decision variables • what propagation might take place • size of the encoding/model (how it scales with problem size) • heuristics (dynamic/static, variable/value) • size of the search/state space • how search goes (example was knight’s tour) • alternative models (dual? hidden? values as variables?) • optimisation (with maximise/minimise, seqn of decision problems) • dealing with conflicts (soft constraints & penalties) • symmetry breaking (ramsey, bin packing, …) • redundant constraints (magic square, MOLS …) • what will make problems hard to solve and what will make them easy?
  • 63. Rhythm Once we are up to speed, an ideal week goes like this !• lecture on new theory • a new problem • Model and solve • “Performance CP” • Consider alternative models • Symmetry breaking • When do problems get hard
  • 64. Where are the really hard problems
  • 65. Where are the really hard problems The usual stuff int x = 3; int y = 5; int z = Math.max(x,y);
  • 66. Where are the really hard problems The usual stuff int x = 3; int y = 5; int z = Math.max(x,y); Our stuff Model model = new CPModel(); IntegerVariable x = makeIntVar(“x”,0,3); IntegerVariable y = makeIntVar(“y”,0,5); IntegerVariable z = makeIntVar(“z”,0,4); model.addConstraint(eq(z,max(x,y)));
  • 67. Where are the really hard problems The usual stuff int x = 3; int y = 5; int z = Math.max(x,y); Our stuff Model model = new CPModel(); IntegerVariable x = makeIntVar(“x”,0,3); IntegerVariable y = makeIntVar(“y”,0,5); IntegerVariable z = makeIntVar(“z”,0,4); model.addConstraint(eq(z,max(x,y))); Breaking the mental model of variables in a programming language
  • 68. Where are the really hard problems The usual stuff int x = 3; int y = 5; int z = Math.max(x,y); Our stuff Model model = new CPModel(); IntegerVariable x = makeIntVar(“x”,0,3); IntegerVariable y = makeIntVar(“y”,0,5); IntegerVariable z = makeIntVar(“z”,0,4); model.addConstraint(eq(z,max(x,y))); • Post x > 0 and propagate • Post z > 0 and propagate • Post z < 3 and propagate
  • 69. Where are the really hard problems Almost anything to do with implication is mind blowing (or maybe I am a bad teacher)
  • 70. arrays Where are the really hard problems
  • 71. arrays Where are the really hard problems Pick off the ith row: easy
  • 72. arrays Where are the really hard problems Pick off the diagonal: easy
  • 73. arrays Where are the really hard problems Pick off the ith column: hard
  • 74. arrays Where are the really hard problems Pick off the diagonal: hard
  • 75. Where are the really hard problems Code comprehension
  • 76. Code comprehension Where are the really hard problems Given n, what does f1 return? Suggest a name for f1.
  • 77. Code comprehension Where are the really hard problems Given n and r, what does f2 return? Suggest a name for f2?
  • 79. Assessed exercises • 1st exercise is sudoku (5%) • To get them to download and use choco
  • 80.
  • 81.
  • 83.
  • 84.
  • 85. Read in 9 rows of 9 numbers Jeez. If I knew it was this hard I never would have attempted it
  • 86.
  • 87. The floggings will continue until morale improves
  • 88. Assessed exercises Exercise 2 (15%) has been !• Car sequencing • Talent scheduling • Meeting Scheduling • Maximum Clique
  • 89. Assessed exercises Exercise 2 (15%) has been !• Car sequencing • Talent scheduling • Meeting Scheduling • Maximum Clique I think that was the best
  • 90. So?
  • 92. Steal
  • 94. The hard bits might not be where you expect them to be.
  • 96. … and remember, your students are not just your students CP(M) CP(M) CP(M) CP(M)