so far:
backtracking and constraint propagation are example of two classes of methods:
local search: first class
mantain a total assigment to all variables
(not partial, like in backtracking)
may satisfy some constraints, but not all
change the value of a single variable
to try to increase the number of satisfied constraints
aim: satisfy all constraints
constraints: x<z, y<z, z<k
assigment x=1, y=1, z=0, k=2
| assignment: | x=1 | y=1 | z=0 | k=2 |   | |
|---|---|---|---|---|---|---|
| constraints: | x<z | x=1 | z=0 |   | NO | |
| y<z | y=1 | z=0 | NO | |||
| z<k | z=0 | k=2 | OK | |||
change from z=0 in z=2:
| assignment: | x=1 | y=1 | z=2 | k=2 |   | |
|---|---|---|---|---|---|---|
| constraints: | x<z | x=1 | z=2 |   | OK | |
| y<z | y=1 | z=2 | OK | |||
| z<k | z=2 | k=2 | NO | |||
one satisfied constraint ⇒ two satisfied constraints
not all satisfied: repeat
| assignment: | x=1 | y=1 | z=2 | k=2 |   | |
|---|---|---|---|---|---|---|
| constraints: | x<z | x=1 | z=2 |   | OK | |
| y<z | y=1 | z=2 | OK | |||
| z<k | z=2 | k=2 | NO | |||
change to z=1: last constraint satisfied, first two violated
change to k=3: all satisfied
| Assegnamento: | x=1 | y=1 | z=2 | k=3 |   | |
|---|---|---|---|---|---|---|
| Vincoli: | x<z | x=1 | z=2 |   | OK | |
| y<z | y=1 | z=2 | OK | |||
| z<k | z=2 | k=3 | OK | |||
a total assignment satisfies some constraints, possibly all
changing some values, some constraints may:
change the assignment to increase the number of satisfied constraints
as much as possible
all satisfied = solution
current total assignment
consider only the assigments that differ from that only on one variable
switch to the best one among them
cost = number of unsatisfied constraints
(in the current assigment
local search tries to minimize it (zero = solution)
space of total assigments
local search moves from one to one next to it
a solution may not be found, even if one exists
local minima: the current assignement cannot be improved by changing a
single variable
but a solution that differ on three variables or more exists
example: the current assignment
all domains are {0,1,2,3}
constraints:
| x<z | z<k | k<r |
| y<z | k<s |
assigment:
x=0, y=0, z=1, k=1, s=2, r=2
only one violated constraint: z<k
decrease number of violated constraints:
change z or k
no single variable change decreases the number of violated constraint
yet, a solution exists:
x=0,y=0,z=1,k=2,s=3,r=3
differs on three variables
choose the single change resulting in a minimal cost
in the example: only choices that maintain the cost
change to s=3 or r=3
current assigment: x=0, y=0, z=1, k=1, s=2, r=2
| x<z | z<k | k<r |
| y<z | k<s |
changing to s=3:
assigment x=0, y=0, z=1, k=1, s=3, r=2
still a violated constraint
k=2 is one of the best moves
assigment x=0, y=0, z=1, k=2, s=3, r=2
with r=3, solution reached
best change of a single variable
disregard cost of current assigment
choose the best among the next around it
still: local minima possible
domain {0,1,2}
| x=z | z<k | k<m | m=r |
| x=y | r=s | ||
| y=z | m=s |
assigment: 0,0,0,1,1,1,1
only one violated constraint: 1<1
change a single variable ⇒ two violated constraints
except with 0,0,0,0,1,1,1
only one violated constraint
again: all changes violate two constraints
except for 0,0,0,1,1,1,1
same assigment as before
solution exists: 0,0,0,1,2,2,2
can be seen in two ways:
variants for solving this problem
from the example:
way out: weight constraints
every time a constraint is violated, increase its cost
cross = extra cost 1
best change:
crosses are not removed
only added when the constraint is violated
best change:
change k=0 has the same cost of m=2
assume bad choice: k=0
again:
now the best choice is m=2
now it's easy:
problem with hill climbing:
weights decrease the importance of these constraints
at some points, they can be violated
other solution to cycling over assignments
different principle: avoid repeating the same choices
tabu list = last last changes made
avoid repeating a change in the tabu list
is actually a fixed-length queue
contains pairs variable = value
queue full = oldest pair removed
for the sake of the example: tabu list length 4
initially empty
first best change is k=0 (same cost)
pair k=0 enters the queue
new best change: k=1 (same cost)
k=1 enters the queue
next best change for hill climbing: k=0
forbidden because in the tabu list
other same-cost change: k=2
all possible changes for k in the tabu list
select one the best remaining choices
for example: m=2
avoid cycling
bad choices were still possible; example: z=1
longer tabu list: this other choices become tabu at some point
good choices forced
in general: longer tabu lists avoid larger cycles
but: may also make some good paths longer