Skip to content

Commit 6ff2770

Browse files
Merge pull request #3 from ParasPuneetSingh/ParasPuneetSingh-MOO-1
Created a new struct and constructors for MOO in scimlfunctions.jl
2 parents 63cbc97 + 55373a8 commit 6ff2770

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

src/problems/optimization_problems.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct OptimizationProblem{iip, F, uType, P, LB, UB, I, LC, UC, S, K} <:
103103
ucons::UC
104104
sense::S
105105
kwargs::K
106-
@add_kwonly function OptimizationProblem{iip}(f::OptimizationFunction{iip}, u0,
106+
@add_kwonly function OptimizationProblem{iip}(f::Union{OptimizationFunction{iip}, MultiObjectiveOptimizationFunction{iip}}, u0,
107107
p = NullParameters();
108108
lb = nothing, ub = nothing, int = nothing,
109109
lcons = nothing, ucons = nothing,
@@ -119,7 +119,7 @@ struct OptimizationProblem{iip, F, uType, P, LB, UB, I, LC, UC, S, K} <:
119119
end
120120
end
121121

122-
function OptimizationProblem(f::OptimizationFunction, args...; kwargs...)
122+
function OptimizationProblem(f::Union{OptimizationFunction, MultiObjectiveOptimizationFunction}, args...; kwargs...)
123123
OptimizationProblem{isinplace(f)}(f, args...; kwargs...)
124124
end
125125
function OptimizationProblem(f, args...; kwargs...)

src/scimlfunctions.jl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,38 @@ struct OptimizationFunction{iip, AD, F, G, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP,
19231923
lag_hess_colorvec::LHCV
19241924
end
19251925

1926+
"""
1927+
$(TYPEDEF)
1928+
"""
1929+
1930+
struct MultiObjectiveOptimizationFunction{iip, AD, F, J, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O,
1931+
EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} <:
1932+
AbstractOptimizationFunction{iip}
1933+
f::F
1934+
adtype::AD
1935+
jac::J # Replacing grad with jac for the Jacobian
1936+
hess::Vector{H} # Hess will be a vector of type H
1937+
hv::HV
1938+
cons::C
1939+
cons_j::CJ
1940+
cons_jvp::CJV
1941+
cons_vjp::CVJ
1942+
cons_h::CH
1943+
hess_prototype::HP
1944+
cons_jac_prototype::CJP
1945+
cons_hess_prototype::CHP
1946+
observed::O
1947+
expr::EX
1948+
cons_expr::CEX
1949+
sys::SYS
1950+
lag_h::LH
1951+
lag_hess_prototype::LHP
1952+
hess_colorvec::HCV
1953+
cons_jac_colorvec::CJCV
1954+
cons_hess_colorvec::CHCV
1955+
lag_hess_colorvec::LHCV
1956+
end
1957+
19261958
"""
19271959
$(TYPEDEF)
19281960
"""
@@ -3806,6 +3838,62 @@ function OptimizationFunction{iip}(f, adtype::AbstractADType = NoAD();
38063838
cons_hess_colorvec, lag_hess_colorvec)
38073839
end
38083840

3841+
# Function call operator for MultiObjectiveOptimizationFunction
3842+
(f::MultiObjectiveOptimizationFunction)(args...) = f.f(args...)
3843+
3844+
# Convenience constructor
3845+
MultiObjectiveOptimizationFunction(args...; kwargs...) = MultiObjectiveOptimizationFunction{true}(args...; kwargs...)
3846+
3847+
# Constructor with keyword arguments
3848+
function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoAD();
3849+
jac = nothing, hess = Vector{nothing}(undef, 0), hv = nothing,
3850+
cons = nothing, cons_j = nothing, cons_jvp = nothing,
3851+
cons_vjp = nothing, cons_h = nothing,
3852+
hess_prototype = nothing,
3853+
cons_jac_prototype = __has_jac_prototype(f) ?
3854+
f.jac_prototype : nothing,
3855+
cons_hess_prototype = nothing,
3856+
syms = nothing,
3857+
paramsyms = nothing,
3858+
observed = __has_observed(f) ? f.observed :
3859+
DEFAULT_OBSERVED_NO_TIME,
3860+
expr = nothing, cons_expr = nothing,
3861+
sys = __has_sys(f) ? f.sys : nothing,
3862+
lag_h = nothing, lag_hess_prototype = nothing,
3863+
hess_colorvec = __has_colorvec(f) ? f.colorvec : nothing,
3864+
cons_jac_colorvec = __has_colorvec(f) ? f.colorvec :
3865+
nothing,
3866+
cons_hess_colorvec = __has_colorvec(f) ? f.colorvec :
3867+
nothing,
3868+
lag_hess_colorvec = nothing) where {iip}
3869+
isinplace(f, 2; has_two_dispatches = false, isoptimization = true)
3870+
sys = sys_or_symbolcache(sys, syms, paramsyms)
3871+
MultiObjectiveOptimizationFunction{iip, typeof(adtype), typeof(f), typeof(jac), typeof(hess),
3872+
typeof(hv),
3873+
typeof(cons), typeof(cons_j), typeof(cons_jvp),
3874+
typeof(cons_vjp), typeof(cons_h),
3875+
typeof(hess_prototype),
3876+
typeof(cons_jac_prototype), typeof(cons_hess_prototype),
3877+
typeof(observed),
3878+
typeof(expr), typeof(cons_expr), typeof(sys), typeof(lag_h),
3879+
typeof(lag_hess_prototype), typeof(hess_colorvec),
3880+
typeof(cons_jac_colorvec), typeof(cons_hess_colorvec),
3881+
typeof(lag_hess_colorvec)
3882+
}(f, adtype, jac, hess,
3883+
hv, cons, cons_j, cons_jvp,
3884+
cons_vjp, cons_h,
3885+
hess_prototype, cons_jac_prototype,
3886+
cons_hess_prototype, observed, expr, cons_expr, sys,
3887+
lag_h, lag_hess_prototype, hess_colorvec, cons_jac_colorvec,
3888+
cons_hess_colorvec, lag_hess_colorvec)
3889+
end
3890+
3891+
# Placeholder functions for __has_jac_prototype, __has_observed, __has_sys, and __has_colorvec
3892+
__has_jac_prototype(f) = false
3893+
__has_observed(f) = false
3894+
__has_sys(f) = false
3895+
__has_colorvec(f) = false
3896+
38093897
function BVPFunction{iip, specialize, twopoint}(f, bc;
38103898
mass_matrix = __has_mass_matrix(f) ? f.mass_matrix : I,
38113899
analytic = __has_analytic(f) ? f.analytic : nothing,

0 commit comments

Comments
 (0)