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

Start in interior of variable bounds #1073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 25 additions & 4 deletions ext/OptimMOIExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,32 @@ function MOI.add_constraint(
end

function starting_value(optimizer::Optimizer{T}, i) where {T}
if optimizer.starting_values[i] !== nothing
return optimizer.starting_values[i]
start = optimizer.starting_values[i]
v = optimizer.variables
if isfinite(v.lower[i])
if isfinite(v.upper[i])
if !isnothing(start) && v.lower[i] < start < v.upper[i]
return start
else
return (v.lower[i] + v.upper[i]) / 2
end
else
if !isnothing(start) && v.lower[i] < start
return start
else
return v.lower[i] + 1.0
end
end
else
v = optimizer.variables
return min(max(zero(T), v.lower[i]), v.upper[i])
if isfinite(v.upper[i])
if !isnothing(start) && start < v.upper[i]
return start
else
return v.upper[i] - 1.0
end
else
return something(start, 0.0)
end
end
end

Expand Down
39 changes: 14 additions & 25 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module TestOptim

using Test
import Optim
import MathOptInterface
const MOI = MathOptInterface
import MathOptInterface as MOI

function runtests()
for name in names(@__MODULE__; all = true)
Expand All @@ -25,10 +24,7 @@ function test_supports_incremental_interface()
end

function test_MOI_Test()
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
Optim.Optimizer(),
)
model = MOI.instantiate(Optim.Optimizer, with_cache_type = Float64)
MOI.set(model, MOI.Silent(), true)
MOI.Test.runtests(
model,
Expand All @@ -47,26 +43,19 @@ function test_MOI_Test()
MOI.ConstraintDual,
],
),
exclude = String[
exclude = [
# FIXME Incorrect solution
r"test_nonlinear_expression_hs071$",
# FIXME Starting value is not feasible
# See https://github.com/JuliaNLSolvers/Optim.jl/issues/1071
r"test_nonlinear_expression_hs071_epigraph$",
# FIXME objective off by 1, seems fishy
r"test_objective_FEASIBILITY_SENSE_clears_objective$",
# No objective
"test_attribute_SolveTimeSec",
"test_attribute_RawStatusString",
# FIXME The hessian callback for constraints is called with
# `λ = [-Inf, 0.0]` and then we get `NaN`, ...
"expression_hs071",
# Terminates with `OTHER_ERROR`
"test_objective_ObjectiveFunction_duplicate_terms",
"test_objective_ObjectiveFunction_constant",
"test_objective_ObjectiveFunction_VariableIndex",
"test_objective_FEASIBILITY_SENSE_clears_objective",
"test_nonlinear_expression_hs109",
"test_objective_qp_ObjectiveFunction_zero_ofdiag",
"test_objective_qp_ObjectiveFunction_edge_cases",
"test_solve_TerminationStatus_DUAL_INFEASIBLE",
"test_solve_result_index",
"test_modification_transform_singlevariable_lessthan",
"test_modification_delete_variables_in_a_batch",
"test_modification_delete_variable_with_single_variable_obj",
r"test_attribute_SolveTimeSec$",
r"test_attribute_RawStatusString$",
# Detecting infeasibility not supported
r"test_solve_TerminationStatus_DUAL_INFEASIBLE$",
],
)
return
Expand Down
Loading