Skip to content

Commit

Permalink
Merge 3e5b9a9 into 685be2f
Browse files Browse the repository at this point in the history
  • Loading branch information
chkwon committed Dec 22, 2017
2 parents 685be2f + 3e5b9a9 commit a629e3b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/PATHSolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,29 @@ function solveMCP(f_eval::Function, j_eval::Function, lb::Vector, ub::Vector, va
end

function solveLCP(f_eval::Function, lb::AbstractVector, ub::AbstractVector,
var_name=C_NULL, con_name=C_NULL)
var_name=C_NULL, con_name=C_NULL; lcp_check=false)
J = ForwardDiff.jacobian(f_eval, lb)
if lcp_check
Jr = ForwardDiff.jacobian(f_eval, rand(size(lb)))
if norm(J-Jr, 1) > 1e-8
error("The problem does not seem linear. Use `solveMCP()` instead.")
end
end

solveLCP(f_eval, J, lb, ub, var_name, con_name)
end

function solveLCP(f_eval::Function, M::AbstractMatrix,
lb::AbstractVector, ub::AbstractVector,
var_name=C_NULL, con_name=C_NULL)
var_name=C_NULL, con_name=C_NULL; lcp_check=false)

if lcp_check
J = ForwardDiff.jacobian(f_eval, lb)
if norm(J-M, 1) > 1e-8
warn("The user supplied Jacobian does not match with the result by FowardDiff.jacobian(). It proceeds with the user supplied Jacobian.")
end
end

user_f[] = f_eval
cached_J[] = M
cached_J_filled[] = false
Expand Down
31 changes: 31 additions & 0 deletions test/lcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,35 @@

@test isapprox(z, [2.8, 0.0, 0.8, 1.2])
@test status == :Solved



println("-------------------------------------------------------")


function nl_func(x)
val = similar(x)
val[1] = -x[3]^3-x[4] + q[1]
val[2] = x[3] -2x[4]^2 + q[2]
val[3] = x[1]-x[2]+2x[3]^3-2x[4] + q[3]
val[4] = x[1]+2x[2]^2-2x[3]+4x[4] + q[4]
return val
end

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

@test_throws ErrorException solveLCP(nl_func, lb, ub, lcp_check=true)


println("-------------------------------------------------------")



if VERSION > v"0.6"
M2 = rand(size(M))
@test_warn "does not match" solveLCP(elemfunc, M2, lb, ub, lcp_check=true)
end

end

0 comments on commit a629e3b

Please sign in to comment.