-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of coefficient modification (#135)
* improve performance of constraint LHS modification * fix deprecations * more tests with non-Cint indices
- Loading branch information
Showing
5 changed files
with
92 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Gurobi | ||
using Base.Test | ||
using Gurobi: getcoeff | ||
|
||
|
||
@testset "changing coefficients" begin | ||
A = spzeros(2, 2) | ||
A[1, 1] = 1.0 | ||
A[1, 2] = 2.0 | ||
A[2, 1] = 3.0 | ||
b = [0.1, 0.2] | ||
f = [0.0, 0.0] | ||
model = gurobi_model(Gurobi.Env(); f=f, A=A, b=b) | ||
|
||
@test getcoeff(model, 1, 1) == 1.0 | ||
|
||
# Verify that we can pass any kind of `::Integer` to `getcoeff` | ||
@test getcoeff(model, 1, Int8(1)) == 1.0 | ||
@test getcoeff(model, UInt32(1), UInt32(1)) == 1.0 | ||
|
||
@test getcoeff(model, 1, 2) == 2.0 | ||
@test getcoeff(model, 2, 1) == 3.0 | ||
@test getcoeff(model, 2, 2) == 0.0 | ||
|
||
chg_coeffs!(model, 2, 1, 1.5) | ||
# before updating the model, we still get the old coefficient value | ||
@test getcoeff(model, 2, 1) == 3.0 | ||
# after updating the model, we see the new coefficient value | ||
update_model!(model) | ||
@test getcoeff(model, 2, 1) == 1.5 | ||
|
||
# Verify that we are automatically converting the scalars to | ||
# Cint and Float64 as necessary | ||
chg_coeffs!(model, Int8(2), Int128(1), Float32(2.0)) | ||
update_model!(model) | ||
@test getcoeff(model, 2, 1) == 2.0 | ||
|
||
chg_coeffs!(model, [1, 2], [1, 1], [5.0, 6.5]) | ||
update_model!(model) | ||
@test getcoeff(model, 1, 1) == 5.0 | ||
@test getcoeff(model, 2, 1) == 6.5 | ||
@test getcoeff(model, 1, 2) == 2.0 | ||
@test getcoeff(model, 2, 2) == 0.0 | ||
|
||
chg_coeffs!(model, Int8[1, 2], Int8[1, 1], Float32[1.0, 2.0]) | ||
update_model!(model) | ||
@test getcoeff(model, 1, 1) == 1.0 | ||
@test getcoeff(model, 2, 1) == 2.0 | ||
@test getcoeff(model, 1, 2) == 2.0 | ||
@test getcoeff(model, 2, 2) == 0.0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ end | |
@testset "MathOptInterface Tests" begin | ||
evalfile("MOIWrapper.jl") | ||
end | ||
|
||
include("constraint_modification.jl") |