Skip to content

Commit a621c33

Browse files
authored
Add documentation for enum instances (#2186)
1 parent 3f21373 commit a621c33

File tree

5 files changed

+270
-192
lines changed

5 files changed

+270
-192
lines changed

docs/src/reference/callbacks.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ submit
1818

1919
```@docs
2020
CallbackNodeStatus
21-
CallbackNodeStatusCode
2221
CallbackVariablePrimal
22+
CallbackNodeStatusCode
23+
CALLBACK_NODE_STATUS_INTEGER
24+
CALLBACK_NODE_STATUS_FRACTIONAL
25+
CALLBACK_NODE_STATUS_UNKNOWN
2326
```
2427

2528
## Lazy constraints
@@ -40,6 +43,9 @@ UserCut
4043

4144
```@docs
4245
HeuristicCallback
43-
HeuristicSolutionStatus
4446
HeuristicSolution
47+
HeuristicSolutionStatus
48+
HEURISTIC_SOLUTION_ACCEPTED
49+
HEURISTIC_SOLUTION_REJECTED
50+
HEURISTIC_SOLUTION_UNKNOWN
4551
```

docs/src/reference/constraints.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ ConstraintDualStart
3434
ConstraintPrimal
3535
ConstraintDual
3636
ConstraintBasisStatus
37-
BasisStatusCode
3837
ConstraintFunction
3938
CanonicalConstraintFunction
4039
ConstraintSet
40+
BasisStatusCode
41+
BASIC
42+
NONBASIC
43+
NONBASIC_AT_LOWER
44+
NONBASIC_AT_UPPER
45+
SUPER_BASIC
4146
```

docs/src/reference/models.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Name
4141
ObjectiveFunction
4242
ObjectiveFunctionType
4343
ObjectiveSense
44+
OptimizationSense
45+
MIN_SENSE
46+
MAX_SENSE
47+
FEASIBILITY_SENSE
4448
NumberOfVariables
4549
ListOfVariableIndices
4650
ListOfConstraintTypesPresent
@@ -85,9 +89,33 @@ List of attributes useful for optimizers
8589
```@docs
8690
TerminationStatus
8791
TerminationStatusCode
92+
OPTIMIZE_NOT_CALLED
93+
OPTIMAL
94+
INFEASIBLE
95+
DUAL_INFEASIBLE
96+
LOCALLY_SOLVED
97+
LOCALLY_INFEASIBLE
98+
INFEASIBLE_OR_UNBOUNDED
99+
ALMOST_OPTIMAL
100+
ALMOST_INFEASIBLE
101+
ALMOST_DUAL_INFEASIBLE
102+
ALMOST_LOCALLY_SOLVED
103+
ITERATION_LIMIT
104+
TIME_LIMIT
105+
NODE_LIMIT
106+
SOLUTION_LIMIT
107+
MEMORY_LIMIT
108+
OBJECTIVE_LIMIT
109+
NORM_LIMIT
110+
OTHER_LIMIT
111+
SLOW_PROGRESS
112+
NUMERICAL_ERROR
113+
INVALID_MODEL
114+
INVALID_OPTION
115+
INTERRUPTED
116+
OTHER_ERROR
88117
PrimalStatus
89118
DualStatus
90-
ResultStatusCode
91119
RawStatusString
92120
ResultCount
93121
ObjectiveValue
@@ -100,12 +128,31 @@ BarrierIterations
100128
NodeCount
101129
```
102130

131+
### ResultStatusCode
132+
133+
```@docs
134+
ResultStatusCode
135+
NO_SOLUTION
136+
FEASIBLE_POINT
137+
NEARLY_FEASIBLE_POINT
138+
INFEASIBLE_POINT
139+
INFEASIBILITY_CERTIFICATE
140+
NEARLY_INFEASIBILITY_CERTIFICATE
141+
REDUCTION_CERTIFICATE
142+
NEARLY_REDUCTION_CERTIFICATE
143+
UNKNOWN_RESULT_STATUS
144+
OTHER_RESULT_STATUS
145+
```
146+
103147
### Conflict Status
104148

105149
```@docs
106150
compute_conflict!
107151
ConflictStatus
108-
ConflictStatusCode
109152
ConstraintConflictStatus
153+
ConflictStatusCode
110154
ConflictParticipationStatusCode
155+
NOT_IN_CONFLICT
156+
IN_CONFLICT
157+
MAYBE_IN_CONFLICT
111158
```

src/MathOptInterface.jl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,90 @@ function copy_to(dest, src)
233233
)
234234
end
235235

236+
"""
237+
@_documented_enum(args...)
238+
239+
A utility macro for writing `@enum`s with inline documentation strings.
240+
241+
The even arguments are forwarded to the `@enum` macro, and the odd arguments are
242+
used as the docstring for the corresponding even argument.
243+
244+
## Example
245+
246+
```julia
247+
julia> MOI.@_documented_enum(
248+
\"\"\"
249+
MyDocumentedEnum
250+
251+
This is an example for the documentation.
252+
\"\"\",
253+
MyDocumentedEnum,
254+
\"A country down-under\",
255+
AUSTRALIA,
256+
\"Another country down-under\",
257+
NEW_ZEALAND,
258+
)
259+
MyDocumentedEnum
260+
261+
help?> MyDocumentedEnum
262+
search: MyDocumentedEnum
263+
264+
MyDocumentedEnum
265+
266+
This is an example for the documentation.
267+
268+
Values
269+
========
270+
271+
Possible values are:
272+
273+
• AUSTRALIA: A country down-under
274+
275+
• NEW_ZEALAND: Another country down-under
276+
277+
help?> AUSTRALIA
278+
search: AUSTRALIA
279+
280+
AUSTRALIA::MyDocumentedEnum
281+
282+
An instance of the MyDocumentedEnum enum.
283+
284+
AUSTRALIA: A country down-under
285+
```
286+
"""
287+
macro _documented_enum(args...)
288+
@assert iseven(length(args))
289+
code = quote
290+
$(Expr(:macrocall, Symbol("@enum"), __source__, args[2:2:end]...))
291+
end
292+
main_doc, enum = args[1], args[2]
293+
main_doc *= "\n## Values\n\nPossible values are:\n\n"
294+
for i in 3:2:length(args)
295+
docstr, value = args[i], args[i+1]
296+
doc = """
297+
$value::$enum
298+
299+
An instance of the [`$enum`](@ref) enum.\n\n`$value`: $docstr
300+
"""
301+
push!(
302+
code.args,
303+
Expr(:macrocall, Symbol("@doc"), __source__, doc, Meta.quot(value)),
304+
)
305+
main_doc *= " * [`$value`](@ref): $docstr\n"
306+
end
307+
push!(
308+
code.args,
309+
Expr(
310+
:macrocall,
311+
Symbol("@doc"),
312+
__source__,
313+
main_doc,
314+
Meta.quot(args[2]),
315+
),
316+
)
317+
return esc(code)
318+
end
319+
236320
include("error.jl")
237321
include("indextypes.jl")
238322
include("functions.jl")

0 commit comments

Comments
 (0)