@@ -16,56 +16,84 @@ models using [`write_to_file`](@ref) and [`read_from_file`](@ref).
1616You must read and write files to a [ ` FileFormats.Model ` ] ( @ref ) object. Specific
1717the file-type by passing a [ ` FileFormats.FileFormat ` ] ( @ref ) enum. For example:
1818
19- ** The Conic Benchmark Format**
19+ ### The Conic Benchmark Format
2020
2121``` jldoctest
2222julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_CBF)
23- A Conic Benchmark Format (CBF) model
23+ MOI.FileFormats.CBF.Model
24+ ├ ObjectiveSense: FEASIBILITY_SENSE
25+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
26+ ├ NumberOfVariables: 0
27+ └ NumberOfConstraints: 0
2428```
2529
26- ** The LP file format**
30+ ### The LP file format
2731
2832``` jldoctest
2933julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_LP)
30- A .LP-file model
34+ MOI.FileFormats.LP.Model
35+ ├ ObjectiveSense: FEASIBILITY_SENSE
36+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
37+ ├ NumberOfVariables: 0
38+ └ NumberOfConstraints: 0
3139```
3240
33- ** The MathOptFormat file format**
41+ ### The MathOptFormat file format
3442
3543``` jldoctest
3644julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MOF)
37- A MathOptFormat Model
45+ MOI.FileFormats.MOF.Model
46+ ├ ObjectiveSense: FEASIBILITY_SENSE
47+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
48+ ├ NumberOfVariables: 0
49+ └ NumberOfConstraints: 0
3850```
3951
40- ** The MPS file format**
52+ ### The MPS file format
4153
4254``` jldoctest
4355julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS)
44- A Mathematical Programming System (MPS) model
56+ MOI.FileFormats.MPS.Model
57+ ├ ObjectiveSense: FEASIBILITY_SENSE
58+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
59+ ├ NumberOfVariables: 0
60+ └ NumberOfConstraints: 0
4561```
4662
47- ** The NL file format**
63+ ### The NL file format
4864
4965``` jldoctest
5066julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_NL)
51- An AMPL (.nl) model
67+ MOI.FileFormats.NL.Model
68+ ├ ObjectiveSense: unknown
69+ ├ ObjectiveFunctionType: unknown
70+ ├ NumberOfVariables: unknown
71+ └ NumberOfConstraints: unknown
5272```
5373
54- ** The REW file format**
74+ ### The REW file format
5575
5676``` jldoctest
5777julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_REW)
58- A Mathematical Programming System (MPS) model
78+ MOI.FileFormats.MPS.Model
79+ ├ ObjectiveSense: FEASIBILITY_SENSE
80+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
81+ ├ NumberOfVariables: 0
82+ └ NumberOfConstraints: 0
5983```
6084
6185Note that the REW format is identical to the MPS file format, except that all
6286names are replaced with generic identifiers.
6387
64- ** The SDPA file format**
88+ ### The SDPA file format
6589
6690``` jldoctest
6791julia> model = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_SDPA)
68- A SemiDefinite Programming Algorithm Format (SDPA) model
92+ MOI.FileFormats.SDPA.Model
93+ ├ ObjectiveSense: FEASIBILITY_SENSE
94+ ├ ObjectiveFunctionType: MOI.ScalarAffineFunction{Float64}
95+ ├ NumberOfVariables: 0
96+ └ NumberOfConstraints: 0
6997```
7098
7199## Write to file
75103``` jldoctest fileformats
76104julia> src = MOI.Utilities.Model{Float64}();
77105
78- julia> MOI.add_variable(src)
79- MOI.VariableIndex(1)
106+ julia> MOI.add_variable(src);
80107
81- julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MOF)
82- A MathOptFormat Model
108+ julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MOF);
83109
84110julia> MOI.copy_to(dest, src)
85111MathOptInterface.Utilities.IndexMap with 1 entry:
@@ -110,8 +136,7 @@ julia> print(read("file.mof.json", String))
110136
111137To read a MathOptFormat file, use:
112138``` jldoctest fileformats
113- julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MOF)
114- A MathOptFormat Model
139+ julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MOF);
115140
116141julia> MOI.read_from_file(dest, "file.mof.json")
117142
@@ -131,29 +156,14 @@ guess the format from the file extension. For example:
131156``` jldoctest fileformats
132157julia> src = MOI.Utilities.Model{Float64}();
133158
134- julia> dest = MOI.FileFormats.Model(filename = "file.cbf.gz")
135- A Conic Benchmark Format (CBF) model
159+ julia> dest = MOI.FileFormats.Model(filename = "file.cbf.gz");
136160
137161julia> MOI.copy_to(dest, src)
138162MathOptInterface.Utilities.IndexMap()
139163
140164julia> MOI.write_to_file(dest, "file.cbf.gz")
141165
142- julia> src_2 = MOI.FileFormats.Model(filename = "file.cbf.gz")
143- A Conic Benchmark Format (CBF) model
144-
145- julia> src = MOI.Utilities.Model{Float64}();
146-
147- julia> dest = MOI.FileFormats.Model(filename = "file.cbf.gz")
148- A Conic Benchmark Format (CBF) model
149-
150- julia> MOI.copy_to(dest, src)
151- MathOptInterface.Utilities.IndexMap()
152-
153- julia> MOI.write_to_file(dest, "file.cbf.gz")
154-
155- julia> src_2 = MOI.FileFormats.Model(filename = "file.cbf.gz")
156- A Conic Benchmark Format (CBF) model
166+ julia> src_2 = MOI.FileFormats.Model(filename = "file.cbf.gz");
157167
158168julia> MOI.read_from_file(src_2, "file.cbf.gz")
159169
@@ -167,14 +177,22 @@ filename.
167177In some cases ` src ` may contain constraints that are not supported by the file
168178format (for example, the CBF format supports integer variables but not binary).
169179If so, copy ` src ` to a bridged model using [ ` Bridges.full_bridge_optimizer ` ] ( @ref ) :
170- ``` julia
171- src = MOI. Utilities. Model {Float64} ()
172- x = MOI. add_variable (model)
173- MOI. add_constraint (model, x, MOI. ZeroOne ())
174- dest = MOI. FileFormats. Model (format = MOI. FileFormats. FORMAT_CBF)
175- bridged = MOI. Bridges. full_bridge_optimizer (dest, Float64)
176- MOI. copy_to (bridged, src)
177- MOI. write_to_file (dest, " my_model.cbf" )
180+ ``` jldoctest
181+ julia> src = MOI.Utilities.Model{Float64}();
182+
183+ julia> x = MOI.add_variable(src);
184+
185+ julia> MOI.add_constraint(src, x, MOI.ZeroOne());
186+
187+ julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_CBF);
188+
189+ julia> bridged = MOI.Bridges.full_bridge_optimizer(dest, Float64);
190+
191+ julia> MOI.copy_to(bridged, src);
192+
193+ julia> MOI.write_to_file(dest, "my_model.cbf")
194+
195+ julia> rm("my_model.cbf") # Clean up after ourselves.
178196```
179197!!! note
180198 Even after bridging, it may still not be possible to write the model to file
@@ -188,8 +206,7 @@ read and write directly from `IO` streams using `Base.write` and `Base.read!`:
188206``` jldoctest
189207julia> src = MOI.Utilities.Model{Float64}();
190208
191- julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS)
192- A Mathematical Programming System (MPS) model
209+ julia> dest = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS);
193210
194211julia> MOI.copy_to(dest, src)
195212MathOptInterface.Utilities.IndexMap()
@@ -200,8 +217,7 @@ julia> write(io, dest)
200217
201218julia> seekstart(io);
202219
203- julia> src_2 = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS)
204- A Mathematical Programming System (MPS) model
220+ julia> src_2 = MOI.FileFormats.Model(format = MOI.FileFormats.FORMAT_MPS);
205221
206222julia> read!(io, src_2);
207223```
@@ -218,14 +234,12 @@ pass the `use_nlp_block = false` keyword argument to the `Model` constructor:
218234julia> model = MOI.FileFormats.Model(;
219235 format = MOI.FileFormats.FORMAT_MOF,
220236 use_nlp_block = false,
221- )
222- A MathOptFormat Model
237+ );
223238
224239julia> model = MOI.FileFormats.Model(;
225240 format = MOI.FileFormats.FORMAT_NL,
226241 use_nlp_block = false,
227- )
228- An AMPL (.nl) model
242+ );
229243```
230244
231245## Validating MOF files
0 commit comments