Newbie looking for help with Constraints in JuMP



Hi all, I am trying to make a model of an energy market with storage but I’m having some problems using constraints. There are some variables that I want to fix but it doesn’t seem to be working.

I’ve creating a simpler version of the code that doesn’t make any sense physically but produces the same error so perhaps someone can help

using Complementarity
seasons =           ["s1", "s2"]
nodes =             ["n1", "n2"]
@variable(m, q_extract[s in seasons, n in nodes] >=0)
@variable(m, q_inject[s in seasons, n in nodes] >=0)

@mapping(m, KKT_q_extract[s in seasons, n in nodes],    Days["s1"]*0.10)
@mapping(m, KKT_q_inject[s in seasons, n in nodes],     Days["s2"]*0.05)

@complementarity(m, KKT_q_extract,                      q_extract)
@complementarity(m, KKT_q_inject,                       q_inject)

for n in nodes
    @constraints(m, begin
    q_extract["s2",n] == 0
    q_inject["s1",n] == 0


when I run this, I get the error
“BoundsError: attempt to access 8-element Array{Float64,1} at index [9]”

Of course in the main version of my code it is a much larger array but same error. Is there some problem with the way I am using that constraint function?


There is probably a bug in the complementarity package.

You should open an issue in that repo:

When you post the issue, try to reduce the example even further. Do you need q_extract and q_inject? And can you get rid of the seasons set? Also be sure to include the full error message, and provide a link back to this post.

Good luck!

cc/ @chkwon


Thanks for your reply.

I’ve made the post there. I think the two variables are necessary, although the error message is the same with 1 variable it won’t run properly with just 1. Anyway, this is the full error message

BoundsError: attempt to access 4-element Array{Float64,1} at index [5] 
in solveMCP at Complementarity\src\mcp.jl:52 
in #solveMCP#1 at Complementarity\src\mcp.jl:53 
in at base\<missing> 
in #_solve_path#3 at Complementarity\src\mcp.jl:138 
in solveMCP at PATHSolver\src\PATHSolver.jl:56
 in f_user_wrap at PATHSolver\src\PATHSolver.jl:124
 in FunctionWrapper at FunctionWrappers\src\FunctionWrappers.jl:106
 in do_ccall at FunctionWrappers\src\FunctionWrappers.jl:91 
in macro expansion at FunctionWrappers\src\FunctionWrappers.jl:100
 in at FunctionWrappers\src\FunctionWrappers.jl:49 
in myfunc at Complementarity\src\mcp.jl:82
 in eval_g at JuMP\src\nlp.jl:557 and my post there should anyone want to see.