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

<ConsistencyModule:> max_index(+Collection,?Index)

Index is constrained to the index(es) of the variable(s) with the maximum value in Collection
Collection
A collection (a la collection_to_list/2) of integers or (domain) variables
Index
(Domain) variable or integer (array notation accepted)

Description

Index is constrained to the index(es) of the variable(s) with the maximum value in Collection. If Index is a variable, it must not occur in Collection..

You may find it more convenient to embed max_index(Vars) in a constraint expression.

As with all constraints that involve indexes, the index starts from 1, unlike Gecode's native indexes that starts from 0 - a dummy first element is added to Collection in the constraint posted to Gecode if Collection is not empty.

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_gac for domain (generalised arc) consistency.

This constraint is known as max_index in the global constraint catalog, and is implemented using Gecode's maxarg() constraint with tie-break set to false.

Examples

[eclipse 17]: max_index([1,2,3], I).

I = 3

[eclipse 18]: max_index([1,2,3,1,10,9,10], I).

I = I{[5, 7]}

[eclipse 19]: L = [A,B,C,D,E], L :: 1..10, max_index(L, 3), C #> 4.

L = [A{[1 .. 10]}, B{[1 .. 10]}, C{[5 .. 10]}, D{[1 .. 10]}, E{[1 .. 10]}]
A = A{[1 .. 10]}
B = B{[1 .. 10]}
C = C{[5 .. 10]}
D = D{[1 .. 10]}
E = E{[1 .. 10]}

[eclipse 20]:  L = [A,B,C,D,E], L :: 1..10, max_index(L, 3), C #< 4.

L = [A{[1 .. 3]}, B{[1 .. 3]}, C{[1 .. 3]}, D{[1 .. 3]}, E{[1 .. 3]}]
A = A{[1 .. 3]}
B = B{[1 .. 3]}
C = C{[1 .. 3]}
D = D{[1 .. 3]}
E = E{[1 .. 3]}

[eclipse 21]:  L = [A,B,C,D,E], L :: 1..10, max_index(L, 3), B #> 4.

L = [A{[1 .. 10]}, B{[5 .. 10]}, C{[5 .. 10]}, D{[1 .. 10]}, E{[1 .. 10]}]
A = A{[1 .. 10]}
B = B{[5 .. 10]}
C = C{[5 .. 10]}
D = D{[1 .. 10]}
E = E{[1 .. 10]}

[eclipse 23]:  L = [A,B,C,D,E], L :: 1..10, max_index(L, 3), B #< 4.

L = [A{[1 .. 10]}, B{[1 .. 3]}, C{[1 .. 10]}, D{[1 .. 10]}, E{[1 .. 10]}]
A = A{[1 .. 10]}
B = B{[1 .. 3]}
C = C{[1 .. 10]}
D = D{[1 .. 10]}
E = E{[1 .. 10]}

[eclipse 24]: [A,B,D] :: 1..10, C :: 20..30, max_index([A,B,C,D], I).

A = A{[1 .. 10]}
B = B{[1 .. 10]}
D = D{[1 .. 10]}
C = C{[20 .. 30]}
I = 3

See Also

max_first_index / 2, min_index / 2, min_first_index / 2, min / 2, max / 2, eclipse_6 : collection_to_list / 2, lists : collection_to_list / 2