Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at...

34
Constraint Constraint Satisfaction Satisfaction Problems and Problems and Consistency Consistency Restoration Restoration Florent Launay Florent Launay Undergraduate student at FIT Undergraduate student at FIT

Transcript of Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at...

Page 1: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Constraint Constraint Satisfaction Satisfaction

Problems and Problems and Consistency Consistency RestorationRestoration

Florent LaunayFlorent Launay

Undergraduate student at FITUndergraduate student at FIT

Page 2: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

SummarySummary

Focused interest in time point-sequencing Focused interest in time point-sequencing problem.problem.

What are CSP’s ?What are CSP’s ? Crossword Problem.Crossword Problem. Dealing with consistency.Dealing with consistency.

1. Finding and storing consistent relations1. Finding and storing consistent relations 2. Finding a “minimal set to remove 2. Finding a “minimal set to remove

inconsistency”inconsistency” Linking the algorithmsLinking the algorithms Questions, comments.Questions, comments. The ProgramThe Program

Page 3: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Focus interestFocus interest

Relation from {<, >, =, <>, <=, >=, <=>}Relation from {<, >, =, <>, <=, >=, <=>}

P1

P2

P3

Here, we can see that some constraints between the set of points {P1, P2, P3} exist :

•P1 < P2

•P2 < P3

Page 4: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

What are CSP’s ?What are CSP’s ?

ConstraintsConstraints

X >= 5 X <> 9 X < 12

Page 5: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

What are CSP’s ?What are CSP’s ?

Example :Example :

Common names from English vocabulary Common names from English vocabulary beginning with a ‘c’, ending with a ‘t’, beginning with a ‘c’, ending with a ‘t’, but that doesn’t contain any ‘e’…but that doesn’t contain any ‘e’…

Valid set : {‘count’, ‘cart’, ‘chat’, ‘court’, …}Valid set : {‘count’, ‘cart’, ‘chat’, ‘court’, …}

Page 6: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

What are CSP’s ?What are CSP’s ?

Valid regions and ‘Box’Valid regions and ‘Box’

5 9 12

X >= 5 X <> 9

X < 12

Valid regions = {[5,5], [5,9], [9,12]}

X < 15

X > 3

153

Page 7: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

What are CSP’s ?What are CSP’s ?

InconsistenciesInconsistencies

5 9 12

X >= 5 X <> 9 X < 12 X > 13

13

No valid region => The system is inconsistent

Page 8: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

The crossword problemThe crossword problem• Constraints

• Valid Set

Inconsistency

Definition, Size of the world, across or down, eventual existing letters. Definition 13 : Part of the human body, beginning with an ‘H’(ambiguous)

E A D ?A N D ?A I R HO

W

Definition 14 : Negation

{[HEAD], [HAND], [HAIR]}

NOT

A N D

Page 9: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Dealing with consistencyDealing with consistency

Within a set of relations, some Within a set of relations, some relation can conflict with other relation can conflict with other relations in a system, making the relations in a system, making the whole system inconsistent.whole system inconsistent.

Let’s have a look to the Let’s have a look to the following example.following example.

Page 10: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

A simple exampleA simple example

Let s consider a point P1 on a time line basis :Let s consider a point P1 on a time line basis :

Page 11: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

A simple exampleA simple example

Valid regionP2

P2>P1P2>P1

P3<P1 and P3>P2P3<P1 and P3>P2

P1

No valid region can be found for P3 !!!

Page 12: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Dealing with consistencyDealing with consistency

With that kind of inconsistency, two With that kind of inconsistency, two interesting questions arise: interesting questions arise:

Which are the relations that make the Which are the relations that make the system inconsistent ?system inconsistent ?

What would be a minimal set to remove What would be a minimal set to remove to make the system consistent ?to make the system consistent ?

Page 13: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

1. Finding and storing 1. Finding and storing inconsistent relationsinconsistent relations

System of relations

Consistent

YES

NO

Finish

Store inconsistent

relations

Finish

(Call the 2nd algorithm)

Page 14: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations FIND MULTIPLE EQUALITYFIND MULTIPLE EQUALITY

=>Store inconsistent relations=>Store inconsistent relations VERIFY CONSISTENCY IN CASE OF VERIFY CONSISTENCY IN CASE OF

UNIQUE EQUALITYUNIQUE EQUALITY=>Store inconsistent relations=>Store inconsistent relations

FIND THE BOX: PRE-PROCESSINGFIND THE BOX: PRE-PROCESSING=>Store inconsistent relations=>Store inconsistent relations

FIND VALID REGIONSFIND VALID REGIONS=>If no inconsistency has been found=>If no inconsistency has been found

Page 15: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations FIND MULTIPLE EQUALITYFIND MULTIPLE EQUALITY

P2

P1

P3

P4

P5

P6

If Pnew = P3If Pnew = P3

Pnew Pnew

And Pnew = P6And Pnew = P6

The system is inconsistent since P3<>P6The system is inconsistent since P3<>P6

