Pengantar Kecerdasan Buatan Constraint Satisfaction Problems 2 Constraint
Pengantar Kecerdasan Buatan Constraint Satisfaction Problems
2 Constraint Satisfaction Problems • state is defined by variables Xi with values from domain Di • goal test is a set of constraints specifying allowable combinations of values for subsets of variables • A problem is solved when each variable has a value that satisfies all the constraints on the variable • Take adventage of the structure of states and use general-purpose rather than problem-specific heuristics to enable the solution of complex problems • Eliminate large portions of the search space all at once by identifying variable/value combinations that violate the constraints OSCAR KARNALIM, S. T. , M. T.
3 Example: Map-Coloring • Variables WA, NT, Q, NSW, V, SA, T • Domains Di = {red, green, blue} • Constraints: adjacent regions must have different colors • e. g. , WA ≠ NT • (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)} • OSCAR KARNALIM, S. T. , M. T.
4 Constraint Graph • Dipakai untuk menvisualisasikan CSP • nodes are variables, arcs are constraints OSCAR KARNALIM, S. T. , M. T.
5 Variations of Variable • Discrete variables finite domains: • infinite domains: • • Continuous variables OSCAR KARNALIM, S. T. , M. T.
6 Varieties of Constraints • Unary constraints involve a single variable, • • Binary constraints involve pairs of variables, • • e. g. , SA ≠ green e. g. , SA ≠ WA Higher-order constraints / global constraints involve 3 or more variables, • e. g. , alldiff in cryptarithmetic • • Alldiff Each variables must have different values Semua global constraint dapat dikonversi menjadi kumpulan binary constraint OSCAR KARNALIM, S. T. , M. T.
7 Global Constraint Example: Cryptarithmetic • Case : • • TWO + TWO = FOUR Some solution : • • • 216 + 216 = 432 206 + 206 = 412 231 + 231 = 462 236 + 236 = 472 271 + 271 = 542 286 + 286 = 572 • Variables: T, W, O, F, U, R • Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} • Constraints: alldiff OSCAR KARNALIM, S. T. , M. T.
8 Real-world CSPs • Assignment problems • e. g. , who teaches what class • Timetabling problems • Transportation scheduling • Factory scheduling OSCAR KARNALIM, S. T. , M. T.
9 Standard Search Formulation States are defined by the values assigned so far Initial state: the empty assignment { } • Successor function: assign a value to an unassigned variable that does not conflict with current assignment • fail if no legal assignments • Goal test: the current assignment is complete OSCAR KARNALIM, S. T. , M. T.
10 Backtracking Search • Variable assignments are commutative}, i. e. , [ WA = red then NT = green ] same as [ NT = green then WA = red ] • Only need to consider assignments to a single variable at each node • Depth-first search for CSPs with single-variable assignments is called backtracking search • Backtracking search is the basic uninformed algorithm for CSPs • Can solve n-queens for n ≈ 25 OSCAR KARNALIM, S. T. , M. T.
11 Backtracking Search (Cont) OSCAR KARNALIM, S. T. , M. T.
12 Backtracking Example OSCAR KARNALIM, S. T. , M. T.
13 Backtracking Example (Cont) OSCAR KARNALIM, S. T. , M. T.
14 Backtracking Example (Cont) OSCAR KARNALIM, S. T. , M. T.
15 Backtracking Example (Cont) OSCAR KARNALIM, S. T. , M. T.
16 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? • OSCAR KARNALIM, S. T. , M. T.
17 Most Constrained Variable • Most constrained variable: choose the variable with the fewest legal values • a. k. a. minimum remaining values (MRV) heuristic OSCAR KARNALIM, S. T. , M. T.
18 Most Constraining Variable • Tie-breaker among most constrained variables • Most constraining variable: • choose the variable with the most constraints on remaining variables OSCAR KARNALIM, S. T. , M. T.
19 Least Constraining Value • Given a variable, choose the least constraining value: • The one that rules out the fewest values in the remaining variables OSCAR KARNALIM, S. T. , M. T.
20 Dampak Urutan Pemilihan Variabel dan Value • Combining these heuristics makes 1000 queens feasible • Hanya berlaku untuk pencarian untuk satu solusi • • Misal N-queen satu solusi, Map coloring Tidak berlaku untuk pencarian semua solusi • Misal Knapsack, TSP OSCAR KARNALIM, S. T. , M. T.
21 Forward Checking • Idea: Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values • OSCAR KARNALIM, S. T. , M. T.
22 Forward Checking (Cont) OSCAR KARNALIM, S. T. , M. T.
23 Forward Checking (Cont) OSCAR KARNALIM, S. T. , M. T.
24 Constraint Propagation • Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: • NT and SA cannot both be blue! • Constraint propagation repeatedly enforces constraints locally OSCAR KARNALIM, S. T. , M. T.
25 Arc Consistency • Simplest form of propagation makes each arc consistent • X Y is consistent iff for every value x of X there is some allowed OSCAR KARNALIM, S. T. , M. T.
26 Arc Consistency (Cont) • If X loses a value, neighbors of X need to be rechecked • Arc consistency detects failure earlier than forward checking • Can be run as a preprocessor or after each assignment OSCAR KARNALIM, S. T. , M. T.
27 Arc Consistency Algorithm AC-3 • Time complexity: O(n 2 d 3) OSCAR KARNALIM, S. T. , M. T.
28 Local Search for CSPs • Hill-climbing, simulated annealing typically work with "complete" states, i. e. , all variables assigned • To apply to CSPs: allow states with unsatisfied constraints at first, but intend to remove it at goal state • operators reassign variable values • • Variable selection: randomly select any conflicted variable • Value selection by min-conflicts heuristic: choose value that violates the fewest constraints • i. e. , hill-climb with h(n) = total number of violated constraints • OSCAR KARNALIM, S. T. , M. T.
29 Example: 4 -Queens • States: 4 queens in 4 columns (44 = 256 states) • Actions: move queen in column • Goal test: no attacks • Evaluation: h(n) = number of attacks • Given random initial state, can solve n-queens in almost constant time for arbitrary n with high probability (e. g. , n = 10, 000) OSCAR KARNALIM, S. T. , M. T.
30 Referensi • Russell, Stuart J. & Norvig, Peter. Artificial Intelligence: A Modern Approach (3 rd ed. ). Prentice Hall. 2009 • Luger, George F. Artificial Intelligence: Structures and Strategies for Complex Problem Solving. 6 th Edition. Addison Wesley. 2008. • Watson, Mark. , Practical Artificial Intelligence Programming in Java, Open Content – Free e. Book (CC License), 2005. OSCAR KARNALIM, S. T. , M. T.
- Slides: 31