# Newbie looking for help with Constraints in JuMP

**URL:** <https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [July 6, 2018, 12:56am UTC](https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200 "2018-07-06T00:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkt/32/4606_2.png) [@mkt](https://discourse.julialang.org/u/mkt)\
**Post date:** [July 6, 2018, 12:56am UTC](https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200/1 "2018-07-06T00:56:48Z")

</div>

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

```julia
using Complementarity
seasons = ["s1", "s2"]
nodes = ["n1", "n2"]
Days=Dict{String,Float64}()
Days["s1"]=151.0
Days["s2"]=214.0
m=MCPModel()
@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
    end)
end

solveMCP(m)

```

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?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 6, 2018, 5:34am UTC](https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200/2 "2018-07-06T05:34:59Z")

</div>

There is probably a bug in the complementarity package.

You should open an issue in that repo: [https://github.com/chkwon/Complementarity.jl](https://github.com/chkwon/Complementarity.jl)

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

---

<div class="post-metadata">

**Author:** ![mkt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkt/32/4606_2.png) [@mkt](https://discourse.julialang.org/u/mkt)\
**Post date:** [July 6, 2018, 12:42pm UTC](https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200/3 "2018-07-06T12:42:29Z")

</div>

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

```julia
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

```

[https://github.com/chkwon/Complementarity.jl/issues/31](https://github.com/chkwon/Complementarity.jl/issues/31) and my post there should anyone want to see.
