210 likes | 327 Views
Constraint Satisfaction & Knowledge Representation. Outline. Constraint Satisfaction Problems (CSP) Knowledge Representation in Prolog Backtracking search for CSPs. Constraint satisfaction problems (CSPs). Standard search problem: state goal test successor function CSP:
E N D
Constraint Satisfaction & Knowledge Representation CS 3243 - Constraint Satisfaction
Outline • Constraint Satisfaction Problems (CSP) • Knowledge Representation in Prolog • Backtracking search for CSPs CS 3243 - Constraint Satisfaction
Constraint satisfaction problems (CSPs) • Standard search problem: • state • goal test • successor function • CSP: • state is defined by variablesXi with values from domainDi • goal test is a set of constraints specifying allowable combinations of values for subsets of variables • Simple example of a formal representation language • Allows useful general-purpose algorithms with more power than standard search algorithms CS 3243 - Constraint Satisfaction
Example: Map-Coloring • Variables? • Domains? • Constraints? CS 3243 - Constraint Satisfaction
Example: Map-Coloring • Solutions are complete and consistent assignments CS 3243 - Constraint Satisfaction
Constraint graph • Binary CSP: each constraint relates two variables • Constraint graph: nodes are variables, arcs are constraints CS 3243 - Constraint Satisfaction
Varieties of CSPs • Discrete variables • finite domains: • n variables, domain size d O(dn) complete assignments • e.g., Boolean CSPs, incl.~Boolean satisfiability (NP-complete) • infinite domains: • integers, strings, etc. • e.g., job scheduling, variables are start/end days for each job • need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3 • Continuous variables • e.g., start/end times for Hubble Space Telescope observations • linear constraints solvable in polynomial time by linear programming CS 3243 - Constraint Satisfaction
Varieties of constraints • Unary constraints involve a single variable, • e.g., SA ≠ green • Binary constraints involve pairs of variables, • e.g., SA ≠ WA • Higher-order constraints involve 3 or more variables, • e.g., cryptarithmetic column constraints CS 3243 - Constraint Satisfaction
Example: Cryptarithmetic • Variables: F T U W R O X1 X2 X3 • Domains: {0,1,2,3,4,5,6,7,8,9} • Constraints: Alldiff (F,T,U,W,R,O) • O + O = R + 10 · X1 • X1 + W + W = U + 10 · X2 • X2 + T + T = O + 10 · X3 • X3 = F, T ≠ 0, F≠ 0 CS 3243 - Constraint Satisfaction
Knowledge Representation • How you choose to represent the world • Often bound by the software you want to use • Prolog predicates • Logic problem, 8-queens problem, farmer problem CS 3243 - Constraint Satisfaction
Real-world CSPs • Assignment problems • e.g., who teaches what class • Timetabling problems • e.g., which class is offered when and where? • Transportation scheduling • Factory scheduling • Notice that many real-world problems involve real-valued variables CS 3243 - Constraint Satisfaction
Backtracking search • Variable assignments are commutative • Only need to consider assignments to a single variable at each node branching factor = d and there are dn leaves • Depth-first search for CSPs with single-variable assignments is called backtracking search • Backtracking search is the basic uninformed algorithm for CSPs CS 3243 - Constraint Satisfaction
Backtracking example CS 3243 - Constraint Satisfaction
Backtracking example CS 3243 - Constraint Satisfaction
Backtracking example CS 3243 - Constraint Satisfaction
Backtracking example CS 3243 - Constraint Satisfaction
Improving backtracking efficiency • General-purpose methods can give huge gains in speed: • Which variable should be assigned next? • In what order should its values be tried? • Can we detect inevitable failure early? CS 3243 - Constraint Satisfaction
Minimum-Remaining-Values • MRV: choose the variable with the fewest legal values CS 3243 - Constraint Satisfaction
Degree Heuristic • Tie-breaker among most constrained variables • Degree Heuristic: • choose the variable with the most constraints on remaining variables CS 3243 - Constraint Satisfaction
Least constraining value • Given a variable, choose the least constraining value: • the one that rules out the fewest values in the remaining variables • Combining these heuristics makes 1000 queens feasible CS 3243 - Constraint Satisfaction
Summary • CSPs are a special kind of problem: • states defined by values of a fixed set of variables • goal test defined by constraints on variable values • Backtracking = depth-first search with one variable assigned per node • Prolog does this naturally • Variable ordering and value selection heuristics help significantly CS 3243 - Constraint Satisfaction