Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/manual/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ The following attributes are available:
* [`SolveTimeSec`](@ref)
* [`TimeLimitSec`](@ref)
* [`ObjectiveLimit`](@ref)
* [`SolutionLimit`](@ref)
1 change: 1 addition & 0 deletions docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SolverVersion
Silent
TimeLimitSec
ObjectiveLimit
SolutionLimit
RawOptimizerAttribute
NumberOfThreads
RawSolver
Expand Down
1 change: 1 addition & 0 deletions docs/src/tutorials/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ method for each attribute.
| [`Silent`](@ref) | Yes | Yes | Yes |
| [`TimeLimitSec`](@ref) | Yes | Yes | Yes |
| [`ObjectiveLimit`](@ref) | Yes | Yes | Yes |
| [`SolutionLimit`](@ref) | Yes | Yes | Yes |
| [`RawOptimizerAttribute`](@ref) | Yes | Yes | Yes |
| [`NumberOfThreads`](@ref) | Yes | Yes | Yes |
| [`AbsoluteGapTolerance`](@ref) | Yes | Yes | Yes |
Expand Down
26 changes: 26 additions & 0 deletions src/Test/test_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ function setup_test(
return
end

function test_attribute_SolutionLimit(model::MOI.AbstractOptimizer, ::Config)
@requires MOI.supports(model, MOI.SolutionLimit())
# Get the current value to restore it at the end of the test
value = MOI.get(model, MOI.SolutionLimit())
MOI.set(model, MOI.SolutionLimit(), 3)
@test MOI.get(model, MOI.SolutionLimit()) == 3
MOI.set(model, MOI.SolutionLimit(), nothing)
@test MOI.get(model, MOI.SolutionLimit()) === nothing
MOI.set(model, MOI.SolutionLimit(), 1)
@test MOI.get(model, MOI.SolutionLimit()) == 1
MOI.set(model, MOI.SolutionLimit(), value)
_test_attribute_value_type(model, MOI.SolutionLimit())
return
end

test_attribute_SolutionLimit(::MOI.ModelLike, ::Config) = nothing

function setup_test(
::typeof(test_attribute_SolutionLimit),
model::MOIU.MockOptimizer,
::Config,
)
MOI.set(model, MOI.SolutionLimit(), nothing)
return
end

"""
test_attribute_AbsoluteGapTolerance(model::MOI.AbstractOptimizer, config::Config)

Expand Down
29 changes: 29 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,35 @@ the [`TerminationStatus`](@ref) should be `OBJECTIVE_LIMIT`.
"""
struct ObjectiveLimit <: AbstractOptimizerAttribute end

"""
SolutionLimit()

An optimizer attribute for setting a limit on the number of available feasible
solutions.

## Default values

The provided limit must be a `Union{Nothing,Int}`.

When `set` to `nothing`, the limit reverts to the solver's default.

The default value is `nothing`.

## Termination criteria

The solver may stop when the [`ResultCount`](@ref) is larger than or equal to
the `SolutionLimit`. If stopped because of this attribute, the
[`TerminationStatus`](@ref) must be `SOLUTION_LIMIT`.

## Solution quality

The quality of the available solutions is solver-dependent. The set of resulting
solutions is not guaranteed to contain an optimal solution.
"""
struct SolutionLimit <: AbstractOptimizerAttribute end

attribute_value_type(::SolutionLimit) = Union{Nothing,Int}

"""
RawOptimizerAttribute(name::String)

Expand Down