Routing, Geometric and Regulations Constraints
Nicolas Beldiceanu SICS
Lägerhyddsvägen 5 SE-75237 Uppsala, Sweden (nicolas@sics.se)
Routing, Geometric and Regulations Constraints Nicolas Beldiceanu - - PowerPoint PPT Presentation
Routing, Geometric and Regulations Constraints Nicolas Beldiceanu SICS Lgerhyddsvgen 5 SE-75237 Uppsala, Sweden (nicolas@sics.se) The cycle constraint
Lägerhyddsvägen 5 SE-75237 Uppsala, Sweden (nicolas@sics.se)
Covering a directed graph with N circuits in such a way that each vertex belongs to one single circuit. cycle(N,Succ)
cycle(2, {2,4,1,3,6,5}) S1 S2 S3 S4 S5 S6 DEFINITION CONSTRAINT
Number N of cycles of a permutation (other interpretation) Extensions, constraints sur :
∉ ∉ ∉ to the same circuit,
S1 :: {2,6} S2 :: {3,4} S3 :: {1} S4 :: {2,3} S5 :: {2,6} S6 :: {2,5} S1 S2 S3 S4 S5 S6
ARGUMENTS :
ctr_arguments(cycle,[NCYCLE-dvar, NODES-collection(index-int, succ-dvar)]).
PURPOSE :
Consider a directed graph G. Number of circuits for covering G in such a way that each vertex
ORIGIN : [BeldiceanuContejean94] EXAMPLE :
cycle(2, [[index-1, succ-2], [index-2, succ-1], [index-3, succ-5], [index-4, succ-3], [index-5, succ-4]])
NODES
INITIAL GRAPH
CLIQUE
ctr_graph(cycle, [NODES], 2, [CLIQUE>>collection(nodes1,nodes2)], [nodes1.succ = nodes2.index], [NTREE = 0 , NCC = NCYCLE]).
1:index succ 2:index succ
nodes1.succ = nodes2.index ARC CONSTRAINT
cycle(2, [[index-1, succ-2], [index-2, succ-1], [index-3, succ-5], [index-4, succ-3], [index-5, succ-4]])
FINAL GRAPH
NTREE=0, NCC=2
INITIAL GRAPH
NODES CLIQUE
S1 S2 S3 S4 S5 S6 cycle(N, {S1,S2,S3,S4,S5,S6}) S1 S2 S3 S4 S5 S6 N ≤ ≤ ≤ ≤ 2 S6 ≠ ≠ ≠ ≠ 2 S2 ≠ ≠ ≠ ≠ 3 S4 ≠ ≠ ≠ ≠ 2
(matching and minimum weight)
DEFINITION Two vertices v1 and v2 of a directed graph G belong to the same strongly connected component iff: (1) There is a path from v1 to v2, (2) There is also a path from v2 to v1. S1 S2 S3 S4 S5 S6
RULE 1 Adjust the minimum number of circuits to the number of strongly connected components. S1 S2 S3 S4 S5 S6
RULE 2 Remove all the links between vertices that do not belong to the same strongly connected component. S1 S2 S3 S4 S5 S6
S1 S2 S3 S4 S5 S6 DEFINITION A chain is a sequence of vertices v1,v2,...,vn (n>2) such that for all i in 2..n-1: (1) vi has only vi-1 and vi+1 as possible successors, (2) v2 is one possible successor of v1, (3) vn-1 is one possible successor of vn.
S1 S2 S3 S4 S5 S6 RULE Consider a chain v1,v2,...,vn. If n is strictly less than the number of vertices of the smallest circuit then one can not close the previous chain.
cycle(2, {2,4,1,3,6,5}) S1 S2 S3 S4 S5 S6 cycle(1, {6,4,1,3,2,5}) S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 N ≤ 2 S6 ≠ 2 S2 ≠ 3 S4 ≠ 2 S1 = 6 S1 = 2
ARGUMENTS :
ctr_arguments(binary_tree,[NTREES-dvar , NODES-collection(index-int, succ-dvar)]).
PURPOSE :
Cover the directed graph G described by the NODES collection with NTREES binary trees in such a way that each vertex of G belongs to
ORIGIN : [Beldiceanu00] EXAMPLE :
binary_tree(2, [[index-1, succ-1], [index-2, succ-3], [index-3, succ-5], [index-4, succ-7], [index-5, succ-1], [index-6, succ-1], [index-7, succ-7], [index-8, succ-5]])
CLIQUE NODES
INITIAL GRAPH ctr_graph(binary_tree, [NODES], 2, [CLIQUE>>collection(nodes1,nodes2)], [nodes1.succ = nodes2.index], [MAX_NSCC =< 1, NCC = NTREES, MAX_IN_DEGREE =< 2]).
1:index succ 2:index succ
nodes1.succ = nodes2.index ARC CONSTRAINT
FINAL GRAPH
MAX_NSCC=1, NCC=2 MAX_IN_DEGREE=2 CC#1 CC#2
binary_tree(2, [[index-1, succ-1], [index-2, succ-3], [index-3, succ-5], [index-4, succ-7], [index-5, succ-1], [index-6, succ-1], [index-7, succ-7], [index-8, succ-5]])
ARGUMENTS :
ctr_arguments(tree_range,[NTREES-dvar, RANGE-dvar, NODES-collection(index-int, succ-dvar)]).
PURPOSE :
Cover the directed graph G described by the NODES collection with NTREES trees in such a way that each vertex of G belongs to one distinct tree. RANGE is the difference between the longest and the shortest paths of the final graph.
ORIGIN : Derived from tree. EXAMPLE :
tree_range(2,1,[[index-1, succ-1], [index-2, succ-5], [index-3, succ-5], [index-4, succ-7], [index-5, succ-1], [index-6, succ-1], [index-7, succ-7], [index-8, succ-5]])
INITIAL GRAPH FINAL GRAPH
ARGUMENTS :
ctr_arguments(map, [NBCYCLE-dvar, NBTREE-dvar, NODES-collection(index-int, succ-dvar)]).
PURPOSE :
Number of trees and cycles of a map. Every map decomposes into a set of connected components, also called connected maps. Each component consists of the set of all points that wind up on the same cycle, with each point on the cycle attached to a tree of all points that enter the cycle at that point.
ORIGIN : Inspired by [SedgewickFlajolet96] EXAMPLE :
map(2,3, [[index-1, succ-5],[index-2, succ-9],[index-3, succ-8], [index-4, succ-2],[index-5, succ-9],[index-6, succ-2], [index-7, succ-9],[index-8, succ-8],[index-9, succ-1]])
ctr_graph(map, ['NODES'], 2, ['CLIQUE'>>collection(nodes1,nodes2)], [nodes1.succ = nodes2.index], ['NCC' = 'NBCYCLE', 'NTREE' = 'NBTREE' ]).
INITIAL GRAPH
map(2,3,
[[index-1, succ-5], [index-2, succ-9], [index-3, succ-8], [index-4, succ-2], [index-5, succ-9], [index-6, succ-2], [index-7, succ-9], [index-8, succ-8], [index-9, succ-1]])
FINAL GRAPH
Depth-first search on a directed graph find some information about the structure of the graph (see chapter 23 of Introduction to Algorithms from Cormen, Leiserson, Rivest). Assume we have to cover a directed graph with one single circuit. Assume we make a depth-first search on that graph. Find some typical patterns on the depth-first forest which lead to some pruning.
ARGUMENTS :
ctr_types(two_quad_do_not_overlap, [QUADRANGLE-collection(ori-dvar, size-dvar, end-dvar)]). ctr_arguments(two_quad_do_not_overlap, [QUADRANGLE1-QUADRANGLE, QUADRANGLE2-QUADRANGLE]).
PURPOSE :
Enforce two quadrangles to not overlap. Two quadrangles do not overlap if there exists at least one dimension where they do not overlap.
ORIGIN : Used for defining diffn. EXAMPLE :
two_quad_do_not_overlap([[ori-2,siz-2,end-4], [ori-1,siz-3,end-4]], [[ori-4,siz-4,end-8], [ori-3,siz-3,end-6]])
ctr_graph(two_quad_do_not_overlap, [QUADRANGLE1,QUADRANGLE2], 2, [SYMMETRIC_PRODUCT(=)>> collection(quadrangle1,quadrangle2)], [quadrangle1.end =< quadrangle2.ori #\/ quadrangle1.size = 0], [NARC >= 1]).
1:ori size end 2:ori size end
ARC CONSTRAINT quadrangle1.end ≤ ≤ ≤ ≤ quadrangle2.ori \/ quadrangle1.size = 0 SYMMETRIC_PRODUCT(=) QUADRANGLE1 QUADRANGLE2 INITIAL GRAPH
SYMMETRIC_PRODUCT(=) QUADRANGLE1 QUADRANGLE2 INITIAL GRAPH FINAL GRAPH
NARC=1
two_quad_do_not_overlap([[ori-2,siz-2,end-4], [ori-1,siz-3,end-4]], [[ori-4,siz-4,end-8], [ori-3,siz-3,end-6]])
ARGUMENTS :
ctr_types(two_quad_do_not_overlap, [QUADRANGLE-collection(ori-dvar, size-dvar, end-dvar)]). ctr_arguments(diffn, [QUADRANGLES-collection(quad-QUADRANGLE)]).
PURPOSE :
Holds if for each pair of quadrangles the two quadrangles do not overlap. Two quadrangles do not overlap if there exists at least one dimension where they do not overlap.
ORIGIN : [BeldiceanuContejean94] EXAMPLE :
diffn([[quad-[[ori-2, siz-2, end-4 ], [ori-1, siz-3, end-4]] ], [quad-[[ori-4, siz-4, end-8 ], [ori-3, siz-3, end-3]] ], [quad-[[ori-9, siz-2, end-11], [ori-4, siz-3, end-7]] ]])
INITIAL GRAPH FINAL GRAPH
1) Is it possible to place 5 squares of size 2x2 in a square of size 5x5 in such a waht that:
2) Find a general method for exploiting the previous fact.
ARGUMENTS :
ctr_types(place_in_pyramid, [QUADRANGLE-collection(ori-dvar, siz-dvar, end-dvar)]). ctr_arguments(place_in_pyramid, [QUADRANGLES-collection(quad-QUADRANGLE), VERTICAL_DIM-int]).
PURPOSE :
Each quadrangle of the collection QUADRANGLES should be supported by one other object or by the ground.
ORIGIN : N.Beldiceanu EXAMPLE :
place_in_pyramid([[quad-[[ori-1, siz-2, end-3], [ori-1, siz-3, end-4 ]] ], [quad-[[ori-3, siz-3, end-6], [ori-1, siz-2, end-3 ]] ], [quad-[[ori-1, siz-2, end-3], [ori-5, siz-6, end-11]] ], [quad-[[ori-3, siz-2, end-5], [ori-5, siz-2, end-7 ]] ], [quad-[[ori-3, siz-2, end-5], [ori-8, siz-3, end-11]] ], [quad-[[ori-5, siz-2, end-7], [ori-8, siz-2, end-10]] ]],1)
INITIAL GRAPH FINAL GRAPH
Standard technique in the design of efficient algorithms, described in:
[Preparata & Shamos, 1985]
[Berg, Kreveld, Overmars & Schwarzkopf, 1997]
[Boissonnat & Yvinec, 1995]
(in the context of line segment intersection) y x
event point sweep line sweep line status (1) (2)
Steps of the sweep algorithm:
(1) Move to the next event point (2) Update the sweep line status:
GOAL: the worst case complexity should also depend of the number of intersections
Two intervals inf_x..sup_x and inf_y..sup_y such that: For all x in inf_x..sup_x, y in inf_y..sup_y: Ctr with the assignment X=x and Y=y is false. DEFINITION forbidden region according to a constraint Ctr and two variables X,Y of Ctr : EXAMPLE forbidden regions of alldifferent({X,Y,R}) according to X and Y :
X Y 0 1 2 3 4 1 2 3 4
(A) (B) (C) (D) (E)
0≤ ≤ ≤ ≤X≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤Y≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤R≤ ≤ ≤ ≤9 X Y 0 1 2 3 4 1 2 3 4 X Y 0 1 2 3 4 1 2 3 4 X Y 0 1 2 3 4 1 2 3 4 0≤ ≤ ≤ ≤X≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤Y≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤X≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤Y≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤T≤ ≤ ≤ ≤2 0≤ ≤ ≤ ≤U≤ ≤ ≤ ≤3 X Y 0 1 2 3 4 1 2 3 4 0≤ ≤ ≤ ≤X≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤Y≤ ≤ ≤ ≤4 alldifferent({X,Y,R}) |X-Y|>2 X Y 0 1 2 3 4 1 2 3 4 0≤ ≤ ≤ ≤X≤ ≤ ≤ ≤4 0≤ ≤ ≤ ≤Y≤ ≤ ≤ ≤4 1≤ ≤ ≤ ≤S≤ ≤ ≤ ≤6 X+2Y≤ ≤ ≤ ≤S X+2≤ ≤ ≤ ≤T ∨ ∨ ∨ ∨ T+3≤ ≤ ≤ ≤X ∨ ∨ ∨ ∨ Y+4≤ ≤ ≤ ≤U ∨ ∨ ∨ ∨ U+2≤ ≤ ≤ ≤Y X+Y≡ ≡ ≡ ≡0 (mod 2)
get_first_forbidden_regions(X,Y,Ctr) get_next_forbidden_regions(X,Y,Ctr,Previous) get_last_forbidden_regions(X,Y,Ctr) get_prev_forbidden_regions(X,Y,Ctr,Previous) check_if_in_forbidden_regions(x,y,Ctr)
X Y
0 1 2 3 4
1 2 3 4 get_first_forbidden_regions X Y 0 1 2 3 4 1 2 3 4 get_next_forbidden_regions X Y 0 1 2 3 4 1 2 3 4 get_next_forbidden_regions max(Y) X Y 0 1 2 3 4 1 2 3 4 min(X) max(X) min(Y) X+Y≡ ≡ ≡ ≡0 (mod 2)
Accumulates forbiden regions that come from different constraints involving two given variables X and Y CTR1(X,Y,…) CTR2(X,Y,…) ……………… CTRn(X,Y,…) Y X sweep line
Is min(X) feasible ? No, so move the sweep-line.
event point sweep line status
Y For each y ∈ ∈ ∈ ∈ dom(Y): number of forbidden regions containing the point (∆ ∆ ∆ ∆,y) Y X
sweep line status
1 2 1 1 1 1
X Remove a value ∆ ∆ ∆ ∆ ∈ ∈ ∈ ∈ dom(X) if : for all y ∈ ∈ ∈ ∈ dom(Y) the number
X Y X Y X Y
Y X = 0
1 2 3 4
0≤X≤4 0≤Y≤4 1≤S≤6 0≤T≤2 0≤U≤3 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
PROBLEM:
Adjust minimum of X according to Y and to all following constraints: alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
Y x=0
1 2 3 4
Y
1 2 3 4
X = 1 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
0≤X≤4 0≤Y≤4 1≤S≤6 0≤T≤2 0≤U≤3 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
PROBLEM:
Adjust minimum of X according to Y and to all following constraints:
Y X=0
1 2 3 4
Y
1 2 3 4
X=1 Y
1 2 3 4
X=2 Y
1 2 3 4
X=3
Y
1 2 3 4
X = 4
0≤X≤4 0≤Y≤4 1≤S≤6 0≤T≤2 0≤U≤3 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
PROBLEM:
Adjust minimum of X according to Y and to all following constraints:
Deduction: X>3
alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S X+2≤T ∨ ∨ ∨ ∨ T+3≤X ∨ ∨ ∨ ∨ Y+4≤U ∨ ∨ ∨ ∨ U+2≤Y X+Y≡0 (mod 2)
I N P U T
G E N E R A T O R
I N P U T
G E N E R A T O R
A R I T Y
C O N S T R A I N T
P R O P E R T Y : OBJECTS: collection(X-dvar,Y-dvar,...) : required(OBJECTS.X,OBJECTS.Y) : OBJECTS : IDENTITY : OBJECTS : CLIQUE(≠ ≠ ≠ ≠) : 2 : : NEDGE = |OBJECTS|.|OBJECTS| - |OBJECTS|
X1,Y1 X2,Y2 X3,Y3 X4,Y4
Non-overlapping Scheduling with set-up Cyclic scheduling
Come up with a formula for computing the forbidden region(s) according to the non-overlapping constraint between two rectangles. Each rectangle is characterized by: (1) the coordinates Ox,Oy of its origin (leftmost lower point), (2) its sizes Sx, Sy.
Ox Oy Sx Sy
ARGUMENTS :
ctr_arguments(change, [NCHANGE-dvar , VARIABLES-collection(var-dvar), CTR-atom ]).
PURPOSE :
NCHANGE is the number of times that CTR holds on consecutive variables of the collection VARIABLES.
ORIGIN : CHIP EXAMPLE :
change(3,[[var-4],[var-4],[var-3],[var-4],[var-1]],≠)
PATH VARIABLES INITIAL GRAPH ctr_graph(change, [VARIABLES], 2, [PATH>>collection(variables1,variables2)], [CTR(variables1.var,variables2.var)], [NARC = NCHANGE]).
1:var 2:var
CTR(variables1.var,variables2.var) ARC CONSTRAINT
PATH VARIABLES INITIAL GRAPH
NARC=3
FINAL GRAPH change(3,[[var-4],[var-4],[var-3],[var-4],[var-1]],≠)
smooth(C, T, {V1,..,Vn }) smooth(1,2,{1,3,4,5, 2}) change(C, {V1,..,Vn }, ≠) change(3,{4,4, 3, 4, 1}, ≠) C : 0..n− − − −1 Vi ≠Vi +1 2 Arity Bounds for C and constraint CTR Member and example of solution cyclic_change(C, L, {V1,..,Vn }) cyclic_change(2,5,{2,3,4,0, 2,3, 1}) C : 0..n− − − −1 (Vi +1)mod L≠Vi +1 2 C : 0..n− − − −1 |Vi − − − −Vi +1 | >T 2 number_of_rest(C, {V1,..,Vn }) number_of_rest(2,{2,0, 0,1,1,0,2,0, 0,1,2 }) C : 0..n− − − −2 Vi =0 ∧ ∧ ∧ ∧Vi +1=0 ∧ ∧ ∧ ∧Vi +2 ≠0 3 relaxed_sliding_sum(a,b,low,up,k,{V1,..,Vn }) relaxed_sliding_sum(3,4,3,7,4,{2,4, 2, 0, 0,3,4}) C : a..b low ≤ ≤ ≤ ≤ Σ
Σ Σ ΣVi ≤
≤ ≤ ≤ up k
j=i i+k − − − − 1
cyclic_change(C, 5, {V1,V2,V3,V4,V5,V6,V7,V8,V9})
V1: 0,3 V2: 2,3,4 V3: 0,4 V4: 0,1,2,3,4 V5: 0,1,2,3 V6: 0,2,4 V7: 0,1,2 V8: 0,1,2 V9: 0,4 V1: 0,3 V1: 3 V1: 3 V1: 3 V1: 3 contradiction V2: 4 V2: 4 V2: 4 V2: 4 V3: 0 V3: 0 V3: 0 V4: 1 V4: 1 V5: 2 (V1+1)mod 5=V2 (V2+1)mod 5=V3 (V3+1)mod 5=V4 (V4+1)mod 5=V5 (V5+1)mod 5=V6 V6: 0,2,4 V6: 0,4 V6: 0,4 contradiction V7: 0,1 V7: 0,1 V8: 1,2 (V6+1)mod 5=V7 (V7+1)mod 5=V8 (V8+1)mod 5=V9 V9: 0,4 CTR: (Vi+1) mod 5 ≠ Vi+1
min(C) ≥ ≥ ≥ ≥ 2
Set min_break to 0. Set choice to 1. Create_choice_point. for i =1 to n -k +1 do Set before[i ] to min_break. if choice=0 then Set choice to 1. Create_choice_point. if enforce ¬CTR(Vi,..,Vi+k-1) fails then
Set min_break to min_break +1. Set vbefore[i+k-1] to dom(Vi+k-1).
before[i ] (1≤ ≤ ≤ ≤i ≤ ≤ ≤ ≤n-k+1):
min.number of constraints that hold in
{CTR(V1,..,Vk),..,CTR(Vi-1,..,Vi+k-2} vbefore[i ] (k≤ ≤ ≤ ≤i ≤ ≤ ≤ ≤n):
state of dom(Vi) after stating constraint CTR(Vi-k+1,..,Vi)
Set min_break to 0. Set choice to 1. Create_choice_point. for i = n -k +1 to 1 (step -1) do Set after[i ] to min_break. if choice=0 then Set choice to 1. Create_choice_point. if enforce ¬CTR(Vi,..,Vi+k-1) fails then
Set min_break to min_break +1. Set vafter[i ] to dom(Vi).
after[i ] (n-k+1≥ ≥ ≥ ≥i ≥ ≥ ≥ ≥1):
min.number of constraints that hold in
{CTR(Vi+1,..,Vi+k),..,CTR(Vn-k+1,..,Vn} vafter[i ] (n-k+1≥ ≥ ≥ ≥i ≥ ≥ ≥ ≥1):
state of dom(Vi) after stating constraint CTR(Vi,..,Vi+k-1)
for i =1 to n -k +1 do if before[i ]+after[i ]+1>max(C) then enforce ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1).
¬ ¬ ¬ ¬CTR(V1,..,Vk) ¬ ¬ ¬ ¬CTR(Vi-1,..,Vi+k-2)
¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1)
¬ ¬ ¬ ¬CTR(Vi+1,..,Vi+k) ¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ...
k ≤ i ≤ n -k +1: if before[i –k+2]+after[i -1]+2 > max(C) then Vi ⊆ ⊆ ⊆ ⊆ vbefore[i ]∪ ∪ ∪ ∪vafter[i ].
If Vi ∉ ∉ ∉ ∉ vbefore[i ]∪ ∪ ∪ ∪vafter[i ] then at least before[i –k+2]+after[i -1]+2 constraints CTR hold We prove that :
k ≤ i ≤ n -k +1: if before[i –k+2]+after[i -1]+2>max(C) then Vi ⊆ ⊆ ⊆ ⊆vbefore[i ]∪ ∪ ∪ ∪vafter[i ].
¬ ¬ ¬ ¬CTR(V1,..,Vk) ¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1) ¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ... ... ...
...
The k constraints which mention variable Vi
¬ ¬ ¬ ¬CTR(V1,..,Vk) ¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1) ¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ...
¬ ¬ ¬ ¬CTR(Vf-1,..,Vf+k-2)
¬ ¬ ¬ ¬CTR(Vf,..,Vf+k-1) ... ...
...
f: smallest value ≤ i-k+1 such that:
¬ ¬ ¬CTR(Vf,..,Vf+k-1),.., ¬
¬ ¬ ¬CTR(Vi-k+1,..,Vi) during first iteration
a failure occurs after stating ¬ ¬ ¬ ¬CTR(Vf-1,..,Vf+k-2)
¬ ¬ ¬ ¬CTR(V1,..,Vk) ¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1) ¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ...
¬ ¬ ¬ ¬CTR(Vf-1,..,Vf+k-2) ¬ ¬ ¬ ¬CTR(Vf,..,Vf+k-1)
... ... ¬ ¬ ¬ ¬CTR(Vl,..,Vl+k-1)
¬ ¬ ¬ ¬CTR(Vl+1,..,Vl+k)
...
l: largest value ≥ i such that:
¬ ¬ ¬CTR(Vl,..,Vl+k-1),.., ¬
¬ ¬ ¬CTR(Vi,..,Vi+k-1) during first iteration
a failure occurs after stating ¬ ¬ ¬ ¬CTR(Vl+1,..,Vl+k)
¬ ¬ ¬ ¬CTR(V1,..,Vk)
¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1)
¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ...
¬ ¬ ¬ ¬CTR(Vf-1,..,Vf+k-2) ¬ ¬ ¬ ¬CTR(Vf,..,Vf+k-1)
... ...
¬ ¬ ¬ ¬CTR(Vl,..,Vl+k-1) ¬ ¬ ¬ ¬CTR(Vl+1,..,Vl+k)
...
If fail after posting ¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) then: vbefore[i ]=dom(Vi) (since we backtrack and restore domain of Vi) So dom(Vi) − − − − vbefore[i ]∪ ∪ ∪ ∪vafter[i ] is empty, and we prune nothing. If fail after posting ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1) then: vafter[i ]=dom(Vi) (since we backtrack and restore domain of Vi) So dom(Vi) − − − − vbefore[i ]∪ ∪ ∪ ∪vafter[i ] is empty, and we prune nothing.
¬ ¬ ¬ ¬CTR(V1,..,Vk) ¬ ¬ ¬ ¬CTR(Vi-k+1,..,Vi) ¬ ¬ ¬ ¬CTR(Vi,..,Vi+k-1) ¬ ¬ ¬ ¬CTR(Vn-k+1,..,Vn)
... ...
¬ ¬ ¬ ¬CTR(Vf-1,..,Vf+k-2) ¬ ¬ ¬ ¬CTR(Vf,..,Vf+k-1)
... ...
¬ ¬ ¬ ¬CTR(Vl,..,Vl+k-1) ¬ ¬ ¬ ¬CTR(Vl+1,..,Vl+k)
...
Now let’s assume that:
¬ ¬ ¬CTR(Vi-k+1,..,Vi) ,
∉ ∉ ∉ vbefore[i] ,
¬ ¬ ¬CTR(Vi,..,Vi+k-1) ,
∉ ∉ ∉ vafter[i] .
And evaluate the minimum number
≥ before[f] = before[i-k+2] (from definition of f) ≥ 1 (since Vi ∉ ∉ ∉ ∉ vbefore[i] ) ≥ after[l] = after[i-1] (from definition of l) ≥ 1 (since Vi ∉ ∉ ∉ ∉ vafter[i] ) CONCLUSION: the minimum is
before[i-k+2]+after[i-1]+2
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V1+1)mod 5 = V2
4 3 2
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V2+1)mod 5 = V3
4 3 2 4
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V3+1)mod 5 = V4
4 3 2 4 4 3 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V4+1)mod 5 = V5
4 3 2 4 4 3 2 1 3 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V5+1)mod 5 = V6
4 3 2 4 4 3 2 1 3 2 1
fails
4 2
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V6+1)mod 5 = V7
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V7+1)mod 5 = V8
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
(V8+1)mod 5 = V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1
fails
1 4
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4 2 1
(V8+1)mod 5 = V9
fails
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4 2 1
(V7+1)mod 5 = V8
1 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4 2 1
(V6+1)mod 5 = V7
1 2 1 4 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4 2 1
(V5+1)mod 5 = V6
1 2 1 4 2 1 3 2 1 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4
(V4+1)mod 5 = V5
1 1 3 2 1 4 2 2 1 2 1 1 1 4 3 2 1
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4
(V3+1)mod 5 = V4
1 1 3 2 1 4 2 2 1 2 1 1 1 4 3 2 1
fails
1 4
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4
(V2+1)mod 5 = V3
1 1 3 2 1 4 2 2 1 2 1 1 1 4 3 2 1 1 4 2 4 3 2
V1
3 4 3 2 4 4 3 2 1 3 2 1 4 2 2 1 2 1 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8] V2 V3 V4 V5 V6 V7 V8 V9
4 3 2 4 4 3 2 1 3 2 1 4 2 1 2 1 1 2 1 1 4
(V1+1)mod 5 = V2
1 1 3 2 1 4 2 2 1 2 1 1 1 4 3 2 1 1 4 2 4 3 2 2 3
Rule 1 IF before[i]+after[i]+1>max(C) THEN enforces not ctr(Vi,..Vi+k-1)
V1
3 4 3 2
vbefore before after vafter [2..9] [1..8] [1..8] [1..8]
V2
4 3 2 2 4 3 2
2
3
Let’s assume max(C)=2 Since before[1]+after[1]+1>max(C) enforces (V1+1)mod 5=V2:
Rule 2 IF before[i-k+2]+after[i-1]+2>max(C) THEN Vi in vbefore[i] ∪ ∪ ∪ ∪ vafter[i]
Let’s assume max(C)=3 Since before[2]+after[1]+2>max(C):
V1
3 4 3 2 4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8]
V2 V3 4
3 2 4 1 4 2
4 3
2
2
3
Let’s assume max(C)=3 Since before[2]+after[1]+2>max(C):
V1
3
4
vbefore before after vafter [2..9] [1..8] [1..8] [1..8]
V2 V3 4
3 2 4 1 4 2
4 3
2
2
3
Two more constraints will fail if V2=2
ARGUMENTS :
ctr_arguments(group, [NGroup-dvar, MinSize-dvar, MaxSize-dvar, MinDist-dvar, MaxDist-dvar, NVal-dvar, VARIABLES-collection(var-dvar), VALUES-collection(val-int)]).
PURPOSE :
consecutives groups or between one border and one group,
consecutives groups or between one border and one group,
in the set of values VALUES.
ORIGIN : CHIP EXAMPLE :
group(2,1,2,2,4,3, [[var-2],[var-8],[var-1],[var-7],[var-4],[var-5],[var-1],[var-1],[var-1]], [[val-0],[val-2],[val-4],[val-6],[val-8]])
INITIAL GRAPH FINAL GRAPH
ARGUMENTS :
ctr_arguments(stretch_circuit, [VARIABLES-collection(var-dvar), VALUES-collection(val-int, lmin-int, lmax-int)]).
PURPOSE :
An item (val-v, lmin-min, lmax-max) gives the minimum value min as well as the maximum value max for the span of a stretch of value v.
ORIGIN : [Pesant01] EXAMPLE :
stretch_circuit([[var-6],[var-6],[var-3],[var-1], [var-1],[var-1],[var-6],[var-6]], [[val-1, lmin-2, lmax-4],[val-2, lmin-2, lmax-3], [val-3, lmin-1, lmax-6],[val-6, lmin-2, lmax-4]])
INITIAL GRAPH FINAL GRAPH