-
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.
Merge pull request #95 from odow/testsets
Change to testsets
- Loading branch information
Showing
13 changed files
with
324 additions
and
362 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
using Gurobi, MathProgBase | ||
using Gurobi, MathProgBase, Base.Test | ||
|
||
env = Gurobi.Env() | ||
@testset "Env" begin | ||
env = Gurobi.Env() | ||
|
||
# Test supplying environment manually | ||
# Test supplying environment manually | ||
|
||
solver = GurobiSolver(env) | ||
# Check that the env for each model is the same | ||
m1 = MathProgBase.LinearQuadraticModel(solver) | ||
@assert m1.inner.env === env | ||
m2 = MathProgBase.LinearQuadraticModel(solver) | ||
@assert m2.inner.env === env | ||
# Check that finalizer doesn't touch env when manually provided | ||
finalize(m1.inner) | ||
@assert Gurobi.is_valid(env) | ||
solver = GurobiSolver(env) | ||
# Check that the env for each model is the same | ||
m1 = MathProgBase.LinearQuadraticModel(solver) | ||
@test m1.inner.env === env | ||
m2 = MathProgBase.LinearQuadraticModel(solver) | ||
@test m2.inner.env === env | ||
# Check that finalizer doesn't touch env when manually provided | ||
finalize(m1.inner) | ||
@test Gurobi.is_valid(env) | ||
|
||
# Test creating environment automatically | ||
# Test creating environment automatically | ||
|
||
solver = GurobiSolver() | ||
# Check that the env for each model is different | ||
m3 = MathProgBase.LinearQuadraticModel(solver) | ||
@assert m3.inner.env !== env | ||
m4 = MathProgBase.LinearQuadraticModel(solver) | ||
@assert m4.inner.env !== env | ||
@assert m3.inner.env !== m4.inner.env | ||
# Check that env is finalized with model when not supplied manually | ||
finalize(m3.inner) | ||
@assert !Gurobi.is_valid(m3.inner.env) | ||
solver = GurobiSolver() | ||
# Check that the env for each model is different | ||
m3 = MathProgBase.LinearQuadraticModel(solver) | ||
@test m3.inner.env !== env | ||
m4 = MathProgBase.LinearQuadraticModel(solver) | ||
@test m4.inner.env !== env | ||
@test m3.inner.env !== m4.inner.env | ||
# Check that env is finalized with model when not supplied manually | ||
finalize(m3.inner) | ||
@test !Gurobi.is_valid(m3.inner.env) | ||
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
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 |
---|---|---|
@@ -1,58 +1,56 @@ | ||
# Test get/set objective coefficients in LP | ||
|
||
using Gurobi | ||
using Base.Test | ||
using Gurobi, Base.Test | ||
|
||
env = Gurobi.Env() | ||
@testset "LP 03" begin | ||
env = Gurobi.Env() | ||
|
||
# original model | ||
# | ||
# maximize 2x + 2y | ||
# | ||
# s.t. 0.2 <= x, y <= 1 | ||
# | ||
# original model | ||
# | ||
# maximize 2x + 2y | ||
# | ||
# s.t. 0.2 <= x, y <= 1 | ||
# | ||
|
||
model = gurobi_model(env; | ||
name="lp_03", | ||
sense=:maximize, | ||
f=[2.0, 2.0], | ||
lb=[0.2, 0.2], | ||
ub=[1.0, 1.0]) | ||
model = gurobi_model(env; | ||
name="lp_03", | ||
sense=:maximize, | ||
f=[2.0, 2.0], | ||
lb=[0.2, 0.2], | ||
ub=[1.0, 1.0]) | ||
|
||
println(model) | ||
println(model) | ||
|
||
lb_ = lowerbounds(model) | ||
ub_ = upperbounds(model) | ||
c_ = objcoeffs(model) | ||
lb_ = lowerbounds(model) | ||
ub_ = upperbounds(model) | ||
c_ = objcoeffs(model) | ||
|
||
@test lb_ == [0.2, 0.2] | ||
@test ub_ == [1.0, 1.0] | ||
@test c_ == [2.0, 2.0] | ||
@test lb_ == [0.2, 0.2] | ||
@test ub_ == [1.0, 1.0] | ||
@test c_ == [2.0, 2.0] | ||
|
||
optimize(model) | ||
optimize(model) | ||
|
||
println() | ||
println("soln = $(get_solution(model))") | ||
println("objv = $(get_objval(model))") | ||
@test get_solution(model) == [1.0, 1.0] | ||
@test get_objval(model) == 4.0 | ||
|
||
# change objective (warm start) | ||
# | ||
# maximize x - y | ||
# | ||
# s.t. 0.2 <= x, y <= 1 | ||
# | ||
|
||
# change objective (warm start) | ||
# | ||
# maximize x - y | ||
# | ||
# s.t. 0.2 <= x, y <= 1 | ||
# | ||
set_objcoeffs!(model, [1, -1]) | ||
update_model!(model) | ||
|
||
set_objcoeffs!(model, [1, -1]) | ||
update_model!(model) | ||
c_ = objcoeffs(model) | ||
@test c_ == [1.0, -1.0] | ||
|
||
c_ = objcoeffs(model) | ||
@test c_ == [1.0, -1.0] | ||
optimize(model) | ||
|
||
optimize(model) | ||
@test get_solution(model) == [1.0, 0.2] | ||
@test get_objval(model) == 0.8 | ||
|
||
println() | ||
println("soln = $(get_solution(model))") | ||
println("objv = $(get_objval(model))") | ||
|
||
gc() | ||
gc() | ||
end |
Oops, something went wrong.