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

Delete constraint(s), add and remove multiple warmstarts #121

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
15 changes: 15 additions & 0 deletions src/cpx_constrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ function add_rangeconstrs!(model::Model, A::CoeffMat, lb::Vector, ub::Vector)
add_rangeconstrs_t!(model, transpose(A), lb, ub)
end

del_constrs!{T<:Signed}(model::Model, ind::T) = del_constrs!(model, ind, ind)

function del_constrs!{T<:Signed}(model::Model, start_ind::T, end_ind::T)
stat = @cpx_ccall(delrows, Cint, (
Ptr{Void},
Ptr{Void},
Cint,
Cint
),
model.env.ptr, model.lp, convert(Cint, start_ind-1), convert(Cint, end_ind-1))
if stat != 0
throw(CplexError(model.env, stat))
end
end

function num_constr(model::Model)
ncons = @cpx_ccall(getnumrows, Cint, (
Ptr{Void},
Expand Down
51 changes: 51 additions & 0 deletions src/cpx_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,57 @@ function set_warm_start!(model::Model, indx::IVec, val::FVec, effortlevel::Integ
end
end

function add_warm_start!(model::Model, x::Vector{Vector{Float64}}, efforts::Vector{Cint})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not crazy about the naming here. Probably better to write this as set_warm_starts!.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

beg::Vector{Cint}, inds::Vector{Cint}, vals::Vector{Cdouble} = Cint[], Cint[], Cdouble[]
count::Int64 = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type annotation here shouldn't be necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. Its just an old habit.

for i in 1:length(x)
push!(beg, count)
for j in 1:length(x[i])
push!(inds, j)
push!(vals, x[i][j])
count += 1
end
end
add_warm_start!(model, convert(Cint, length(x)), beg, inds, vals, efforts)
end

add_warm_start!{T<:Signed}(model::Model, x::Vector{Float64}, effort::T) = add_warm_start!(model, convert(Cint, 1), Cint[1], Cint[1:length(x);], x, [convert(Cint, effort)])

function add_warm_start!(model::Model, num_warm_starts::Cint, beg::Vector{Cint}, inds::Vector{Cint}, vals::Vector{Cdouble}, efforts::Vector{Cint})
stat = @cpx_ccall(addmipstarts, Cint, (
Ptr{Void},
Ptr{Void},
Cint,
Cint,
Ptr{Cint},
Ptr{Cint},
Ptr{Cdouble},
Ptr{Cint},
Ptr{Ptr{Cchar}}
),
model.env.ptr, model.lp, num_warm_starts, length(inds), beg - 1, inds - 1, vals, efforts, fill(C_NULL, num_warm_starts))
if stat != 0
throw(CplexError(model.env, stat))
end
end

del_warm_start!{T<:Signed}(model::Model, ind::T) = del_warm_start!(model, convert(Cint, ind), convert(Cint, ind))

del_warm_start!{T<:Signed}(model::Model, start_ind::T, end_ind::T) = del_warm_start!(model, convert(Cint, start_ind), convert(Cint, end_ind))

function del_warm_start!(model::Model, start_ind::Cint, end_ind::Cint)
stat = @cpx_ccall(delmipstarts, Cint, (
Ptr{Void},
Ptr{Void},
Cint,
Cint
),
model.env.ptr, model.lp, start_ind-1, end_ind-1)
if stat != 0
throw(CplexError(model.env, stat))
end
end

function free_problem(model::Model)
tmp = Ptr{Void}[model.lp]
stat = @cpx_ccall(freeprob, Cint, (Ptr{Void}, Ptr{Void}), model.env.ptr, tmp)
Expand Down