AMPL > >Sets and Indexing > >I have declared “set S” and “param b {S}”. How do I write an AMPL expression for the arg min of b[i] — that is, the s in S such that b[s] equals the minimum of b[i] over all i in S?

There’s no specific arg min operator in AMPL. However, proceeding directly from the definition, you can define the arg min explicitly by a set expression like

{s in S: b[s] = min {i in S} b[i]}

This expression gives a subset of S, however, containing all of the members of S that achieve the minimum. To get just one member representing the arg min, you can define this to be an ordered set,

set b_argmin ordered := {s in S: b[s] = min {i in S} b[i]};

Then first(b_argmin) is guaranteed to be one member of S that minimizes b[i].

As an alternative, you can use AMPL’s for and if commands to write a script that loops over S to compute the arg min explicitly: