Skip to content

Update Model #389

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

Merged
merged 5 commits into from
Jun 14, 2018
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
2 changes: 1 addition & 1 deletion src/Bridges/intervalbridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function MOI.modifyconstraint!(model::MOI.ModelLike, c::SplitIntervalBridge, cha
MOI.modifyconstraint!(model, c.upper, change)
end

MOI.canset(model::MOI.ModelLike, ::MOI.ConstraintSet, c::SplitIntervalBridge, ::Type{MOI.Interval}) = true
MOI.canset(model::MOI.ModelLike, ::MOI.ConstraintSet, ::Type{<:SplitIntervalBridge}) = true
function MOI.set!(model::MOI.ModelLike, ::MOI.ConstraintSet, c::SplitIntervalBridge, change::MOI.Interval)
MOI.set!(model, MOI.ConstraintSet(), c.lower, MOI.GreaterThan(change.lower))
MOI.set!(model, MOI.ConstraintSet(), c.upper, MOI.LessThan(change.upper))
Expand Down
14 changes: 7 additions & 7 deletions src/Test/contlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function linear1test(model::MOI.ModelLike, config::TestConfig)
# s.t. x + y + z <= 1
# x >= -1
# y,z >= 0
@test MOI.canset(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(vc1))
MOI.set!(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan(-1.0))

if config.solve
Expand All @@ -255,7 +255,7 @@ function linear1test(model::MOI.ModelLike, config::TestConfig)
# max x + 2z
# s.t. x + y + z <= 1
# x, y >= 0, z = 0 (vc3)
@test MOI.canset(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(vc1))
MOI.set!(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan(0.0))

@test MOI.candelete(model, vc3)
Expand Down Expand Up @@ -666,7 +666,7 @@ function linear4test(model::MOI.ModelLike, config::TestConfig)
# Min x - y
# s.t. 100.0 <= x
# y <= 0.0
@test MOI.canset(model, MOI.ConstraintSet(), c1, MOI.GreaterThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c1))
MOI.set!(model, MOI.ConstraintSet(), c1, MOI.GreaterThan(100.0))
if config.solve
MOI.optimize!(model)
Expand All @@ -681,7 +681,7 @@ function linear4test(model::MOI.ModelLike, config::TestConfig)
# Min x - y
# s.t. 100.0 <= x
# y <= -100.0
@test MOI.canset(model, MOI.ConstraintSet(), c2, MOI.LessThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c2))
MOI.set!(model, MOI.ConstraintSet(), c2, MOI.LessThan(-100.0))
if config.solve
MOI.optimize!(model)
Expand Down Expand Up @@ -905,7 +905,7 @@ function linear6test(model::MOI.ModelLike, config::TestConfig)
# Min x - y
# s.t. 100.0 <= x
# y <= 0.0
@test MOI.canset(model, MOI.ConstraintSet(), c1, MOI.GreaterThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c1))
MOI.set!(model, MOI.ConstraintSet(), c1, MOI.GreaterThan(100.0))
if config.solve
MOI.optimize!(model)
Expand All @@ -920,7 +920,7 @@ function linear6test(model::MOI.ModelLike, config::TestConfig)
# Min x - y
# s.t. 100.0 <= x
# y <= -100.0
@test MOI.canset(model, MOI.ConstraintSet(), c2, MOI.LessThan{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c2))
MOI.set!(model, MOI.ConstraintSet(), c2, MOI.LessThan(-100.0))
if config.solve
MOI.optimize!(model)
Expand Down Expand Up @@ -1330,7 +1330,7 @@ function linear10test(model::MOI.ModelLike, config::TestConfig)
end
end

@test MOI.canset(model, MOI.ConstraintSet(), c, MOI.Interval{Float64})
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c))
MOI.set!(model, MOI.ConstraintSet(), c, MOI.Interval(2.0, 12.0))

if config.query
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/mockoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ end

MOI.canset(mock::MockOptimizer, ::MOI.ConstraintSet, c::CI{F,S}, set::Type{S}) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet} = true
function MOI.set!(mock::MockOptimizer, ::MOI.ConstraintSet, c::CI{F,S}, set::S) where {F<:MOI.AbstractFunction, S<:MOI.AbstractSet}
MOI.set!(mock.inner_model, ConstraintSet(), xor_index(c), set)
MOI.set!(mock.inner_model, MOI.ConstraintSet(), xor_index(c), set)
end

function MOI.canmodifyobjective(mock::MockOptimizer, change)
Expand Down
14 changes: 11 additions & 3 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function MOI.set!(model::AbstractModel, ::MOI.ObjectiveFunction, f::MOI.Abstract
model.objective = deepcopy(f)
end

MOI.canmodifyobjective(model::AbstractModel, ::Type{<:MOI.AbstractFunctionModification}) = true
MOI.canmodifyobjective(::AbstractModel, ::Type{<:MOI.AbstractFunctionModification}) = true
function MOI.modifyobjective!(model::AbstractModel, change::MOI.AbstractFunctionModification)
model.objective = modifyfunction(model.objective, change)
end
Expand Down Expand Up @@ -248,8 +248,16 @@ function MOI.delete!(model::AbstractModel, ci::CI)
end
end

MOI.canmodifyconstraint(model::AbstractModel, ci::CI, change) = true
function MOI.modifyconstraint!(model::AbstractModel, ci::CI, change)
MOI.canmodifyconstraint(::AbstractModel, ::CI, ::Type{<:MOI.AbstractFunctionModification}) = true
function MOI.modifyconstraint!(model::AbstractModel, ci::CI, change::MOI.AbstractFunctionModification)
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
end
MOI.canset(::AbstractModel, ::MOI.ConstraintFunction, ::Type{<:CI}) = true
function MOI.set!(model::AbstractModel, ::MOI.ConstraintFunction, ci::CI, change::MOI.AbstractFunction)
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
end
MOI.canset(::AbstractModel, ::MOI.ConstraintSet, ::Type{<:CI}) = true
function MOI.set!(model::AbstractModel, ::MOI.ConstraintSet, ci::CI, change::MOI.AbstractSet)
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
end

Expand Down
2 changes: 1 addition & 1 deletion test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ end
f3 = MOIU.modifyfunction(f3, MOI.ScalarCoefficientChange(y, 2))

@test !(MOI.get(model, MOI.ConstraintFunction(), c1) ≈ f3)
MOI.modifyconstraint!(model, c1, f3)
MOI.set!(model, MOI.ConstraintFunction(), c1, f3)
@test MOI.get(model, MOI.ConstraintFunction(), c1) ≈ f3

f4 = MOI.VectorAffineFunction(MOI.VectorAffineTerm.([1, 1, 2], MOI.ScalarAffineTerm.([2, 4, 3], [x, y, y])), [5, 7])
Expand Down