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

Small Bug Fix TO Eventhandler #293

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion src/event_handler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function include_event_handler(
eventhdlr = pointer_from_objref(event_handler)

if name == ""
name = "__eventhdlr__$(length(eventhdlrs))"
name = "__eventhdlr__$(length(scipd.eventhdlrs))"
end

@SCIP_CALL SCIPincludeEventhdlrBasic(
Expand Down
57 changes: 57 additions & 0 deletions test/eventhdlr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,60 @@ end
# free the problem
finalize(inner)
end

@testset "Nameless Event handler" begin
# create an empty problem
optimizer = SCIP.Optimizer()
inner = optimizer.inner
sepa_set_scip_parameters((par, val) -> SCIP.set_parameter(inner, par, val))

# add variables
x, y = MOI.add_variables(optimizer, 2)
MOI.add_constraint(optimizer, x, MOI.ZeroOne())
MOI.add_constraint(optimizer, y, MOI.ZeroOne())

# add constraint: x + y ≤ 1.5
MOI.add_constraint(
optimizer,
MOI.ScalarAffineFunction(
MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]),
0.0,
),
MOI.LessThan(1.5),
)

# minimize -x - y
MOI.set(
optimizer,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(
MOI.ScalarAffineTerm.([-1.0, -1.0], [x, y]),
0.0,
),
)
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MIN_SENSE)

# add eventhandler
eventhdlr = FirstLPEventTest.FirstLPEvent(inner, 10)
SCIP.include_event_handler(
inner,
eventhdlr;
name="firstlp",
desc="Store the objective value of the first LP solve at the root node",
)

# transform the problem into SCIP
SCIP.@SCIP_CALL SCIP.SCIPtransformProb(inner)

# catch the event. Again this can only be done after the problem is transformed
SCIP.catch_event(inner, SCIP.SCIP_EVENTTYPE_FIRSTLPSOLVED, eventhdlr)

# solve the problem
SCIP.@SCIP_CALL SCIP.SCIPsolve(inner.scip[])

# test if the event handler worked
@test eventhdlr.firstlpobj != 10

# free the problem
finalize(inner)
end
Loading