|
| 1 | +const modificationtests = Dict{String, Function}() |
| 2 | + |
| 3 | +""" |
| 4 | + solve_modify_variable_bound(model::MOI.ModelLike, config::TestConfig) |
| 5 | +
|
| 6 | +Test set modification SingleVariable-in-LessThan constraint. If |
| 7 | +`config.solve=true` confirm that it solves correctly, and if |
| 8 | +`config.duals=true`, check that the duals are computed correctly. |
| 9 | +""" |
| 10 | +function solve_modify_variable_bound(model::MOI.ModelLike, config::TestConfig) |
| 11 | + MOI.empty!(model) |
| 12 | + MOIU.loadfromstring!(model,""" |
| 13 | + variables: x |
| 14 | + maxobjective: 1.0x |
| 15 | + """) |
| 16 | + x = MOI.get(model, MOI.VariableIndex, "x") |
| 17 | + c = MOI.addconstraint!(model, MOI.SingleVariable(x), MOI.LessThan(1.0)) |
| 18 | + if config.solve |
| 19 | + test_model_solution(model, config; |
| 20 | + objective_value = 1.0, |
| 21 | + variable_primal = [(x, 1.0)], |
| 22 | + constraint_primal = [(c, 1.0)], |
| 23 | + constraint_dual = [(c, -1.0)] |
| 24 | + ) |
| 25 | + end |
| 26 | + @test MOI.canset(model, MOI.ConstraintSet(), typeof(c)) |
| 27 | + MOI.set!(model, MOI.ConstraintSet(), c, MOI.LessThan(2.0)) |
| 28 | + @test MOI.canget(model, MOI.ConstraintSet(), typeof(c)) |
| 29 | + @test MOI.get(model, MOI.ConstraintSet(), c) == MOI.LessThan(2.0) |
| 30 | + if config.solve |
| 31 | + test_model_solution(model, config; |
| 32 | + objective_value = 2.0, |
| 33 | + variable_primal = [(x, 2.0)], |
| 34 | + constraint_primal = [(c, 2.0)], |
| 35 | + constraint_dual = [(c, -1.0)] |
| 36 | + ) |
| 37 | + end |
| 38 | +end |
| 39 | +modificationtests["solve_modify_variable_bound"] = solve_modify_variable_bound |
| 40 | + |
| 41 | +""" |
| 42 | + solve_modify_rhs(model::MOI.ModelLike, config::TestConfig) |
| 43 | +
|
| 44 | +Test modifying set of ScalarAffineFunction-in-LessThan constraint. If |
| 45 | +`config.solve=true` confirm that it solves correctly, and if |
| 46 | +`config.duals=true`, check that the duals are computed correctly. |
| 47 | +""" |
| 48 | +function solve_modify_rhs(model::MOI.ModelLike, config::TestConfig) |
| 49 | + MOI.empty!(model) |
| 50 | + MOIU.loadfromstring!(model,""" |
| 51 | + variables: x |
| 52 | + maxobjective: 1.0x |
| 53 | + """) |
| 54 | + x = MOI.get(model, MOI.VariableIndex, "x") |
| 55 | + c = MOI.addconstraint!(model, |
| 56 | + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), |
| 57 | + MOI.LessThan(1.0) |
| 58 | + ) |
| 59 | + if config.solve |
| 60 | + test_model_solution(model, config; |
| 61 | + objective_value = 1.0, |
| 62 | + variable_primal = [(x, 1.0)], |
| 63 | + constraint_primal = [(c, 1.0)], |
| 64 | + constraint_dual = [(c, -1.0)] |
| 65 | + ) |
| 66 | + end |
| 67 | + @test MOI.canset(model, MOI.ConstraintSet(), typeof(c)) |
| 68 | + MOI.set!(model, MOI.ConstraintSet(), c, MOI.LessThan(2.0)) |
| 69 | + @test MOI.canget(model, MOI.ConstraintSet(), typeof(c)) |
| 70 | + @test MOI.get(model, MOI.ConstraintSet(), c) == MOI.LessThan(2.0) |
| 71 | + if config.solve |
| 72 | + test_model_solution(model, config; |
| 73 | + objective_value = 2.0, |
| 74 | + variable_primal = [(x, 2.0)], |
| 75 | + constraint_primal = [(c, 2.0)], |
| 76 | + constraint_dual = [(c, -1.0)] |
| 77 | + ) |
| 78 | + end |
| 79 | +end |
| 80 | +modificationtests["solve_modify_rhs"] = solve_modify_rhs |
| 81 | + |
| 82 | +@moitestset modification |
0 commit comments