chkwon / Complementarity.jl

provides a modeling interface for mixed complementarity problems (MCP) and math programs with equilibrium problems (MPEC) via JuMP
Other
75 stars 20 forks source link

@constraints bug #31

Closed trivedymk closed 6 years ago

trivedymk commented 6 years ago

Hi again. I posted this on the discourse JULIA forum and was told it could be a bug with this package.

I am trying to set some constraints on some of my variables and get an error message.

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

@mapping(m, KKT_q_extract[n in nodes],    q_inject[n])
@mapping(m, KKT_q_inject[n in nodes],     q_extract[n])

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

for n in nodes
    @constraints(m, begin
    q_extract[n] == 0
    q_inject[n] == 0
    end)
end

solveMCP(m))

This is a highly reduced version of the code to only one variable (doesnt make physical sense but gives same error message).

Without this constraints loop, the model solves.

Including the loop setting the constraints, causes this 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

Here's the post I made on discourse: https://discourse.julialang.org/t/newbie-looking-for-help-with-constraints-in-jump/12200

chkwon commented 6 years ago

In the current form, this package does not support constraints. In the standard form of complementarity problems, there are no constraints. You will have to either reformulate your problem as a standard form problem or develop an algorithm that solves standard-form complementarity problems iteratively. Unfortunately, I'm not an expert in this area.

maxxb77 commented 4 years ago

Does this apply to the NLexpression macro as well?

chkwon commented 4 years ago

@mapping is in fact an alias for @NLexpression.

maxxb77 commented 4 years ago

That makes a bit more sense

I was trying to use NLexpression to create a substitution variable (similar to a GAMS macro) but it looks like I'm back to the drawing board... any thoughts?

chkwon commented 4 years ago

@maxxb77 Does this help?