Skip to content

Commit 98f82af

Browse files
blegatodow
authored andcommitted
Update Model (#389)
Updates from @blegat
1 parent 3f7be94 commit 98f82af

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

src/Bridges/intervalbridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function MOI.modifyconstraint!(model::MOI.ModelLike, c::SplitIntervalBridge, cha
5757
MOI.modifyconstraint!(model, c.upper, change)
5858
end
5959

60-
MOI.canset(model::MOI.ModelLike, ::MOI.ConstraintSet, c::SplitIntervalBridge, ::Type{MOI.Interval}) = true
60+
MOI.canset(model::MOI.ModelLike, ::MOI.ConstraintSet, ::Type{<:SplitIntervalBridge}) = true
6161
function MOI.set!(model::MOI.ModelLike, ::MOI.ConstraintSet, c::SplitIntervalBridge, change::MOI.Interval)
6262
MOI.set!(model, MOI.ConstraintSet(), c.lower, MOI.GreaterThan(change.lower))
6363
MOI.set!(model, MOI.ConstraintSet(), c.upper, MOI.LessThan(change.upper))

src/Test/contlinear.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function linear1test(model::MOI.ModelLike, config::TestConfig)
229229
# s.t. x + y + z <= 1
230230
# x >= -1
231231
# y,z >= 0
232-
@test MOI.canset(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan{Float64})
232+
@test MOI.canset(model, MOI.ConstraintSet(), typeof(vc1))
233233
MOI.set!(model, MOI.ConstraintSet(), vc1, MOI.GreaterThan(-1.0))
234234

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

261261
@test MOI.candelete(model, vc3)
@@ -666,7 +666,7 @@ function linear4test(model::MOI.ModelLike, config::TestConfig)
666666
# Min x - y
667667
# s.t. 100.0 <= x
668668
# y <= 0.0
669-
@test MOI.canset(model, MOI.ConstraintSet(), c1, MOI.GreaterThan{Float64})
669+
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c1))
670670
MOI.set!(model, MOI.ConstraintSet(), c1, MOI.GreaterThan(100.0))
671671
if config.solve
672672
MOI.optimize!(model)
@@ -681,7 +681,7 @@ function linear4test(model::MOI.ModelLike, config::TestConfig)
681681
# Min x - y
682682
# s.t. 100.0 <= x
683683
# y <= -100.0
684-
@test MOI.canset(model, MOI.ConstraintSet(), c2, MOI.LessThan{Float64})
684+
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c2))
685685
MOI.set!(model, MOI.ConstraintSet(), c2, MOI.LessThan(-100.0))
686686
if config.solve
687687
MOI.optimize!(model)
@@ -905,7 +905,7 @@ function linear6test(model::MOI.ModelLike, config::TestConfig)
905905
# Min x - y
906906
# s.t. 100.0 <= x
907907
# y <= 0.0
908-
@test MOI.canset(model, MOI.ConstraintSet(), c1, MOI.GreaterThan{Float64})
908+
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c1))
909909
MOI.set!(model, MOI.ConstraintSet(), c1, MOI.GreaterThan(100.0))
910910
if config.solve
911911
MOI.optimize!(model)
@@ -920,7 +920,7 @@ function linear6test(model::MOI.ModelLike, config::TestConfig)
920920
# Min x - y
921921
# s.t. 100.0 <= x
922922
# y <= -100.0
923-
@test MOI.canset(model, MOI.ConstraintSet(), c2, MOI.LessThan{Float64})
923+
@test MOI.canset(model, MOI.ConstraintSet(), typeof(c2))
924924
MOI.set!(model, MOI.ConstraintSet(), c2, MOI.LessThan(-100.0))
925925
if config.solve
926926
MOI.optimize!(model)
@@ -1330,7 +1330,7 @@ function linear10test(model::MOI.ModelLike, config::TestConfig)
13301330
end
13311331
end
13321332

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

13361336
if config.query

src/Utilities/mockoptimizer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ end
212212

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

218218
function MOI.canmodifyobjective(mock::MockOptimizer, change)

src/Utilities/model.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function MOI.set!(model::AbstractModel, ::MOI.ObjectiveFunction, f::MOI.Abstract
203203
model.objective = deepcopy(f)
204204
end
205205

206-
MOI.canmodifyobjective(model::AbstractModel, ::Type{<:MOI.AbstractFunctionModification}) = true
206+
MOI.canmodifyobjective(::AbstractModel, ::Type{<:MOI.AbstractFunctionModification}) = true
207207
function MOI.modifyobjective!(model::AbstractModel, change::MOI.AbstractFunctionModification)
208208
model.objective = modifyfunction(model.objective, change)
209209
end
@@ -248,8 +248,16 @@ function MOI.delete!(model::AbstractModel, ci::CI)
248248
end
249249
end
250250

251-
MOI.canmodifyconstraint(model::AbstractModel, ci::CI, change) = true
252-
function MOI.modifyconstraint!(model::AbstractModel, ci::CI, change)
251+
MOI.canmodifyconstraint(::AbstractModel, ::CI, ::Type{<:MOI.AbstractFunctionModification}) = true
252+
function MOI.modifyconstraint!(model::AbstractModel, ci::CI, change::MOI.AbstractFunctionModification)
253+
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
254+
end
255+
MOI.canset(::AbstractModel, ::MOI.ConstraintFunction, ::Type{<:CI}) = true
256+
function MOI.set!(model::AbstractModel, ::MOI.ConstraintFunction, ci::CI, change::MOI.AbstractFunction)
257+
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
258+
end
259+
MOI.canset(::AbstractModel, ::MOI.ConstraintSet, ::Type{<:CI}) = true
260+
function MOI.set!(model::AbstractModel, ::MOI.ConstraintSet, ci::CI, change::MOI.AbstractSet)
253261
_modifyconstraint!(model, ci, getconstrloc(model, ci), change)
254262
end
255263

test/model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ end
6262
f3 = MOIU.modifyfunction(f3, MOI.ScalarCoefficientChange(y, 2))
6363

6464
@test !(MOI.get(model, MOI.ConstraintFunction(), c1) f3)
65-
MOI.modifyconstraint!(model, c1, f3)
65+
MOI.set!(model, MOI.ConstraintFunction(), c1, f3)
6666
@test MOI.get(model, MOI.ConstraintFunction(), c1) f3
6767

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

0 commit comments

Comments
 (0)