|
481 | 481 | MOI.set(model, MOI.RawParameter("OutputFlag"), 0) |
482 | 482 | @test MOI.get(model, MOI.RawParameter("OutputFlag")) == 0 |
483 | 483 | end |
| 484 | + |
| 485 | +@testset "QCPDuals without needing to pass QCPDual=1" begin |
| 486 | + @testset "QCPDual default" begin |
| 487 | + model = Gurobi.Optimizer(GUROBI_ENV, OutputFlag=0) |
| 488 | + MOI.Utilities.loadfromstring!(model, """ |
| 489 | + variables: x, y, z |
| 490 | + minobjective: 1.0 * x + 1.0 * y + 1.0 * z |
| 491 | + c1: x + y == 2.0 |
| 492 | + c2: x + y + z >= 0.0 |
| 493 | + c3: 1.0 * x * x + -1.0 * y * y + -1.0 * z * z >= 0.0 |
| 494 | + c4: x >= 0.0 |
| 495 | + c5: y >= 0.0 |
| 496 | + c6: z >= 0.0 |
| 497 | + """) |
| 498 | + MOI.optimize!(model) |
| 499 | + @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL |
| 500 | + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT |
| 501 | + @test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT |
| 502 | + c1 = MOI.get(model, MOI.ConstraintIndex, "c1") |
| 503 | + c2 = MOI.get(model, MOI.ConstraintIndex, "c2") |
| 504 | + c3 = MOI.get(model, MOI.ConstraintIndex, "c3") |
| 505 | + @test MOI.get(model, MOI.ConstraintDual(), c1) ≈ 1.0 atol=1e-6 |
| 506 | + @test MOI.get(model, MOI.ConstraintDual(), c2) ≈ 0.0 atol=1e-6 |
| 507 | + @test MOI.get(model, MOI.ConstraintDual(), c3) ≈ 0.0 atol=1e-6 |
| 508 | + end |
| 509 | + @testset "QCPDual=0" begin |
| 510 | + model = Gurobi.Optimizer(GUROBI_ENV, OutputFlag=0, QCPDual=0) |
| 511 | + MOI.Utilities.loadfromstring!(model, """ |
| 512 | + variables: x, y, z |
| 513 | + minobjective: 1.0 * x + 1.0 * y + 1.0 * z |
| 514 | + c1: x + y == 2.0 |
| 515 | + c2: x + y + z >= 0.0 |
| 516 | + c3: 1.0 * x * x + -1.0 * y * y + -1.0 * z * z >= 0.0 |
| 517 | + c4: x >= 0.0 |
| 518 | + c5: y >= 0.0 |
| 519 | + c6: z >= 0.0 |
| 520 | + """) |
| 521 | + MOI.optimize!(model) |
| 522 | + @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL |
| 523 | + @test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT |
| 524 | + @test MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION |
| 525 | + c1 = MOI.get(model, MOI.ConstraintIndex, "c1") |
| 526 | + c2 = MOI.get(model, MOI.ConstraintIndex, "c2") |
| 527 | + c3 = MOI.get(model, MOI.ConstraintIndex, "c3") |
| 528 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c1) |
| 529 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c2) |
| 530 | + @test_throws Gurobi.GurobiError MOI.get(model, MOI.ConstraintDual(), c3) |
| 531 | + end |
| 532 | +end |
0 commit comments