+ All Categories
Home > Documents > Chapter 4

Chapter 4

Date post: 12-Jan-2016
Category:
Upload: zea
View: 32 times
Download: 0 times
Share this document with a friend
Description:
Shaqra University College of Computer and Information Sciences Information Technology Department Cs 401 - Intelligent systems. Chapter 4. Constraint Satisfaction Problems. Constraint Satisfaction Problems. Introduction - PowerPoint PPT Presentation
43
Chapter 4 Constraint Satisfaction Problems Shaqra University College of Computer and Information Sciences Information Technology Department Cs 401 - Intelligent systems
Transcript
Page 1: Chapter 4

Chapter 4

Constraint Satisfaction Problems

Shaqra UniversityCollege of Computer and Information Sciences Information Technology DepartmentCs 401 - Intelligent systems

Page 2: Chapter 4

2

Constraint Satisfaction ProblemsIntroduction

• Standard search problem: state is a black box supporting goal test, successor function and heuristic function.

• The internal structure of a state is problem specific.

• Constraint Satisfaction Problems (CSP) are a kind of problem where states and goal test conform to a standard, structured, and very simple representation.

• This representation allows defining general purpose heuristics rather than problem-specific ones.

Page 3: Chapter 4

3

Constraint Satisfaction ProblemsSome definitions • A CSP is defined by:

– a set of variables X1, X2,…,Xn where each variable Xi has a non-empty domain Di of possible values.

– a set of constraints C1, C2,…,Cn where each constraint Ci involves some subset of the variables and specifies the allowable combinations of values for that subset.

• A state in a CSP: is defined by an assignment of values to some or all the variables. {Xi = vi, Xj = vj, …}

• Consistent assignment: the one that does not violate any constraint (also called legal assignment).

• Complete assignment: the one in which every variable is mentioned.

Page 4: Chapter 4

4

Constraint Satisfaction ProblemsSome definitions• Solution in CSP: It is a complete assignment that satisfies all the constraints.

– Some CSPs also require a solution that maximizes an objective function.

• Constraint graph: a CSP can be visualized by a constraint graph where nodes correspond to variables and arc to constraints.

• Benefits– Successor function and goal test can be written in a generic way that applies to all

CSPs.– It is possible to develop effective, generic heuristics that require no additional,

domain specific expertise.– The structure of the constraint graph can be used to simplify the solution process.

Page 5: Chapter 4

5

Constraint Satisfaction ProblemsMap coloring example

Color a map so that no adjacent regions have same color using three colors.

• Variables: Regions Ci, i=1 to i=6

• Domains: {Red, Blue, Green}

• Constraints: C1≠C2, C1≠C3, C1≠C5, C5≠C6, etc

• Constraint Graph

C1C2

C3

C5

C6

C4

Page 6: Chapter 4

6

Constraint Satisfaction ProblemsReal world CSPs

• Assignment problems: e.g. who teaches what class?

• Timetabling problems: e.g. which class is offered, when and where?

• Transportation scheduling.

• Hardware configuration.

• Planning problems

• Etc …

Page 7: Chapter 4

7

Constraint Satisfaction ProblemsCSP formulation

A) Incremental formulation

• Initial state: empty assignment {}, in which all variables are unassigned.

• Successor function: a value can be assigned to any unassigned variable provided that it does not conflict with previously assigned variables.

• Goal test: the current assignment is complete.

• Path cost: a constant cost for every step.

Questions: What is the depth of the search tree in this case? Which strategy is suitable?

B) Complete formulation• Every state is a complete assignment that might or might not satisfy the constraints.

Page 8: Chapter 4

8

Constraint Satisfaction ProblemsCSPs Varieties

– Discrete variables• with finite domains

– e.g. Map coloring – Boolean CSPs, where variables can be either true of false.

• with infinite domains – e.g. job scheduling when a deadline is not defined

If d is the maximum domain size for any variable, and n is the number of variables, then the number of possible complete assignments is O(dn)

– Continuous variables• common in the real world; • e.g. Hubble Space Telescope requires precise timing of observations;

Page 9: Chapter 4

9

Constraint Satisfaction ProblemsConstraints varieties• Unary constraint: involves a single variable.

– e.g. C1 ≠ green• Binary constraint: involves pairs of variables.

– e.g. C1 ≠ C3• High order variables: involves 3 or more variables.

• Preferences (soft constraints): – e.g. red is better than blue– often represented by a cost for each variable assignment →

constrained optimization problems

Page 10: Chapter 4

10

Constraint Satisfaction Problems

State space in incremental CSP• Problem: Let’s consider Map coloring problem with 3 regions

and 3 colors.

Page 11: Chapter 4

11

Constraint Satisfaction ProblemsThe state space using the generic CSP incremental formulation has the following

properties:

