introduction to gecode
play

Introduction to Gecode Marco Chiarandini Department of Mathematics - PowerPoint PPT Presentation

DM841 Discrete Optimization Part II Lecture 3 Introduction to Gecode Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark Outline Solving CSP Overview 1. Solving CSP Overview 2 Outline


  1. DM841 Discrete Optimization Part II Lecture 3 Introduction to Gecode Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark

  2. Outline Solving CSP – Overview 1. Solving CSP – Overview 2

  3. Outline Solving CSP – Overview 1. Solving CSP – Overview 3

  4. General Purpose Algorithms Solving CSP – Overview Search algorithms organize and explore the search tree ◮ Search tree with branching factor at the top level nd and at the next level ( n − 1 ) d . The tree has n ! · d n leaves even if only d n possible complete assignments. ◮ Insight: CSP is commutative in the order of application of any given set of action (the order of the assignment does not influence final answer) ◮ Hence we can consider search algs that generate successors by considering possible assignments for only a single variable at each node in the search tree. The tree has d n leaves. Backtracking search depth first search that chooses one variable at a time and backtracks when a variable has no legal values left to assign. 4

  5. Backtrack Search Solving CSP – Overview 5

  6. Backtrack Search Solving CSP – Overview ◮ No need to copy solutions all the times but rather extensions and undo extensions ◮ Since CSP is standard then the alg is also standard and can use general purpose algorithms for initial state, successor function and goal test. ◮ Backtracking is uninformed and complete. Other search algorithms may use information in form of heuristics 6

  7. General Purpose Backtracking Solving CSP – Overview Implementation refinements 1) [Search] Which variable should we assign next, and in what order should its values be tried? 2) [Propagation] What are the implications of the current variable assignments for the other unassigned variables? 3) [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? 7

  8. Search Solving CSP – Overview 1) Which variable should we assign next, and in what order should its values be tried? ◮ Select-Initial-Unassigned-Variable degree heuristic (reduces the branching factor) also used as tie breaker ◮ Select-Unassigned-Variable Most constrained variable (DSATUR) = fail-first heuristic = Minimum remaining values (MRV) heuristic (speeds up pruning) ◮ Order-Domain-Values least-constraining-value heuristic (leaves maximum flexibility for subsequent variable assignments) NB: If we search for all the solutions or a solution does not exists, then the ordering does not matter. 8

  9. Search Solving CSP – Overview Branching (aka, Labelling) 1. Pick a variable x with at least two values 2. Pick value v from D ( x ) 3. Branch with x = v x � = v x ≤ v x > v The constraints for branching become part of the model in the subproblems generated The inner nodes (blue circles) are choices, the red square leaf nodes are failures, and the green diamond leaf node is a solution. 9

  10. Exercise Solving CSP – Overview ◮ Solve in Gecode the problem: send + more = money example using lexicographic and first-fail search. Which of the two search strategeis is the best? ◮ Repeat the analysis on this other instance of the problem: gerald + donald = robert Is the conclusion the same as in the point above? 10

  11. Constraint Propagation Solving CSP – Overview 2) What are the implications of the current variable assignments for the other unassigned variables? Definition (Domain consistency) A constraint C on the variables X 1 , . . . , X k is called domain consistent if for each variable X i and each value v i ∈ D ( X i ) ( i = 1 , . . . , k ) , there exists a value v j ∈ D ( X j ) for all j � = i such that ( d 1 , . . . , d k ) ∈ C . Loose definition Domain filtering is the removal of values from variable domains that are not consistent with an individual constraint. Constraint propagation is the repeated application of all domain filtering of individual constraints until no domanin reduction is possible anymore. 12

  12. Constraint Propagation Solving CSP – Overview Three consistency levels Trade off between speed and propagation ◮ Forward checking ◮ Bounds consistency ◮ Domain consistency 13

  13. Constraint Propagation Solving CSP – Overview Problem shown as matrix Each cell corresponds to a variable Instantiated: Shows integer value (large) Uninstantiated: Shows values in domain Currently active constraint highlighted Values removed at a step shown in blue Values assigned at a step shown in red 14

  14. Solving CSP – Overview alldifferent ( distinct ) ◮ Argument: list of variables ◮ Meaning: variables are pairwise different ◮ Reasoning: Forward Checking (FC) ◮ When variable is assigned to value, remove the value from all other variables ◮ If a variable has only one possible value, then it is assigned ◮ If a variable has no possible values, then the constraint fails ◮ Constraint is checked whenever one of its variables is assigned ◮ Equivalent to decomposition into binary disequality constraints 15

  15. Forward checking Solving CSP – Overview H. Simonis’ demo, slides 18-48 16

  16. Can we do better? Solving CSP – Overview Example: P = � X = ( x , y , z ) , DE = { D ( x ) = { 1 , 2 } , D ( x ) = { 1 , 2 } , D ( x ) = { 1 .. 3 }} , C = { C 1 ≡ alldiff ( x , y , z ) }� 17

  17. Bound Consistency Solving CSP – Overview Example: Idea (Hall Intervals) ◮ Take each interval of possible values, say size N ◮ Find all K variables whose domain is completely contained in interval ◮ If K > N then the constraint is infeasible ◮ If K = N then no other variable can use that interval ◮ Remove values from such variables if their bounds change ◮ If K < N do nothing ◮ Re-check whenever domain bounds change 18

  18. Bound Consistency Solving CSP – Overview Definition A constraint achieves bounds consistency, if for the lower and upper bound of every variable, it is possible to find values for all other variables between their lower and upper bounds which satisfy the constraint. 19

  19. Can we do better? Solving CSP – Overview ◮ Bounds consistency only considers min/max bounds ◮ Ignores "holes" in domain ◮ Sometimes we can improve propagation looking at those holes Example: P = � X = ( x , y , z ) , DE = { D ( x ) = { 1 , 3 } , D ( x ) = { 1 , 3 } , D ( x ) = { 1 .. 3 }} , C = { C 1 ≡ alldiff ( x , y , z ) }� 20

  20. Solutions and maximal matchings Solving CSP – Overview ◮ A Matching is subset of edges which do not coincide in any node ◮ No matching can have more edges than number of variables ◮ Every solution corresponds to a maximal matching and vice versa ◮ If a link does not belong to some maximal matching, then it can be removed 21

  21. Domain Consistency Solving CSP – Overview Definition A constraint achieves domain consistency, if for every variable and for every value in its domain, it is possible to find values in the domains of all other variables which satisfy the constraint. ◮ Also called generalized arc consistency (GAC) ◮ or hyper arc consistency 22

  22. Can we still do better? Solving CSP – Overview ◮ NO! This extracts all information from this one constraint ◮ We could perhaps improve speed, but not propagation ◮ But possible to use different model ◮ Or model interaction of multiple constraints 23

  23. Solving CSP – Overview H. Simonis’ demo, slides 80-142 24

  24. Typical? Solving CSP – Overview ◮ This does not always happen ◮ Sometimes, two methods produce same amount of propagation ◮ Possible to predict in certain special cases ◮ In general, tradeoff between speed and propagation ◮ Not always fastest to remove inconsistent values early ◮ But often required to find a solution at all 25

  25. Search Solving CSP – Overview 3) 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? Backtracking-Search ◮ chronological backtracking, the most recent decision point is revisited ◮ backjumping, backtracks to the most recent variable in the conflict set (set of previously assigned variables connected to X by constraints). every branch pruned by backjumping is also pruned by forward checking idea remains: backtrack to reasons of failure. 26

  26. Optimization Problems Solving CSP – Overview Objective function to minimize F ( X 1 , X 2 , . . . , X n ) ◮ Naive approach: find all solutions and choose the best ◮ Branch and Bound approach ◮ Solve a modified Constraint Satisfaction Problem by setting an (upper) bound z ∗ in the objective function Dichotomic search: U upper bound, L lower bound M = U + L 2 27

  27. Types of Variables and Values Solving CSP – Overview ◮ Discrete variables with finite domain: complete enumeration is O ( d n ) ◮ Discrete variables with infinite domains: Impossible by complete enumeration. Propagation by reasoning on bounds. Eg, project planning. S j + p j ≤ S k NB: if only linear constraints, then integer linear programming ◮ Variables with continuous domains (time intervals) branch and reduce NB: if only linear constraints or convex functions then mathematical programming ◮ structured domains (eg, sets, graphs) 28

Recommend


More recommend