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

# <ConsistencyModule:> min_index(+Collection,?Index)

Index is constrained to the index(es) of the variable(s) with the minimum 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 minimum value in Collection. If Index is a variable, it must not occur in Collection..

You may find it more convenient to embed `min_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 min_index in the global constraint catalog, and is implemented using Gecode's minarg() constraint with tie-break set to false.

## Examples

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

    I = 1

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

    I = I{[1, 4]}

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

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

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

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

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

    L = [A{[1 .. 10]}, B{[1 .. 3]}, C{[1 .. 3]}, D{[1 .. 10]}, E{[1 .. 10]}]
    A = A{[1 .. 10]}
    B = B{[1 .. 3]}
    C = C{[1 .. 3]}
    D = D{[1 .. 10]}
    E = E{[1 .. 10]}
    [eclipse 7]: [A,B,D] :: 1..10, C :: 20..30, min_index([A,B,C,D], I).

    A = A{[1 .. 10]}
    B = B{[1 .. 10]}
    D = D{[1 .. 10]}
    C = C{[20 .. 30]}
    I = I{[1, 2, 4]}

## See Also

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