From d40a9a3f18b3bd27b1ae296c9bb205fb885ccef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 10 May 2024 18:23:12 +0200 Subject: [PATCH 1/7] Fix Bridges.runtests when model has not variable --- src/Bridges/Bridges.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 821e2f398a..eed287c642 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -277,7 +277,8 @@ function runtests( bridge_supported = all(values(Variable.bridges(model))) do bridge return MOI.supports(model, attr, typeof(bridge)) end - if MOI.supports(model, attr, MOI.VariableIndex) && bridge_supported + if MOI.supports(model, attr, MOI.VariableIndex) && bridge_supported && + MOI.get(model, MOI.NumberOfVariables()) > 0 x = MOI.get(model, MOI.ListOfVariableIndices()) MOI.set(model, attr, x, fill(nothing, length(x))) Test.@test all(isnothing, MOI.get(model, attr, x)) From f7774bc6cdb38042d709949b6d6a87919257c4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Fri, 10 May 2024 18:25:45 +0200 Subject: [PATCH 2/7] Fix format --- src/Bridges/Bridges.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index eed287c642..4f93397601 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -277,8 +277,9 @@ function runtests( bridge_supported = all(values(Variable.bridges(model))) do bridge return MOI.supports(model, attr, typeof(bridge)) end - if MOI.supports(model, attr, MOI.VariableIndex) && bridge_supported && - MOI.get(model, MOI.NumberOfVariables()) > 0 + if MOI.supports(model, attr, MOI.VariableIndex) && + bridge_supported && + MOI.get(model, MOI.NumberOfVariables()) > 0 x = MOI.get(model, MOI.ListOfVariableIndices()) MOI.set(model, attr, x, fill(nothing, length(x))) Test.@test all(isnothing, MOI.get(model, attr, x)) From e96e7df828527e843f868950bc8c9ed1633de8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sun, 12 May 2024 08:45:21 +0200 Subject: [PATCH 3/7] Remove fix --- src/Bridges/Bridges.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 4f93397601..821e2f398a 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -277,9 +277,7 @@ function runtests( bridge_supported = all(values(Variable.bridges(model))) do bridge return MOI.supports(model, attr, typeof(bridge)) end - if MOI.supports(model, attr, MOI.VariableIndex) && - bridge_supported && - MOI.get(model, MOI.NumberOfVariables()) > 0 + if MOI.supports(model, attr, MOI.VariableIndex) && bridge_supported x = MOI.get(model, MOI.ListOfVariableIndices()) MOI.set(model, attr, x, fill(nothing, length(x))) Test.@test all(isnothing, MOI.get(model, attr, x)) From a8230163fc1170f08f6e7efd593730fbc86e9733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 11 May 2024 17:17:00 +0200 Subject: [PATCH 4/7] Add test --- test/Bridges/Constraint/flip_sign.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Bridges/Constraint/flip_sign.jl b/test/Bridges/Constraint/flip_sign.jl index 036aaf503f..64d3dc3444 100644 --- a/test/Bridges/Constraint/flip_sign.jl +++ b/test/Bridges/Constraint/flip_sign.jl @@ -436,6 +436,11 @@ function test_runtests() VectorNonlinearFunction([-(2.1 * x - 1.0)]) in Nonnegatives(1) """, ) + MOI.Bridges.runtests( + MOI.Bridges.Constraint.GreaterToLessBridge, + model -> MOI.add_constraint(model, zero(MOI.ScalarAffineFunction{Float64}), MOI.GreaterThan(1.0)), + model -> MOI.add_constraint(model, zero(MOI.ScalarAffineFunction{Float64}), MOI.LessThan(-1.0)), + ) return end From 8b91af7b20795ece45dee1f96f880a288508534c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sun, 12 May 2024 09:38:02 +0200 Subject: [PATCH 5/7] Fix format --- test/Bridges/Constraint/flip_sign.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/Bridges/Constraint/flip_sign.jl b/test/Bridges/Constraint/flip_sign.jl index 64d3dc3444..00a8fb577c 100644 --- a/test/Bridges/Constraint/flip_sign.jl +++ b/test/Bridges/Constraint/flip_sign.jl @@ -438,8 +438,16 @@ function test_runtests() ) MOI.Bridges.runtests( MOI.Bridges.Constraint.GreaterToLessBridge, - model -> MOI.add_constraint(model, zero(MOI.ScalarAffineFunction{Float64}), MOI.GreaterThan(1.0)), - model -> MOI.add_constraint(model, zero(MOI.ScalarAffineFunction{Float64}), MOI.LessThan(-1.0)), + model -> MOI.add_constraint( + model, + zero(MOI.ScalarAffineFunction{Float64}), + MOI.GreaterThan(1.0), + ), + model -> MOI.add_constraint( + model, + zero(MOI.ScalarAffineFunction{Float64}), + MOI.LessThan(-1.0), + ), ) return end From 039ad775ef31ccdfa2e45da3fd6f60bb57e23863 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 13 May 2024 09:38:33 +1200 Subject: [PATCH 6/7] Fix tests --- src/Bridges/Bridges.jl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index 821e2f398a..db1c7cac40 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -283,7 +283,10 @@ function runtests( Test.@test all(isnothing, MOI.get(model, attr, x)) primal_start = fill(constraint_start, length(x)) MOI.set(model, attr, x, primal_start) - Test.@test MOI.get(model, attr, x) ≈ primal_start + if !isempty(x) + # ≈ does not work if x is empty because the return of get is Any[] + Test.@test MOI.get(model, attr, x) ≈ primal_start + end end # Test ConstraintPrimalStart and ConstraintDualStart for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent()) @@ -295,7 +298,11 @@ function runtests( Test.@test MOI.get(model, attr, ci) === nothing start = _fake_start(constraint_start, set) MOI.set(model, attr, ci, start) - Test.@test MOI.get(model, attr, ci) ≈ start + if !isempty(ci) + # ≈ does not work if ci is empty because the return of + # get is Any[] + Test.@test MOI.get(model, attr, ci) ≈ start + end end end end From a60a0367adba6a4f09b9559297a9120f31906bcb Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 13 May 2024 09:47:04 +1200 Subject: [PATCH 7/7] Update Bridges.jl --- src/Bridges/Bridges.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index db1c7cac40..119007c243 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -298,11 +298,7 @@ function runtests( Test.@test MOI.get(model, attr, ci) === nothing start = _fake_start(constraint_start, set) MOI.set(model, attr, ci, start) - if !isempty(ci) - # ≈ does not work if ci is empty because the return of - # get is Any[] - Test.@test MOI.get(model, attr, ci) ≈ start - end + Test.@test MOI.get(model, attr, ci) ≈ start end end end