# Index of element in MILP vector decision variable that equals 1

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.

My interpretation is that you want $$y$$ to be $$i$$ if $$p_i=1$$. You can do that with a simple multiplication $$y=c^Tp$$ where the constant vector $$c$$ is given by $$c_i=i$$.
Assuming your index goes from 0 to $$n$$ you can do $$k = \sum_{i = 0}^{n}i \cdot p_i$$ where $$k$$ is the desired index.