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

Complementarity.jl in Julia 1.5.3 #56

Closed njgallagher closed 3 years ago

njgallagher commented 3 years ago

I am trying to run MCP in Julia. I started with example 1 in the documentation. I cannot get it running in Julia 1.5.3. I had to change a bit of syntax to run in 1.5.3. (No curly bracket syntax and needed result_value.(x)). Here's the code:

using Complementarity, JuMP

m = MCPModel()

M = [0  0 -1 -1 ;
     0  0  1 -2 ;
     1 -1  2 -2 ;
     1  2 -2  4 ]

q = [2; 2; -2; -6]

lb = zeros(4)
ub = Inf*ones(4)

items = 1:4

# @variable(m, lb[i] <= x[i in items] <= ub[i])
@variable(m, x[i in items] >= 0)
@mapping(m, F[i in items], sum(M[i,j]*x[j] for j in items) + q[i])
@complementarity(m, F, x)

status = solveMCP(m, solver=:PATHSolver; convergence_tolerance=1e-8,
    output="yes", time_limit=3600)

z = result_value.(x)

Here's the output:

Stacktrace:
 [1] top-level scope at /Users/G/Desktop/School/AAE706/Classwork/MCP_example.jl:25
 [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088
in expression starting at /Users/G/Desktop/School/AAE706/Classwork/MCP_example.jl:25
┌ Warning: Assignment to `#136#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#136#F_name` will be treated as a new local. Disambiguate by using `local #136#F_name` to suppress this warning or `global #136#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:411
┌ Warning: Assignment to `#136#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#136#F_name` will be treated as a new local. Disambiguate by using `local #136#F_name` to suppress this warning or `global #136#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:427
┌ Warning: Assignment to `#163#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#163#F_name` will be treated as a new local. Disambiguate by using `local #163#F_name` to suppress this warning or `global #163#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:411
┌ Warning: Assignment to `#163#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#163#F_name` will be treated as a new local. Disambiguate by using `local #163#F_name` to suppress this warning or `global #163#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:427
┌ Warning: Assignment to `#190#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#190#F_name` will be treated as a new local. Disambiguate by using `local #190#F_name` to suppress this warning or `global #190#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:411
┌ Warning: Assignment to `#190#F_name` in soft scope is ambiguous because a global variable by the same name exists: `#190#F_name` will be treated as a new local. Disambiguate by using `local #190#F_name` to suppress this warning or `global #190#F_name` to assign to the existing global variable.
└ @ ~/.julia/packages/Complementarity/oQSd5/src/mcp.jl:427

julia> z
1-dimensional DenseAxisArray{Float64,1,...} with index sets:
    Dimension 1, 1:4
And data, a 4-element Array{Float64,1}:
 NaN
 NaN
 NaN
 NaN
chkwon commented 3 years ago

Thanks for reporting this error. It should be :PATH.

using Complementarity, JuMP

m = MCPModel()

M = [0  0 -1 -1 ;
     0  0  1 -2 ;
     1 -1  2 -2 ;
     1  2 -2  4 ]

q = [2; 2; -2; -6]

lb = zeros(4)
ub = Inf*ones(4)

items = 1:4

# @variable(m, lb[i] <= x[i in items] <= ub[i])
@variable(m, x[i in items] >= 0)
@mapping(m, F[i in items], sum(M[i,j]*x[j] for j in items) + q[i])
@complementarity(m, F, x)

status = solveMCP(m, solver=:PATH, convergence_tolerance=1e-8, output="yes", time_limit=3600)

z = result_value.(x)
njgallagher commented 3 years ago

Thank you very much!