Hello, I am having some difficulty with coding in GAMS and would like to ask for your help.

I have a parameter **A(EV, Prob)**, where EV stands for electric vehicle and Prob represents probability.

**Prob** is defined by a set of 5 elements **(p1 to p5)**.

I would like to create **a new parameter B that assigns a value of 1 to the two Prob indices with the highest probability, and 0 to the rest**.

For example:

A(“EV1”, “p1”) = 0.10;

A(“EV1”, “p2”) = 0.15;

A(“EV1”, “p3”) = 0.25;

A(“EV1”, “p4”) = 0.20;

A(“EV1”, “p5”) = 0.30;

In this case, I want **B(“EV1”, “p3”)** and **B(“EV1”, “p5”)** to be set to 1, and the other indices to be 0.

Could you please advise how I could structure the code to achieve this?

The below code is my approach but I guess there would be better way…

```
Loop(EV,
maxProb = smax(Prob, A(EV, Prob));
B(EV, Prob)$(A(EV, Prob) = maxProb) = 1;
A(EV, Prob)$(A(EV, Prob) = maxProb) = -1e6;
secondMaxProb = smax(Prob, A(EV, Prob));
B(EV, Prob)$(A(EV, Prob) = secondMaxProb) = 1;
A(EV, Prob)$(A(EV, Prob) = -1e6) = maxProb;
);
```