Download presentation
Presentation is loading. Please wait.
Published byDorthy Doyle Modified over 8 years ago
1
An Introduction to Constraint Programming in JChoco
6
Constraint satisfaction Constraint satisfaction problem (CSP) is a triple where: –V is set of variables –Each X in V has set of values, D_X Usually assume finite domain {true,false}, {red,blue,green}, [0,10], … –C is set of constraints Goal: find assignment of values to variables to satisfy all the constraints
7
Di = {1,2,3,4,5} V1 V3 V2 V4 V4 V3 V1 V4 1 V4 + V2 = 5 V1 V2 V2 V3 6 AR33 figure 18, page 35 What can you infer?
8
Di = {1,2,3,4,5} V1 V3 V2 V4 V4 V3 V1 V4 1 V4 + V2 = 5 V1 V2 V2 V3 6 D1 = {1,2} D2 = {2,3} D3 = {4,5} D4 = {2,3} Do you agree? Was that easy?
9
A program that models csp6
10
With print statements and search
11
Packages used
12
Can throw an exception
13
Create a problem
16
Create variables
19
Post constraints
20
Establish AC
21
Magic code to get all solutions
22
Code to count solutions
23
output/trace Problem with no V or C
24
variables
25
Variables and constraints
26
Made AC
27
All solutions
28
2 colour K 3 The difference allDifferent makes Just how weak/powerful is AC processing?
29
Prop0.java Run it Make it AC
30
allDifferent Prop1.java Run it
31
X + Y + Z = 20 X,Y,Z {1..10} See Test.java How many solutions? AF2 assessed exercise One of 5 questions
32
Test.java Count number of solutions
35
As a decision problem: is there a glomb ruler with n ticks with length no more than m units?
37
How many n digit numbers are there where the number must contain at least 0ne number 3 and at least one number 5? n = 6 330095 501633 333335 120583 555355 … See ThreesAndFives.java AF2 assessed exercise
39
Magic square An example of how to represent a problem An idea from Chris Beck
40
put a number in each square each number is different a number is in the range 1 to 16 the sum of a column is the same as a sum of a row the same as the sum of a main diagonal
41
put a number in each square each number is different a number is in the range 1 to 16 the sum of a column is the same as a sum of a row the same as the sum of a main diagonal 1st stab Use sum(x) = sum(y) where x and y are - different rows - different columns - different diagonals Every element of the array is different - represent as a clique of not equals How does it go? For propagation and search?
42
put a number in each square each number is different a number is in the range 1 to 16 the sum of a column is the same as a sum of a row the same as the sum of a main diagonal 2nd stab But what is k? How does model perform?
44
Magic square on the web http://mathforum.org/alejandre/magic.square.html http://mathworld.wolfram.com/MagicSquare.html
53
Thanks to Chris Beck
54
Thanks to Bouygues
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.