1 / 67

Chapter 12 Constraint-Satisfaction Problems (CSP)

Chapter 12 Constraint-Satisfaction Problems (CSP). Examples of CSP problems. N-Queens Problem : Given an N x N chessboard, the task is to place N queens on the board so that no two queens are on the same row, column, or diagonal. Graph Coloring :

asis
Download Presentation

Chapter 12 Constraint-Satisfaction Problems (CSP)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 12 Constraint-Satisfaction Problems (CSP)

  2. Examples of CSP problems N-Queens Problem: Given an N x N chessboard, the task is to place N queens on the board so that no two queens are on the same row, column, or diagonal. Graph Coloring : Given a graph of nodes and edges, the task is to assign a color to each node, such that no two adjacent nodes are assigned the same color. Boolean Satisfiability Given a propositional logic formula in conjunctive normal form, must find an assignment of true or false to each variable that results in the entire expression evaluating to true.

  3. Properties of CSP Problems • The CSP Problems stay apart from single-agent-path-finding problems and two player games. • The reason is that in CSP we are not generally interested in the series of moves made to reach a solution, but simply finding a problem state that satisfies all the constraints. • In CSPs, the goal state is always given implicitly, since and explicit description of the goal is a solution of the problem. • While constraint-satisfaction problems appear somewhat different from path-finding problems and two-player games, there is a string similarity among the algorithms employed.

  4. Representation • CSP problems can be represented as set of variables, with a set of values for each variable. • Set of constraints on the values that the variables can be assigned : • unary constraint - specifies a subset of all possible values that can be assigned. • binary constraint - specifies which possible combinations of assignments to a pair of variables satisfy the constraint between them. • ternary constraint - limits the set of values that can be simultaneously assigned to three different variables. • etc.

  5. Dual Representations - Example 1 • Example : a three-by-three crossword puzzle, which is equivalent to solving such a problem with no clues ( any valid words are legal). • Representation #1: • six variables : one for each row and column. • legal values : all possible three-letter words. • nine binary constraints between each row and column: word chosen must assign the same letter to the square common.

  6. Dual Representations - Example 1 • Representation #2: • nine variables : for each square of the puzzle. • legal values : 26 letters of the alphabet. • six ternary constraintsthe letters in each row and column must constitute a legal three-word letter. These two different representations of the problem are duals of each other.

  7. Dual Representation Original Representation constraints constraints variables variables Dual Representations • Every CSP problem formulated as a set of variables, values and constraints has a dual representation. • Each variable of the original representation becomes a constraint in the dual representation. • Each constraint of the original representation becomes a variable in the dual representation.

  8. Dual Representations - Example 2 • Consider representation of a graph coloring problem : • variables : the edges of the original graph. • values : ordered pairs of colors. • constraints : whenever more than one edge is connected to the same node, they all must assign the same color to that node.

  9. Dual Representations • The dual of the dual representation of a CSP is the original representation. • Choice of representation have an effect on the efficiency of solving the problem - it may be easier to solve the dual than the original problem. • For example : the crossword-puzzle is likely to be easier to solve by using the first representation.

  10. Brute-Force Search Brute-Force approach : • Try all the possible assignments of the values to the variables, and check them against the constraints, rejecting those that violate any of them. • If there are n variables and k different values than : k^n possible assignments.

  11. Chronological Backtracking • A much better approach to CSP is a chronological backtracking: • Select an order for variables and values. Assign values to the variables one at a time. • Assign values to the variables one at a time. • Each assignment is made so that all the constraints involving any of the variables that already been assigned are satisfied.

  12. Chronological Backtracking - cont • This allows large parts of the search tree to be pruned. • If variable has no legal assignment, then the last variable that was assigned is reassigned to it’s next legal value. • The algorithm continues until a complete, consistent assignment is found - success, or all possible assignments are shown to violate some constraints - failure. • Can be continued after success in order to find all possible assignments.

  13. Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Chronological Backtracking Tree Generated to solve Four-Queens Problem

  14. Chronological Backtracking • Lets look on the tree generated by chronological backtracking to find all solutions to the Four-Queens problem. • There are 4 variables and 4 possible values. • Chronological Backtracking generates only 16 nodes in contrast of the brute-force algorithm that would generate 256 nodes. • Maximum depth of the tree is the number of variables - 4 in the example. • Branching factor of a node is the number of legal values for the given variable - maximum 4 in the example. • Since these trees have fixed depth,and all the solutions are at the maximum depth, simple depth-first search can be used.

  15. Intelligent Backtracking • We can improve the performance of chronological backtracking using a number of techniques, such as: • variable ordering • backjumping • forward checking

  16. Variable Ordering • The idea of variable ordering is to order the variables from the constrained to least constrained. In general, the variables should be instantiated in increasing order of the size of their remaining domains. • It can be done statically at the beginning of the search or dynamically reordering the remaining variables each time a variable is assigned.

  17. Value Ordering • The order of the values determines the order in which the tree is searched. • It doesn’t effect the tree size and makes no difference if all the solutions are to be found • If only one solution is required it can decrease the time required to find solution • We should order the values from least constraining to most constraining, in order to minimize the time required to find a first solution.

  18. Backjumping • The idea :When a dead-end is reached, instead of simply undoing the last decision made, the decision that actually caused the failure should be modified.

  19. Forward Checking • The idea :When a variable is assigned a value, check each remaining uninstantiated variable to make sure that there is at least one assignment for each that is consistent with all the currently instantiated variables. If not, the current variable is assigned its next value.

  20. Constraint Recording • In CSP problems some constraints are explicitly specified, and others are implied by the explicit constraints. Implicit constraints may be discovered during a backtracking ,or in advance in a preprocessing phase. • The idea : once these implicit constraints are discovered, they should be saved explicitly so that they don’t have to be rediscovered.

  21. Constraint Recording - Example • The constraint graph on the figure consists of • 3 variables (x,y,z) • unary constraint of each variable • x can only be assigned the values a and b • y can only be assigned the values c and d • z can only be assigned the values e and f • binary constraint between each pair of variables. • x and z can only be assigned as x=b,z=e or x=a, z=f • etc.

  22. {a,b} X {ׂ(b,c),(b,d)} {ׂ(b,e),(a,f)} Y Z {c,d} {ׂ(c,e),(d,f)} {e,f} Constraint Recording - Example

  23. Arc Consistency • For each pair of variables X and Y that are related by a binary constraint, we remove from the domain of X any values that do not have at least one corresponding consistent assignment to Y, and vice versa. • Several iterations often required to achieve complete arc consistency. • Algorithm terminates when no additional values are removed in an iteration of examining all the arcs.

  24. Arc Consistency - Example • Because of the constraint between variables x and y, if variable x is assigned to a, then there is no consistent value that can be assigned to variable y. Thus, value a can be deleted from the domain of variable x, since no solution to the problem can assign a to x.

  25. Path Consistency • Path Consistency is a generalization of arc consistency where instead of considering pairs of variables,we examine triples of constrained variables and the path between them.

  26. Path Consistency - Example • Without performing arc consistency first, consider the combinations of assignments to variables x and y that are allowed by the constraint between them. • In particular, if x=b and y=d, then there is no possible assignment to variable z that is consistent with these two assignments. Thus, we can remove the ordered pair (b,d) from the set of pairs allowed by the constraint between x and y.

  27. Arc and Path Consistency • The effect of performing arc or path consistency the resulting search space can be dramatically reduced. • In some cases can eliminate the need for search entirely. • Can be generalized into large groupings of variables, called k-consistency. • The complexity of consistency checks is polynomial in k. • At some point , high order consistency checks become less effective than backtracking search. In practice, arc consistency is almost always worth doing, and path consistency is often worth performing prior to backtracking search.

  28. Heuristic Repair • The idea : Search a space of inconsistent but complete assignments to the variables, until a consistent complete assignment is found. • Example: • In the N-queens problem, this amounts to placing all N queens on the board at the same time, and moving the queens one at a time until a solution is found. • The heuristic, called min-conflicts, is to move a queen that is in conflict with the most other queens, and move it to a position where it conflicts with the fewest other queens.

  29. Advantage of Heuristic Repair • While backtracking techniques can solve on the order of 100-queen problem, heuristic repair can solve million-queen problems, often with only about 50 individual queen moves. • Note: this strategy has been extensively explored in the context of boolean satisfiability where it is referred to as GSAT.

  30. Disadvantage of Heuristic Repair • The main drawback of these approach is that it is not complete , in the sense that it is not guaranteed to find a solution in a finite amount of time, even if one exists. • If there is no solution, these algorithms will run forever, whereas backtracking will eventually discover that the problem is not solvable.

  31. CSP - Conclusion • While CSP problems appear somewhat different from single-agent path-finding and two-player games, there is a strong similarity among the algorithms employed. • For example: backtracking can be viewed as a form of branch-and-bound. • Heuristic repair can be viewed as a heuristic search with the same evaluation function and goal state.

  32. Chapter 13 Parallel Search Algorithms

  33. Parallel Search Algorithms • Search is very computation-intensive process. As a result, there is motivation to apply the most powerful computers available to the task. • In terms of raw computing cycles, the most powerful machines are parallel processors. • Thus, we turn our attention to parallel search algorithms, of three general classes: • parallel node generation and evaluation • parallel window search • tree splitting algorithms.

  34. Parallel Search Algorithms • Space Complexity - is solved by iterative and local search algorithms • Time Complexity - is solved by paralleling the activities to many processors.

  35. Parallel Node Generation • In this approach we parallelize the generation and evaluation of each node. For example, the deep-Blue chess machine uses parallel custom VLSI hardware to generate the next legal moves , and to apply the heuristic evaluation function to each node.

  36. B A D F C E Parallel Node Generation - Example Algorithm - BFS Number of Processors - 5 Problem - Get from A to F

  37. A P. 1 P. 2 B C P. 3 P. 2 P. 1 D E B C E P. 1 P. 2 F D E B P. 1 P. 2 P. 3 P. 1 p. x= processor Parallel Node Generation - Example

  38. Parallel Node Generation - limitations • The technique is inherently domain-specific. • The total amount of parallelism is limited by the domain: • There will always be a maximum amount of parallelism that can be extracted from any domain. • Beyond this amount, additional processors will not speed up the search any further. • (In the example, although there were 5 processors, we eventually used only 3 of them).

  39. Parallel Window Search • In this parallelism approach we give different processors different guesses of the goal. In this way we cutoff many iterations of wrong guesses. This approach is mainly used in Alpha-Beta and IDA* algorithms.

  40. Parallel Window Searchin Alpha-Beta • The main idea : The closer the alpha and beta variables reach the final result value, the more branches are cutoff in search. • The implementation : Given multiple processors, we can divide the range from - to  to series of contiguous but smaller alpha-beta windows, and give each processor the entire three to search from the same root but with different initial values of alpha and beta. One of them will return the actual min-max value , and faster then usual.

  41. Alpha= - 3 Beta= 12  8  2  4  6  14  5  2  Parallel Window Searchin Alpha-Beta- Example1 3  In the alpha-beta original algorithm we cutoff only 2 branches

  42. Alpha= 0 3 Beta=20 3  12  8  2  4  6  14  5  2  Parallel Window Searchin Alpha-Beta- Example2 If we divide the range to 4 slices : -inf to 0, 0 to 3, 3 to 20, 20 to inf, then we can see that the 3rd processor will reach the result, with cutting 4 branches (2 more then before)

  43. Parallel Window Search -Alpha-Beta- Limitations The limit of this parallelism is that even in the actual min-max value, meaning alpha=beta = the final result, b= branching factord=search depth thecomplexity is still O(bd/2)

  44. Parallel Window Searchin IDA* • The main idea : As close the cutoff threshold is close to the result, less nodes are expanded. • The implementation : Given multiple processors, we can initialize each processor with a different cutoff threshold, while all of them search the entire tree. As soon as a processor complete its assigned iteration, it begins the iteration with the next cutoff threshold that not yet assigned to a processor.

  45. 1 6 1 2 8 3 2 4 8 7 4 5 3 7 6 5 Parallel Window Searchin IDA* - Example Start state Goal state Heuristic function = Manhattan Distance

  46. 1 6 8 2 4 7 5 3 1 6 1 6 4 8 2 4 8 2 7 5 3 7 5 3 Parallel Window Searchin IDA* - Example Cutoff Threshold = 6 6 1+7=8 1+7=8

  47. 6 Cutoff Threshold = 8 1 6 8 2 4 1+7=8 1+7=8 7 5 3 1 6 1 6 4 8 2 8 2 4 7 5 3 7 5 3 2+6=8 1 6 4 1 6 2 1 6 6 4 1 8 2 8 4 8 2 8 3 4 2 2+8=10 2+8=10 2+6=8 7 5 3 7 5 3 7 5 7 5 3 1 6 2 1 6 1 6 1 6 2 2 4 3+5=8 4 8 8 8 4 4 8 2 3 5 4+6=10 7 5 3 7 5 3 7 3 7 5 1 6 1 6 4 4 8 2 8 3 3 3+7=10 4+6=10 3+7=10 3+7=10 7 5 7 2 5 Parallel Window Searchin IDA* - Example

  48. Parallel Window Searchin IDA* - Example Cutoff Threshold = 12 • If we continue to process to Threshold=12(and skip also Threshold=10) we would see that it generates only 22 nodes. • The process with Threshold=12 would find the solution very close to the time of the process with Threshold= 8.

  49. 1 6 6 8 2 4 7 5 3 1+7=8 1 6 4 6 1 8 2 4 10+2=12 8 2 1 2 7 3 5 11+1=12 1 2 3 3 8 4 3 7 5 3+9=12 3+9=12 6 4 1 6 1 8 4 4 7 5 6 8 5 2 8 2 2+8=10 7 5 6 1 6 4 7 5 3 7 3 9+3=12 8 2 1 2 4+8=12 4 1 7 5 3 3 8 4 9+3=12 8 6 2 4 4 1 1 2 2 12+0=12 1 2 3 7 5 3 3 3 8 8 7 5 6 7 5 7 5 6 6 8 4 3+7=10 1 4 7 5 6 10+4=14 1 2 8 2 6 3 8 4 7 5 3 7 5 6 6+8=14 1 4 2 6 8 3 7 5 5+7=12 7+5=12 6+6=12 4+6=10 8+4=12 1 1 1 4 4 2 2 4 2 1 1 4 4 2 3 8 6 8 6 8 6 3 3 8 6 2 8 7 5 3 7 5 7 5 7 5 3 7 5 6 8+6=14 1 4 2 3 8 6 7 5 Parallel Window Searchin IDA* - Example Cutoff Threshold = 12(we skipped the 10) 2+6=8 9+5=14

  50. Parallel Window Searchin IDA* - Example Summary • IDA* with one processor would build the 6,8,10,12 iterations A • about 20-30 extra nodes. • IDA* with parallel window , 4 processors would start (6,8,10,12) and the “12” would return the result. • a time of 3 iterations would be saved.

More Related