Date post: | 20-Dec-2015 |
Category: |
Documents |
View: | 214 times |
Download: | 0 times |
Encoding digraphs
X1
X2
X5X4
X3 X1 in 5..5, X2 in {1,5},X3 in 2..2, X4 in {2,3},X5 in 4..4
?- X1 in 5..5, X2 in {1,5},X3 in 2..2, X4 in {2,3},X5 in 4..4,circuit([X1,X2,X3,X4,X5]).
Circuit/1
X1
X2
X5X4
X3
X1=5 X2=1 X3=2 X4=3 X5=4
Find a Hamiltonian circuit in a digraph.
Cycle/2 (CHIP only)
X1
X2
X3
X4X5
X6graph(L) :- L = [X1,X2,X3,X4,X5,X6], X1 :: [2,6], X2 :: [3,4], X3 :: [1], X4 :: [2,3], X5 :: [2,6], X6 :: [2,5], cycle(2, L), labeling(L).
?- graph(L).
L = [2,4,1,3,6,5]
Among/5 (CHIP only)
group
Each 20-day period the staff must have 4 breaks.Each break must be 2-4 days.The staff must work no more than 3 days in a row.There must be at least 10 days off.
Among/5
among([Nmin,Nmax,Smin,Smax,Dmin,Dmax,Tmin,Tmax], [V1,...,Vn], [C1,...,Cn], [V1,...,Vi], all)
Nmin - Nmax groupsSmin - Smax size of each groupDmin - Dmax distance between groupsTmin - Tmax total size of groupsV1,...,Vi are group elements
Among/5
?- [X1,...,X20] :: 0..1, among([4, 4, 2, 4, 1, 3, 10, 20], [X1,...,X20], [0,...,0], [0], all).
Outline
Constrain-and-generateDisjunctive constraintsReified constraintsRedundant constraintsLocal search strategies
NP-complete problems
Characteristic features of CLP(FD) problems: The depth of the computation which leads
to a solution is often polynomially bounded There may be exponentially many choices
Try to avoid as many choices as possible, or delay choices as late as possible
Generate and test
nqueens(N, L) :-intlist(1, N, Diag),permutation(Diag, L),safe(L).
safe([]).safe([X|Xs]) :-
no_attack(X, Xs, 1),safe(Xs).
...
Search tree
Constrain and generate
nqueens(N, L) :-length(L, N),safe(L),labeling([], L).
safe([]).safe([X|Xs]) :-
no_attack(X, Xs, 1),safe(Xs).
...
Constrain and generate
Search
Set up the constraints
Create variableA constraintstore
Anotherconstraintstore
Disjunctive problem
sequence(task(S1, D1), task(S2, D2)) :-S1 + D1 #=< S2.
sequence(task(S1, D1), task(S2, D2)) :-S2 + D2 #=< S1.
Some problems are disjunctive by nature
Disjunctive constraints
sequence(task(S1, D1), task(S2, D2)) :-(S1 + D1 #=< S2) #\/ (S2 + D2 #=< S1).
Global constraints
sequence(task(S1, D1), task(S2, D2)) :-cumulative([S1, S2], [D1, D2], [1, 1], 1).
Global constraints provide efficientpropagation algorithms for disjunctiveproblems:
Avoiding disjunction
contact(X1, X2) :- X1+1 #= X2.contact(X1, X2) :- X1 #= X2+1.
contact(X1, X2) :- abs(X1-X2) #= 1.
x
Reified constraints
Assume that we want precisely twoof C1, C2 and C3 to hold
two(C1, C2, C3) :- C1, C2, ~C3.two(C1, C2, C3) :- C1, ~C2, C3.two(C1, C2, C3) :- ~C1, C2, C3.
Reified constraints
Constraint #<=> B
The (reified) constraint:
holds when (1) B=1 and Constraint isentailed by the store, or (2) B=0 and~Constraint is entailed by the store.
Ask and tell constraints
A tell-constraint is added to the store, (which may become inconsistent). E.g. sat(~A*B).
Ask-constraints are used to check the state of the store. They are not added to the store. E.g. taut(~A*B, 1).
Reified constraints are generalized ask-constraints!
Example
two(C1, C2, C3) :-B1 in 0..1,B2 in 0..1,B3 in 0..1,C1 #<=> B1,C2 #<=> B2,C3 #<=> B3,B1 + B2 + B3 #= 2.
Example
sequence(tast(S1, D1), task(S2, D2)) :-(S1 + D1 #=< S2) #<=> B1,(S2 + D2 #=< S1) #<=> B2,B1 + B2 #= 1.
or(C1, C2) :-C1 #<=> B1,C2 #<=> B2,B1 + B2 #= 1.
Example
exactly([], 0). exactly([C|Cs], N) :-
C #<=> B,N #= B + M,exactly(Cs, M)
Reified constraints IV
count(_, [], 0). count(X, [Y|Ys], N) :-
(X #= Y) #<=> B,N #= M+B,count(X, Ys, M).
?- X in 1..2, X1 in 0..2, X2 in 2..4, count(X, [X1,X2], 2).
X = X1 = X2 = 2
Redundant constraints
Constraints that do not contribute to the solution(s), ...
...but may prune the search space,......or improve the propagation in case
of incomplete solvers.Can also be used to prune symmetric
solutions.
Redundant constraint II
The constraint:X #< Z
is redundant in the presence ofX #< Y , Y #< Z
More constraints may improve the propagation, but may impose more work.
Example: Protein folding
H P H P P H H P H P P H P H H P P H P H
H
P
Hydrophobic
Polar
A protein is a string of amino-acids (monomers):
For instance:
Energy: -1
2-D lattice model
Energy: -2Energy: -3Energy: -4Energy: -5Energy: -6Energy: -7Energy: -8Energy: -9HP
H
P P
H H
P H P
PH
PH
H P
PHP
H
Constraint problem?
Constraints: Self-avoidance; Unit distance between adjacent
monomers;
Optimisation problem: Minimize energy induced by non-local
contacts between H-monomers;
Variables
We associate coordinates (Xi ,Yi) with each monomer i;
We associate a boolean contact variable Cij with each pair of non-adjacent H-monomers;
Constraints
DX in 0..1, DX #= abs(Xi - Xi+1),DY in 0..1, DY #= abs(Yi - Yi+1),DX + DY #= 1
Adjacent monomers must be distance 1 apart:
abs(Xi - Xj) + abs(Yi - Yj) #> 0
Self avoidance (for all i and j s.t. i < j):
Non-local H-contacts
DX #= abs(Xi - Xj),DY #= abs(Yi - Yj),Cij in 0..1,(DX + DY #= 1) #<=> Cij
Modelling potential contacts between non-adjacentH-monomers:
Minimize sum of all (-1 * Cij).
Constrain and generate
fold(String) :-length(String, N1), N is 2 * N1,create_coordinates(String, Xs, Ys),create_contacts(String, Xs, Ys, Contacts),domain(Xs, 0, N),domain(Ys, 0, N),setup_initial(Xs, Ys, N1, N1),setup_distance(Xs, Ys),setup_different(Xs, Ys),setup_energy(Contacts, Xs, Ys, Energy),merge(Xs, Ys, Coord),labeling([ff, minimize(Energy)], Coord).
Redundant constraints
There can be no contact between H-monomers in even (or odd) positions.
Internal H-monomers can have at most 2 non-local H-contacts. H-monomers at the ends can have at most three H-contacts.
Search strategies
optimal optimalNo pruning
Branch & bound
Incomplete strategies
Local search random or steepest descent tabu search
Monte carlo search simulated annealing random walk genetic algorithms
S1
S2
S3S4
S5
Local search
S, S’: solutionsN(S): solutions in the neighborhood of SF: objective function
S0 N(S0)
Local search scheme
1. Select initial solution S2. Let S be some solution in N(S)3. Repeat 2 until some stop
criterion
Random descent
1. Let S be initial solution2. Select S’ in N(S) such that F(S’)
> F(S)3. Let S := S’4. Repeat steps 2-3 until local
optimum
Steepest descent
1. Let S be initial solution2. Select S’ in N(S) such that:
(i) F(S’) > F(S)(ii) F(S’) >= F(S’’) for all S’’ in
N(S)3. Let S := S’4. Repeat steps 2-3 until local
optimum
Avoiding local optima
Extend the neighborhoodRepeat the whole procedure starting
from alternative initial solutions (iterated descent)
Make the neighborhood dependent on the history; forbid certain moves (tabu search)
Monte Carlo search
1. Let S be an initial solution2. Let S’ be a random solution in N(S)3. Let S := S’ if F(S’) > F(S)4. Otherwise let S := S’ with a
probabilitymonotone in F(S’) - F(S)
5. Repeat 2-5 until some stop condition
Monte carlo methods
Simulated annealing: The probability of bad moves is reduced as the search proceeds;
Random walk: Let p be a low probability. Make an improving move with probability 1-p; make a completely random move with probability p.