Skip to content

[FileFormats.MOF] support writing non-Float64 functions #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2023
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
8 changes: 4 additions & 4 deletions src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end
# ========== Typed scalar functions ==========

function moi_to_object(
foo::MOI.ScalarAffineTerm{Float64},
foo::MOI.ScalarAffineTerm,
name_map::Dict{MOI.VariableIndex,String},
)
return OrderedObject(
Expand All @@ -151,7 +151,7 @@ function moi_to_object(
end

function moi_to_object(
foo::MOI.ScalarAffineFunction{Float64},
foo::MOI.ScalarAffineFunction,
name_map::Dict{MOI.VariableIndex,String},
)
return OrderedObject(
Expand All @@ -162,7 +162,7 @@ function moi_to_object(
end

function moi_to_object(
foo::MOI.ScalarQuadraticTerm{Float64},
foo::MOI.ScalarQuadraticTerm,
name_map::Dict{MOI.VariableIndex,String},
)
return OrderedObject(
Expand All @@ -173,7 +173,7 @@ function moi_to_object(
end

function moi_to_object(
foo::MOI.ScalarQuadraticFunction{Float64},
foo::MOI.ScalarQuadraticFunction,
name_map::Dict{MOI.VariableIndex,String},
)
return OrderedObject(
Expand Down
20 changes: 20 additions & 0 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,26 @@ function test_parse_nonlinear_objective_only()
return
end

function test_integer_coefficients()
x = MOI.VariableIndex(1)
names = Dict(x => "x")
f = 2 * x * x + 3 * x + 4
@test MOF.moi_to_object(f, names) == MOF.OrderedObject(
"type" => "ScalarQuadraticFunction",
"affine_terms" =>
[MOF.OrderedObject("coefficient" => 3, "variable" => "x")],
"quadratic_terms" => [
MOF.OrderedObject(
"coefficient" => 4,
"variable_1" => "x",
"variable_2" => "x",
),
],
"constant" => 4,
)
return
end

end

TestMOF.runtests()