Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove error from feasibility sense #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/objective_coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/Problems/Feasibility/feasibility_problems.jl
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions test/Tests/test_dualize_feasibility.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down