This predicate instantiates a set variable to a possible value, according to its domain. The predicate backtracks over all possible set instantiations. The three option arguments allow to choose between a number of different enumeration orders. Giving a variable as option argument will select the default.
The CardSel argument determines whether the sets are enumerated according to their cardinality. It can take the following values:
The ElemSel argument determines which potential set elements are considered first for inclusion or exclusion. It can take the following values:
The Order argument determines whether it is first tried to make the selected potential element a set member, or whether to exclude it first. The argument can take the following values:
Note that there are many different enumeration strategies for a set variable, and insetdomain/4 only allows a limited number of them. For an actual application, it might be more appropriate to choose a problem-specific enumeration order. This can be programmed easily. As a guideline, here is the code for insetdomain with the default options:
insetdomain(Set, _, _, _) :- nonvar(Set). insetdomain(Set, any, small_first, in_notin) :- var(Set), potential_members(Set, PotentialElements), PotentialElements = [Element|_], ( Element in Set ; Element notin Set ), insetdomain(Set, any, small_first, in_notin).
?- X::[]..[1,2,3], insetdomain(X,_,_,_), writeln(X), fail. [1, 2, 3] [1, 2] [1, 3] [1] [2, 3] [2] [3] [] no (more) solution. ?- X::[]..[1,2,3], insetdomain(X,increasing,_,_), writeln(X), fail. [] [1] [2] [3] [1, 2] [1, 3] [2, 3] [1, 2, 3] no (more) solution. ?- X::[]..[1,2,3], insetdomain(X,_,big_first,_), writeln(X), fail. [1, 2, 3] [2, 3] [1, 3] [3] [1, 2] [2] [1] [] no (more) solution. ?- X::[]..[1,2,3], insetdomain(X,_,_,notin_in), writeln(X), fail. [] [3] [2] [2, 3] [1] [1, 3] [1, 2] [1, 2, 3] no (more) solution. ?- X::[]..[1,2,3], insetdomain(X, increasing, heavy_first([](2,9,4,7)), _), writeln(X), fail. [] [2] [3] [1] [2, 3] [1, 2] [1, 3] [1, 2, 3] no (more) solution.