Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new attribute NodeLimit #2552

Merged
merged 3 commits into from
Oct 8, 2024
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 @@ -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}`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about problems with more than typemax(Int32) nodes solved on 32-bit machines 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the same issue for many other attributes no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's common to explore more than 2_147_483_647 nodes on a 32-bit machine 😄


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
Loading