From c3339450b1619180228fc4a6cdb80b2bc350b91a Mon Sep 17 00:00:00 2001 From: guilhermebodin Date: Fri, 2 Jun 2023 04:34:14 -0300 Subject: [PATCH] Remove error from feasibility sense --- src/objective_coefficients.jl | 6 ++- .../Feasibility/feasibility_problems.jl | 21 ++++++++ test/Tests/test_dualize_feasibility.jl | 53 +++++++++++++++++++ test/runtests.jl | 2 + 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 test/Problems/Feasibility/feasibility_problems.jl create mode 100644 test/Tests/test_dualize_feasibility.jl diff --git a/src/objective_coefficients.jl b/src/objective_coefficients.jl index be5c04b..beb16ce 100644 --- a/src/objective_coefficients.jl +++ b/src/objective_coefficients.jl @@ -19,8 +19,10 @@ function set_dual_model_sense( MOI.MAX_SENSE elseif primal_sense == MOI.MAX_SENSE MOI.MIN_SENSE - else # primal_sense == MOI.FEASIBILITY_SENSE - error(primal_sense, " is not supported") + elseif primal_sense == MOI.FEASIBILITY_SENSE + # We assume fesibility sense is a Min 0 + # so the dual would be Max ... + MOI.MAX_SENSE end MOI.set(dual_model, MOI.ObjectiveSense(), dual_sense) return diff --git a/test/Problems/Feasibility/feasibility_problems.jl b/test/Problems/Feasibility/feasibility_problems.jl new file mode 100644 index 0000000..0b70e9b --- /dev/null +++ b/test/Problems/Feasibility/feasibility_problems.jl @@ -0,0 +1,21 @@ +function feasibility_1_test() + #= + min 0 + s.t. + x_1 + 2x_2 <= 3 + x_1 >= 3 + =# + model = TestModel{Float64}() + + X = MOI.add_variables(model, 2) + + MOI.add_constraint( + model, + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0], X), 0.0), + MOI.LessThan(3.0), + ) + + MOI.add_constraint(model, X[1], MOI.GreaterThan(3.0)) + + return model +end \ No newline at end of file diff --git a/test/Tests/test_dualize_feasibility.jl b/test/Tests/test_dualize_feasibility.jl new file mode 100644 index 0000000..eff3fe7 --- /dev/null +++ b/test/Tests/test_dualize_feasibility.jl @@ -0,0 +1,53 @@ +@testset "linear problems" begin + @testset "feasibility_1_test" begin + #= + primal + min 0 + s.t. + x_1 >= 3 :y_2 + x_1 + 2x_2 <= 3 :y_3 + dual + max 3y_2 + 3y_3 + s.t. + y_2 >= 0 + y_3 <= 0 + y_2 + y_3 == 0 :x_1 + 2y_3 == 0 :x_2 + =# + primal_model = feasibility_1_test() + dual_model, primal_dual_map = dual_model_and_map(primal_model) + + @test MOI.get(dual_model, MOI.NumberOfVariables()) == 2 + list_of_cons = MOI.get(dual_model, MOI.ListOfConstraintTypesPresent()) + @test Set(list_of_cons) == Set( + [ + (MOI.VariableIndex, MOI.GreaterThan{Float64}) + (MOI.VariableIndex, MOI.LessThan{Float64}) + (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) + ], + ) + @test MOI.get( + dual_model, + MOI.NumberOfConstraints{ + MOI.VariableIndex, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + @test MOI.get( + dual_model, + MOI.NumberOfConstraints{MOI.VariableIndex,MOI.LessThan{Float64}}(), + ) == 1 + @test MOI.get( + dual_model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == 2 + obj_type = MOI.get(dual_model, MOI.ObjectiveFunctionType()) + @test obj_type == MOI.ScalarAffineFunction{Float64} + obj = MOI.get(dual_model, MOI.ObjectiveFunction{obj_type}()) + @test MOI.constant(obj) == 0.0 + @test MOI.coefficient.(obj.terms) == [3.0; 3.0] + end +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index e0e4e51..22f63e6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -54,6 +54,7 @@ include("Problems/RSOC/rsoc_problems.jl") include("Problems/SDP/sdp_triangle_problems.jl") include("Problems/Exponential/exponential_cone_problems.jl") include("Problems/Power/power_cone_problems.jl") +include("Problems/Feasibility/feasibility_problems.jl") # Run tests to travis ci include("Tests/test_structures.jl") @@ -63,6 +64,7 @@ include("Tests/test_dual_model_variables.jl") include("Tests/test_dual_sets.jl") include("Tests/test_dualize_conic_linear.jl") include("Tests/test_dualize_linear.jl") +include("Tests/test_dualize_feasibility.jl") include("Tests/test_dualize_soc.jl") include("Tests/test_dualize_rsoc.jl") include("Tests/test_dualize_sdp.jl")