• maximum depth is n (number of variables).

• The depth of the solution is n.

• Branching factor at the top is nd ( d: size of the domain).

• Branching factor at the next level is (n-1)d * nd = n(n-1)d2 and so on for n levels.

• Number of leaves is n!dn even though there are only dn possible complete assignments.

• Suitable search technique is DFS.

Page 12: Chapter 4

12

Constraint Satisfaction Problems

This can be improved dramatically by noting the following:

• The formulation does not take into account one property of CSPs → Commutativity. In CSP the order of assignment is irrelevant, so many paths are equivalent; the order of application of any given set of actions has no effect on the outcome.

• All CSPs search algorithms generate successors by considering possible assignments for only a single variable at each node in the search space.

• Adding assignments cannot correct a violated constraint.

Page 13: Chapter 4

13

Constraint Satisfaction Problems

Backtracking search for CSPs

• Basic idea : backtracking search uses depth first search choosing values for one variable at a time and backtracks when a variable has no legal values left to assign.

• Backtracking search is the basic uninformed algorithm for CSPs.

• Policy: when a branch of the search fails, search backs up to the preceding variable and tries a different value for it. This is called chronological backtracking because the most recent decision point is revisited.

Page 14: Chapter 4

14

Constraint Satisfaction Problems

Function backtracking-search (csp) returns a solution, or failurereturn recursive-backtracking ({}, csp)

Function Recursive-Backtracking(assignment, csp) returns a solution, or failureIf assignment is complete return assignmentvar ← SELECT-UNASSIGNED-VARIABLE (variable [csp], assignment, csp)For each value in ORDER-DOMAIN-VALUES(var, assignment,csp) doif value is consistent with assignment according to Constraint[csp] then add {var = value} to assignment result ← Recursive-backtracking(assignment, csp) if result ≠ failure then return result remove {var = value} from assignmentEndreturn failure

Page 15: Chapter 4

15

WA: Western Australia NT: Northern Territory SA: South Australia Q: QueenslandNSW: New South Wales V: Victoria T: Tasmania

WANT

SAQ

NSWV

T

Page 16: Chapter 4

16

Page 17: Chapter 4

17

Page 18: Chapter 4

18

Page 19: Chapter 4

19

Constraint Satisfaction Problems

Notice:

• Standard representation → no need for domain specific initial state, successor function or goal test.

• SELECT-UNASSIGNED-VARIABLE and ORDER-DOMAIN-VALUES can be used to implement the general purpose heuristics.

• This algorithm is not effective for large problems.

• Improvements: can be achieved if the following questions are addressed:

Page 20: Chapter 4

20

Constraint Satisfaction Problems

Questions:

• Which variable should be assigned next and in what order should its values be tried?

• What are the implication of the current variable assignments for the other UNASSIGNED variables?

• When a path fails, can the search avoid repeating this failure in subsequent paths?

Page 21: Chapter 4

21

Constraint Satisfaction Problems Variable and value ordering

var ← SELECT-UNASSIGNED-VARIABLE (variable [csp], assignment, csp)

• This statement simply selects the next unassigned variable in the order given by the list variable [csp].

• It seldom results in efficient search. • Solution: Choose variable with the fewest “legal” values

→ Minimum Remaining Value (MRV heuristic) also called most constrained variable.

Notice: if there is a variable with zero legal values remaining, the MRV heuristic will select X and failure will be detected immediately avoiding pointless search through other variables which always will fail when X is finally selected.

Page 22: Chapter 4

22

Constraint Satisfaction Problems

Problem: Example WA = red, NT = green → SA = blue rather than assigning Q.

After assigning SA, values for Q, NSW and V are all forced.

The performance is 3 to 3000 times better than simple backtracking (What is the cost of computing heuristic values).

Page 23: Chapter 4

23

Constraint Satisfaction Problems

Degree heuristic: What is the first region to color?

Idea: Choose the variable that is involved in the largest number of constraints on other unassigned variables.

Example: degree heuristic for SA is 5

Page 24: Chapter 4

24

Constraint Satisfaction Problems

Variable and value ordering

• Least constraining value (LCV): Once a variable is selected, how to decide on the order in which to examine the values?

• Solution: Choose the least constraining value so that to leave maximum flexibility for subsequent variable assignments.

• Example: WA=red, NT=green, choosing blue for Q is a bad choice because it eliminates the last legal value for SA.

Page 25: Chapter 4

25

Constraint Satisfaction Problems

Page 26: Chapter 4

26

Constraint Satisfaction Problems

Propagating Information through constraints

• Key Idea: Instead of considering the constraints on a variable only at the time that the variable is chosen by SELECT-UNASSIGNED-VARIABLE , LOOK at some constraint earlier or even before.

One alternative: Forward Checking (FC).

