Skip to content

Commit

Permalink
Merge pull request #249 from scipopt/fix-varname
Browse files Browse the repository at this point in the history
support variable name
  • Loading branch information
matbesancon authored Oct 21, 2022
2 parents 68237a1 + 5dff6d3 commit fffd958
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SCIP"
uuid = "82193955-e24f-5292-bf16-6f2c5261a85f"
version = "0.11.7"
version = "0.11.8"

[deps]
Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7"
Expand Down
26 changes: 14 additions & 12 deletions src/MOI_wrapper/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ function MOI.set(o::Optimizer, ::MOI.VariableName, vi::VI, name::String)
return nothing
end

MOI.supports(::Optimizer, ::MOI.VariableName, ::Type{MOI.VariableIndex}) = true

function MOI.get(o::Optimizer, ::Type{MOI.VariableIndex}, name::String)
ptr = SCIPfindVar(o, name)
if ptr == C_NULL
return nothing
end
var_ref = get(o.reference, ptr, nothing)
if var_ref === nothing
return var_ref
end
return MOI.VariableIndex(var_ref.val)
end

function MOI.delete(o::Optimizer, vi::VI)
# Note: SCIP does not currently support deletion of variables that are still
# present in some constraint. We don't want the overhead of keeping track of
Expand Down Expand Up @@ -327,15 +341,3 @@ end
function MOI.set(::Optimizer, ::MOI.ConstraintFunction, ::CI{VI}, ::VI)
throw(MOI.SettingVariableIndexNotAllowed())
end

function MOI.get(o::Optimizer, ::Type{MOI.VariableIndex}, name::String)
ptr = SCIPfindVar(o, name)
if ptr == C_NULL
return nothing
end
var_ref = get(o.reference, ptr, nothing)
if var_ref === nothing
return var_ref
end
return MOI.VariableIndex(var_ref.val)
end
14 changes: 4 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ end
end

const MOI_BASE_EXCLUDED = [
"Semicontinuous",
"ScalarAffineFunction_Semiinteger",
"ScalarQuadraticFunction_Semiinteger",
"VectorAffineFunction_GeometricMeanCone",
"Indicator_GreaterThan",
"Indicator_LessThan",
"Indicator_LessThan", # indicator must be binary error in SCIP
"Indicator_ACTIVATE_ON_ZERO", # odd MOI bug?
"test_constraint_get_ConstraintIndex", # accessing constraint from string name
"BoundAlreadySet", # see TODO,
"ScalarAffineFunction_ConstraintName", # get(::SCIP.Optimizer, ::Type{MathOptInterface.ConstraintIndex}, ::String)
"duplicate_VariableName", # two identical variable names should error
"test_conic_empty_matrix",
"duplicate_VariableName", # two identical variable names should error at get time
"test_model_VariableName", # same issue
"test_model_Name_VariableName_ConstraintName",
"test_modification_delete_variables_in_a_batch",
"test_modification_set_function_single_variable",
"test_modification_set_scalaraffine_",
Expand All @@ -59,8 +55,6 @@ const MOI_BASE_EXCLUDED = [
"test_nonlinear_", # None of tests provide expression graphs in the evaluator.
"ObjectiveFunction_ScalarAffineFunction", # requires conversion of objective function
"test_objective_set_via_modify", # ListOfModelAttributesSet
# Upstream issue in MOI.Test
"test_cpsat_CountGreaterThan",
]

@testset "MathOptInterface tests (direct)" begin
Expand Down

2 comments on commit fffd958

@matbesancon
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/70761

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.8 -m "<description of version>" fffd958aa2d32a98576ea5190cae0263c3611d23
git push origin v0.11.8

Please sign in to comment.