Skip to content

Commit c7d262d

Browse files
blegatodow
authored andcommitted
Swap model and function
1 parent c75e265 commit c7d262d

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/constraints.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ function moi_function(constraint::AbstractConstraint)
769769
return moi_function(jump_function(constraint))
770770
end
771771

772-
function moi_function(constraint::AbstractConstraint, model)
773-
return moi_function(jump_function(constraint), model)
772+
function moi_function(model, constraint::AbstractConstraint)
773+
return moi_function(model, jump_function(constraint))
774774
end
775775

776776
"""
@@ -1038,7 +1038,7 @@ function check_belongs_to_model(f::Vector, model)
10381038
end
10391039
end
10401040

1041-
function moi_function(f, model)
1041+
function moi_function(model, f)
10421042
check_belongs_to_model(f, model)
10431043
return moi_function(f)
10441044
end
@@ -1059,7 +1059,7 @@ function add_constraint(
10591059
name::String = "",
10601060
)
10611061
con = model_convert(model, con)
1062-
func, set = moi_function(con, model), moi_set(con)
1062+
func, set = moi_function(model, con), moi_set(con)
10631063
# The type of backend(model) is unknown so we directly redirect to another
10641064
# function.
10651065
cindex = _moi_add_constraint(

src/nlp_expr.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,8 @@ end
584584
moi_function(x::Number) = x
585585

586586
function moi_function(
587-
f::GenericNonlinearExpr{V},
588587
model::JuMP.GenericModel,
588+
f::GenericNonlinearExpr{V},
589589
) where {V}
590590
cache = model.subexpressions
591591
key = objectid(f)
@@ -598,7 +598,7 @@ function moi_function(
598598
if f.args[i] isa GenericNonlinearExpr{V}
599599
push!(stack, (ret, i, f.args[i]))
600600
elseif f.args[i] isa AbstractJuMPScalar
601-
ret.args[i] = moi_function(f.args[i], model)
601+
ret.args[i] = moi_function(model, f.args[i])
602602
else
603603
ret.args[i] = moi_function(f.args[i])
604604
end
@@ -1244,7 +1244,7 @@ end
12441244

12451245
function MOI.VectorNonlinearFunction(f::Vector{<:AbstractJuMPScalar})
12461246
model = owner_model(first(f))
1247-
return MOI.VectorNonlinearFunction(moi_function.(f, model))
1247+
return MOI.VectorNonlinearFunction(moi_function.(model, f))
12481248
end
12491249

12501250
"""
@@ -1290,7 +1290,7 @@ x
12901290
```
12911291
"""
12921292
function simplify(model::GenericModel, f::AbstractJuMPScalar)
1293-
g = MOI.Nonlinear.SymbolicAD.simplify(moi_function(f, model))
1293+
g = MOI.Nonlinear.SymbolicAD.simplify(moi_function(model, f))
12941294
return jump_function(model, g)
12951295
end
12961296

@@ -1342,7 +1342,7 @@ function derivative(
13421342
x::GenericVariableRef{T},
13431343
) where {T}
13441344
df_dx =
1345-
MOI.Nonlinear.SymbolicAD.derivative(moi_function(f, model), index(x))
1345+
MOI.Nonlinear.SymbolicAD.derivative(moi_function(model, f), index(x))
13461346
return jump_function(model, MOI.Nonlinear.SymbolicAD.simplify!(df_dx))
13471347
end
13481348

@@ -1387,7 +1387,7 @@ julia> ∇f[y]
13871387
```
13881388
"""
13891389
function gradient(model::GenericModel{T}, f::AbstractJuMPScalar) where {T}
1390-
g = moi_function(f, model)
1390+
g = moi_function(model, f)
13911391
∇f = Dict{GenericVariableRef{T},Any}()
13921392
for xi in MOI.Nonlinear.SymbolicAD.variables(g)
13931393
df_dx = MOI.Nonlinear.SymbolicAD.simplify!(

src/objective.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ end
280280

281281
function set_objective_function(model::GenericModel, func::AbstractJuMPScalar)
282282
check_belongs_to_model(func, model)
283-
set_objective_function(model, moi_function(func, model))
283+
set_objective_function(model, moi_function(model, func))
284284
return
285285
end
286286

@@ -299,7 +299,7 @@ function set_objective_function(
299299
for f in func
300300
check_belongs_to_model(f, model)
301301
end
302-
set_objective_function(model, moi_function(func, model))
302+
set_objective_function(model, moi_function(model, func))
303303
return
304304
end
305305

0 commit comments

Comments
 (0)