[ library(gfd) | Reference Manual | Alphabetic Index ]

<ConsistencyModule:> sorted(?Unsorted, ?Sorted)

Sorted is a sorted permutation of Unsorted
Unsorted
Collection of N (domain) variables or integers
Sorted
Collection of N (domain) variables or integers

Description

Declaratively: The two collections have the same length and Sorted is a sorted permutation of Unsorted.

Operationally: the elements in both collections are constrained such that their domains are consistent with the assumption that Sorted is the sorted version of Unsorted.

One of the two arguments can be uninstantiated at call time.

Any input variables which is not already a domain variable will be turned into a domain variable with default bounds.

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_bc for bounds consistency.

This constraint is known as sort in the global constraint catalog, and is implemented using Gecode's sorted() constraint.

Modes and Determinism

Examples

[eclipse 2]: sorted([1,9,1,5,2|L], [1,1,1,2,5,9]).

L = [1]

[eclipse 3]:  sorted([1,9,1,5,2,1], S).

S = [1, 1, 1, 2, 5, 9]

[eclipse 4]: length(Xs,4), Xs::0..100, sorted(Xs,Ys), Xs = [8,20|_].

Xs = [8, 20, _694{[0 .. 100]}, _714{[0 .. 100]}]
Ys = [_774{[0 .. 8]}, _794{[0 .. 20]}, _814{[8 .. 100]}, _834{[20 .. 100]}]

[eclipse 5]: length(Ys,4), Ys::0..100, sorted(Xs,Ys), Ys = [8,20|_].

Ys = [8, 20, _694{[20 .. 100]}, _714{[20 .. 100]}]
Xs = [_832{[8 .. 100]}, _852{[8 .. 100]}, _872{[8 .. 100]}, _892{[8 .. 100]}]

    

See Also

fd_global : sorted / 2, ic_global : sorted / 2, sorted / 3, ordered / 2