+ All Categories
Home > Documents > More global constraints Ulf Nilsson IDA, Linköping university [email protected].

More global constraints Ulf Nilsson IDA, Linköping university [email protected].

Date post: 20-Dec-2015
Category:
View: 214 times
Download: 0 times
Share this document with a friend
44
More global constraints Ulf Nilsson IDA, Linköping university [email protected]
Transcript
Page 1: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

More global constraints

Ulf NilssonIDA, Linköping [email protected]

Page 2: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 3: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

?- 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.

Page 4: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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]

Page 5: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 6: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 7: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Among/5

?- [X1,...,X20] :: 0..1, among([4, 4, 2, 4, 1, 3, 10, 20], [X1,...,X20], [0,...,0], [0], all).

Page 8: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Reducing search

Ulf NilssonIDA, Linköping [email protected]

Page 9: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Outline

Constrain-and-generateDisjunctive constraintsReified constraintsRedundant constraintsLocal search strategies

Page 10: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 11: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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).

...

Page 12: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Search tree

Page 13: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Constrain and generate

nqueens(N, L) :-length(L, N),safe(L),labeling([], L).

safe([]).safe([X|Xs]) :-

no_attack(X, Xs, 1),safe(Xs).

...

Page 14: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Constrain and generate

Search

Set up the constraints

Create variableA constraintstore

Anotherconstraintstore

Page 15: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 16: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Disjunctive constraints

sequence(task(S1, D1), task(S2, D2)) :-(S1 + D1 #=< S2) #\/ (S2 + D2 #=< S1).

Page 17: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Global constraints

sequence(task(S1, D1), task(S2, D2)) :-cumulative([S1, S2], [D1, D2], [1, 1], 1).

Global constraints provide efficientpropagation algorithms for disjunctiveproblems:

Page 18: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Avoiding disjunction

contact(X1, X2) :- X1+1 #= X2.contact(X1, X2) :- X1 #= X2+1.

contact(X1, X2) :- abs(X1-X2) #= 1.

x

Page 19: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 20: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 21: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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!

Page 22: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 23: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 24: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Example

exactly([], 0). exactly([C|Cs], N) :-

C #<=> B,N #= B + M,exactly(Cs, M)

Page 25: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 26: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 27: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 28: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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:

Page 29: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 30: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Constraint problem?

Constraints: Self-avoidance; Unit distance between adjacent

monomers;

Optimisation problem: Minimize energy induced by non-local

contacts between H-monomers;

Page 31: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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;

Page 32: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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):

Page 33: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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).

Page 34: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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).

Page 35: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.

Page 36: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Search strategies

optimal optimalNo pruning

Branch & bound

Page 37: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Incomplete strategies

Local search random or steepest descent tabu search

Monte carlo search simulated annealing random walk genetic algorithms

Page 38: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

S1

S2

S3S4

S5

Local search

S, S’: solutionsN(S): solutions in the neighborhood of SF: objective function

S0 N(S0)

Page 39: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

Local search scheme

1. Select initial solution S2. Let S be some solution in N(S)3. Repeat 2 until some stop

criterion

Page 40: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 41: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 42: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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)

Page 43: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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

Page 44: More global constraints Ulf Nilsson IDA, Linköping university ulfni@ida.liu.se.

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.


Recommended