Skip to content

Commit 0e0d6a5

Browse files
authored
Merge branch 'master' into conic_reformulations
2 parents e9837dc + a4ebe8a commit 0e0d6a5

1 file changed

Lines changed: 25 additions & 35 deletions

File tree

test/constraints/hull.jl

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function test_aggregate_variable()
6363
@test prep_bounds(x, model, Hull()) isa Nothing
6464
method = DP._Hull(Hull(1e-3), vrefs)
6565
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
66-
refcons = Vector{JuMP.AbstractConstraint}()
66+
refcons = Vector{JuMP.AbstractConstraint}()
6767
DP._aggregate_variable(model, refcons, x, method)
6868
@test length(refcons) == 1
6969
@test refcons[1].func == -x + sum(method.disjunction_variables[x])
@@ -80,7 +80,7 @@ function test_disaggregate_expression_var()
8080
@test prep_bounds(x, model, Hull()) isa Nothing
8181
method = DP._Hull(Hull(1e-3), vrefs)
8282
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
83-
83+
8484
refexpr = DP.disaggregate_expression(model, x, bvrefs[z], method)
8585
x_z = variable_by_name(model, "x_z")
8686
@test refexpr == x_z
@@ -96,7 +96,7 @@ function test_disaggregate_expression_var_binary()
9696
method = DP._Hull(Hull(1e-3), vrefs)
9797
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
9898
@test isnothing(variable_by_name(model, "x_z"))
99-
99+
100100
refexpr = DP.disaggregate_expression(model, x, bvrefs[z], method)
101101
@test refexpr == x
102102
end
@@ -111,7 +111,7 @@ function test_disaggregate_expression_affine()
111111
@test prep_bounds(x, model, Hull()) isa Nothing
112112
method = DP._Hull(Hull(1e-3), vrefs)
113113
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
114-
114+
115115
refexpr = DP.disaggregate_expression(model, 2x + 1, bvrefs[z], method)
116116
x_z = variable_by_name(model, "x_z")
117117
zbin = variable_by_name(model, "z")
@@ -129,7 +129,7 @@ function test_disaggregate_expression_affine_mip()
129129
@test prep_bounds(x, model, Hull()) isa Nothing
130130
method = DP._Hull(Hull(1e-3), vrefs)
131131
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
132-
132+
133133
refexpr = DP.disaggregate_expression(model, 2x + y + 1, bvrefs[z], method)
134134
x_z = variable_by_name(model, "x_z")
135135
zbin = variable_by_name(model, "z")
@@ -146,7 +146,7 @@ function test_disaggregate_expression_quadratic()
146146
@test prep_bounds(x, model, Hull()) isa Nothing
147147
method = DP._Hull(Hull(1e-3), vrefs)
148148
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
149-
149+
150150
refexpr = DP.disaggregate_expression(model, 2x^2 + 1, bvrefs[z], method)
151151
x_z = variable_by_name(model, "x_z")
152152
zbin = variable_by_name(model, "z")
@@ -169,7 +169,7 @@ function test_disaggregate_nl_expression_c()
169169
@test prep_bounds(x, model, Hull()) isa Nothing
170170
method = DP._Hull(Hull(1e-3), vrefs)
171171
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
172-
172+
173173
refexpr = DP._disaggregate_nl_expression(model, 1, bvrefs[z], method)
174174
@test refexpr == 1
175175
end
@@ -183,7 +183,7 @@ function test_disaggregate_nl_expression_var_binary()
183183
vrefs = Set([x])
184184
method = DP._Hull(Hull(1e-3), vrefs)
185185
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
186-
186+
187187
refexpr = DP._disaggregate_nl_expression(model, x, bvrefs[z], method)
188188
ϵ = method.value
189189
@test refexpr.head == :/
@@ -201,7 +201,7 @@ function test_disaggregate_nl_expression_var()
201201
method = DP._Hull(Hull(1e-3), vrefs)
202202
@test prep_bounds(x, model, Hull()) isa Nothing
203203
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
204-
204+
205205
refexpr = DP._disaggregate_nl_expression(model, x, bvrefs[z], method)
206206
x_z = variable_by_name(model, "x_z")
207207
zbin = variable_by_name(model, "z")
@@ -221,7 +221,7 @@ function test_disaggregate_nl_expression_aff()
221221
method = DP._Hull(Hull(1e-3), vrefs)
222222
@test prep_bounds(x, model, Hull()) isa Nothing
223223
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
224-
224+
225225
refexpr = DP._disaggregate_nl_expression(model, 2x + 1, bvrefs[z], method)
226226
x_z = variable_by_name(model, "x_z")
227227
zbin = variable_by_name(model, "z")
@@ -245,7 +245,7 @@ function test_disaggregate_nl_expression_aff_mip()
245245
method = DP._Hull(Hull(1e-3), vrefs)
246246
@test prep_bounds(x, model, Hull()) isa Nothing
247247
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
248-
248+
249249
refexpr = DP._disaggregate_nl_expression(model, 2x + y + 1, bvrefs[z], method)
250250
flatten!(refexpr)
251251
x_z = variable_by_name(model, "x_z")
@@ -271,7 +271,7 @@ function test_disaggregate_nl_expression_quad()
271271
method = DP._Hull(Hull(1e-3), vrefs)
272272
@test prep_bounds(x, model, Hull()) isa Nothing
273273
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
274-
274+
275275
refexpr = DP._disaggregate_nl_expression(model, 2x^2 + 1, bvrefs[z], method)
276276
x_z = variable_by_name(model, "x_z")
277277
zbin = variable_by_name(model, "z")
@@ -294,7 +294,7 @@ function test_disaggregate_nl_expession()
294294
method = DP._Hull(Hull(1e-3), vrefs)
295295
@test prep_bounds(x, model, Hull()) isa Nothing
296296
@test DP._disaggregate_variables(model, z, vrefs, method) isa Nothing
297-
297+
298298
refexpr = DP._disaggregate_nl_expression(model, 2x^3 + 1, bvrefs[z], method)
299299
x_z = variable_by_name(model, "x_z")
300300
zbin = variable_by_name(model, "z")
@@ -391,16 +391,10 @@ function test_scalar_quadratic_hull_1sided(moiset)
391391
x_z = variable_by_name(model, "x_z")
392392
ref = reformulate_disjunct_constraint(model, constraint_object(con), zbin, method)
393393
@test length(ref) == 1
394-
@test ref[1].func.head == :-
395-
@test 5zbin in ref[1].func.args
396-
arg2 = setdiff(ref[1].func.args, [5zbin])[1]
397-
@test 0*zbin in arg2.args
398-
arg3 = setdiff(arg2.args, [0*zbin])[1]
399-
@test arg3.head == :/
400-
@test x_z^2 in arg3.args
401-
@test (1-ϵ)*zbin+ϵ in arg3.args
402-
@test ref[1].set isa moiset
403-
@test DP._set_value(ref[1].set) == 0
394+
A = (x_z^2 / ((1 - ϵ) * zbin + ϵ)) - (5 * zbin)
395+
B = (zero(AffExpr) + (x_z^2 / ((1 - ϵ) * zbin + ϵ))) - (5 * zbin)
396+
@test isequal_canonical(ref[1].func, A) || isequal_canonical(ref[1].func, B)
397+
return
404398
end
405399
#nonpositives, nonnegatives, zeros
406400
function test_vector_quadratic_hull_1sided(moiset)
@@ -569,18 +563,14 @@ function test_scalar_quadratic_hull_2sided()
569563
ref = reformulate_disjunct_constraint(model, constraint_object(con), zbin, method)
570564
@test length(ref) == 2
571565
sets = (MOI.GreaterThan, MOI.LessThan)
572-
for i in 1:2
573-
@test ref[i].func.head == :-
574-
@test 5zbin in ref[i].func.args
575-
arg2 = setdiff(ref[i].func.args, [5zbin])[1]
576-
@test 0*zbin in arg2.args
577-
arg3 = setdiff(arg2.args, [0*zbin])[1]
578-
@test arg3.head == :/
579-
@test x_z^2 in arg3.args
580-
@test (1-ϵ)*zbin+ϵ in arg3.args
581-
@test ref[i].set isa sets[i]
582-
@test DP._set_value(ref[i].set) == 0
566+
A = (x_z^2 / ((1 - ϵ) * zbin + ϵ)) - (5 * zbin)
567+
B = (zero(AffExpr) + (x_z^2 / ((1 - ϵ) * zbin + ϵ))) - (5 * zbin)
568+
for (r, S) in zip(ref, sets)
569+
@test isequal_canonical(r.func, A) || isequal_canonical(r.func, B)
570+
@test r.set isa S
571+
@test DP._set_value(r.set) == 0
583572
end
573+
return
584574
end
585575
function test_scalar_nonlinear_hull_2sided_error()
586576
model = GDPModel()
@@ -963,4 +953,4 @@ end
963953
test_vector_soc_hull()
964954
test_vector_rsoc_hull()
965955
test_vector_exp_hull()
966-
end
956+
end

0 commit comments

Comments
 (0)