Skip to content

Commit

Permalink
Rebase and fix on 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 17, 2021
1 parent e5a5888 commit dc25770
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
23 changes: 16 additions & 7 deletions src/Test/UnitTests/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ for attr in (
MOI.optimize!(model)
attribute = MOI.$(attr)()
T = MOI.attribute_value_type(attribute)
# Use this syntax if T is a small union like Union{Nothing,Int}.
@test @inferred(T, MOI.get(model, attribute)) isa T
if VERSION < 1.5
@test MOI.get(model, attribute) isa T
else
@test @inferred(T, MOI.get(model, attribute)) isa T
end
end
# unittests["test_attribute_$(attr)"]
end
end

# Variable attributes.
for attr in (
:VariableName,
)
for attr in (:VariableName,)
f = Symbol("test_attribute_$(attr)")
@eval begin
function $(f)(model::MOI.ModelLike, config::TestConfig)
Expand All @@ -177,7 +178,11 @@ for attr in (
MOI.optimize!(model)
attribute = MOI.$(attr)()
T = MOI.attribute_value_type(attribute)
@test @inferred(T, MOI.get(model, attribute, x)) isa T
if VERSION < 1.5
@test MOI.get(model, attribute, x) isa T
else
@test @inferred(T, MOI.get(model, attribute, x)) isa T
end
end
# unittests["test_attribute_$(attr)"]
end
Expand All @@ -204,7 +209,11 @@ for attr in (
MOI.set(model, MOI.ConstraintName(), ci, "ci")
attribute = MOI.$(attr)()
T = MOI.attribute_value_type(attribute)
@test @inferred(T, MOI.get(model, attribute, ci)) isa T
if VERSION < 1.5
@test MOI.get(model, attribute, ci) isa T
else
@test @inferred(T, MOI.get(model, attribute, ci)) isa T
end
end
# unittests["test_attribute_$(attr)"]
end
Expand Down
7 changes: 2 additions & 5 deletions src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,7 @@ function MOI.supports(
(m.state == NO_OPTIMIZER || MOI.supports(m.optimizer, attr))
end

function MOI.get(
model::CachingOptimizer,
attr::MOI.AbstractModelAttribute,
)
function MOI.get(model::CachingOptimizer, attr::MOI.AbstractModelAttribute)
if MOI.is_set_by_optimize(attr)
if state(model) == NO_OPTIMIZER
if attr == MOI.TerminationStatus()
Expand Down Expand Up @@ -883,7 +880,7 @@ function MOI.get(
MOI.get(
m.optimizer,
attr.attr,
m.model_to_optimizer_map[idx]
m.model_to_optimizer_map[idx],
)::MOI.attribute_value_type(attr.attr),
)
end
Expand Down
7 changes: 4 additions & 3 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,9 @@ A constraint attribute indicating whether the constraint participates
in the conflict. Its type is [`ConflictParticipationStatusCode`](@ref).
"""
struct ConstraintConflictStatus <: AbstractConstraintAttribute end
attribute_value_type(::ConstraintConflictStatus) = ConflictParticipationStatusCode
function attribute_value_type(::ConstraintConflictStatus)
return ConflictParticipationStatusCode
end

## Termination status

Expand Down Expand Up @@ -1606,8 +1608,7 @@ end

# Cost of bridging F-in-S constraints
struct ConstraintBridgingCost{F<:AbstractFunction,S<:AbstractSet} <:
AbstractModelAttribute
end
AbstractModelAttribute end

attribute_value_type(::ConstraintBridgingCost) = Float64

Expand Down
6 changes: 3 additions & 3 deletions test/Utilities/mockoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ end

@testset "test_model_optimizer_attributes" begin
model = MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
)
config = MOI.Test.TestConfig()
MOI.set(model, MOI.NumberOfThreads(), 4)
Expand Down Expand Up @@ -282,15 +282,15 @@ end

@testset "test_variable_attributes" begin
model = MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
)
config = MOI.Test.TestConfig()
MOI.Test.test_attribute_VariableName(model, config)
end

@testset "test_constraint_attributes" begin
model = MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
)
config = MOI.Test.TestConfig()
MOI.Test.test_attribute_ConstraintFunction(model, config)
Expand Down

0 comments on commit dc25770

Please sign in to comment.