Page 16: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations VERIFY CONSISTENCY IN CASE OF VERIFY CONSISTENCY IN CASE OF

UNIQUE EQUALITYUNIQUE EQUALITY

P2

P1

P3

P4

P5

P6

Pnew

If Pnew = P3If Pnew = P3And Pnew < P2And Pnew < P2The system is inconsistentThe system is inconsistent

Page 17: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations FIND THE BOX: PRE-PROCESSINGFIND THE BOX: PRE-PROCESSING

P2

P1

P3

P4

P5

P6

If If we found that a valid region for Pnew If If we found that a valid region for Pnew was {[P3,P4], [P4,P5]}was {[P3,P4], [P4,P5]}

Then, no other relation should forbid that : ex Pnew > P6,Then, no other relation should forbid that : ex Pnew > P6,Or the system becomes inconsistentOr the system becomes inconsistent

Page 18: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations FIND VALID REGIONSFIND VALID REGIONS

=>If no inconsistency has been found=>If no inconsistency has been found

P2

P1

P3

P4

P5

P6

A valid region region could be :A valid region region could be : {[P2,P3], [P3,P3], [P3,P4], [P4,P5], [P5,P5], [P5,P6]}{[P2,P3], [P3,P3], [P3,P4], [P4,P5], [P5,P5], [P5,P6]}

Page 19: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Inconsistent relationsInconsistent relations

End of the first algorithm…End of the first algorithm…

Page 20: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

2. Finding a minimal set to 2. Finding a minimal set to remove to make the system remove to make the system

consistentconsistentSET OF RELATIONS MAKING THE SYSTEM INCONSISTENT

Algorithm

MINIMUM SET OF RELATIONS MAKING THE SYSTEM INCONSISTENT

MAXIXMUM SET OF CONSISTENT RELATIONS

Page 21: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

2. Finding a minimal set to 2. Finding a minimal set to remove to make the system remove to make the system

consistentconsistent

This short algorithm finds a This short algorithm finds a minimal set. We will illustrate this minimal set. We will illustrate this with an other example. But first, we with an other example. But first, we have to introduce the notion of have to introduce the notion of “degree of inconsistency”.“degree of inconsistency”.

Page 22: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Degree of inconsistencyDegree of inconsistencyHere, if we want to add a new point Pnew such Here, if we want to add a new point Pnew such

that:that:Pnew < P1,Pnew < P1, Pnew > P5Pnew > P5Pnew < P2, Pnew < P2, Pnew > P6Pnew > P6Pnew < P3, Pnew < P3, Pnew < P4,Pnew < P4,

P2

P1

P3

P4

P5

P6

Page 23: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Degree of inconsistencyDegree of inconsistencyFrom here, we can see that :From here, we can see that :

Pnew < P1 conflicts with Pnew > P5Pnew < P1 conflicts with Pnew > P5 Pnew < P3 conflicts Pnew < P3 conflicts with Pnew > P5with Pnew > P5Pnew < P1 conflicts with Pnew > P6Pnew < P1 conflicts with Pnew > P6 Pnew < P3 conflicts Pnew < P3 conflicts with Pnew > P6with Pnew > P6Pnew < P2 conflicts with Pnew > P5Pnew < P2 conflicts with Pnew > P5 Pnew < P4 conflicts Pnew < P4 conflicts with Pnew > P5with Pnew > P5Pnew < P2 conflicts with Pnew > P6Pnew < P2 conflicts with Pnew > P6 Pnew < P4 conflicts Pnew < P4 conflicts with Pnew > P6with Pnew > P6

P2

P1

P3

P4

P5

P6

Page 24: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Questions before we move to the Questions before we move to the Algorithm ?Algorithm ?

Page 25: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

AlgorithmAlgorithm Var: Var:

S = set of all relations making the system S = set of all relations making the system inconsistentinconsistent

nnSS = number of relations in S = number of relations in S

R = Temporary relation with highest degree R = Temporary relation with highest degree of of inconsistency in Sinconsistency in S

mmRR = degree of inconsistency of R = degree of inconsistency of R

I = a set of minimal relation to remove in I = a set of minimal relation to remove in order to order to make the system consistentmake the system consistent

Page 26: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

AlgorithmAlgorithm Initialize I to be empty;Initialize I to be empty;

While (nWhile (nSS != 0) { != 0) {* Find the relation R with highest inconsistent * Find the relation R with highest inconsistent

degree m;degree m;

* n* nSS = n = nSS – m – mRR;;* Remove 1 from every inconsistent degree * Remove 1 from every inconsistent degree

from every from every relation conflicting with R;relation conflicting with R;* Record R in I;* Record R in I;* Remove every inconsistent relation * Remove every inconsistent relation

conflicting with R from S;conflicting with R from S;* Remove R from S;* Remove R from S;

}}

Page 27: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

ExampleExample

Let us consider the last example. Here Let us consider the last example. Here are the variables of the algorithm.are the variables of the algorithm.

