Skip to content

Commit 282b864

Browse files
committed
Add IndicatorSet
1 parent efdbae0 commit 282b864

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Here is a summary of the sets defined by MathOptFormat.
231231
| `"PositiveSemidefiniteConeSquare"` | The cone of symmetric positive semidefinite matrices, with side length `side_dimension`. The entries of the matrix are given column by column (or equivalently, row by row). The matrix is both constrained to be symmetric and to be positive semidefinite. That is, if the functions in entries `(i, j)` and `(j, i)` are different, then a constraint will be added to make sure that the entries are equal. | {"head": "PositiveSemidefiniteConeSquare", "side_dimension": 2} |
232232
| `"PowerCone"` | [x, y, z] ∈ {R³: x^{exponent} y^{1-exponent} ≥ \|z\|; x, y ≥ 0} | {"head": "PowerCone", "exponent": 2.0} |
233233
| `"DualPowerCone"` | [u, v, w] ∈ {R³: (u / exponent)^{exponent} (v / (1-exponent))^{1-exponent} ≥ \|w\|; u, v ≥ 0} | {"head": "DualPowerCone", "exponent": 2.0} |
234+
| `"IndicatorSet"` | If `activate_on=one`: (y, x) ∈ {0,1}×Rᴺ: y = 0 ⟹ x ∈ S, otherwise when `activate_on=zero`: (y, x) ∈ {0,1}×Rᴺ: y = 1 ⟹ x ∈ S. | {"head": "IndicatorSet", "set": {"head": "LessThan", "upper": 2.0}, "activate_on": "one"} |
234235

235236
### Nonlinear functions
236237

mof.schema.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,26 @@
749749
"type": "number"
750750
}
751751
}
752+
}, {
753+
"description": "If `activate_on=one`: (y, x) ∈ {0,1}×Rᴺ: y = 0 ⟹ x ∈ S, otherwise when `activate_on=zero`: (y, x) ∈ {0,1}×Rᴺ: y = 1 ⟹ x ∈ S.",
754+
"examples": ["{\"head\": \"IndicatorSet\", \"set\": {\"head\": \"LessThan\", \"upper\": 2.0}, \"activate_on\": \"one\"}"],
755+
"required": ["set", "activate_on"],
756+
"properties": {
757+
"head": {
758+
"const": "IndicatorSet"
759+
},
760+
"set": {
761+
"oneOf": [{
762+
"$ref": "#/definitions/scalar_sets"
763+
}, {
764+
"$ref": "#/definitions/vector_sets"
765+
}]
766+
},
767+
"activate_on": {
768+
"enum": ["one", "zero"]
769+
}
770+
}
752771
}]
753772
}
754773
}
755-
}
774+
}

mof/mof.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,36 @@ import (
1313
//go:generate go run generate-static-schema.go ../mof.schema.json
1414

1515
func main() {
16-
switch os.Args[1] {
17-
case "validate":
18-
if len(os.Args) != 3 {
19-
fmt.Println("Invalid arguments to `mof validate`")
16+
if len(os.Args) < 2 {
17+
fmt.Println("Invalid arguments to `mof`. Here is the help:\n")
18+
PrintHelp()
19+
} else {
20+
switch os.Args[1] {
21+
case "validate":
22+
if len(os.Args) != 3 {
23+
fmt.Println("Invalid arguments to `mof validate`")
24+
PrintHelp()
25+
}
26+
filename := os.Args[2]
27+
if err := ValidateFile(filename); err != nil {
28+
fmt.Printf("%s is not a valid MOF file\nThe error is:\n", filename)
29+
fmt.Println(err)
30+
} else {
31+
fmt.Printf("Success! %s conforms to the MathOptFormat schema", filename)
32+
}
33+
case "summarize":
34+
summary, err := SummarizeSchema()
35+
if err != nil {
36+
fmt.Println(err)
37+
} else {
38+
fmt.Println(summary)
39+
}
40+
case "help":
41+
PrintHelp()
42+
default:
43+
fmt.Println("Invalid arguments to `mof`.")
2044
PrintHelp()
2145
}
22-
filename := os.Args[2]
23-
if err := ValidateFile(filename); err != nil {
24-
fmt.Printf("%s is not a valid MOF file\nThe error is:\n", filename)
25-
fmt.Println(err)
26-
} else {
27-
fmt.Printf("Success! %s conforms to the MathOptFormat schema", filename)
28-
}
29-
case "summarize":
30-
summary, err := SummarizeSchema()
31-
if err != nil {
32-
fmt.Println(err)
33-
} else {
34-
fmt.Println(summary)
35-
}
36-
case "help":
37-
PrintHelp()
38-
default:
39-
fmt.Println("Invalid arguments to `mof`.")
40-
PrintHelp()
4146
}
4247
}
4348

0 commit comments

Comments
 (0)