Giter Club home page Giter Club logo

mathoptformat.jl's Introduction

MathOptFormat.jl

Build Status Coverage
Build Status Codecov branch

Read and write MathOptInterface models to a variety of mathematical optimization file formats.

In order to read or write a mathematical optimization problem to/from a file, first create a MathOptInterface model. This can be done using JuMP or via one of the solver packages, for example, GLPK.jl.

In the rest of this documentation, we assume that this model is a Julia variable named user_model.

Write to file

To write user_model to file filename, follow these steps.

  1. Create a MathOptFormat model mathoptformat_model
    • mathoptformat_model = MathOptFormat.MOF.Model()
  2. Copy user_model into mathoptformat_model
    • MOI.copy_to(mathoptformat_model, user_model)
  3. Write mathoptformat_model to filename
    • MOI.write_to_file(mathoptformat_model, filename)

Step 1) assumes that you want to write a MathOptFormat file (.mof.json). For other formats, replace MathOptFormat.MOF.Model with an appropriate model. See Supported file formats for details.

Example

using MathOptInterface, MathOptFormat, GLPK
const MOI = MathOptInterface

user_model = GLPK.Optimizer()
x = MOI.add_variable(user_model)
MOI.set(user_model, MOI.VariableName(), x, "x")
MOI.add_constraint(user_model, MOI.SingleVariable(x), MOI.GreaterThan(0.0))

mathoptformat_model = MathOptFormat.MPS.Model()
MOI.copy_to(mathoptformat_model, user_model)
MOI.write_to_file(mathoptformat_model, "my_model.mps")

Read from file

To read a file filename into user_model, steps 2 and 3 are reversed:

  1. Create a MathOptFormat model mathoptformat_model
    • mathoptformat_model = MathOptFormat.MOF.Model()
  2. Read filename into mathoptformat_model
    • MOI.read_from_file(mathoptformat_moodel, filename)
  3. Copy mathoptformat_model into user_model
    • MOI.copy_to(user_model, mathoptformat_model)

Step 1) assumes that you want to read a MathOptFormat file (.mof.json). For other formats, replace MathOptFormat.MOF.Model with an appropriate model. See Supported file formats for details.

Example

using MathOptInterface, MathOptFormat, GLPK
const MOI = MathOptInterface

mathoptformat_model = MathOptFormat.MPS.Model()
MOI.read_from_file(mathoptformat_model, "my_model.mps")

user_model = GLPK.Optimizer()
MOI.copy_to(user_model, mathoptformat_model)

x = MOI.get(user_model, MOI.VariableIndex, "x")

Supported file formats

File-formats supported are

  • Conic benchmark format (.cbf):
    • Use MathOptFormat.CBF.Model
  • Linear programming format (.lp):
    • Use MathOptFormat.LP.Model
  • MathOptFormat (.mof.json):
    • Use MathOptFormat.MOF.Model
  • Mathematical programming system (.mps):
    • Use MathOptFormat.MPS.Model

Notes

  • The LP file format does not (yet) support MOI.read_from_file.
  • The MathOptFormat file format (.mof.json) is under active development. No backward compatibility yet!

GZipped files

To read and write GZip'ed files, append .gz to the filename. For example:

# Uncompressed version:
MOI.write_to_file(model, "my_model.mps")
# Compressed version:
MOI.write_to_file(model, "my_model.mps.gz")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.