# PATHsolver not working

Hello all,

I am trying to run a simple mixed complementary problem using PATHsolver, but it is giving me this error “UndefVarError: solveMCP not defined”

My code is:

using PATHSolver

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

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

myfunc(x) = Mx + q
n = 4
lb = zeros(n)
ub = 100
ones(n)
z, f = solveMCP(myfunc, lb, ub)

Can anyone help me out here whats going on? Thanks.

You can see the example usage of PATHSolver here: GitHub - chkwon/PATHSolver.jl: provides a Julia wrapper for the PATH Solver for solving mixed complementarity problems

If you don’t want to use JuMP, the less-documented method is `PATHSolver.solve_mcp`:

1 Like

Thank, but still doesnt work, giving me the error please see it in the attachments.

here is my code:

using PATHSolver

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

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

myfunc(x) = M*x + q

n = 4
lb = zeros(n)
ub = 100*ones(n)

status, z, f = PATHSolver.solve_mcp(myfunc, lb, ub)

P.S , i am implementing it at as explained in "Readme · PATHSolver.jl

Those docs are for an old version of the package. Here are the new docs: Readme · PATHSolver.jl

``````julia> import PATHSolver

julia> import SparseArrays

julia> M = [
0 0 -1 -1
0 0 1 -2
1 -1 2 -2
1 2 -2 4
]
4×4 Matrix{Int64}:
0   0  -1  -1
0   0   1  -2
1  -1   2  -2
1   2  -2   4

julia> M_sparse = convert(
SparseArrays.SparseMatrixCSC{Cdouble,Cint},
SparseArrays.sparse(M),
)
4×4 SparseArrays.SparseMatrixCSC{Float64, Int32} with 12 stored entries:
⋅     ⋅   -1.0  -1.0
⋅     ⋅    1.0  -2.0
1.0  -1.0   2.0  -2.0
1.0   2.0  -2.0   4.0

julia> q = Float64[2, 2, -2, -6]
4-element Vector{Float64}:
2.0
2.0
-2.0
-6.0

julia> z = zeros(4)
4-element Vector{Float64}:
0.0
0.0
0.0
0.0

julia> lb, ub = zeros(4), fill(100.0, 4)
([0.0, 0.0, 0.0, 0.0], [100.0, 100.0, 100.0, 100.0])

julia> status, sol, info = PATHSolver.solve_mcp(M_sparse, q, lb, ub, z)
Path 5.0.03 (Fri Jun 26 09:58:07 2020)
Written by Todd Munson, Steven Dirkse, Youngdae Kim, and Michael Ferris

Crash Log
major  func  diff  size  residual    step       prox   (label)
0     0             1.2295e+01             0.0e+00 (f[    4])
1     2     4     2 1.0267e+01  8.0e-01    0.0e+00 (f[    1])
2     3     2     4 8.4839e-01  1.0e+00    0.0e+00 (f[    4])
3     4     0     3 4.4409e-16  1.0e+00    0.0e+00 (f[    3])
pn_search terminated: no basis change.

Major Iteration Log
major minor  func  grad  residual    step  type prox    inorm  (label)
0     0     5     4 4.4409e-16           I 0.0e+00 4.4e-16 (f[    3])

Major Iterations. . . . 0
Minor Iterations. . . . 0
Restarts. . . . . . . . 0
Crash Iterations. . . . 3
Gradient Steps. . . . . 0
Function Evaluations. . 5
Basis Time. . . . . . . 0.000013
Total Time. . . . . . . 0.000526
Residual. . . . . . . . 4.440892e-16
(PATHSolver.MCP_Solved, [2.8, 0.0, 0.8, 1.2], PATHSolver.Information(4.4408920985006247e-16, 0.0, 0.0, 0.000526, 1.3000000000000001e-5, 0.0, 0, 0, 3, 5, 4, 0, 0, 0, 0, false, false, false, true, false, false, false))

julia> sol
4-element Vector{Float64}:
2.8
0.0
0.8
1.2

julia> status
MCP_Solved::MCP_Termination = 1
``````
1 Like