|
318 | 318 | MOI.set(model, MOI.RawParameter("OutputFlag"), 0) |
319 | 319 | @test MOI.get(model, MOI.RawParameter("OutputFlag")) == 0 |
320 | 320 | end |
| 321 | + |
| 322 | +@testset "QCPDuals without needing to pass QCPDual=1" begin |
| 323 | + @testset "QCPDual default" begin |
| 324 | + model = Gurobi.Optimizer(GUROBI_ENV, OutputFlag=0) |
| 325 | + MOI.Utilities.loadfromstring!(model, """ |
| 326 | + variables: x, y, z |
| 327 | + minobjective: 1.0 * x + 1.0 * y + 1.0 * z |
| 328 | + c1: x + y == 2.0 |
| 329 | + c2: x + y + z >= 0.0 |
| 330 | + c3: 1.0 * x * x + -1.0 * y * y + -1.0 * z * z >= 0.0 |
| 331 | + c4: x >= 0.0 |
| 332 | + c5: y >= 0.0 |
| 333 | + c6: z >= 0.0 |
| 334 | + """) |
| 335 | + MOI.optimize!(model) |
| 336 | + @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL |
| 337 | + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT |
| 338 | + @test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT |
| 339 | + c1 = MOI.get(model, MOI.ConstraintIndex, "c1") |
| 340 | + c2 = MOI.get(model, MOI.ConstraintIndex, "c2") |
| 341 | + c3 = MOI.get(model, MOI.ConstraintIndex, "c3") |
| 342 | + @test MOI.get(model, MOI.ConstraintDual(), c1) ≈ 1.0 atol=1e-6 |
| 343 | + @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=1e-6 |
| 344 | + @test MOI.get(model, MOI.ConstraintDual(), c3) ≈ 0.0 atol=1e-6 |
| 345 | + end |
| 346 | + @testset "QCPDual=0" begin |
| 347 | + model = Gurobi.Optimizer(GUROBI_ENV, OutputFlag=0, QCPDual=0) |
| 348 | + MOI.Utilities.loadfromstring!(model, """ |
| 349 | + variables: x, y, z |
| 350 | + minobjective: 1.0 * x + 1.0 * y + 1.0 * z |
| 351 | + c1: x + y == 2.0 |
| 352 | + c2: x + y + z >= 0.0 |
| 353 | + c3: 1.0 * x * x + -1.0 * y * y + -1.0 * z * z >= 0.0 |
| 354 | + c4: x >= 0.0 |
| 355 | + c5: y >= 0.0 |
| 356 | + c6: z >= 0.0 |
| 357 | + """) |
| 358 | + MOI.optimize!(model) |
| 359 | + @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL |
| 360 | + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT |
| 361 | + @test MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION |
| 362 | + c1 = MOI.get(model, MOI.ConstraintIndex, "c1") |
| 363 | + c2 = MOI.get(model, MOI.ConstraintIndex, "c2") |
| 364 | + c3 = MOI.get(model, MOI.ConstraintIndex, "c3") |
| 365 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c1) |
| 366 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c2) |
| 367 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c3) |
| 368 | + end |
| 369 | +end |
0 commit comments