I’m trying to model an mathematical program with equilibrium constraints (MPEC) in Julia/JuMP. I am currently using the Complementarity.jl package. I am following this example (“bard1”) and try to adapt it to my needs.
Now, I run into problems when I try to include a summation statement in a complementarity constraint. To explain the issue, consider the following reformulation of the bard1 example, which works fine:
using JuMP, Ipopt, Complementarity m = Model(Ipopt.Optimizer) @variable(m, x[i in 1:2]>=0) @variable(m, l[j in 1:3]) @NLobjective(m, Min, (x - 5)^2 + (2*x + 1)^2) @NLconstraint(m, 2*(x-1) - 1.5*x + l - l*0.5 + l == 0) @complements(m, 0 <= 3*x - x - 3, l >= 0) @complements(m, 0 <= - x + 0.5*x + 4, l >= 0) @complements(m, 0 <= - x - x + 7, l >= 0) optimize!(m)
Now, my problem arises when I try to rewrite the third complementarity constraint as follows:
@complements(m, 0 <= - sum(x[i] for i in 1:2) + 7, l >= 0)
If I try to run this line, I get the following error message:
ERROR: UndefVarError: i not defined Stacktrace:  macro expansion @ C:\Users\egbertrv\.julia\packages\JuMP\klrjG\src\parse_nlp.jl:521 [inlined]  macro expansion @ C:\Users\egbertrv\.julia\packages\JuMP\klrjG\src\macros.jl:1978 [inlined]  top-level scope @ C:\Users\egbertrv\.julia\packages\Complementarity\sQ4xs\src\mpec.jl:265
Of course I could hardcode all the constraints without using the summation function, but that will not be practically feasible for my problem.
Does anyone have an idea how to solve this issue? I’m open for any alternative that allows me to formulate and solve an MPEC in Julia/JuMP.