Skip to content

Commit

Permalink
New proc MaxDistinct
Browse files Browse the repository at this point in the history
  • Loading branch information
Torsten Anders committed Apr 25, 2014
1 parent 667284d commit 6fa3137
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion strasheela/contributions/anders/Pattern/Pattern.oz
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export
RotateList RotateSublists
Average

HowManyDistinct MinDistinct
HowManyDistinct MinDistinct MaxDistinct
HowManyAs
HowMany Once
ForN ForPercent NDifferences ForNEither
Expand Down Expand Up @@ -956,6 +956,26 @@ define
Card = {FS.card Set}
Card >=: N
end
/** %% At most N elements in Xs are pairwise distinct. Xs is a list of FD integers, N is a FD integer.
%% */
proc {MaxDistinct Xs N}
%% Implementation inspired by Denys Duchier
%%
%% Map all elements in Xs into a list of singleton sets. The union
%% of all these singletons is a Set whose cardiality is the number
%% of distict elements in Xs.
Set = {FS.var.decl}
Set1s = {Map Xs proc {$ X Set1}
Set1 = {FS.var.decl}
{FS.include X Set1}
{FS.card Set1 1}
end}
Card = {FD.decl}
in
{FoldL Set1s.2 FS.union Set1s.1 Set}
Card = {FS.card Set}
Card =<: N
end

/** %% N elements in Xs are 'as' Val, i.e. either equal, or greater etc. A states the relation of the N elements to Val (A is one of '=:', '>:', '>=:', '<:', '=<:', '\\=:').
%% Xs is a list of FD integers, Val and N are FD integers.
Expand Down

0 comments on commit 6fa3137

Please sign in to comment.