diff --git a/src/CUTEst.jl b/src/CUTEst.jl index be217920..c2c604f0 100644 --- a/src/CUTEst.jl +++ b/src/CUTEst.jl @@ -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} @@ -374,6 +375,7 @@ 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) @@ -381,22 +383,7 @@ function CUTEstModel( 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) diff --git a/src/julia_interface.jl b/src/julia_interface.jl index ee097923..b321f91d 100644 --- a/src/julia_interface.jl +++ b/src/julia_interface.jl @@ -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 @@ -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]