Skip to content

Commit 4632075

Browse files
committed
Change how multiple objectives are stored
1 parent 4f32cec commit 4632075

File tree

7 files changed

+68
-52
lines changed

7 files changed

+68
-52
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ It is heavily inspired by [MathOptInterface](https://github.com/JuliaOpt/MathOpt
1010
MathOptFormat is a generic file format for mathematical optimization problems
1111
encoded in the form
1212

13-
min/max: fᵢ(x) i=1,2,…,I
14-
subject to: gⱼ(x) ∈ Sⱼ j=1,2,…,J
13+
min/max: f₀(x)
14+
subject to: fᵢ(x) ∈ Sᵢ i=1,2,…,I
1515

16-
where `x ∈ ℝᴺ`, `fᵢ: ℝᴺ → `, and `gⱼ: ℝᴺ → ℝᴹʲ`, and `Sⱼ ⊆ ℝᴹʲ`.
16+
where `x ∈ ℝᴺ`, `fᵢ: ℝᴺ → ℝᴹⁱ`, and `Sᵢ ⊆ ℝᴹⁱ`.
1717

18-
The functions `fᵢ` and `gⱼ`, and sets `Sⱼ` supported by MathOptFormat are
19-
defined in the [MathOptFormat schema](#the-schema).
18+
The functions `fᵢ` and sets `Sᵢ` supported by MathOptFormat are defined in the
19+
[MathOptFormat schema](#the-schema).
2020

2121
The current list of supported functions and sets is not exhaustive. It is
2222
intended that MathOptFormat will be extended in future versions to support
@@ -32,19 +32,19 @@ consider the following linear program:
3232

3333
Encoded in our standard form, we have
3434

35-
f(x) = 2x + 1
36-
g₁(x) = x
35+
f(x) = 2x + 1
36+
f₁(x) = x
3737
S₁ = [1, ∞)
3838

3939
Encoded into the MathOptFormat file format, this example becomes:
4040
```json
4141
{
4242
"version": {
4343
"major": 0,
44-
"minor": 3
44+
"minor": 4
4545
},
4646
"variables": [{"name": "x"}],
47-
"objectives": [{
47+
"objective": {
4848
"sense": "min",
4949
"function": {
5050
"head": "ScalarAffineFunction",
@@ -53,7 +53,7 @@ Encoded into the MathOptFormat file format, this example becomes:
5353
],
5454
"constant": 1
5555
}
56-
}],
56+
},
5757
"constraints": [{
5858
"name": "x >= 1",
5959
"function": {"head": "SingleVariable", "variable": "x"},
@@ -88,14 +88,15 @@ required keys at the top level:
8888
variable. It is illegal to have two variables with the same name. These names
8989
will be used later in the file to refer to each variable.
9090

91-
- `"objectives"`
91+
- `"objective"`
9292

93-
A list of JSON objects, with one element for each objective in the model.
94-
Each object has two required keys:
93+
A JSON objects describing the objective of the model. It has one required
94+
keys:
9595

9696
- `"sense"`
9797

98-
A string which must be `"min"` or `"max"`.
98+
A string which must be `"min"`, `"max"`, or `"feasibility"`. If the sense
99+
is `min` or `max`, a second key `"function"`, must be defined:
99100

100101
- `"function"`
101102

@@ -163,8 +164,8 @@ adding to this documentation, clarifying edits should be made to the
163164

164165
The list of functions supported by MathOptFormat are contained in the
165166
`#/definitions/scalar_functions` and `#/definitions/vector_functions` fields of
166-
the schema. Scalar functions are functions for which `Mj=1`, while vector
167-
functions are functions for which `Mj≥1`.
167+
the schema. Scalar functions are functions for which `Mi=1`, while vector
168+
functions are functions for which `Mi≥1`.
168169

169170
Here is a summary of the functions defined by MathOptFormat.
170171

examples/biobjective.mof.json

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
{
2-
"description": "The problem: [min{2x - y + 1}, max{y}]",
2+
"description": "The problem: [min{2x - y + 1, -y}]",
33
"version": {
44
"major": 0,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [{
88
"name": "x"
99
}, {
1010
"name": "y"
1111
}],
12-
"objectives": [{
12+
"objective": {
1313
"sense": "min",
1414
"function": {
15-
"head": "ScalarAffineFunction",
15+
"head": "VectorAffineFunction",
1616
"terms": [{
17+
"output_index": 1,
18+
"scalar_term": {
1719
"coefficient": 2,
1820
"variable": "x"
19-
},
20-
{
21+
}
22+
}, {
23+
"output_index": 1,
24+
"scalar_term": {
2125
"coefficient": -1,
2226
"variable": "y"
2327
}
24-
],
25-
"constant": 1
26-
}
27-
}, {
28-
"sense": "max",
29-
"function": {
30-
"head": "SingleVariable",
31-
"variable": "y"
28+
}, {
29+
"output_index": 2,
30+
"scalar_term": {
31+
"coefficient": -1,
32+
"variable": "y"
33+
}
34+
}],
35+
"constants": [1, 0]
3236
}
33-
}],
37+
},
3438
"constraints": []
3539
}

examples/milp.mof.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"description": "The problem: min{x | x + y >= 1, x ∈ [0, 1], y ∈ {0, 1}}",
33
"version": {
44
"major": 0,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [{
88
"name": "x",
@@ -11,13 +11,13 @@
1111
"name": "y",
1212
"primal_start": 1.0
1313
}],
14-
"objectives": [{
14+
"objective": {
1515
"sense": "min",
1616
"function": {
1717
"head": "SingleVariable",
1818
"variable": "x"
1919
}
20-
}],
20+
},
2121
"constraints": [{
2222
"name": "x + y >= 1",
2323
"function": {

examples/nlp.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"description": "The problem: min{2x + sin(x)^2 + y}.",
33
"version": {
44
"major": 0,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [{
88
"name": "x"
99
}, {
1010
"name": "y"
1111
}],
12-
"objectives": [{
12+
"objective": {
1313
"sense": "min",
1414
"function": {
1515
"head": "ScalarNonlinearFunction",
@@ -55,6 +55,6 @@
5555
}]
5656
}]
5757
}
58-
}],
58+
},
5959
"constraints": []
6060
}

examples/quadratic.mof.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"description": "The problem: min{x^2 + x * y + y^2}",
33
"version": {
44
"major": 0,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [{
88
"name": "x"
99
}, {
1010
"name": "y"
1111
}],
12-
"objectives": [{
12+
"objective": {
1313
"sense": "min",
1414
"function": {
1515
"description": "Note that the format is `a'x + 0.5 x' Q x + c`.",
@@ -33,6 +33,6 @@
3333
],
3434
"constant": 0
3535
}
36-
}],
36+
},
3737
"constraints": []
3838
}

examples/vector.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
"description": "The problem: min{0 | [1 2; 3 4][x, y] + [5, 6] ∈ R+.",
33
"version": {
44
"major": 0,
5-
"minor": 3
5+
"minor": 4
66
},
77
"variables": [{
88
"name": "x"
99
}, {
1010
"name": "y"
1111
}],
12-
"objectives": [],
12+
"objective": {
13+
"sense": "feasibility"
14+
},
1315
"constraints": [{
1416
"function": {
1517
"head": "VectorAffineFunction",

mof.schema.json

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"$id": "https://github.com/odow/MathOptFormat/blob/master/mof.schema.json",
44
"title": "The schema for MathOptFormat",
55
"type": "object",
6-
"required": ["version", "variables", "objectives", "constraints"],
6+
"required": ["version", "variables", "objective", "constraints"],
77
"properties": {
88
"version": {
99
"description": "The version of MathOptFormat that this schema validates against.",
1010
"type": "object",
1111
"required": ["minor", "major"],
1212
"properties": {
1313
"minor": {
14-
"const": 3
14+
"const": 4
1515
},
1616
"major": {
1717
"const": 0
@@ -48,21 +48,30 @@
4848
},
4949
"uniqueItems": true
5050
},
51-
"objectives": {
52-
"description": "An array of objectives in the model.",
53-
"type": "array",
54-
"items": {
55-
"type": "object",
56-
"required": ["sense", "function"],
51+
"objective": {
52+
"description": "The objective of the model.",
53+
"type": "object",
54+
"required": ["sense"],
55+
"oneOf": [{
5756
"properties": {
5857
"sense": {
5958
"enum": ["min", "max"]
6059
},
6160
"function": {
62-
"$ref": "#/definitions/scalar_functions"
61+
"oneOf": [{
62+
"$ref": "#/definitions/scalar_functions"
63+
}, {
64+
"$ref": "#/definitions/vector_functions"
65+
}]
6366
}
6467
}
65-
}
68+
}, {
69+
"properties": {
70+
"sense": {
71+
"const": "feasibility"
72+
}
73+
}
74+
}]
6675
},
6776
"constraints": {
6877
"description": "An array of constraints in the model. Scalar-valued functions can only be paired with scalar-sets, and the same applies for vector-valued functions and sets.",

0 commit comments

Comments
 (0)