Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ function _convert_nonlinear_to_mof(
return name_map[variable]
end

function _convert_nonlinear_to_mof(
::Type{T},
f::MOI.AbstractScalarFunction,
node_list::Vector{Any},
name_map::Dict{MOI.VariableIndex,String},
) where {T<:Object}
return _convert_nonlinear_to_mof(
T,
convert(MOI.ScalarNonlinearFunction, f),
node_list,
name_map,
)
end

function _convert_nonlinear_to_mof(
::Type{T},
value::Real,
Expand Down
62 changes: 62 additions & 0 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,68 @@ function test_nonlinear_variable_real_nodes()
return
end

function test_mof_scalaraffinefunction()
x = MOI.VariableIndex(1)
f = 1.0 * x + 2.0
g = MOI.ScalarNonlinearFunction(:log, Any[f])
name_map = Dict(x => "x")
object = MOF.moi_to_object(g, name_map)
object_dest = MOF.OrderedObject(
"type" => "ScalarNonlinearFunction",
"root" => MOF.OrderedObject("type" => "node", "index" => 3),
"node_list" => Any[
MOF.OrderedObject("type" => "*", "args" => [1.0, "x"]),
MOF.OrderedObject(
"type" => "+",
"args" => [
MOF.OrderedObject("type" => "node", "index" => 1),
2.0,
],
),
MOF.OrderedObject(
"type" => "log",
"args" => Any[MOF.OrderedObject(
"type" => "node",
"index" => 2,
)],
),
],
)
@test object == object_dest
return
end

function test_mof_scalarquadraticfunction()
x = MOI.VariableIndex(1)
f = 1.0 * x * x + 2.0
g = MOI.ScalarNonlinearFunction(:log, Any[f])
name_map = Dict(x => "x")
object = MOF.moi_to_object(g, name_map)
object_dest = MOF.OrderedObject(
"type" => "ScalarNonlinearFunction",
"root" => MOF.OrderedObject("type" => "node", "index" => 3),
"node_list" => Any[
MOF.OrderedObject("type" => "*", "args" => [1.0, "x", "x"]),
MOF.OrderedObject(
"type" => "+",
"args" => [
MOF.OrderedObject("type" => "node", "index" => 1),
2.0,
],
),
MOF.OrderedObject(
"type" => "log",
"args" => Any[MOF.OrderedObject(
"type" => "node",
"index" => 2,
)],
),
],
)
@test object == object_dest
return
end

end

TestMOF.runtests()