Docsity

Constraint Satisfaction Problems: Solving Complex Problems with Artificial Intelligence - , Study notes of Computer Science

Partial preview of the text

Download Constraint Satisfaction Problems: Solving Complex Problems with Artificial Intelligence - and more Study notes Computer Science in PDF only on Docsity!

Artificial Intelligence Programming^ Constraint Satisfaction

Chris BrooksDepartment of Computer ScienceUniversity of San Francisco

Department of Computer Science — University of San Francisco – p. 1/

7-2:^ Constraint Satisfaction^ •^ So far, we’ve focused on using search to find the

best^ solution.

-^ In many cases, you just need to find a solution that satisfiessome criteria. •^ These criteria are called constraints. •^ A problem in which we want to find any solution that satisfiesour constraints is a

constraint satisfaction problem

-^ Constraints provide us with additional knowledge about theproblem that we can exploit.^ ◦^ We can also consider optimizing constrained problems.

Department of Computer Science — University of San Francisco – p. 2/

7-4:^ Formalizing a CSP^ •^ We can think of a CSP as a set of variables

{x, x, ..., x^12

}n

-^ Each variable as a domain of possible values

D, D, ..., D^12

n

-^ We also have a set of constraints

C, C, ...^12

◦^ Unary constraints:

x <^10 , ymod

2 == 0, etc

◦^ Binary constraints:

x < y, x^ +^ y <^50 ,

no two adjacent

squares can be the same color, etc ◦ N-ary constraints:

x+^ x+^1

...^ +^ x= 75n^

, weight of chassis

plus engine plus body must be less than 3000 lbs, etc. • An assignment of values to variables that satisfies allconstraints is called a

consistent

solution.

-^ We might might also have an objective function

y^ =^ f^ (x^1

, ..., x)n

that lets us compare solutions.

Department of Computer Science — University of San Francisco – p. 4/

7-5:^ Approaches^ •^ If the domain of all variables is continuous (i.e. real numbers)and constraints are all linear functions, we can use

linear

programming

to solve the problem. ◦^ Express the problem as a system of equations • In other cases, we can use

dynamic programming

-^ Dynamic programming is a form of search. •^ In the most general case, we can express a CSP as a searchproblem.

Department of Computer Science — University of San Francisco – p. 5/

7-7:^ Constraint graph^ •^ Often, the most difficult part of solving a CSP is formulating theproblem.^ •^ It is often useful to visualize the CSP as a

constraint graph

-^ Nodes represent variables, edges represent binary constraints.^ ◦^ For n-ary constraints, we must add nodes that representcombinations of values.

Department of Computer Science — University of San Francisco – p. 7/

7-8:^ Example - Coloring a Bay Area Map

-^ Can we color this map usingonly^ four

colors^ (R,Y,B,G), so that no adjacent countieshave the same color?^ Department of Computer Science — University of San Francisco – p. 8/

7-10:^ Example - Coloring a Bay Area Map^ •^ Initially, pick a color for SF. (Red)^ •^ Our successor function will return all possible colorings thatdon’t violate the constraint.^ ◦^ Marin = Blue, Solano = Red, Alameda = Yellow, Napa =Yellow, etc^ •^ We can be more clever about how to approach this problem^ ◦^ CSPs are commutative; it doesn’t matter which order weassign colors to counties.^ ◦^ Therefore, we should consider one assignment at a time.^ •^ For the moment, let’s start by always assigning a color to thecounty with the smallest domain.

Department of Computer Science — University of San Francisco – p. 10/

7-11:^ Example - Coloring a Bay Area Map^ •^ SF = Red.^ •^ SF = Red, Marin = Blue^ •^ SF = Red, Marin = Blue, Alameda = Yellow^ •^ SF = Red, Marin = Blue, Alameda = Yellow, CC = Green^ •^ etc.^ •^ In this case, we can find a consistent four-coloring,^ •^ What about a 3-coloring?

Department of Computer Science — University of San Francisco – p. 11/

7-13:^ Example - Australia^ •^ Neighbors of Q have a domain of Green, Blue - smallest.^ •^ Choose a neighbor and select a color that satisfies allconstraints.^ •^ NSW = Green.^ •^ Now SA has a domain of size 1 (Blue)^ •^ Coloring SA then fixes the choices for V and NT.

Department of Computer Science — University of San Francisco – p. 13/

7-14:^ Heuristics^ •^ How do we pick which country to color next?^ •^ How do we choose what color to give it?^ •^ Intuition: always try to make decisions that leave as muchflexibility as possible.^ •^ Most constrained variable: pick the variable (country) that hasthe fewest possible choices.^ •^ Least constraining value: pick the value (color) that has theleast effect on possible values for other variables.

Department of Computer Science — University of San Francisco – p. 14/

7-16:^ Example - 8-queens

-^ Problem: place each queenon the board so that noqueen is attacking another. •^ We can reduce this to: Whatrow should each queen bein?

Department of Computer Science — University of San Francisco – p. 16/

7-17:^ Chronological Backtracking^ •^ The easiest approach is to use depth-first search.^ •^ If we reach a point where we can’t place a queen, back up andundo the most recent placement.^ •^ If that placement can’t be changed, undo its predecessor.^ •^ Always undo asignments in reverse order of when they weredone.^ •^ This is called

chronological backtracking

.^ Department of Computer Science — University of San Francisco – p. 17/

7-19:^ Backjumping^ •^ What we’d like to do is identify those variables that are causinga problem and change them directly.^ •^ To do this, when we reach a variable for which we cannot find aconsistent value, we look for all variables that it shares aconstraint with.^ •^ We call these variables the conflict set.^ •^ We then ’unroll’ our search and undo the most recently-setvariable in the conflict set.

Department of Computer Science — University of San Francisco – p. 19/

7-20:^ Example - Australia^ WesternAustralia

NorthernTerritoryQueenslandSouthAustralia

NewSouthWalesVictoriaTasmania

-^ Let’s say our searchalgorithm did the followingcoloring:^ ◦^ Q: Red, NSW: Green, V:Blue, T: Red •^ There is no consistent colorfor SA. •^ Backtracking will try allother colors for T, whichcannot possibly help. •^ The conlict set for SA is{Q,NSW,V}. •^ We backjump and undo V.Once V: Red, we can colorSA.

Department of Computer Science — University of San Francisco – p. 20/