next_inactive up previous







Computational Logic
Constraint Programming: Finite Domains

Introduction

Constraint Satisfaction Problems

A Simple Backtracking Solver

Chronological Backtracking Solver

INPUT: a CSP with constraint $C$ and domain $D$.
OUTPUT: Returns $true$ if $C$ is satisfiable (has one or more solutions), otherwise $false$.
METHOD:


back_solve($C, D$) 

if $vars(C) \equiv \emptyset$ then return partial_satisfiable($C$)
else choose $x \in vars(C)$
for each values $d \in D(x)$ do
let $C_1$ be obtained from $C$ by replacing $x$ by $d$
if partial_satisfiable($C_1$) then
if back_solve($C_1, D$) then return $true$ endif
endif
endfor
return $false$
endif

Chronological Backtracking Solver (Contd.)


partial_satisfiable($C$) 

let $C$ be of the form $c_1 \wedge \cdots \wedge c_n$ (each $c_i$ is aprimitive constraint)
for $i$ := 1 to $n$ do
if $vars(c_i) \equiv \emptyset$ then
if satisfiable($c_i$) $\equiv false$ then return $false$ endif
endif
endfor
return $true$

Exercise: apply the algorithm to the CSP with constraint

$X < Y \wedge Y < Z$

and domain $D$, such that $D(X) = D(Y) = D(Z) = \{1,2\}$.

Node and Arc Consistency

Node and Arc Consistency (Contd.)

Node and Arc Consistency: Definitions

Node and Arc Consistency: Examples

Algorithm for Node Consistency

INPUT: a CSP with constraint $C$ and domain $D_1$.
OUTPUT: a domain $D_2$ such that the CSP with constraint $C$ and domain $D_2$ is node consistent and is equivalent to the input CSP.
METHOD: $D_2$ := node_consistent($C, D_1$).


node_consistent($C, D$) ($C$ is a constraint and $D$ a domain) 

let $C$ be of the form $c_1 \wedge \cdots \wedge c_n$ (each $c_i$ is aprimitive constraint)
for $i$ := 1 to $n$ do
$D$ := node_consistent_primitive($c_i, D$)
endfor
return $D$

node_consistent_primitive($c, D$)
if $\vert vars(c)\vert = 1$ then
let $\{x\} = vars(c)$ ($x$ is a variable)
$D(x)$ := $\{d \in D(x) \ \vert \ \{x \mapsto d\}$ is a solution of$c \ \}$ ($d$ is a domain value).
endif
return $D$

Algorithm for Arc Consistency

INPUT: a CSP with constraint $C$ and domain $D_1$.
OUTPUT: a domain $D_2$ such that the CSP with constraint $C$ and domain $D_2$ is arc consistent and is equivalent to the input CSP.
METHOD: $D_2$ := arc_consistent($C, D_1$).


arc_consistent($C, D$) ($C$ is a constraint and $D$ a domain) 

let $C$ be of the form $c_1 \wedge \cdots \wedge c_n$ (each $c_i$ is aprimitive constraint)
repeat $W$ := $D$
for $i$ := 1 to $n$ do $D$ := arc_consistent_primitive($c_i, D$) endfor
until $W \equiv D$
return $D$


arc_consistent_primitive($c, D$) 

if $\vert vars(c)\vert = 2$ then
let $\{x, y\} = vars(c)$ ($x$ and $y$ are variables)
$D(x)$ := $\{d_x \in D(x) \ \vert $ for some $ d_y \in D(y) $, $\{x \mapsto d_x, y \mapsto d_y \}$ is a solution of$c \ \}$
$D(y)$ := $\{d_y \in D(y) \ \vert $ for some $ d_x \in D(x) $, $\{x \mapsto d_x, y \mapsto d_y \}$ is a solution of$c \ \}$
endif
return $D$

Incomplete Node and Arc Consistency Solver

INPUT: a CSP with constraint $C$ and domain $D$.
OUTPUT: Returns true, false or unknown. true if the CSP is satisfiable (has one or more solutions); false if the CSP is unsatisfiable (has no solutions); and unknown if the algorithm is not able of determining the satisfaction of the CSP.

METHOD:


arc_solv($C, D$) 

$D$ := node_arc_consistent($C, D$)
if $D$ is a false domain then return false
elseif $D$ is a valuation domain then return $satisfiable(C, D)$
else return unknown
endif

node_arc_consistent($C, D$) 

$D$ := node_consistent($C, D$)
$D$ := arc_consistent($C, D$)
return $D$

Incomplete Node and Arc Consistency Solver: Example

Complete Node and Arc Consistency Solver

