Professional Documents
Culture Documents
Constraint Modelling 1
Constraint Modelling 1
3
How does this relate to Constraint Solving?
Compared to what we have seen up to now:
only optimization
requires defining:
▶ neighborhood and
▶ selection criterion (single state)
▶ stopping criterion
⇒ incomplete (i.e., not optimal) but low cost (time and memory)
4
Constraint-Based Local Search
A pure CSP can be transformed easily into a LS problem:
5
Constraint-Based Local Search
A pure CSP can be transformed easily into a LS problem:
Use constraint violations as cost function
Some constraints can be given an infinite cost, these are hard
constraints that all states have to satisfy
Other are soft constraints that will guide the search
Allows us to solve over-constrained problems
Neighborhood is defined as changing a single variable assignment
In that framework redundant constraints play two roles:
5
Constraint-Based Local Search
A pure CSP can be transformed easily into a LS problem:
Use constraint violations as cost function
Some constraints can be given an infinite cost, these are hard
constraints that all states have to satisfy
Other are soft constraints that will guide the search
Allows us to solve over-constrained problems
Neighborhood is defined as changing a single variable assignment
In that framework redundant constraints play two roles: propagation
and
5
Constraint-Based Local Search
A pure CSP can be transformed easily into a LS problem:
Use constraint violations as cost function
Some constraints can be given an infinite cost, these are hard
constraints that all states have to satisfy
Other are soft constraints that will guide the search
Allows us to solve over-constrained problems
Neighborhood is defined as changing a single variable assignment
In that framework redundant constraints play two roles: propagation
and search
5
Violations
Can be composed:
𝑉(𝑐1 ∧ 𝑐2 ) = 𝑉(𝑐1 ) + 𝑉(𝑐2 )
𝑉(𝑐1 ∨ 𝑐2 ) = min(𝑉(𝑐1 ), 𝑉(𝑐2 ))
6
Violations
Can be composed:
𝑉(𝑐1 ∧ 𝑐2 ) = 𝑉(𝑐1 ) + 𝑉(𝑐2 )
𝑉(𝑐1 ∨ 𝑐2 ) = min(𝑉(𝑐1 ), 𝑉(𝑐2 ))
6
N-Queens as a Local Search problem
constraint alldifferent(q);
constraint alldifferent([q[i] + i | i in 1..n]);
constraint alldifferent([q[i] - i | i in 1..n]);
7
N-Queens as a Local Search problem
constraint alldifferent(q);
constraint alldifferent([q[i] + i | i in 1..n]);
constraint alldifferent([q[i] - i | i in 1..n]);
8
alldifferent lists:
→[4, 3, 4, 3] ↘
4
qZqZ
3
ZqZq
2
0Z0Z
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗
4
qZqZ
3
ZqZq
2
0Z0Z
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ Violations:
3
ZqZq
2
0Z0Z
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ Violations:
3
ZqZq 2+
2
0Z0Z
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ Violations:
3
ZqZq 2+2+
2
0Z0Z
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ Violations:
3
ZqZq 2+2+1 = 5
2
0Z0Z Neighborhood:
1
Z0Z0
a b c d
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ Violations:
3
ZqZq 2+2+1 = 5
2
0Z0Z Neighborhood:
1
Z0Z0
a b c d
Move one queen in its column
i.e., change the valuation of a single
variable
8
alldifferent lists:
→[4, 3, 4, 3] ↘[4, 4, 6, 6] ↗[4, 2, 2, 0]
4
qZqZ
4 5
Violations:
3
ZqZq
5 4
2+2+1 = 5
2
0Z0Z
5 2 5 3
Neighborhood:
1
Z0Z0
3 3 2 5
a b c d
Move one queen in its column
i.e., change the valuation of a single
variable
8
Example: Greedy Local Search (aka. Hill-climbing)
9
Example: Min. Conflict Search (MCS) / Heuristics (MCH)
Original heuristics for CBLS on SAT problems (and still part of GSAT,
WalkSAT, etc.)
10
Example: Min. Conflict Search (MCS) / Heuristics (MCH)
Original heuristics for CBLS on SAT problems (and still part of GSAT,
WalkSAT, etc.)
10
Issues
11
Issues
Local extrema
11
Issues
Local extrema
Plateaus
11
Issues
Local extrema
Plateaus
11
Issues
Local extrema
Plateaus
Big neighborhood (might require two steps: variable and then value
selection)
11
0Z0l
ZqZ0
qZ0Z
Z0l0
a b c d
Violation cost =
12
0Z0l 0Z0L
3 2 4
ZqZ0 ZQZ0
2 2 1
qZ0Z QZ0Z
3 2 2
Z0l0
a b c d
Z0L0
3 3
a b c
3
d
12
0Z0l 0Z0L
3 2 4 0Z0L
2 1 4
ZqZ0 ZQZ0
2 2 1 ZQZ0
2 3 2
qZ0Z QZ0Z
3 2 2 QZ0Z
3 3 3
Z0l0
a b c d
Z0L0
3 3
a b c
3
d
Z0L0
2 2
a b c
3
d
12
8
0L0Z0Z0Z
4 2 3 3 2 4 3
Z0Z0Z0ZQ
7 4 4 3 3 3 3 3
Line-wise costs
0ZQZ0Z0Z
6 1 2 2 2 3 2 2
Real local optimum
Z0Z0Z0L0
5 3 3 3 5 4 3 3
0Z0L0Z0Z
4 3 3 3 5 4 3 4 Necessary to get through a
Z0Z0ZQZ0
3 1 2 3 2 3 3 1 worse solution to get to a
2
QZ0Z0Z0Z
3 3 4 3 4 4 3 global optimum
Z0Z0L0Z0
1 3 4 3 3 2 3 4
a b c d e f g h
13
Example: Random walk
14
Being smarter
⇒ combine a way to escape local extrema with some Hill-climbing
Some examples:
diagonal moves (see Practical work session)
15
Being smarter
⇒ combine a way to escape local extrema with some Hill-climbing
Some examples:
diagonal moves (see Practical work session)
Simulated annealing (idem)
15
Being smarter
⇒ combine a way to escape local extrema with some Hill-climbing
Some examples:
diagonal moves (see Practical work session)
Simulated annealing (idem)
Tabu search
15
Being smarter
⇒ combine a way to escape local extrema with some Hill-climbing
Some examples:
diagonal moves (see Practical work session)
Simulated annealing (idem)
Tabu search
random restarts (underrated!)
15
Being smarter
⇒ combine a way to escape local extrema with some Hill-climbing
Some examples:
diagonal moves (see Practical work session)
Simulated annealing (idem)
Tabu search
random restarts (underrated!)
15
Simulated annealing
17
© Texas Materials Institute (UTexas)
18
Practically
At each step:
select a random neighbor (no guidance at all…)
compare its cost with the current cost
accept it or not depending on the temperature but always
accept improving moves
stop if the move was rejected and the temperature too low
(return the best solution found)
Parameters: initial/stopping temperature, cooling regime,
acceptance condition
19
Parameters
Initial temperature:
20
Parameters
Initial temperature: allow any move (random-walk)
Ending temperature:
20
Parameters
Initial temperature: allow any move (random-walk)
Cooling regime:
20
Parameters
Initial temperature: allow any move (random-walk)
Acceptance condition:
20
Parameters
Initial temperature: allow any move (random-walk)
20
Results
21
Results
21
Tabu search
Created by F. Glover in 1986
22
Tabu search
Created by F. Glover in 1986
22
Types of memory
The Tabu-list is usually a list of recently visited states, to avoid cycles
(classical issue with random diagonal moves)
23
6
qZ0Z0Z
5
l0Z0Z0 10
4
qZ0Z0Z 10 10
3
l0Z0Z0 10 10
2
qZ0Z0Z 10
1
l0Z0Z0
a b c d e f
24
6
qZ0Z0Z
6
5
Z0Z0Zq
4
qZ0Z0Z
3
l0Z0Z0 6
2
qZ0Z0Z6
1
l0Z0Z0
a b c d
6
e f
24
6
0l0Z0Z
5
Z0Z0Zq
4
qZ0Z0Z
3
l0Z0Z0
2
qZ0Z0Z3 3
1
l0Z0Z0
a b c d
3
e f
24
6
0l0Z0Z
5
Z0Z0Zq
4
qZ0Z0Z
1
3
l0Z0Z0
2
0Z0l0Z
1
l0Z0Z0
a b c d e f
24
6
0l0Z0Z
5
Z0Z0Zq
4
0ZqZ0Z
3
l0Z0Z0 1
2
0Z0l0Z
1
l0Z0Z0
a b c
1 1
d e f
24
6
0l0Z0Z
5
Z0Z0Zq 1
4
0ZqZ0Z
3
Z0Z0Zq
1
2
0Z0l0Z
1
l0Z0Z0
a b c d e f
24
6
0l0Z0Z
5
Z0Z0l0 1
4
0ZqZ0Z
3
Z0Z0Zq
2
0Z0l0Z
1
l0Z0Z0
a
1
b c d e f
24
6
0l0Z0Z
1
5
Z0Z0l0
4
0ZqZ0Z
1
3
Z0Z0Zq
1
2
0Z0l0Z
1
ZqZ0Z0
1
a b c d e f
24
6
qZ0Z0Z
1
5
Z0Z0l0
4
0ZqZ0Z
1
3
Z0Z0Zq
2
0Z0l0Z
1
ZqZ0Z0
a b c d e f
24
6
qZ0Z0Z
1 1
5
Z0Z0l0
1
4
qZ0Z0Z
1
3
Z0Z0Zq
2
0Z0l0Z
1
ZqZ0Z0
a b c d e f
24
6
0l0Z0Z
1 1
5
Z0Z0l0
4
qZ0Z0Z
1
3
Z0Z0Zq
2
0Z0l0Z
1
ZqZ0Z0
a b
1
c d e
1
f
24
6
0Z0ZqZ
1 1
5
Z0Z0l0
0
4
qZ0Z0Z
3
Z0Z0Zq
2
0Z0l0Z
1
ZqZ0Z0
a b c d e f
24
6
0Z0ZqZ
5
Z0l0Z0
4
qZ0Z0Z
3
Z0Z0Zq
2
0Z0l0Z
1
ZqZ0Z0
a b c d e f
24
Results
25
Population-based approaches
26
Conclusion
Incomplete but efficient method, even with simple algorithms (e.g.,
Hill-climbing with restarts and diagonal moves)
Used for hard problems for which a complete search is not tractable
(e.g., Ant Colony on graph problems by C. Solnon)
Or for problems that are over-constrained (and can be expressed as
optimization) (e.g., MaxSAT)
Can be made generic for CSPs once violations are defined
Remains often tricky to parametrize
Does never prove optimality
27