Skip to content

Commit

Permalink
add Counters
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxenceGollier committed Jul 23, 2024
1 parent 5e6e79f commit 3a5680b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/quasi-newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mutable struct LBFGSModel{
Op <: LBFGSOperator{T},
} <: QuasiNewtonModel{T, S}
meta::Meta
counters::Counters
model::M
op::Op
end
Expand All @@ -29,6 +30,7 @@ mutable struct LSR1Model{
Op <: LSR1Operator{T},
} <: QuasiNewtonModel{T, S}
meta::Meta
counters::Counters
model::M
op::Op
end
Expand All @@ -41,20 +43,21 @@ mutable struct DiagonalQNModel{
Op <: AbstractDiagonalQuasiNewtonOperator{T},
} <: AbstractDiagonalQNModel{T, S}
meta::Meta
counters::Counters
model::M
op::Op
end

"Construct a `LBFGSModel` from another type of model."
function LBFGSModel(nlp::AbstractNLPModel{T, S}; kwargs...) where {T, S}
op = LBFGSOperator(T, nlp.meta.nvar; kwargs...)
return LBFGSModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
return LBFGSModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, Counters(), nlp, op)
end

"Construct a `LSR1Model` from another type of nlp."
function LSR1Model(nlp::AbstractNLPModel{T, S}; kwargs...) where {T, S}
op = LSR1Operator(T, nlp.meta.nvar; kwargs...)
return LSR1Model{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
return LSR1Model{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, Counters() ,nlp, op)
end

"""
Expand All @@ -71,7 +74,7 @@ function DiagonalPSBModel(
d0::S = fill!(S(undef, nlp.meta.nvar), one(T)),
) where {T, S}
op = DiagonalPSB(d0)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, Counters(), nlp, op)
end

"""
Expand All @@ -88,7 +91,7 @@ function DiagonalAndreiModel(
d0::S = fill!(S(undef, nlp.meta.nvar), one(T)),
) where {T, S}
op = DiagonalAndrei(d0)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, Counters(), nlp, op)
end

"""
Expand All @@ -102,7 +105,7 @@ for more information about the used algorithms.
"""
function SpectralGradientModel(nlp::AbstractNLPModel{T, S}; σ::T = one(T)) where {T, S}
op = SpectralGradient(σ, nlp.meta.nvar)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, nlp, op)
return DiagonalQNModel{T, S, typeof(nlp), typeof(nlp.meta), typeof(op)}(nlp.meta, Counters(), nlp, op)
end

NLPModels.show_header(io::IO, nlp::QuasiNewtonModel) =
Expand Down

0 comments on commit 3a5680b

Please sign in to comment.