From b3fa54e6714caecde5112c1ae0021fdfe06f1107 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 15 May 2026 13:43:10 +1200 Subject: [PATCH] Fix writing to a MOI.FileFormats.MOF file This is necessary for Sienna. Rather than do something custom, we just force-add the constraint. --- src/MathOptLazy.jl | 7 +++++++ test/runtests.jl | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/MathOptLazy.jl b/src/MathOptLazy.jl index c48e128..509f3d7 100644 --- a/src/MathOptLazy.jl +++ b/src/MathOptLazy.jl @@ -23,6 +23,13 @@ function MOI.Utilities.shift_constant(set::LazyScalarSet, constant) return LazyScalarSet(MOI.Utilities.shift_constant(set.set, constant)) end +function MOI.FileFormats.MOF.moi_to_object( + set::LazyScalarSet, + x::Dict{MOI.VariableIndex,String}, +) + return MOI.FileFormats.MOF.moi_to_object(set.set, x) +end + """ Lazy(; lazy::Bool = true) diff --git a/test/runtests.jl b/test/runtests.jl index d9e4fd8..bc406d1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -162,6 +162,18 @@ function test_basic_scalaraffinefunction_lessthan() return end +function test_writing_mof_file() + src = MathOptLazy.Optimizer(HiGHS.Optimizer) + x = MOI.add_variable(src) + c = MOI.add_constraint(src, x, MathOptLazy.LazyScalarSet(MOI.ZeroOne())) + dest = MOI.FileFormats.MOF.Model() + _ = MOI.copy_to(dest, src) + contents = sprint(write, dest) + @test occursin("ZeroOne", contents) + @test !occursin("LazyScalarSet", contents) + return +end + end # TestMathOptLazy TestMathOptLazy.runtests()