INPUT: a CSP with constraint $C$ and domain $D$.
OUTPUT: Returns $true$ if the CSP is satisfiable (has one or more solutions), otherwise return $false$.
METHOD: if back_arc_solv($C, D$) returns $false$, then return $false$, otherwise return $true$.


back_arc_solv($C, D$) 

$D$ := node_arc_consistent($C, D$)
if $D$ is a false domain then return $false$
elseif $D$ is a valuation domain then
if $satisfiable(C, D)$ then return $D$ else return $false$ endif
endif
Choose a variable $x$ such that $\vert D(x)\vert \geq 2$
for each value $d \in D(x)$ do
$D_1$ := back_arc_solv($C \wedge x = d, \ D$)
if $D_1 \neq false$ then return $D_1$ endif
endfor
return $false$

Hyper-Arc Consistency

Bounds Consistency

Bounds Consistency (Contd.)

Bounds Consistency: Example

Propagation Rules

Propagation Rules for the Constraint $X = Y + Z$

INPUT: a domain $D$.
OUTPUT: a domain which is bounds consistent with the constraint $X = Y + Z$.
METHOD:


bounds_consistency_addition($D$) 

$X_{min}$ := $maximum(min_{D}(X), min_{D}(Y) + min_{D}(Z))$
$X_{max}$ := $minimum(max_{D}(X), max_{D}(Y) + max_{D}(Z))$
$D(X)$ := $\{ d_X \in D(X) \ \vert \ X_{min} \leq d_X \leq X_{max} \}$
$Y_{min}$ := $maximum(min_{D}(Y), min_{D}(X) - max_{D}(Z))$
$Y_{max}$ := $minimum(max_{D}(Y), max_{D}(X) - min_{D}(Z))$
$D(Y)$ := $\{ d_Y \in D(Y) \ \vert \ Y_{min} \leq d_Y \leq Y_{max} \}$
$Z_{min}$ := $maximum(min_{D}(Z), min_{D}(X) - max_{D}(Y))$
$Z_{max}$ := $minimum(max_{D}(Z), max_{D}(X) - min_{D}(Y))$
$D(Z)$ := $\{ d_Z \in D(Z) \ \vert \ Z_{min} \leq d_Z \leq Z_{max} \}$
return $D$

Example of Propagation Rules for the Constraint $X = Y + Z$

Propagation Rules for More Complicated Linear Arithmetic Constraints

Propagation Rules for the Constraint $4 W + 3 P + 2 C \leq 9$

INPUT: a domain $D$.
OUTPUT: a domain which is bounds consistent with the constraint
$4 W + 3 P + 2 C \leq 9$.
METHOD:


bounds_consistency_addition($D$) 

$W_{max}$ := $minimum(max_{D}(W), \lfloor \frac{9}{4} - \frac{3}{4}P - \frac{2}{4} C \rfloor)$
$D(W)$ := $\{ d_W \in D(W) \ \vert \ d_W \leq W_{max} \}$
$P_{max}$ := $minimum(max_{D}(P), \lfloor P \frac{9}{3} -\frac{4}{3} W - \frac{2}{3} C \rfloor)$
$D(P)$ := $\{ d_P \in D(P) \ \vert \ d_P \leq P_{max} \}$
$C_{max}$ := $minimum(max_{D}(C), \lfloor \frac{9}{2} - 2 W -\frac{3}{2} P \rfloor)$
$D(C)$ := $\{ d_C \in D(C) \ \vert \ d_C \leq C_{max} \}$
return $D$

Propagation Rules for Nonlinear Constraints

Bounds Consistency Algorithm

Bounds Consistency Algorithm (Contd.)


bounds_consistent($C, D$) ($C$ is a constraint and $D$ a domain) 

let $C$ be of the form $c_1 \wedge \cdots \wedge c_n$ (each $c_i$ is aprimitive constraint)
$C_0$ := $\{c_1, \ldots, c_n\}$
while $C_0 \not\equiv \emptyset$ do
choose $c \in C_0$
$C_0$ := $C_0 \backslash \{c \}$
$D_1$ := bounds_consistent_primitive($c, D$)
if $D_1$ is a false domain then return $D_1$ endif
for $i$ := 1 to $n$ do
if there exists $x \in vars(c_i)$ such that $D_1(x) \neq D(x)$ then $C_0$ := $C_0 \cup \{c_i \}$
endif
endfor
$D$ := $D_1$
endwhile
return $D$

Bounds Consistency Algorithm (Contd.)

bounds_consistent_primitive($c, D$)

Bounds Consistency Algorithm: Example of Execution

