Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraint Programming Peter van Beek University of Waterloo.

Similar presentations


Presentation on theme: "Constraint Programming Peter van Beek University of Waterloo."— Presentation transcript:

1 Constraint Programming Peter van Beek University of Waterloo

2 Applications n Reasoning tasks: ä abductive, diagnostic, temporal, spatial n Cognitive tasks: ä machine vision, natural language processing n Combinatorial tasks: ä scheduling, sequencing, planning

3 Constraint Programming n CP = solve problems by specifying constraints on acceptable solutions n Why CP? ä constraints often a natural part of problems ä once problem is modeled using constraints, wide selection of solution techniques available

4 Constraint-based problem solving n Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains ä define constraints in some language n Solve model ä define search space / choose algorithm –incremental assignment / backtracking search –complete assignments / stochastic search ä design/choose heuristics n Verify and analyze solution

5 n Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains ä define constraints in some language n Solve model ä define search space / choose algorithm –incremental assignment / backtracking search –complete assignments / stochastic search ä design/choose heuristics n Verify and analyze solution Constraint-based problem solving Constraint Satisfaction Problem

6 Constraint satisfaction problem n A CSP is defined by ä a set of variables ä a domain of values for each variable ä a set of constraints between variables n A solution is ä an assignment of a value to each variable that satisfies the constraints

7 n Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains ä define constraints in some language n Solve model ä define search space / choose algorithm –incremental assignment / backtracking search –complete assignments / stochastic search ä design/choose heuristics n Verify and analyze solution Constraint-based problem solving

8 Example: Assembly line sequencing n What order should the cars be manufactured? n Constraints: ä even distributions ä changes in colors ä run length constraints

9 Example: Scheduling What is the earliest that they can all set of for school? Four students, Algy, Bertie, Charlie, and Digby share a flat. Four newspapers are delivered. Each student reads the newspapers in a particular order and for a specified amount of time. Algy arises at 8:30, Bertie and Charlie at 8:45, Digby at 9:30.

10 Schedule Sun 8 am91011 Express Guardian FT

11 Example: Graph coloring Given k colors, does there exist a coloring of the nodes such that adjacent nodes are assigned different colors

12 Example: 3-coloring Variables: v 1, v 2, v 3, v 4, v 5 Domains: {1, 2, 3} Constraints: v i v j if v i and v j are adjacent v2v2 v3v3 v1v1 v5v5 v4v4

13 Example: 3-coloring One solution: v 1 1 v 2 2 v 3 2 v 4 1 v 5 3 v2v2 v3v3 v1v1 v5v5 v4v4

14 Example: Boolean satisfiability Given a Boolean formula, does there exist a satisfying assignment (an assignment of true or false to each variable such that the formula evaluates to true)

15 Example: 3-SAT Variables: x 1, x 2, x 3, x 4, x 5 Domains: {True, False} Constraints: ( x 1 x 2 x 4 ), ( x 2 x 4 x 5 ), ( x 3 x 4 x 5 ) ( x 1 x 2 x 4 ) ( x 2 x 4 x 5 ) ( x 3 x 4 x 5 )

16 Example: 3-SAT One solution: x 1 False x 2 False x 3 False x 4 True x 5 False ( x 1 x 2 x 4 ) ( x 2 x 4 x 5 ) ( x 3 x 4 x 5 )

17 Example: n-queens Place n-queens on an n n board so that no pair of queens attacks each other

18 Example: 4-queens x1 x1 x2x2 x3 x3 x4 x4 Variables: x 1, x 2, x 3, x 4 Domains: {1, 2, 3, 4} Constraints: x i x j and | x i - x j | | i - j |

19 Example: 4-queens One solution: x 1 2 x 2 4 x 3 1 x x1 x1 x2x2 x3 x3 x4 x4 Q Q Q Q

20 Search tree for 4-queens x1 x1 x2x2 x3 x3 x4 x (1,1,1,1)(4,4,4,4)(2,4,1,3)(3,1,4,2)

21 Specification of forward checking Invariant:1 i c, c j n, ( x j, x i ) is arc-consistent x1 x1 x c-1 xc xc x c+1 xn xn currentpastfuture

22 Forward checking {2}{5} Q Q Q {3} {1,4,6} {1,3,4} {3,4,6} x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x2 1

23 Enforcing arc-consistency {a, b, c} < xi xi xj xj

24 Enforcing path-consistency < {a, b, c} xi xi xj xj xk xk < <

25 Search graph for 4-queens (1,1,1,1) (1,1,4,2) (2,4,1,3) (3,1,4,2) (1,1,1,2) (1,1,1,3) (1,1,1,4) (1,4,1,3) (4,1,4,2)

26 Stochastic search Q Q Q x1 x1 Q Initial assignment x2 x2 x3 x3 x4 x4 112 Pick queen in conflict Q Q Q x1 x1 Q x2 x2 x3 x3 x4 x4 Move to min. conflicts Q Q Q x1 x1 Q x2 x2 x3 x3 x4 x4 02 Pick queen in conflict Q Q Q x1 x1 Q x2 x2 x3 x3 x4 x4 2

27 Tractability NP NP-Complete P (SAT, TSP, ILP, CSP, …)

28 Reducibility NP-Complete 3-SAT ILP CSP binary CSP (0,1)-ILP

29 CSP, binary CSP, SAT, 3-SAT, ILP,... n Model and solve in one of these languages n Model in one language, translate into another to solve Options


Download ppt "Constraint Programming Peter van Beek University of Waterloo."

Similar presentations


Ads by Google