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 set_start_value(x, ::Nothing) #2551

Merged
merged 2 commits into from
Mar 31, 2021
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
16 changes: 7 additions & 9 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -898,24 +898,22 @@ function start_value(v::VariableRef)::Union{Nothing,Float64}
end

"""
set_start_value(variable::VariableRef, value::Number)
set_start_value(variable::VariableRef, value::Union{Real,Nothing})

Set the start value (MOI attribute `VariablePrimalStart`) of the variable `v` to
Set the start value (MOI attribute `VariablePrimalStart`) of the `variable` to
`value`.

Pass `nothing` to unset the start value.

Note: `VariablePrimalStart`s are sometimes called "MIP-starts" or "warmstarts".

See also [`start_value`](@ref).
"""
function set_start_value(variable::VariableRef, value::Number)
MOI.set(
owner_model(variable),
MOI.VariablePrimalStart(),
variable,
Float64(value),
)
function set_start_value(variable::VariableRef, value::Union{Nothing,Float64})
MOI.set(owner_model(variable), MOI.VariablePrimalStart(), variable, value)
return
end
set_start_value(x::VariableRef, v::Number) = set_start_value(x, Float64(v))

"""
value(v::VariableRef; result = 1)
Expand Down
12 changes: 12 additions & 0 deletions test/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,18 @@ function test_Model_relax_integrality_error_cases(::Any, ::Any)
@test_throws err relax_integrality(model)
end

function test_start_value(::Any, ::Any)
model = Model()
@variable(model, x)
@test start_value(x) === nothing
set_start_value(x, 1.0)
@test start_value(x) == 1.0
set_start_value(x, nothing)
@test start_value(x) === nothing
set_start_value(x, 1)
@test start_value(x) == 1.0
end

function runtests()
for name in names(@__MODULE__; all = true)
if !startswith("$(name)", "test_")
Expand Down