Skip to content

Commit a41e7d3

Browse files
committed
Fix MathOptNLPModel
1 parent 9e5441f commit a41e7d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/moi_nlp_model.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ function NLPModels.grad!(nlp::MathOptNLPModel, x::AbstractVector, g::AbstractVec
9090
g .= nlp.obj.gradient
9191
end
9292
if nlp.obj.type == "QUADRATIC"
93-
coo_sym_prod!(nlp.obj.hessian.rows, nlp.obj.hessian.cols, nlp.obj.hessian.vals, x, g)
94-
g .+= nlp.obj.gradient
93+
g .= nlp.obj.gradient
94+
coo_sym_add_mul!(nlp.obj.hessian.rows, nlp.obj.hessian.cols, nlp.obj.hessian.vals, x, g, 1.0)
9595
end
9696
if nlp.obj.type == "NONLINEAR"
9797
MOI.eval_objective_gradient(nlp.eval, g, x)
@@ -303,11 +303,12 @@ function NLPModels.hess_coord!(
303303
view(vals, 1:(nlp.obj.nnzh)) .= obj_weight .* nlp.obj.hessian.vals
304304
end
305305
if (nlp.obj.type == "NONLINEAR") || (nlp.meta.nnln > nlp.quadcon.nquad)
306+
λ = view(y, (nlp.meta.nlin + nlp.quadcon.nquad + 1):(nlp.meta.ncon))
306307
MOI.eval_hessian_lagrangian(nlp.eval,
307308
view(vals, (nlp.obj.nnzh + nlp.quadcon.nnzh + 1):(nlp.meta.nnzh)),
308309
x,
309310
obj_weight,
310-
view(y, (nlp.meta.nlin + nlp.quadcon.nquad + 1)::(nlp.meta.ncon))
311+
λ
311312
)
312313
end
313314
if nlp.quadcon.nquad > 0
@@ -384,8 +385,8 @@ function NLPModels.hprod!(
384385
hv .= 0.0
385386
end
386387
if nlp.obj.type == "QUADRATIC"
387-
coo_sym_prod!(nlp.obj.hessian.rows, nlp.obj.hessian.cols, nlp.obj.hessian.vals, v, hv)
388-
hv .*= obj_weight
388+
hv .= 0.0
389+
coo_sym_add_mul!(nlp.obj.hessian.rows, nlp.obj.hessian.cols, nlp.obj.hessian.vals, v, hv, obj_weight)
389390
end
390391
if nlp.obj.type == "NONLINEAR"
391392
λ = zeros(nlp.meta.nnln - nlp.quadcon.nquad) # Should be stored in the structure MathOptNLPModel

0 commit comments

Comments
 (0)