Consider a decision variable in a MILP constrained:

$$\sum\_i p\_i = 1$$

$$p\_i\ \in \{0, 1\}$$

Obviously one element in $p$ is 1 and all others are 0. How can I set a decision variable to the index i of the element $p\_i$ = 1?

I think I can do this by multiple if-then-else constraints but that's a bit clunky.