Skip to content

Commit 951465c

Browse files
authored
Add support for MOI.write_to_file (#265)
1 parent 577ecc2 commit 951465c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/MOI_wrapper.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,6 +3179,12 @@ function MOI.set(model::Optimizer, attr::CallbackFunction, f::Function)
31793179
return
31803180
end
31813181

3182+
function MOI.write_to_file(model::Optimizer, filename::String)
3183+
ret = Highs_writeModel(model, filename)
3184+
_check_ret(ret)
3185+
return
3186+
end
3187+
31823188
# These enums are deprecated. Use the `kHighsXXX` constants defined in
31833189
# libhighs.jl instead.
31843190

test/MOI_wrapper.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,26 @@ function test_ObjectiveFunction_VectorAffineFunction_to_ScalarQuadraticFunction(
10301030
return
10311031
end
10321032

1033+
function test_write_to_file()
1034+
dir = mktempdir()
1035+
model = HiGHS.Optimizer()
1036+
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(1.0))
1037+
MOI.set(model, MOI.VariableName(), x, "x")
1038+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1039+
f = 1.0 * x + 2.0
1040+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
1041+
filename = joinpath(dir, "model.mps")
1042+
MOI.write_to_file(model, filename)
1043+
contents = read(filename, String)
1044+
@test occursin("ENDATA", contents)
1045+
filename = joinpath(dir, "model.lp")
1046+
MOI.write_to_file(model, filename)
1047+
contents = read(filename, String)
1048+
@test occursin("obj:", contents)
1049+
@test occursin("bounds", contents)
1050+
return
1051+
end
1052+
10331053
end # module
10341054

10351055
TestMOIHighs.runtests()

0 commit comments

Comments
 (0)