-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from chkwon/rdeits-lcp
appveyor for julia 0.6
- Loading branch information
Showing
5 changed files
with
296 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
@testset "linear complementarity problem" begin | ||
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 = solveLCP(myfunc, M, lb, ub) | ||
@show status | ||
@show z | ||
@show f | ||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
status, z, f = solveLCP(myfunc, lb, ub) | ||
@show status | ||
@show z | ||
@show f | ||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
|
||
println("-------------------------------------------------------") | ||
|
||
|
||
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) | ||
|
||
options(convergence_tolerance=1e-2, output=:no, time_limit=3600) | ||
|
||
status, z, f = solveLCP(myfunc, M, lb, ub) | ||
@show status | ||
@show z | ||
@show f | ||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
status, z, f = solveLCP(myfunc, lb, ub) | ||
@show status | ||
@show z | ||
@show f | ||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
|
||
|
||
println("-------------------------------------------------------") | ||
|
||
|
||
function elemfunc(x) | ||
val = similar(x) | ||
val[1] = -x[3]-x[4] + q[1] | ||
val[2] = x[3] -2x[4] + q[2] | ||
val[3] = x[1]-x[2]+2x[3]-2x[4] + q[3] | ||
val[4] = x[1]+2x[2]-2x[3]+4x[4] + q[4] | ||
return val | ||
end | ||
|
||
n = 4 | ||
lb = zeros(n) | ||
ub = 100*ones(n) | ||
|
||
var_name = ["x1", "x2", "x3", "x4"] | ||
con_name = ["F1", "F2", "F3", "F4"] | ||
|
||
options(convergence_tolerance=1e-2, output=:yes, time_limit=3600) | ||
|
||
status, z, f = solveLCP(elemfunc, M, lb, ub) | ||
status, z, f = solveLCP(elemfunc, M, lb, ub, var_name) | ||
status, z, f = solveLCP(elemfunc, M, lb, ub, var_name, con_name) | ||
status, z, f = solveLCP(elemfunc, lb, ub) | ||
status, z, f = solveLCP(elemfunc, lb, ub, var_name) | ||
status, z, f = solveLCP(elemfunc, lb, ub, var_name, con_name) | ||
|
||
@show status | ||
@show z | ||
@show f | ||
|
||
|
||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
@testset "mixed complementarity problem" begin | ||
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 = solveMCP(myfunc, lb, ub) | ||
@show status | ||
@show z | ||
@show f | ||
|
||
|
||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
|
||
println("-------------------------------------------------------") | ||
|
||
|
||
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) | ||
|
||
options(convergence_tolerance=1e-2, output=:no, time_limit=3600) | ||
|
||
status, z, f = solveMCP(myfunc, lb, ub) | ||
|
||
@show status | ||
@show z | ||
@show f | ||
|
||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
|
||
|
||
println("-------------------------------------------------------") | ||
|
||
|
||
function elemfunc(x) | ||
val = similar(x) | ||
val[1] = -x[3]-x[4] + q[1] | ||
val[2] = x[3] -2x[4] + q[2] | ||
val[3] = x[1]-x[2]+2x[3]-2x[4] + q[3] | ||
val[4] = x[1]+2x[2]-2x[3]+4x[4] + q[4] | ||
return val | ||
end | ||
|
||
n = 4 | ||
lb = zeros(n) | ||
ub = 100*ones(n) | ||
|
||
var_name = ["x1", "x2", "x3", "x4"] | ||
con_name = ["F1", "F2", "F3", "F4"] | ||
|
||
options(convergence_tolerance=1e-2, output=:yes, time_limit=3600) | ||
|
||
|
||
jacfunc(x) = M | ||
|
||
status, z, f = solveMCP(elemfunc, lb, ub) | ||
status, z, f = solveMCP(elemfunc, lb, ub, var_name) | ||
status, z, f = solveMCP(elemfunc, lb, ub, var_name, con_name) | ||
status, z, f = solveMCP(elemfunc, jacfunc, lb, ub) | ||
status, z, f = solveMCP(elemfunc, jacfunc, lb, ub, var_name) | ||
status, z, f = solveMCP(elemfunc, jacfunc, lb, ub, var_name, con_name) | ||
|
||
|
||
@show status | ||
@show z | ||
@show f | ||
|
||
|
||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
|
||
function test_in_local_scope() | ||
# Verify that we can solve MCPs in local scope. Surprisingly, this is | ||
# is relevant because it affects the way closures are generated. To be | ||
# specific, you can do the following in global scope: | ||
# | ||
# julia> y = [1] | ||
# julia> cfunction(x -> x + y[1], Int, (Int,)) | ||
# | ||
# but running the same code inside a function will fail with: | ||
# ERROR: closures are not yet c-callable | ||
|
||
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) | ||
|
||
options(convergence_tolerance=1e-2, output=:no, time_limit=3600) | ||
|
||
status, z, f = solveMCP(myfunc, lb, ub) | ||
|
||
@show status | ||
@show z | ||
@show f | ||
|
||
@test isapprox(z, [2.8, 0.0, 0.8, 1.2]) | ||
@test status == :Solved | ||
end | ||
|
||
test_in_local_scope() | ||
end |
Oops, something went wrong.