Constraint Networks basic concepts Alessandro Farinelli Department of Computer Science University of Verona Verona, Italy alessandro.farinelli@univr.it
Motivations: Combinatorial Problems Given a set of possible solutions find the best Combinatorial Problems Main issue: Space of possible solutions is huge Usually exponentialy large Complete search of all solutions is impossible A. Farinelli 2 of 39
Combinatorial Problems: Decision Graph Colouring Given a graph Combinatorial Problems k colours ● colour each node ● such that no two adjacent nodes have the same colour Decision Yes No A. Farinelli 3 of 39
Combinatorial Problems: Optimisation Graph Colouring (optimisation) Given a graph Combinatorial Problems k colours ● colour each node ● Optimisation such that the minimum number of two adjacent nodes have the same colour Decision No No Best A. Farinelli 4 of 39
Combinatorial Problems: Multi-Objective Opt. Portfolio investment Given a set of investments Combinatorial Problems Find a subset of them MO Optimisation (portfolio) Optimisation Such that: Decision Minimise Risk Maximise Profit A. Farinelli 5 of 39
Combinatorial Problems: Graphical Models Characteristics: ● A set of Variables Combinatorial Problems ● A set of Domains, one for MO Optimisation each variable Optimisation ● A set of Local functions Decision Global function is an Graphical Model aggregation of local function A. Farinelli 6 of 39
Combinatorial Problems: Graphical Models II Graph Colouring ● Local functions: number of conflict Combinatorial Problems for each link ● Global function: sum of local MO Optimisation functions Optimisation Graphical Models: Decision Exploit problem structure Graphical Model Extremely efficient Very general, used in many fields: ● Constraint Reasoning ● Bayesian Network ● Error Correcting codes ● ... A. Farinelli 7 of 39
Application: Wide AreaSurveillance Dense Deployment To detect events (e.g., vehicle activity) Energy Harvesting Energy Neutral Operations Sense/sleep modes Sensor Model Activity can be detected by single sensor Neighbors (i.e., overlapping sensors) can communicate Only Neighbors are aware of each other sensors A. Farinelli 8 of 39
The Coordination Problem Energy neutral operation: Constraints on sense/sleep schedules duty cycle Coordination: time Maximise detection probability given constraints on schedules Minimise periods where no sensor is actively sensing Combinatorial problem Similar to Graph Coloring but: Overlapping Areas -> weights ● duty cycle Non binary relationships ● time ● A. Farinelli 9 of 39
W. A. S. Demo A. Farinelli 10 of 39
Field of Constraint Processing Where it comes from ● Artificial Intelligence (vision) ● Programming Languages (Logic Programming) ● Logic based languages (propositional logic) Related Areas ● Hardware and Software Verification ● Operation Research (Integer Programing) ● Information Theory (error correcting codes) ● Agents and Multi Agent Systems (coordination) A. Farinelli 11 of 39
CP: what can we express with constraints All problems that can be formulated as follow: ● Given a set of variables and a set of domains ● Find values for variables such that a given relation holds among them Graph colouring: Variables: nodes ● Domain: colour ● Find colour for nodes such that adjacent nodes do not have ● same colour N-Queens problem: Find positions for N queens on a N by N chessboard such that ● none of them can eat another in one move A. Farinelli 12 of 39
4-Queens problem: first formulation A possible Formulation: 8 variables: ● x1,y1,x2,y2,x3,y3,x4,y4 No two queens on same ● row: x1 != x2, x1 != x3, ... X2 = 2 y2=1 No two queens on same ● column: y1 != y2, y1 != y3, ... Q2 No two queens on same ● diagonal: |x1-x2| != |y1– y2| ... Q1 Q4 X1 = 1 y1=2 Q3 A. Farinelli 13 of 39
4-Queens alternative formulation A (better) Formulation In every valid solution one column for each queen ● Variables: columns r1,r2,r3,r4 r1 = 2 r2 = 1 ● Domain: rows [1...8] Q2 Constraints: Q1 Q4 Columns are all different ● r1 != r2, ... ● |r1 – r2| != 1, |r1 – r3| != 2, ... ● Q3 A. Farinelli 14 of 39
Constraints encode information Constraint as information: ● This class is 45 min. Long ● Four nucleotides that make up the a DNA can only combine in a particular sequence ● In a clause all variable are universally quantified ● In a valid n-queen solutions all queens are in different rows We can exploit constraint to avoid reasoning about useless options ● Encode the n-queens problem with n variables that have n values each A. Farinelli 15 of 39
Constraint Network A constraint network is R=(X,D,C) X set of variables X = {x1,...,xn} D set of domains D = {D1,...,Dn} Di = {v1,...,vk(i)} C set of constraints (Si,Ri) [Si ⊆ X] scope: variables involved in Ri ● Ri subset of cartesian product of variables in Si ● Ri expresses allowed tuples over Si ● Solution: assignment of all variables that satisfies all constraints Tasks: consistency check, find one or all solutions, count solutions, find best solution (optimisation) A. Farinelli 16 of 39
4-Queens example Four variables all with domain [1,...,4] r1 r2 r3 r4 C1 = (S1,R1) S1 = {r1,r2} 1 Q no R1 = {(1,3)(1,4)(2,4)(3,1)(4,1)(4,2)} = R1-2 2 no ... C4 = (S4,R4) 3 ok S4 = {r2,r3} 4 ok R4 = {(1,3)(1,4)(2,4)(3,1)(4,1)(4,2)} = R2-3 ... A. Farinelli 17 of 39
Solution and partial consistent solutions Partial Solution Assignment of a subset of variables ● Consistent partial solution: Partial solution that satisfies all the constraints whose scope contains no un- ● instantiated variables ● A consistent partial solution may not be a subset of a solution r1 r2 r3 r4 r1 r2 r3 r4 r1 r2 r3 r4 1 Q 1 Q 1 Q 2 Q 2 Q 2 Q 3 3 3 Q 4 Q 4 Q 4 Q consistent inconsistent solution A. Farinelli 18 of 39
Map Colouring Given a map decide whether the map can be coloured with 4 different colours so that no adjacent countries have the same colour x2 x1 x4 x5 x3 C1 = ({x1,x2}, x1 != x2) Solution C2 = ({x1,x3}, x1 != x3) ... A. Farinelli 19 of 39
Constraint Network C1 C1 x2 r1 r2 x1 C4 x4 C2 x5 x3 r3 r4 Map Colouring 4-Queens A. Farinelli 20 of 39
Constraint Graph Primal graph ● Node: variable ● Arc: constraint holding between variables C1 x2 x1 x4 C2 x5 x3 Map Colouring A. Farinelli 21 of 39
Dual Graph Nodes: constraints’ scopes Arcs: shared variables x2 x1,x2 x2 x2,x5 x2 x2,x4 x1 x1 x1,x4 x4 x5 x3 x1,x3 x3,x4 x4,x5 x3 x4 Map Colouring A. Farinelli 22 of 39
Crossword Puzzle: Primal graph X1 X2 X3 Possible words: {MAP, ARC} Only word of correct length X4 x1 x3 X5 x2 Di : letters of the alphabet C1 [{x1,x2,x3},(MAP)(ARC)] x4 x5 C2 [{x2,x4,x5},(MAP)(ARC)] A. Farinelli 23 of 39
Crossword Puzzle: dual graph Di : letters of the alphabet C1 [{x1,x2,x3},(MAP)(ARC)] C2 [{x2,x4,x5},(MAP)(ARC)] x1 x3 x2 x1,x2,x3 x2,x4,x5 x2 x4 x5 A. Farinelli 24 of 39
Hypergraphs and Dual Graphs x1 x3 x1 x3 x2 x4 x5 x2 x4 x5 x2 x1,x2,x3 x2,x4,x5 A. Farinelli 25 of 39
Hypergraph and Binary graphs Can always convert a hypergraph into a binary graph ● The dual graph of an Hypergraph is a binary graph ● We can use it to represent our problem But each variable has an exponentially larger domain ● This is a problem for efficiency A. Farinelli 26 of 39
Representing Constraints Tables ● Show all allowed tuples Words in the crossword puzzle ● Arithmetic expressions ● Give an arithmetic expression that allowed tuples should meet X1 != X2 in the n-queen problem ● Propositional formula ● Boolean values of variables Boolean values that satisfy the formula ● (a or b) = {(0,1)(1,0)(1,1)} ● A. Farinelli 27 of 39
Propositional CNF Consider the set of clauses: ● {x1 or not x2, not x2 or not x3, not x3} C3 ● Constraint formulation for SAT x1 x3 ● C1 ({x1,x2},(0,0)(1,0)(1,1)) C1 C2 ● C2 ({x2,x3},(0,0)(1,0)(0,1)) x2 ● C3 ({x3},(0)) Unary constraint ● Ex: Compute dual graph Ex: Consider the set of clauses: {not C, A or B or C, not A or B or E, not B or C or D} ● ● Give CP formulation ● Give Primal and dual graph A. Farinelli 28 of 39
Set operations with relations Relations are subsets of the cartesian product of the variables in their scope ● S: x1,x2,x3 ● R: {(a,b,c,)(c,b,a)(a,a,b)} We can apply standard set-operations on relations ● Intersection ● Union ● Difference Scope must be the same A. Farinelli 29 of 39
Selection, Projection and Join A. Farinelli 30 of 39
Binary constraint Network Constraint Inference x1 x2 R R Given R13 and R23 Y Y R13=R23 = (R,Y)(Y,R) ● != != We can infer R12 R x3 R12 = (R,R)(Y,Y) ● Y Composition x1 x2 = R R Y Y != != R x3 Y A. Farinelli 31 of 39
Binary constraint Network R12 is redundant x1 x2 ● Every deduced constraint is R R Y Y Equivalence of Constraint != Networks: != R ● Same set of variables x3 Y ● Same set of solutions x1 x2 Redundant Constraint = R R ● RC constraint network Y Y ● RC’ = removing R* from RC != != R ● If RC is equivalent to RC’ then x3 Y R*is redundant A. Farinelli 32 of 39
Recommend
More recommend