S= {P1,P2, P3, P4, P5, P6}S= {P1,P2, P3, P4, P5, P6} 2 Pinc < P1 * Pinc > 2 Pinc < P1 * Pinc > P5 4P5 4 22 Pinc < P1 * Pinc > Pinc < P1 * Pinc > P6 4P6 4

2 Pinc < P3 * Pinc > 2 Pinc < P3 * Pinc > P6 4P6 4

22 Pinc < P2 * Pinc > Pinc < P2 * Pinc > P5 4P5 4 22 Pinc < P2 * Pinc > Pinc < P2 * Pinc > P6 4P6 4

2 Pinc < P4 * Pinc > 2 Pinc < P4 * Pinc > P5 4P5 4

2 Pinc < P3 * Pinc > 2 Pinc < P3 * Pinc > P5 4P5 4

2 Pinc < P4 * Pinc > 2 Pinc < P4 * Pinc > P6 4P6 4

nnSS = 8 = 8 R = {}R = {}mmRR = 0 = 0

I = {}I = {}

S

nSS relatio

ns

Degree of inconsistency

Page 28: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

ExampleExample

One relation with highest One relation with highest inconsistency degree is :inconsistency degree is :Pinc > P5.Pinc > P5.

S= {P1,P2, P3, P4, P5, P6}S= {P1,P2, P3, P4, P5, P6} 2 Pinc < P1 * Pinc > 2 Pinc < P1 * Pinc > P5 4P5 4 22 Pinc < P1 * Pinc > Pinc < P1 * Pinc > P6 4P6 4

2 Pinc < P3 * Pinc > 2 Pinc < P3 * Pinc > P6 4P6 4

22 Pinc < P2 * Pinc > Pinc < P2 * Pinc > P5 4P5 4 22 Pinc < P2 * Pinc > Pinc < P2 * Pinc > P6 4P6 4

2 Pinc < P4 * Pinc > 2 Pinc < P4 * Pinc > P5 4P5 4

2 Pinc < P3 * Pinc > 2 Pinc < P3 * Pinc > P5 4P5 4

2 Pinc < P4 * Pinc > 2 Pinc < P4 * Pinc > P6 4P6 4

nnSS = 8 = 8 R = {}R = {}mmRR = 0 = 0

I = {}I = {}

S

8 – 4 = 48 – 4 = 4{Pinc>P5}{Pinc>P5}

44

{Pinc>P5}{Pinc>P5}

11111111

Find the relation R with highest inconsistency degreenS = nS – mR Remove 1 from every inconsistent degree from every relation conflicting with R

Record R in IRemove every inconsistent relation conflicting with R from SRemove R from S

11111111

Page 29: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

ExampleExample

The variables are now :The variables are now :

S= {P1,P2, P3, P4, P6}S= {P1,P2, P3, P4, P6}

11 Pinc < P1 * Pinc > Pinc < P1 * Pinc > P6 4P6 4

1 Pinc < P3 * Pinc > 1 Pinc < P3 * Pinc > P6 4P6 4

11 Pinc < P2 * Pinc > Pinc < P2 * Pinc > P6 4P6 4

1 Pinc < P4 * Pinc > 1 Pinc < P4 * Pinc > P6 4P6 4

nnSS = 4 = 4R = {Pinc>P5}R = {Pinc>P5}mmRR = 4 = 4

I = {Pinc>P5}I = {Pinc>P5}

S

The relation with highest The relation with highest inconsistency degree is now inconsistency degree is now Pinc>P6.Pinc>P6.

44

{Pinc>P6}{Pinc>P6}4 – 4 = 04 – 4 = 0

{Pinc>P5 , Pinc>P6}{Pinc>P5 , Pinc>P6}

n = 0, the system is now consistent, and a minimal set to removen = 0, the system is now consistent, and a minimal set to remove is found : I = {Pinc>P5, Pinc>P6}is found : I = {Pinc>P5, Pinc>P6}Find the relation R with highest inconsistency degreenS = nS – mR Remove 1 from every inconsistent degree from every relation

conflicting with RRecord R in IRemove every inconsistent relation conflicting with R from SRemove R from S

00000000

Page 30: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Linking the algorithmsLinking the algorithms

Page 31: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Linking the algorithmsLinking the algorithms

Consistent ? Store InputYes

No

Find Set of inconsistent

relations

Find minimal set to remove to make the system consistent

Set constraints

Choose input

S

I

Perform algorithm

Page 32: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

””Constraint programming represents Constraint programming represents one of the closest approaches one of the closest approaches computer science has yet made to computer science has yet made to the Holy Grail of programming: the the Holy Grail of programming: the user states the problem, the user states the problem, the computer solves it.”computer solves it.”

Eugene C. Freuder, Eugene C. Freuder, CONSTRAINTSCONSTRAINTS, , April 1997 April 1997

Page 33: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

Questions, comments ?Questions, comments ?

Page 34: Constraint Satisfaction Problems and Consistency Restoration Florent Launay Undergraduate student at FIT.

The Program…The Program…