Skip to content

Commit

Permalink
improve cons_lin (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Aug 8, 2022
1 parent c9acb80 commit 4743a8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
19 changes: 3 additions & 16 deletions src/CUTEst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mutable struct CUTEstModel <: AbstractNLPModel{Float64, Vector{Float64}}
jcols::Vector{Int32}

lin_structure_reliable::Bool
blin::Vector{Float64}
clinrows::Vector{Int32}
clincols::Vector{Int32}
clinvals::Vector{Float64}
Expand Down Expand Up @@ -374,29 +375,15 @@ function CUTEstModel(
work = Vector{Int32}(undef, ncon)

lin_structure_reliable = false
blin = Vector{Float64}(undef, nlin)
clinrows = Vector{Int32}(undef, lin_nnzj)
clincols = Vector{Int32}(undef, lin_nnzj)
clinvals = Vector{Float64}(undef, lin_nnzj)

Jval = Array{Cdouble}(undef, nvar)
Jvar = Array{Cint}(undef, nvar)

nlp = CUTEstModel(
meta,
Counters(),
hrows,
hcols,
jac_structure_reliable,
jrows,
jcols,
lin_structure_reliable,
clinrows,
clincols,
clinvals,
work,
Jval,
Jvar,
)
nlp = CUTEstModel(meta, Counters(), hrows, hcols, jac_structure_reliable, jrows, jcols, lin_structure_reliable, blin, clinrows, clincols, clinvals, work, Jval, Jvar)

cutest_instances += 1
finalizer(cutest_finalize, nlp)
Expand Down
19 changes: 5 additions & 14 deletions src/julia_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,9 @@ function NLPModels.cons!(nlp::CUTEstModel, x::AbstractVector, c::AbstractVector)
end

function NLPModels.cons_lin!(nlp::CUTEstModel, x::AbstractVector, c::AbstractVector)
_cx = Vector{Float64}(undef, nlp.meta.nlin)
cons_lin!(nlp, x, _cx)
c .= _cx
return c
end

function NLPModels.cons_lin!(nlp::CUTEstModel, x::AbstractVector, c::StrideOneVector)
k = 1
for j in nlp.meta.lin
cifn(Cint[0], Cint[nlp.meta.nvar], Cint[j], x, view(c, k:k))
k += 1
end
eval_lin_structure!(nlp)
coo_prod!(nlp.clinrows, nlp.clincols, nlp.clinvals, x, c)
c .+= nlp.blin
nlp.counters.neval_cons_lin += 1
return c
end
Expand Down Expand Up @@ -372,11 +363,11 @@ end
function eval_lin_structure!(nlp::CUTEstModel)
if !nlp.lin_structure_reliable
nvar = Cint[nlp.meta.nvar]
ci = [0.0]
nnzj = Cint[0]
i = 1
for j in nlp.meta.lin
ccifsg(Cint[0], nvar, Cint[j], nlp.meta.x0, ci, nnzj, nvar, nlp.Jval, nlp.Jvar, Cint[true])
x0 = zeros(nlp.meta.nvar)
ccifsg(Cint[0], nvar, Cint[j], x0, view(nlp.blin, j:j), nnzj, nvar, nlp.Jval, nlp.Jvar, Cint[true])
for k = 1:nnzj[1]
nlp.clinrows[i] = findfirst(x -> x == j, nlp.meta.lin)
nlp.clincols[i] = nlp.Jvar[k]
Expand Down

0 comments on commit 4743a8d

Please sign in to comment.