Skip to content

Commit b3081d5

Browse files
authored
Added JuMP.write_to_file function extension (#141)
* added write_to_file function * Updated doc string
1 parent f8fcb75 commit b3081d5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/optigraph.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,29 @@ function JuMP.unregister(graph::OptiGraph, key::Symbol)
14901490
return delete!(object_dictionary(graph), key)
14911491
end
14921492

1493+
"""
1494+
write_to_file(graph::OptiGraph, filename::string)
1495+
1496+
Write the model stored in `graph` to `filename.` See [`MOI.FileFormats.FileFormat`](@ref)
1497+
for a list of supported formats. Format is determined automatically based on given file
1498+
extension (e.g., .mps, .lp, .mof.json, .sdpa). Note that this output does not explicitly
1499+
include any graph structure information.
1500+
1501+
Plasmo does not support loading the file back into Julia as an OptiGraph.
1502+
"""
1503+
function JuMP.write_to_file(graph::OptiGraph, filename::String)
1504+
m = MOI.FileFormats.Model(filename=filename)
1505+
f = () -> MOI.FileFormats.Model(filename=filename)
1506+
1507+
inner = MOI.instantiate(f)
1508+
moi_graph_model = graph.backend.moi_backend.model_cache.model
1509+
1510+
innter_map = MOI.copy_to(inner, moi_graph_model)
1511+
inner_backend = JuMP.unsafe_backend(inner)
1512+
1513+
MOI.write_to_file(inner_backend, filename)
1514+
end
1515+
14931516
# TODO Methods
14941517
# num_linked_variables(graph)
14951518
# linked_variables(graph)

0 commit comments

Comments
 (0)