Skip to content

Commit

Permalink
Add new attribute NodeLimit (#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon authored Oct 8, 2024
1 parent 3c10947 commit fe76b33
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/manual/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ The following attributes are available:
* [`TimeLimitSec`](@ref)
* [`ObjectiveLimit`](@ref)
* [`SolutionLimit`](@ref)
* [`NodeLimit`](@ref)
* [`AutomaticDifferentiationBackend`](@ref)
1 change: 1 addition & 0 deletions docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Silent
TimeLimitSec
ObjectiveLimit
SolutionLimit
NodeLimit
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 @@ -335,6 +335,7 @@ method for each attribute.
| [`TimeLimitSec`](@ref) | Yes | Yes | Yes |
| [`ObjectiveLimit`](@ref) | Yes | Yes | Yes |
| [`SolutionLimit`](@ref) | Yes | Yes | Yes |
| [`NodeLimit`](@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 @@ -252,6 +252,32 @@ function setup_test(
return
end

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

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

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

"""
test_attribute_AbsoluteGapTolerance(model::MOI.AbstractOptimizer, config::Config)
Expand Down
24 changes: 24 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,30 @@ struct SolutionLimit <: AbstractOptimizerAttribute end

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

"""
NodeLimit()
An optimizer attribute for setting a limit on the number of branch-and-bound
nodes explored by a mixed-integer program (MIP) solver.
## 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 [`NodeCount`](@ref) is larger than or equal to
the `NodeLimit`. If stopped because of this attribute, the
[`TerminationStatus`](@ref) must be `NODE_LIMIT`.
"""
struct NodeLimit <: AbstractOptimizerAttribute end

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

"""
RawOptimizerAttribute(name::String)
Expand Down

0 comments on commit fe76b33

Please sign in to comment.