|
1 | 1 | # MathOptFormat |
2 | | -Specification and description of the MathOptFormat file format |
| 2 | + |
| 3 | +This repository describes a file-format for mathematical optimization problems |
| 4 | +called _MathOptFormat_ with the file extension `.mof.json`. |
| 5 | + |
| 6 | +It is heavily inspired by [MathOptInterface](https://github.com/JuliaOpt/MathOptInterface.jl). |
| 7 | + |
| 8 | +## Standard form |
| 9 | + |
| 10 | +MathOptFormat is a generic file format for mathematical optimization problems |
| 11 | +encoded in the form |
| 12 | + |
| 13 | + min/max: fᵢ(x) i=1,2,…,I |
| 14 | + subject to: gⱼ(x) ∈ Sⱼ j=1,2,…,J |
| 15 | + |
| 16 | +where `x ∈ ℝᴺ`, `fᵢ: ℝᴺ → ℝ`, and `gⱼ: ℝᴺ → ℝᴹʲ`, and `Sⱼ ⊆ ℝᴹʲ`. |
| 17 | + |
| 18 | +The functions `fᵢ` and `gⱼ`, and sets `Sⱼ` supported by MathOptFormat are |
| 19 | +detailed below. This list is not exhaustive. It is intended that MathOptFormat |
| 20 | +will be extended in future versions to support additional functions and sets. |
| 21 | + |
| 22 | +## An example |
| 23 | + |
| 24 | +The standard form described above is very general. To give a concrete example, |
| 25 | +consider the following linear program: |
| 26 | + |
| 27 | + min: 2x + 1 |
| 28 | + subject to: x ≥ 1 |
| 29 | + |
| 30 | +Encoded in our standard form, we have |
| 31 | + |
| 32 | + f₁(x) = 2x + 1 |
| 33 | + g₁(x) = x |
| 34 | + S₁ = [1, ∞) |
| 35 | + |
| 36 | +Encoded into the MathOptFormat file format, this example becomes: |
| 37 | +```json |
| 38 | +{ |
| 39 | + "version": 1, |
| 40 | + "variables": [{"name": "x"}], |
| 41 | + "objectives": [{ |
| 42 | + "sense": "min", |
| 43 | + "function": { |
| 44 | + "head": "ScalarAffineFunction", |
| 45 | + "terms": [ |
| 46 | + {"coefficient": 2, "variable": "x"} |
| 47 | + ], |
| 48 | + "constant": 1 |
| 49 | + } |
| 50 | + }], |
| 51 | + "constraints": [{ |
| 52 | + "name": "x >= 1", |
| 53 | + "function": {"head": "SingleVariable", "variable": "x"}, |
| 54 | + "set": {"head": "GreaterThan", "lower": 1} |
| 55 | + }] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +Let us now describe each part of the file format in turn. First, notice that the |
| 60 | +file format is a valid JSON (JavaScript Object Notation) file. This enables the |
| 61 | +MathOptFormat to be both _human-readable_, and _machine-readable_. Some readers |
| 62 | +may argue that JSON is tricky to edit as a human due to the quantity of brackets |
| 63 | +and "boiler-plate" such as `"function"` and `"head"`. We do not disagree. |
| 64 | +However, we believe that JSON strikes a fine balance between human and machine |
| 65 | +readability. |
| 66 | + |
| 67 | +Inside the document, the model is stored as a single JSON object. JSON objects |
| 68 | +are key-value mappings enclosed by curly braces (`{` and `}`). There are four |
| 69 | +required keys at the top level: |
| 70 | + |
| 71 | + - `"version"` |
| 72 | + |
| 73 | + An integer describing the minimum version of MathOptFormat needed to parse |
| 74 | + the file. This is included to safeguard against later revisions. |
| 75 | + |
| 76 | + - `"variables"` |
| 77 | + |
| 78 | + A list of JSON objects, with one object for each variable in the model. Each |
| 79 | + object has a required key `"name"` which maps to a unique string for that |
| 80 | + variable. It is illegal to have two variables with the same name. These names |
| 81 | + will be used later in the file to refer to each variable. |
| 82 | + |
| 83 | + - `"objectives"` |
| 84 | + |
| 85 | + A list of JSON objects, with one element for each objective in the model. |
| 86 | + Each object has two required keys: |
| 87 | + |
| 88 | + - `"sense"` |
| 89 | + |
| 90 | + A string which must be `"min"` or `"max"`. |
| 91 | + |
| 92 | + - `"function"` |
| 93 | + |
| 94 | + A JSON object that describes the function. There are many different types |
| 95 | + of functions that MathOptFormat recognizes, each of which has a different |
| 96 | + structure. However, each function has a required key called `"head"` which |
| 97 | + is used to describe the type of the function. In this case, the function |
| 98 | + is `"ScalarAffineFunction"`. |
| 99 | + |
| 100 | + A `"ScalarAffineFunction"` is the function `f(x) = aᵀx + b`, where `a` is |
| 101 | + a constant `N×1` vector, and `b` is a scalar constant. In addition to |
| 102 | + `"head"`, it has two required keys: |
| 103 | + |
| 104 | + - `"terms"` |
| 105 | + |
| 106 | + A list of JSON objects, containing one object for each non-zero element |
| 107 | + in `a`. Each object has two required keys: `"coefficient"`, and |
| 108 | + `"variable"`. `"coefficient"` maps to a real number that is the |
| 109 | + coefficient in `a` corresponding to the variable (identified by its |
| 110 | + string name) in `"variable"`. |
| 111 | + |
| 112 | + - `"constant"` |
| 113 | + |
| 114 | + The value of `b`. |
| 115 | + |
| 116 | + - `"constraints"` |
| 117 | + |
| 118 | + A list of JSON objects, with one element for each constraint in the model. |
| 119 | + Each object has three required fields: |
| 120 | + |
| 121 | + - `"name"` |
| 122 | + |
| 123 | + A unique string name for the constraint. |
| 124 | + |
| 125 | + - `"function"` |
| 126 | + |
| 127 | + A JSON object that describes the function `gⱼ` associated with constraint |
| 128 | + `j`. The function field is similar to the function field in |
| 129 | + `"objectives"`; however, in this example, our function is a single |
| 130 | + variable function of the variable `"x"`. |
| 131 | + |
| 132 | + - `"set"` |
| 133 | + |
| 134 | + A JSON object that describes the set `Sⱼ` associated with constraint `j`. |
| 135 | + In this example, the set `[1, ∞)` is the MathOptFormat set `GreaterThan` |
| 136 | + with a lower bound of `1`. |
| 137 | + |
| 138 | +## The schema |
| 139 | + |
| 140 | +A [JSON schema](http://json-schema.org/) for the `mof.json` file-format is |
| 141 | +provided in the file `mof.schema.json`. |
| 142 | + |
| 143 | +## Examples |
| 144 | + |
| 145 | +A number of examples of optimization problems encoded using MathOptFormat are |
| 146 | +provided in the `/examples` directory. |
0 commit comments