Skip to content

Commit

Permalink
Add support for MOI.write_to_file (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Feb 24, 2025
1 parent 577ecc2 commit 951465c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,12 @@ function MOI.set(model::Optimizer, attr::CallbackFunction, f::Function)
return
end

function MOI.write_to_file(model::Optimizer, filename::String)
ret = Highs_writeModel(model, filename)
_check_ret(ret)
return
end

# These enums are deprecated. Use the `kHighsXXX` constants defined in
# libhighs.jl instead.

Expand Down
20 changes: 20 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,26 @@ function test_ObjectiveFunction_VectorAffineFunction_to_ScalarQuadraticFunction(
return
end

function test_write_to_file()
dir = mktempdir()
model = HiGHS.Optimizer()
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(1.0))
MOI.set(model, MOI.VariableName(), x, "x")
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
f = 1.0 * x + 2.0
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
filename = joinpath(dir, "model.mps")
MOI.write_to_file(model, filename)
contents = read(filename, String)
@test occursin("ENDATA", contents)
filename = joinpath(dir, "model.lp")
MOI.write_to_file(model, filename)
contents = read(filename, String)
@test occursin("obj:", contents)
@test occursin("bounds", contents)
return
end

end # module

TestMOIHighs.runtests()

0 comments on commit 951465c

Please sign in to comment.