|
79 | 79 | # free the problem
|
80 | 80 | finalize(inner)
|
81 | 81 | end
|
| 82 | + |
| 83 | +@testset "Nameless Event handler" begin |
| 84 | + # create an empty problem |
| 85 | + optimizer = SCIP.Optimizer() |
| 86 | + inner = optimizer.inner |
| 87 | + sepa_set_scip_parameters((par, val) -> SCIP.set_parameter(inner, par, val)) |
| 88 | + |
| 89 | + # add variables |
| 90 | + x, y = MOI.add_variables(optimizer, 2) |
| 91 | + MOI.add_constraint(optimizer, x, MOI.ZeroOne()) |
| 92 | + MOI.add_constraint(optimizer, y, MOI.ZeroOne()) |
| 93 | + |
| 94 | + # add constraint: x + y ≤ 1.5 |
| 95 | + MOI.add_constraint( |
| 96 | + optimizer, |
| 97 | + MOI.ScalarAffineFunction( |
| 98 | + MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]), |
| 99 | + 0.0, |
| 100 | + ), |
| 101 | + MOI.LessThan(1.5), |
| 102 | + ) |
| 103 | + |
| 104 | + # minimize -x - y |
| 105 | + MOI.set( |
| 106 | + optimizer, |
| 107 | + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), |
| 108 | + MOI.ScalarAffineFunction( |
| 109 | + MOI.ScalarAffineTerm.([-1.0, -1.0], [x, y]), |
| 110 | + 0.0, |
| 111 | + ), |
| 112 | + ) |
| 113 | + MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MIN_SENSE) |
| 114 | + |
| 115 | + # add eventhandler |
| 116 | + eventhdlr = FirstLPEventTest.FirstLPEvent(inner, 10) |
| 117 | + SCIP.include_event_handler( |
| 118 | + inner, |
| 119 | + eventhdlr; |
| 120 | + name="firstlp", |
| 121 | + desc="Store the objective value of the first LP solve at the root node", |
| 122 | + ) |
| 123 | + |
| 124 | + # transform the problem into SCIP |
| 125 | + SCIP.@SCIP_CALL SCIP.SCIPtransformProb(inner) |
| 126 | + |
| 127 | + # catch the event. Again this can only be done after the problem is transformed |
| 128 | + SCIP.catch_event(inner, SCIP.SCIP_EVENTTYPE_FIRSTLPSOLVED, eventhdlr) |
| 129 | + |
| 130 | + # solve the problem |
| 131 | + SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[]) |
| 132 | + |
| 133 | + # test if the event handler worked |
| 134 | + @test eventhdlr.firstlpobj != 10 |
| 135 | + |
| 136 | + # free the problem |
| 137 | + finalize(inner) |
| 138 | +end |
0 commit comments