Presentation is loading. Please wait.

Presentation is loading. Please wait.

Set Domain Solvers. 2 ic_sets - the set constraint solver  Load the ic_sets library by using :- lib(ic_sets). at the beginning of your code, or type.

Similar presentations


Presentation on theme: "Set Domain Solvers. 2 ic_sets - the set constraint solver  Load the ic_sets library by using :- lib(ic_sets). at the beginning of your code, or type."— Presentation transcript:

1 Set Domain Solvers

2 2 ic_sets - the set constraint solver  Load the ic_sets library by using :- lib(ic_sets). at the beginning of your code, or type lib(ic_sets). at the top-level ECLiPSe prompt.  Sets must be finite and contain only integers  We write sets as sorted lists  Note: there is another set solver lib(conjunto) which is being phased out, and lib(fd_sets) which is identical to ic_sets, but works with lib(fd)

3 3 Functionality The ic_sets library implements  variables with finite integers set domains  basic constraints over set expressions  constraints over set cardinality and weights  a search primitive The ic_sets library implements  variables with finite integers set domains  basic constraints over set expressions  constraints over set cardinality and weights  a search primitive

4 4 Set domain variables  An integer (ground) set X = [1,7,12,19]  A set variable Set :: [7]..[1,7,12,19] attaches an initial domain to a variable or intersect their old domain with the new one.  Set variables have a lower and upper bound Both bounds are (ground) sets lower bound: set of elements that are definitely in the set upper bound: set of elements that may be in the set They also have a separate lower and upper bound on cardinality.  An integer (ground) set X = [1,7,12,19]  A set variable Set :: [7]..[1,7,12,19] attaches an initial domain to a variable or intersect their old domain with the new one.  Set variables have a lower and upper bound Both bounds are (ground) sets lower bound: set of elements that are definitely in the set upper bound: set of elements that may be in the set They also have a separate lower and upper bound on cardinality.

5 5 The basic set of constraints  X in S, X notin S Set membership.  S1 sameset S2, S1 subset S2, S1 disjoint S2 Set equality, subset, disjointness.  all_union(Sets,Union), all_disjoint(Sets) Generalised union and disjointness.  #(Set, Card), weight(Set, ElementWeights, Weight) Set cardinality and set weight.  Set expressions are allowed: Intersection S1 /\ S2, Union S1 \/ S2, Difference S1 \ S2  X in S, X notin S Set membership.  S1 sameset S2, S1 subset S2, S1 disjoint S2 Set equality, subset, disjointness.  all_union(Sets,Union), all_disjoint(Sets) Generalised union and disjointness.  #(Set, Card), weight(Set, ElementWeights, Weight) Set cardinality and set weight.  Set expressions are allowed: Intersection S1 /\ S2, Union S1 \/ S2, Difference S1 \ S2

6 6 Bound propagation  Constraints affect set bounds: ?- S::[]..[1,2,3,4,5]. S = S{([].. [1, 2, 3, 4, 5]) : C{[0.. 5]}} yes. ?- S::[]..[1,2,3,4,5], 3 in S, 5 notin S. S = S{[3] \/ ([].. [1, 2, 4]) : C{[1.. 4]}} yes. ?- S::[]..[1,2,3,4,5], S subset [1,5,6]. S = S{([].. [1, 5]) : C{[0.. 2]}} yes. ?- S::[2,4]..[1,2,3,4,5], #(S,2). S = [2, 4] yes.  Constraints affect set bounds: ?- S::[]..[1,2,3,4,5]. S = S{([].. [1, 2, 3, 4, 5]) : C{[0.. 5]}} yes. ?- S::[]..[1,2,3,4,5], 3 in S, 5 notin S. S = S{[3] \/ ([].. [1, 2, 4]) : C{[1.. 4]}} yes. ?- S::[]..[1,2,3,4,5], S subset [1,5,6]. S = S{([].. [1, 5]) : C{[0.. 2]}} yes. ?- S::[2,4]..[1,2,3,4,5], #(S,2). S = [2, 4] yes.

7 7 Basic search support  insetdomain(SetVar, Options…) Try to instantiate SetVar to a ground set. [eclipse 23]: A :: []..[1,2,3,4,5], insetdomain(A,_,_,_). A = [1, 2, 3, 4, 5] More? (;) A = [1, 2, 3, 4] More? (;) A = [1, 2, 3, 5] More? (;)  insetdomain(SetVar, Options…) Try to instantiate SetVar to a ground set. [eclipse 23]: A :: []..[1,2,3,4,5], insetdomain(A,_,_,_). A = [1, 2, 3, 4, 5] More? (;) A = [1, 2, 3, 4] More? (;) A = [1, 2, 3, 5] More? (;)

8 8 Set example – Steiner triplets  Ternary Steiner system of order n: the set of triplets taking values between 1 and n such that all pairs included in any triplets are different.   a triplet can share at most one number with any other triplet.  Set has n(n-1)/6 triplets.  Not easy to express generically (for any n) with fd only….

9 9 Steiner Triplets (Program) :- lib(ic_sets). steiner(N, LS) :- NB is N * (N-1) // 6, % compute number of set variables needed intsets(LS, NB, 1, N), % NB sets can take values between 1 and N ( foreach(S,LS) do #(S,3) ), % sets are triplets ( fromto(LS,[S1|Ss],Ss,[]) do ( foreach(S2,Ss), param(S1) do % no triplet can share more than one number with another #(S1 /\ S2,C), ic: (C #=< 1) ) ), label_sets(LS). label_sets([]). label_sets([S | LS]) :- insetdomain(S,_,_,_), label_sets(LS).


Download ppt "Set Domain Solvers. 2 ic_sets - the set constraint solver  Load the ic_sets library by using :- lib(ic_sets). at the beginning of your code, or type."

Similar presentations


Ads by Google