# PATHsolver not working

**URL:** <https://discourse.julialang.org/t/pathsolver-not-working/89156>\
**Category:** Optimization (Mathematical)\
**Tags:** package\
**Created:** [October 23, 2022, 5:35pm UTC](https://discourse.julialang.org/t/pathsolver-not-working/89156 "2022-10-23T17:35:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Nadeem](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Muhammad\_Nadeem](https://discourse.julialang.org/u/Muhammad_Nadeem)\
**Post date:** [October 23, 2022, 5:35pm UTC](https://discourse.julialang.org/t/pathsolver-not-working/89156/1 "2022-10-23T17:35:39Z")

</div>

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) = M_x + 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.

---

<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:** [October 23, 2022, 8:49pm UTC](https://discourse.julialang.org/t/pathsolver-not-working/89156/2 "2022-10-23T20:49:02Z")

</div>

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](https://github.com/chkwon/PATHSolver.jl)

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

> <https://github.com/chkwon/PATHSolver.jl/blob/2087cc0669fa9e1a6faf994bd6b942fadb324a40/src/C_API.jl#L680-L709>

---

<div class="post-metadata">

**Author:** ![Muhammad\_Nadeem](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Muhammad\_Nadeem](https://discourse.julialang.org/u/Muhammad_Nadeem)\
**Post date:** [October 23, 2022, 9:43pm UTC](https://discourse.julialang.org/t/pathsolver-not-working/89156/3 "2022-10-23T21:43:16Z")

</div>

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](https://docs.juliahub.com/PATHSolver/xyGrF/0.6.0/)

 ![error](https://global.discourse-cdn.com/julialang/original/3X/c/d/cd6b92e434bf15a5d7e9297128a3605fa268c958.png)

---

<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:** [October 23, 2022, 11:25pm UTC](https://discourse.julialang.org/t/pathsolver-not-working/89156/4 "2022-10-23T23:25:00Z")

</div>

Those docs are for an old version of the package. Here are the new docs: [Readme · PATHSolver.jl](https://docs.juliahub.com/PATHSolver/xyGrF/1.3.0/)

```nohighlight
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
Gradient Evaluations. . 4
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

```
