Hi,
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[1] - 5)^2 + (2*x[2] + 1)^2)
@NLconstraint(m, 2*(x[2]-1) - 1.5*x[1] + l[1] - l[2]*0.5 + l[3] == 0)
@complements(m, 0 <= 3*x[1] - x[2] - 3, l[1] >= 0)
@complements(m, 0 <= - x[1] + 0.5*x[2] + 4, l[2] >= 0)
@complements(m, 0 <= - x[1] - x[2] + 7, l[3] >= 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[3] >= 0)
If I try to run this line, I get the following error message:
ERROR: UndefVarError: i not defined
Stacktrace:
[1] macro expansion
@ C:\Users\egbertrv\.julia\packages\JuMP\klrjG\src\parse_nlp.jl:521 [inlined]
[2] macro expansion
@ C:\Users\egbertrv\.julia\packages\JuMP\klrjG\src\macros.jl:1978 [inlined]
[3] 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.