@@ -225,46 +225,52 @@ Return a JuMP model read from `filename` in the format `format`.
225
225
226
226
See [`MOI.FileFormats.FileFormat`](@ref) for a list of supported formats.
227
227
228
- ## Compression
229
-
230
- If the filename ends in `.gz`, the file will be uncompressed using GZip.
231
-
232
- If the filename ends in `.bz2`, the file will be uncompressed using BZip2.
233
-
234
228
## Keyword arguments
235
229
236
230
Other `kwargs` are passed to the `Model` constructor of the chosen format.
237
231
238
232
For details, see the docstring each file format's `Model` constructor. For
239
233
example, [`MOI.FileFormats.MPS.Model`](@ref).
240
234
235
+ ## Nonlinear models
236
+
237
+ To maintain backwards compatibility, nonlinear models in `.mof.json` and `.nl`
238
+ files are parsed into a [`MOI.NLPBlock`](@ref). To parse as [`MOI.ScalarNonlinearFunction`](@ref),
239
+ pass the keyword `use_nlp_block = false`.
240
+
241
+ ## Compression
242
+
243
+ If the filename ends in `.gz`, the file will be uncompressed using GZip.
244
+
245
+ If the filename ends in `.bz2`, the file will be uncompressed using BZip2.
246
+
241
247
## Example
242
248
243
249
```jldoctest
244
250
julia> model = Model();
245
251
246
252
julia> @variable(model, x >= 0);
247
253
248
- julia> @objective(model, Min, 2 * x + 1 );
254
+ julia> @objective(model, Min, log(x) );
249
255
250
- julia> filename = joinpath(mktempdir(), "model.mps ");
256
+ julia> filename = joinpath(mktempdir(), "model.mof.json ");
251
257
252
- julia> write_to_file(model, filename; generic_names = true )
258
+ julia> write_to_file(model, filename)
253
259
254
- julia> new_model = read_from_file(filename)
260
+ julia> new_model = read_from_file(filename; use_nlp_block = false )
255
261
A JuMP Model
256
262
├ solver: none
257
263
├ objective_sense: MIN_SENSE
258
- │ └ objective_function_type: AffExpr
264
+ │ └ objective_function_type: NonlinearExpr
259
265
├ num_variables: 1
260
266
├ num_constraints: 1
261
267
│ └ VariableRef in MOI.GreaterThan{Float64}: 1
262
268
└ Names registered in the model: none
263
269
264
270
julia> print(new_model)
265
- Min 2 C1 + 1
271
+ Min log(x)
266
272
Subject to
267
- C1 ≥ 0
273
+ x ≥ 0
268
274
```
269
275
"""
270
276
function read_from_file (
@@ -298,33 +304,44 @@ Other `kwargs` are passed to the `Model` constructor of the chosen format.
298
304
For details, see the docstring each file format's `Model` constructor. For
299
305
example, [`MOI.FileFormats.MPS.Model`](@ref).
300
306
307
+ ## Nonlinear models
308
+
309
+ To maintain backwards compatibility, nonlinear models in `.mof.json` and `.nl`
310
+ files are parsed into a [`MOI.NLPBlock`](@ref). To parse as [`MOI.ScalarNonlinearFunction`](@ref),
311
+ pass the keyword `use_nlp_block = false`.
312
+
301
313
## Example
302
314
303
315
```jldoctest
304
316
julia> model = Model();
305
317
306
318
julia> @variable(model, x >= 0);
307
319
308
- julia> @objective(model, Min, 2 * x + 1 );
320
+ julia> @objective(model, Min, log(x) );
309
321
310
322
julia> io = IOBuffer();
311
323
312
- julia> write(io, model; format = MOI.FileFormats.FORMAT_MPS );
324
+ julia> write(io, model; format = MOI.FileFormats.FORMAT_MOF );
313
325
314
326
julia> seekstart(io);
315
327
316
- julia> new_model = read(io, Model; format = MOI.FileFormats.FORMAT_MPS)
328
+ julia> new_model = read(
329
+ io,
330
+ Model;
331
+ format = MOI.FileFormats.FORMAT_MOF,
332
+ use_nlp_block = false,
333
+ )
317
334
A JuMP Model
318
335
├ solver: none
319
336
├ objective_sense: MIN_SENSE
320
- │ └ objective_function_type: AffExpr
337
+ │ └ objective_function_type: NonlinearExpr
321
338
├ num_variables: 1
322
339
├ num_constraints: 1
323
340
│ └ VariableRef in MOI.GreaterThan{Float64}: 1
324
341
└ Names registered in the model: none
325
342
326
343
julia> print(new_model)
327
- Min 2 x + 1
344
+ Min log(x)
328
345
Subject to
329
346
x ≥ 0
330
347
```
0 commit comments