# How can I do this in GAMS?

I am mimicking a GAMS model that was introduced in Soler et al. (2013)1 to compare my new model with its results.

In a nutshell, assume we have a variable $$t$$ that is supposed to only take certain discrete values from the set $$D$$ where $$D=\{0.12,0.22,0.32,0.42,0.52, 0.62\}$$.

The proposed method is to relax $$t$$ and make it a continuous variable between two upper and lower limits $$\min D\le t\le\max D$$ and then add a penalty function to the model objective function to force the solver to allocate only discrete values for $$t$$.

The penalty function is $$\sin^2\left(\pi t/(\text{upr}-\text{lwr})\right)$$ where:

• $$\text{upr}$$ is the upper closest values for $$t$$ in $$D$$;

• $$\text{lwr}$$ is the lower closest values for $$t$$ in $$D$$.

This clever trick will make the penalty function take positive values if the allocated value for $$t$$ is not discrete, and zero if $$t$$ is discrete.

During the optimization process, when the solver allocates a value for $$t$$, it needs to find the two closest elements from $$D$$ to the allocated value of $$t$$. Let's say it gives $$t=0.14$$, then it has to find the upper and lower values of $$t$$ from $$D$$ which are $$\text{lwr}=0.12$$ and $$\text{upr}=0.22$$. This has to be done during the optimization process not after it finishes like in some iterative methods.

So, my question is how I should code this in GAMS. How can I tell the solver to find the upper and lower values of a variable from a set during the optimization process? In MATLAB we use the function find but it is not effective.

Reference

[1] Soler, E. M., Asada, E. N., da Costa, G. R. M. (2013). Penalty-based nonlinear solver for optimal reactive power dispatch with discrete controls. IEEE Transactions on Power Systems. 28(3):2174-2182.

• This sounds like a heuristic approach. Probably a better way is to solve as a MINLP model. GAMS supports different MINLP solvers. Note that GAMS is a modeling system and not a programming language for implementing solvers. Dec 24 '19 at 10:50