Bounds Consistency Algorithm: Example of Execution (Contd.)

Incomplete Bounds Consistency Solver

INPUT: an arithmetic CSP with constraint $C$ and domain $D$.
OUTPUT: Returns true, false or unknown. true if the CSP is satisfiable (has one or more solutions); false if the CSP is unsatisfiable (has no solutions); and unknown if the algorithm is not able of determining the satisfaction of the CSP.

METHOD:


bounds_solv($C, D$) 

$D$ := bounds_consistent($C, D$)
if $D$ is a false domain then return false
elseif $D$ is a valuation domain then return $satisfiable(C, D)$
else return unknown
endif

Incomplete Bounds Consistency Solver: Example

Incomplete Bounds Consistency Solver: Example (Contd.)

Complete Bounds Consistency Solver

INPUT: an arithmetic CSP with constraint $C$ and domain $D$.
OUTPUT: Returns $true$ if the CSP is satisfiable (has one or more solutions), otherwise return $false$.
METHOD: if back_bounds_solv($C, D$) returns $false$, then return $false$, otherwise return $true$.


back_bounds_solv($C, D$) 

$D$ := bounds_consistent($C, D$)
if $D$ is a false domain then return $false$
elseif $D$ is a valuation domain then
if $satisfiable(C, D)$ then return $D$ else return $false$ endif
endif
Choose a variable $x$ such that $\vert D(x)\vert \geq 2$
for each value $d \in D(x)$ do
$D_1$ := back_bounds_solv($C \wedge x = d, \ D$)
if $D_1 \neq false$ then return $D_1$ endif
endfor
return $false$

Complete Bounds Consistency Solver: Example

Complete Bounds Consistency Solver: Example

Example Problem: The Smuggler's Knapsack

Example Problem: The Smuggler's Knapsack

Generalized Consistency

Generalized Consistency (Contd.)

A Consistency Method for the alldifferent Primitive Constraint


alldifferent_consistent_primitive($c, D$) ($c$ is a single alldifferent primitive constraint) 

let $c$ be of the form alldifferent($V$)
while exists $v \in V$ with $D(v) = \{d\}$ for some $d$
$V$ := $V - \{v\}$
for each $v' \in V$ do $D(v')$ := $D(v') - \{d\}$ endfor
endwhile
$nv$ := $\vert V\vert$
$r$ := $\emptyset$
for each $v \in V$ do $r$ := $r \cup D(v)$ endfor
if $nv > \vert r\vert$ then return false endif
return $D$

Optimization for Arithmetic CSPs

Integer Optimizer Based on Retrying

INPUT: an arithmetic CSP with constraint $C$ and domain $D$ and an arithmetic expression $f$ which is the objective function.
OUTPUT: an optimal solution $\theta$ or false if the CSP is unsatisfiable.
METHOD: The answer is the result of evaluating retry_int_opt( $C, D, f, false$).


retry_int_opt($C, D, f, \theta_{best}$) ($\theta_{best}$ is either asolution or false) 

$D_{val}$ := int_solv($C, D$) ($D_{val}$ is a valuation domain or false)
if $D_{val}$ $\equiv false$ then
return $\theta_{best}$
else
let $\theta$ be the solution corresponding to $D_{val}$
return retry_int_opt($C \wedge f < \theta(f), D, f, \theta$)
endif

Integer Optimizer Based on Backtracking

INPUT: an arithmetic CSP with constraint $C$ and domain $D$ and an arithmetic expression $f$ which is the objective function.
OUTPUT: an optimal solution $\theta$ or false if the CSP is unsatisfiable.
METHOD: The answer is the result of evaluating back_int_opt( $C, D, f, false$).



back_int_opt($C, D, f, \theta_{best}$) ($\theta_{best}$ is either asolution or false) 

$D$ := int_consistent($C$, $D$)
if $D$ is a false domain then return $\theta_{best}$
elseif $D$ is a valuation domain then return the solutioncorresponding to $D$
endif
choose a variable $x \in varc(C)$ for which $\vert D(x)\vert \geq 2$
$W$ := $D(x)$
for each $d \in W$ do
if $\theta_{best}\not\equiv false$ then $c$ := $f < \theta_{best}(f)$ else $c$ := true endif
$\theta_{best}$ := back_int_opt($C \wedge c \wedge x = d, D, f, \theta_{best}$)
endfor
return $\theta_{best}$


next_inactive up previous
Last modification: Wed Nov 22 23:44:17 CET 2006 <webmaster@clip.dia.fi.upm.es>[CLIP] [FIM] [UNM]