forked from jump-dev/Gurobi.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lp_03.jl
55 lines (41 loc) · 869 Bytes
/
lp_03.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Test get/set objective coefficients in LP
using Gurobi, Test
@testset "LP 03" begin
env = Gurobi.Env()
setparam!(env, "OutputFlag", 0)
# 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])
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]
optimize(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
#
set_objcoeffs!(model, [1, -1])
update_model!(model)
c_ = objcoeffs(model)
@test c_ == [1.0, -1.0]
optimize(model)
@test get_solution(model) == [1.0, 0.2]
@test get_objval(model) == 0.8
GC.gc()
end