Skip to content

Commit 0f55e37

Browse files
authored
[FileFormats.MOF] support writing non-Float64 functions (#2247)
1 parent a049bfe commit 0f55e37

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/FileFormats/MOF/write.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141
# ========== Typed scalar functions ==========
142142

143143
function moi_to_object(
144-
foo::MOI.ScalarAffineTerm{Float64},
144+
foo::MOI.ScalarAffineTerm,
145145
name_map::Dict{MOI.VariableIndex,String},
146146
)
147147
return OrderedObject(
@@ -151,7 +151,7 @@ function moi_to_object(
151151
end
152152

153153
function moi_to_object(
154-
foo::MOI.ScalarAffineFunction{Float64},
154+
foo::MOI.ScalarAffineFunction,
155155
name_map::Dict{MOI.VariableIndex,String},
156156
)
157157
return OrderedObject(
@@ -162,7 +162,7 @@ function moi_to_object(
162162
end
163163

164164
function moi_to_object(
165-
foo::MOI.ScalarQuadraticTerm{Float64},
165+
foo::MOI.ScalarQuadraticTerm,
166166
name_map::Dict{MOI.VariableIndex,String},
167167
)
168168
return OrderedObject(
@@ -173,7 +173,7 @@ function moi_to_object(
173173
end
174174

175175
function moi_to_object(
176-
foo::MOI.ScalarQuadraticFunction{Float64},
176+
foo::MOI.ScalarQuadraticFunction,
177177
name_map::Dict{MOI.VariableIndex,String},
178178
)
179179
return OrderedObject(

test/FileFormats/MOF/MOF.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,26 @@ function test_parse_nonlinear_objective_only()
13441344
return
13451345
end
13461346

1347+
function test_integer_coefficients()
1348+
x = MOI.VariableIndex(1)
1349+
names = Dict(x => "x")
1350+
f = 2 * x * x + 3 * x + 4
1351+
@test MOF.moi_to_object(f, names) == MOF.OrderedObject(
1352+
"type" => "ScalarQuadraticFunction",
1353+
"affine_terms" =>
1354+
[MOF.OrderedObject("coefficient" => 3, "variable" => "x")],
1355+
"quadratic_terms" => [
1356+
MOF.OrderedObject(
1357+
"coefficient" => 4,
1358+
"variable_1" => "x",
1359+
"variable_2" => "x",
1360+
),
1361+
],
1362+
"constant" => 4,
1363+
)
1364+
return
1365+
end
1366+
13471367
end
13481368

13491369
TestMOF.runtests()

0 commit comments

Comments
 (0)