• Forward Checking looks at each unassigned variable Y that is connected to X by a constraint and deletes from Y’s domain any value that is inconsistent with the value chosen for X.

Page 27: Chapter 4

27

Constraint Satisfaction Problems

Page 28: Chapter 4

28

Constraint Satisfaction Problems

Page 29: Chapter 4

29

Constraint Satisfaction Problems

Page 30: Chapter 4

30

Constraint Satisfaction Problems

Page 31: Chapter 4

31

Constraint Satisfaction ProblemsNotice:

• After WA= red and Q= green, NT and SA with simple value. → selection by MRV– FC computes the information that the MRV heuristic needs to do its job.

• After V = blue, FC detects that the partial assignment {WA=red, Q=green, V=blue} is inconsistent → the algorithm will therefore backtracks immediately.

Initial domain RGB

RGB RGB

RGB RGB RGB RGB

After WA=red R GB RGB

RGB RGB GB RGB

After Q=green R B G R B RGB B RGB

After V=blue R B G R B RGB

WA NT Q NSW V SA T

Page 32: Chapter 4

32

Constraint Satisfaction ProblemsConstraint propagation

Problem with FC: cannot detect all inconsistencies.Example: WA=red, Q=green → NT and SA are forced to be blue but they are

adjacent. FC does not detect this as an inconsistency.

Solution: Implications on one variable onto other variables should be propagated. → Arc consistency.

Requirements:1. do this fast.2. Time for propagating constraints should not be greater than

reducing the amount of search.

Page 33: Chapter 4

33

Constraint Satisfaction Problems

Page 34: Chapter 4

34

Constraint Satisfaction ProblemsArc consistency (AC) : stronger than FC

• What is an arc? A directed link between variables in the constraint graph.

• Definition: Given the current domains of SA and NSW, the arc is consistent if, for every value x of SA there is some value y of NSW that is consistent with x.

Example: SA={B}, NSW={R, B}– The arc SA→ NSW is consistent– The arc NSW→ SA is not consistent.

• AC can be applied as a preprocessing before the beginning of the search process or during the search as a propagation step after every assignment.

Page 35: Chapter 4

35

Constraint Satisfaction Problems

Page 36: Chapter 4

36

Constraint Satisfaction Problems

Page 37: Chapter 4

37

Constraint Satisfaction Problems

Page 38: Chapter 4

38

Constraint Satisfaction Problems

Page 39: Chapter 4

39

Constraint Satisfaction ProblemsFunction AC-3 (csp) returns the CSP, possibly with reduced domainsinputs: csp,a binary CSP with variables {X1, X2,…., Xn}local variables: queue, a queue of arcs, initially all the arcs in csp

While queue is not empty do(Xi, Xj) ← Remove-first (queue)if Remove-Inconsistent-Values (Xi, Xj) thenfor each Xk in neighbors [Xi]- {Xi} doadd (Xk, Xi) to queue

Function Remove-Inconsistent-Values (Xi, Xj) returns true iff we remove a value removed ← falsefor each x in Domain [Xi] doif no value y in Domain [Xj] allows (x,y) to satisfy the constraint between Xi and Xjthen delete x from Domain [Xi] ;removed ← true;return removed

Page 40: Chapter 4

40

Constraint Satisfaction Problems• Example:

A

BC

>

<

{1,2,3}

{1,2,3}{1,2,3}

Page 41: Chapter 4

41

Constraint Satisfaction Problems

Local search for CSPs

• Many CSPs can be solved efficiently using local search algorithms.

• They use complete-state formulation.

• Initial state assigns a value to every variable and the successor function works by changing the value of one variable at a time.

• In choosing a new value for a variable, the most obvious heuristic is to select the value that results in the minimum number of conflicts with other variables: « The Min-Conflicts » heuristic.

Page 42: Chapter 4

42

Constraint Satisfaction Problems

Function Min-Conflicts(csp, max_steps) returns a solution or failure inputs csp, a constraint satisfaction problem max_steps, the number of steps allowed before giving up. current ← an initial complete assignment for csp

For i=1 to max_steps doIf current is a solution for csp then return currentvar ← a randomly chosen, conflicted variable from VARIABLES[csp]value← the value v for var that minimizes CONFLICTS(var, current,csp)Set var=value in currentreturn failure

Notice : Local search is very effective for reasonable initial state.

Page 43: Chapter 4

43

Summary

CSP : • What is? Variables, Domains of values, and Constraints• Goal: an assignment that is complete and consistent.• How? Perform search using incremental or complete state

formulation.• Incremental formulation: Backtracking search that can be

improved – using heuristics like MRV, most constraining variable and least

constrained value.– using forward checking– Using constraint propagation: AC3 algorithm.

• Complete formulation: Local search can be applied.


Recommended