Document Sample

Constraint Satisfaction Problems Vijay Srinivas Nori Intelligent Systems Department of CSE, IITKGP Introduction to CSP • Definition: A constraint satisfaction problem is defined by a set of variables Xi and a set of constraints Ci where each variable has a domain of allowed values. Each constraint specifies some subset of variables and the allowable combinations of that subset. Vijay Srinivas Nori Dept of CSE 2 IITKGP Introduction to CSP An assignment that does not violate any constraint is consistent / legal. A solution to a CSP is a complete assignment that satisfies all constraints. Optimization: When more than one complete assignments exist, the solution could be one that optimizes a parameter. Vijay Srinivas Nori Dept of CSE 3 IITKGP Backtracking Search • Definition: Backtracking search is a depth-first search that chooses values for one variable at a time and backtracks when a variable has no legal values left to assign. • Issues: • Which variable to be assigned next ? • In which order should its values be tried? • What are the implications of the current variable assignments for the other unassigned variables? Vijay Srinivas Nori Dept of CSE 4 IITKGP Backtracking Search • When a path fails, that is, a state is reached in which a variable has no legal values can the search avoid repeating this failure in subsequent paths? • The solution methods for CSP answering the above questions are general purpose, they do not need domain specific knowledge to address these issues. Vijay Srinivas Nori Dept of CSE 5 IITKGP Basic CSP heuristics for backtracking search • Minimum Remaining Value: The variable which has the least number of allowed values should be chosen first for assignment since it is the variable which is the most likely to cause a failure soon. • Degree Heuristic: The variable which is involved in the largest number of constraints with other variables should be chosen first • Least Constraining value: A variable should be assigned a value that rules out the fewest choices for the neighbouring variables in the constraint graph. Vijay Srinivas Nori Dept of CSE 6 IITKGP Basic CSP heuristics for backtracking search • Forward Checking: For every variable X assigned, we look at each unassigned variable Y that is connected to X by a constraint and delete from Y ’s domain any value that is inconsistent with the value chosen for X. This detects many inconsistencies. • Constraint Propagation: It is the general term for propagating the implications of a constraint on one variable onto other variables in a fast and efficient manner. Vijay Srinivas Nori Dept of CSE 7 IITKGP Arc Consistency • An arc is a directed edge in the constraint graph • An arc is consistent if for every assignment in the source node = xi, there exists some destination node assignment yi that is consistent with xi. • Arcs can be made consistent by deleting the xi‘s for which the arc is inconsistent from source node. Vijay Srinivas Nori Dept of CSE 8 IITKGP Arc Consistency • It is a fast method of checking which is substantially faster than forward checking • MAC algorithm: Once a domain value of a node is deleted to maintain arc consistency of an outward edge, an inconsistency may arise in an inward edge of the node. Hence the process must be applied repeatedly till no inconsistencies remain. Vijay Srinivas Nori Dept of CSE 9 IITKGP K-consistency • A constraint graph is K consistent if for every set of K-1 variables and consistent assignments to these variables, it is possible to assign a consistent assignment to any kth variable. • K = 2 defines arc consistency and k = 1 defines node consistency. • K = 3 consistency means that any pair of adjacent variables can be extended to a third neighbouring variable which is precisely the notion of path consistency. Vijay Srinivas Nori Dept of CSE 10 IITKGP Strong K-consistency • A graph is strongly K-consistent if it is K- consistent, K-1 consistent, K-2 consistent, K-3 consistent,.. 1 consistent. • Implies: If we have a CSP with n nodes and can make it strongly n consistent, we can solve the problem with no backtracking. • The reason is that we search for a solution for some variable v1. Once we have that we are guaranteed of a solution of v2 since the graph is 2 consistent, and so on, … till n. Vijay Srinivas Nori Dept of CSE 11 IITKGP Strong K-consistency • Of course, an algorithm for establishing n consistency must take time exponential in n in worst case. • There is an optimization here in deciding how much to leave to the search (backtracking) and how much to resolve/prune via consistency checks. • However this is still empirical study in nature. • Special Constraints: resource and at-most x. Vijay Srinivas Nori Dept of CSE 12 IITKGP Intelligent Backtracking • Backtracking should assign different values to the set of variables actually causing the conflict called conflict set. • Backjumping uses the most recent variable in the conflict set. • Forward checking can supply the conflict sets with zero extra work, whenever it deletes some x from domain X while checking with Y, it adds X to Y’s conflict set. However this is redundant if forward checking has already been performed. Vijay Srinivas Nori Dept of CSE 13 IITKGP Conflict directed backjumping • The Constraint directed backjumping algorithm computes the conflict sets in a way to achieve: – It takes us back to the correct point in the search tree where the erroneous branch was followed using – conf(Xi) <- conf(Xi) U conf(Xj) – {Xi} • Constraint learning incorporates fresh constraints preventing us from making similar mistakes again and again in the search. Vijay Srinivas Nori Dept of CSE 14 IITKGP Local Search • Use an initial conflicting assignment and a heuristic. Each variable is changed one at a time to attain the solution • The obvious heuristic is to change the variable to decrease the number of currently occurring conflicts • This technique works particularly well with a good initial assignment and when the solutions are densely distributed in the state space • A comprehensive example 8 Queens is presented now. Vijay Srinivas Nori Dept of CSE 15 IITKGP The 8 Queens Problem • Description: Given a chessboard of 8x8 squares, the goal is to place 8 queens on the board so that no queen can attack any other queen. Each queen can move horizontally, vertically and diagonally in straight lines Vijay Srinivas Nori Dept of CSE 16 IITKGP The 8 Queens Problem • Intuitively the problem implies that since there are 8 queens and 8 rows and columns in all. Hence, not more than one queen can be placed per row and column • Hence exactly one queen needs to be placed per row/column. • Hence the problem simplifies into finding 8 row numbers, one per column, to satisfy the constraint that no queen should be able to attack another. Vijay Srinivas Nori Dept of CSE 17 IITKGP The 8 Queens Problem • The worst case way to tackle the problem would be to enumerate all permutations of 8 numbers and check each one of them with a conflict calculating function, which reports zero conflicts when all constraints have been met. • Local search however works very well with these types of problems. Vijay Srinivas Nori Dept of CSE 18 IITKGP The 8 Queens Problem • The algorithm implemented is a two stage procedure. • Firstly, an initial permutation is chosen for the start configuration • Choosing a permutation ensures that we deal with diagonal conflicts only and not with straight line conflicts. • Then a queen attacking another queen is arbitrarily chosen and swapped with another queen in another column. Vijay Srinivas Nori Dept of CSE 19 IITKGP The 8 Queens Problem • By swapping we ensure that no straight line conflicts get introduced. • If the number of conflicts increases then the swap is reversed and another queen is selected for swapping • Each conflicting queen is thus successively swapped with other queens, when the number of conflicts becomes zero the algorithm quits successfully • If the number of conflicts does not become zero on a fixed number of iterations then the algorithm quits unsuccessfully. Vijay Srinivas Nori Dept of CSE 20 IITKGP The 8 Queens Problem Local Search Algorithm Comments • The algorithm does not find all the solutions to the 8-queens problem which a backtracking algorithm would have found out. • The algorithm does not guarantee that after a certain number of iterations the solution will be attained • The algorithm has been found to be extremely fast when a solution is required. It can be proved that given a good initial assignment function it is linear time. Vijay Srinivas Nori Dept of CSE 21 IITKGP The 8 Queens Problem • Applications: • VLSI testing • Air traffic control • Data/message routing in a multiprocessor computer • Load balancing • Task scheduling • Optical parallel processing • Data compression • Communication systems Vijay Srinivas Nori Dept of CSE 22 IITKGP The 8 Queens Problem • Reference: Efficient Local Search with Conflict minimization: A case study of the N- queens problem—Rok Sosic, IEEE and Jun Gu, IEEE. • Implementation: www.geocities.com/nori_vijay/ Vijay Srinivas Nori Dept of CSE 23 IITKGP The 8 Queens Problem- Sample input Vijay Srinivas Nori Dept of CSE 24 IITKGP The 8 Queens Problem Sample Output Vijay Srinivas Nori Dept of CSE 25 IITKGP The 8 Queens Problem Implementation Eye Openers • Such algorithms are hard to design since it is quite simple, if one were moving a single queen and not swapping, to get a scenario where any move would increase the number of conflicts • Such a scenario would occur when the queens are all on the main diagonal. Any queen moved would increase the number of conflicts. Vijay Srinivas Nori Dept of CSE 26 IITKGP The 8 Queens Problem Implementation Eye Openers • The conflict counting function can influence the direction of alignment greatly. • If for example diagonal conflicts were to be given half the priority of the straight line conflicts, the system has a marked tendency to exhibit only diagonal conflicts and deadlock there. Vijay Srinivas Nori Dept of CSE 27 IITKGP The 8 Queens Problem • The problem is by no means limited to 8 queens, it is in fact an n queens problem. • The algorithm described above can find the solution to 3,000,000 queens in 55 seconds. • Local searches have been found to be much faster than backtracking searches which cannot be applied efficiently for such large problems at all. Vijay Srinivas Nori Dept of CSE 28 IITKGP Hardware Software partitioning • Reference: • Hardware software partitioning - A case for constraint satisfaction by R Mitra and A Basu. Vijay Srinivas Nori Dept of CSE 29 IITKGP Hardware Software partitioning Introduction • Description: A system can be implemented using hardware, software or both hardware and software. The decisions to be taken are which parts of the system to implement as software or hardware. • There are various constraints on the system such as end to end timing constraints, cost constraints and others. Vijay Srinivas Nori Dept of CSE 30 IITKGP Hardware Software partitioning Introduction • Hardware implementation of systems is faster and more efficient than software. • Hardware implementation is less flexible than software. Vijay Srinivas Nori Dept of CSE 31 IITKGP Hardware Software partitioning Introduction • Hardware is expensive and the cost of each hardware module adds directly to system cost. • The cost of software (recurring) is limited to the processor cost, which is usually accounted for already, ROM and RAM costs which is negligible compared to cost of hardware implementation. • An exception is when software needs the support of dedicated hardware to run. Vijay Srinivas Nori Dept of CSE 32 IITKGP Hardware Software partitioning Problem Modelling • The algorithm is modeled as a control and data flow graph (CDFG). • Nodes of the graph are called primitive functions (PFs). Every PF has a set of possible implementations stored in a database, which could be hardware, software, or combinations. • The goal of the algorithm is to select one implementation of each PF to satisfy the constraints Vijay Srinivas Nori Dept of CSE 33 IITKGP Hardware Software partitioning Problem Modelling • Two types of cost are associated with every (PF, PF implementation) pair: • Optimizing costs includes the costs of implementation of each function and the cumulative value must be minimized • Satisfying costs which include the execution periods of the implementations. The interaction between concurrent PFs is taken into account. • Global Timing constraints and cost constraints Vijay Srinivas Nori Dept of CSE 34 IITKGP Hardware Software partitioning Problem Modelling • Inhibiting constraints such as bounded resource allocation and CDFG structure. • System hardware can be reused, PF’s can share the same hardware provided the PF’s are not concurrent. • Software implementations that require hardware support may add extra PF’s to the CDFG, which need to be checked for reuse. • Out of all solutions that satisfy the constraints we pick the one that has least implementation cost. Vijay Srinivas Nori Dept of CSE 35 IITKGP Hardware Software partitioning Algorithm • Select an implementation and control step using the timing constraints and backtrack when necessary. First allocate the PF’s in a zone to some implementation. • Either perform the implementation selections first and schedule them later or vice versa. • A midway strategy: select implementations in the range of a timing constraint, form a schedule of them, hence scheduling only when all relevant information is available. Vijay Srinivas Nori Dept of CSE 36 IITKGP Hardware Software partitioning Algorithm Heuristics • (h1) Order candidate implementations by increasing costs. This increases the possibility that a min cost solution will be found early • (h2) Order by decreasing reuse potential. Because by reusing a module we do not add cost to the target system • (h3) Combining 1 and 2, we do not want unnecessary reuse of very costly modules. • (h4) Choose most constrained variables first: order by increasing implementation list sizes. Vijay Srinivas Nori Dept of CSE 37 IITKGP Hardware Software partitioning Heuristic testing results • h1 is better than h2 but there are several cases where h2 outperforms h1 • h3 consistently outperforms h1, h3 being an intelligent combination of h2 and h1 • Comparing h3 and h4, h4 outperforms h3 in most cases • So a fairly approximate result is h4 > h3 > h1 > h2 Vijay Srinivas Nori Dept of CSE 38 IITKGP Hardware Software partitioning Heuristic testing results Vijay Srinivas Nori Dept of CSE 39 IITKGP Hardware Software partitioning Applications • Implemented in a CAD system called Mickey and applied to • Motor’s speed controller • Electrocardiogram monitoring system • Overcurrent protectors. Vijay Srinivas Nori Dept of CSE 40 IITKGP The End Thank you Vijay Srinivas Nori Dept of CSE 41 IITKGP

DOCUMENT INFO

Shared By:

Categories:

Tags:
Constraint Satisfaction Problems, Constraint Satisfaction, arc consistency, Backtracking search, legal values, constraint propagation, Discrete variables, Continuous variables, local search, linear constraints

Stats:

views: | 12 |

posted: | 3/18/2011 |

language: | English |

pages: | 41 |

OTHER DOCS BY wuyunqing

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.