Skip to content

Commit deca298

Browse files
committed
format files
1 parent b2d3f33 commit deca298

File tree

2 files changed

+21
-68
lines changed

2 files changed

+21
-68
lines changed

src/FileFormats/MOF/write.jl

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ function write_nlpblock(
9595
objective = MOI.objective_expr(nlp_block.evaluator)
9696
objective = _lift_variable_indices(objective)
9797
sense = MOI.get(model, MOI.ObjectiveSense())
98-
object["objective"] = NamedTuple{(:sense, :function)}(
99-
(moi_to_object(sense),
100-
moi_to_object(Nonlinear(objective), name_map))
101-
)
98+
object["objective"] = NamedTuple{(:sense, :function)}((
99+
moi_to_object(sense),
100+
moi_to_object(Nonlinear(objective), name_map),
101+
))
102102
end
103103
for (row, bounds) in enumerate(nlp_block.constraint_bounds)
104104
constraint = MOI.constraint_expr(nlp_block.evaluator, row)
105105
(func, set) = extract_function_and_set(constraint)
106106
func = _lift_variable_indices(func)
107107
push!(
108108
object["constraints"],
109-
NamedTuple{(:function, :set)}(
110-
(moi_to_object(Nonlinear(func), name_map),
111-
moi_to_object(set, name_map),)
112-
)
109+
NamedTuple{(:function, :set)}((
110+
moi_to_object(Nonlinear(func), name_map),
111+
moi_to_object(set, name_map),
112+
)),
113113
)
114114
end
115115
return
@@ -247,10 +247,7 @@ function _convert_nonlinear_to_mof(
247247
)
248248
node = (type = string(f.head), args = Any[])
249249
for arg in f.args
250-
push!(
251-
node[:args],
252-
_convert_nonlinear_to_mof(arg, node_list, name_map),
253-
)
250+
push!(node[:args], _convert_nonlinear_to_mof(arg, node_list, name_map))
254251
end
255252
push!(node_list, node)
256253
return (type = "node", index = length(node_list))
@@ -294,8 +291,7 @@ end
294291

295292
function moi_to_object(foo::Nonlinear, name_map::Dict{MOI.VariableIndex,String})
296293
node_list = Any[]
297-
root =
298-
_convert_nonlinear_to_mof(foo.expr, node_list, name_map)
294+
root = _convert_nonlinear_to_mof(foo.expr, node_list, name_map)
299295
return (
300296
type = "ScalarNonlinearFunction",
301297
root = root,
@@ -322,10 +318,7 @@ function moi_to_object(
322318
foo::MOI.ScalarAffineTerm,
323319
name_map::Dict{MOI.VariableIndex,String},
324320
)
325-
return (
326-
coefficient = foo.coefficient,
327-
variable = name_map[foo.variable],
328-
)
321+
return (coefficient = foo.coefficient, variable = name_map[foo.variable])
329322
end
330323

331324
function moi_to_object(
@@ -536,10 +529,7 @@ function moi_to_object(
536529
set::MOI.Reified,
537530
name_map::Dict{MOI.VariableIndex,String},
538531
)
539-
return (
540-
type = "Reified",
541-
set = moi_to_object(set.set, name_map),
542-
)
532+
return (type = "Reified", set = moi_to_object(set.set, name_map))
543533
end
544534

545535
function moi_to_object(
@@ -556,8 +546,5 @@ function moi_to_object(
556546
set::MOI.Scaled,
557547
name_map::Dict{MOI.VariableIndex,String},
558548
)
559-
return (
560-
type = "Scaled",
561-
set = moi_to_object(set.set, name_map),
562-
)
549+
return (type = "Scaled", set = moi_to_object(set.set, name_map))
563550
end

test/FileFormats/MOF/MOF.jl

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,7 @@ function test_Roundtrip_nonlinear_expressions()
307307
:(ifelse($x > 0, 1, $y)),
308308
]
309309
node_list = Any[]
310-
object = MOF._convert_nonlinear_to_mof(
311-
expr,
312-
node_list,
313-
var_to_string,
314-
)
310+
object = MOF._convert_nonlinear_to_mof(expr, node_list, var_to_string)
315311
@test _convert_mof_to_expr(object, node_list, string_to_var) == expr
316312
end
317313
return
@@ -381,8 +377,7 @@ function test_Blank_variable_name()
381377
variable = MOI.add_variable(model)
382378
@test_throws Exception MOF.moi_to_object(variable, model)
383379
MOI.FileFormats.create_unique_names(model, warn = true)
384-
@test MOF.moi_to_object(variable, model) ==
385-
(name = "x1",)
380+
@test MOF.moi_to_object(variable, model) == (name = "x1",)
386381
end
387382

388383
function test_Duplicate_variable_name()
@@ -1486,14 +1481,9 @@ function test_integer_coefficients()
14861481
f = 2 * x * x + 3 * x + 4
14871482
@test MOF.moi_to_object(f, names) == (
14881483
type = "ScalarQuadraticFunction",
1489-
affine_terms =
1490-
[(coefficient = 3, variable = "x")],
1484+
affine_terms = [(coefficient = 3, variable = "x")],
14911485
quadratic_terms = [
1492-
(
1493-
coefficient = 4,
1494-
variable_1 = "x",
1495-
variable_2 = "x",
1496-
),
1486+
(coefficient = 4, variable_1 = "x", variable_2 = "x"),
14971487
],
14981488
constant = 4,
14991489
)
@@ -1542,20 +1532,8 @@ function test_mof_scalaraffinefunction()
15421532
root = (type = "node", index = 3),
15431533
node_list = Any[
15441534
(type = "*", args = [1.0, "x"]),
1545-
(
1546-
type = "+",
1547-
args = [
1548-
(type = "node", index = 1),
1549-
2.0,
1550-
],
1551-
),
1552-
(
1553-
type = "log",
1554-
args = Any[(
1555-
type = "node",
1556-
index = 2,
1557-
)],
1558-
),
1535+
(type = "+", args = [(type = "node", index = 1), 2.0]),
1536+
(type = "log", args = Any[(type = "node", index = 2)]),
15591537
],
15601538
)
15611539
@test object == object_dest
@@ -1573,20 +1551,8 @@ function test_mof_scalarquadraticfunction()
15731551
root = (type = "node", index = 3),
15741552
node_list = Any[
15751553
(type = "*", args = [1.0, "x", "x"]),
1576-
(
1577-
type = "+",
1578-
args = [
1579-
(type = "node", index = 1),
1580-
2.0,
1581-
],
1582-
),
1583-
(
1584-
type = "log",
1585-
args = Any[(
1586-
type = "node",
1587-
index = 2,
1588-
)],
1589-
),
1554+
(type = "+", args = [(type = "node", index = 1), 2.0]),
1555+
(type = "log", args = Any[(type = "node", index = 2)]),
15901556
],
15911557
)
15921558
@test object == object_dest

0 commit comments

Comments
 (0)