Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warm start #1

Merged
merged 7 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deps/lib/
deps/deps.jl
28 changes: 23 additions & 5 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,24 @@ mutable struct Results
Results() = new(Float64[], Float64[], QPALM.Info(), Float64[], Float64[])
end

function solve!(model::QPALM.Model, results::QPALM.Results=Results())
function warm_start!(model::QPALM.Model;
x_warm_start::Maybe{Vector{Float64}} = nothing,
y_warm_start::Maybe{Vector{Float64}} = nothing)
if model.workspace == C_NULL
error("QPALM Model not setup")
end

ccall(
(:qpalm_warm_start, LIBQPALM_PATH),
Cvoid,
(Ptr{QPALM.Workspace}, Ptr{Float64}, Ptr{Float64}),
model.workspace,
x_warm_start != nothing ? pointer(x_warm_start) : C_NULL,
y_warm_start != nothing ? pointer(y_warm_start) : C_NULL,
)
end

function solve!(model::QPALM.Model, results::QPALM.Results=Results())::QPALM.Results
ccall(
(:qpalm_solve, LIBQPALM_PATH),
Cvoid,
Expand Down Expand Up @@ -272,11 +289,12 @@ function solve!(model::QPALM.Model, results::QPALM.Results=Results())
end
end

if results.info.status == :Non_convex
results.info.obj_val = NaN
end
# An objective value is not calculated at this moment.
# if results.info.status == :Non_convex
# results.info.obj_val = NaN
# end

results
return results
end

function cleanup!(model::QPALM.Model)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("feasible.jl")
include("infeasible.jl")
include("warm_start.jl")
include("linear_programs.jl")
include("update.jl")
49 changes: 49 additions & 0 deletions test/warm_start.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Test

@testset "Warm start" begin

using QPALM
using LinearAlgebra
using SparseArrays

n, m = 2, 3
act = 3

Q = sparse(I, n, n)
A = sparse(ones(m, n))
q = ones(n)
bmin = -ones(m)
bmax = ones(m)


x0 = ones(n)
y0 = ones(m)

@testset "Not setup" begin
model = QPALM.Model()

@test_throws ErrorException QPALM.warm_start!(model, x_warm_start=x0)
end

@testset "Normal usage (1)" begin
model = QPALM.Model()

QPALM.setup!(model, Q=Q, q=q, A=A, bmin=bmin, bmax=bmax)
QPALM.warm_start!(model, x_warm_start=x0, y_warm_start=y0)

results = QPALM.solve!(model)
@test results.info.status == :Solved
end

@testset "Normal usage (2)" begin
model = QPALM.Model()

QPALM.setup!(model, Q=Q, q=q, A=A, bmin=bmin, bmax=bmax)
QPALM.warm_start!(model, y_warm_start=y0)
QPALM.warm_start!(model, x_warm_start=x0)

results = QPALM.solve!(model)
@test results.info.status == :Solved
end

end