Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::GScipEventHandler Class Reference

#include <gscip_event_handler.h>

Public Member Functions

 GScipEventHandler (const GScipEventHandlerDescription &description)
 
 GScipEventHandler (const GScipEventHandler &)=delete
 
GScipEventHandleroperator= (const GScipEventHandler &)=delete
 
virtual ~GScipEventHandler ()=default
 
absl::Status Register (GScip *gscip)
 
virtual SCIP_RETCODE Init (GScip *gscip)
 
virtual SCIP_RETCODE Execute (GScipEventHandlerContext context)
 
virtual SCIP_RETCODE Exit (GScip *gscip)
 

Protected Member Functions

SCIP_RETCODE CatchEvent (SCIP_EVENTTYPE event_type)
 

Friends

SCIP_RETCODE DropAllEvents (GScipEventHandler &handler)
 

Detailed Description

Inherit from this to implement the callback and override Init() to call CatchEvent() for the events you want to listen to.

Usage:

class MyHandler : public GScipEventHandler { public: MyHandler() : GScipEventHandler({ .name = "my handler", .description = "something"}) {}

SCIP_RETCODE Init(GScip* const gscip) override {
SCIP_CALL(CatchEvent(SCIP_EVENTTYPE_SOLFOUND));
return SCIP_OKAY;
}
SCIP_RETCODE Execute(const GScipEventHandlerContext context) override {
...
return SCIP_OKAY;
}
SCIP_RETCODE CatchEvent(SCIP_EVENTTYPE event_type)
virtual SCIP_RETCODE Init(GScip *gscip)
virtual SCIP_RETCODE Execute(GScipEventHandlerContext context)
GurobiMPCallbackContext * context

};

std::unique_ptr<GScip> gscip = ...;

MyHandler handler; handler.Register(gscip.get());

Definition at line 93 of file gscip_event_handler.h.

Constructor & Destructor Documentation

◆ GScipEventHandler() [1/2]

operations_research::GScipEventHandler::GScipEventHandler ( const GScipEventHandlerDescription & description)
inlineexplicit

Definition at line 95 of file gscip_event_handler.h.

◆ GScipEventHandler() [2/2]

operations_research::GScipEventHandler::GScipEventHandler ( const GScipEventHandler & )
delete

◆ ~GScipEventHandler()

virtual operations_research::GScipEventHandler::~GScipEventHandler ( )
virtualdefault

Member Function Documentation

◆ CatchEvent()

SCIP_RETCODE operations_research::GScipEventHandler::CatchEvent ( SCIP_EVENTTYPE event_type)
protected

Catches a global event (i.e. not a variable or row dependent one) based on the input event_type mask.

This method must only be called after the problem is transformed; typically it is called in the Init() virtual method.

Caught events will be automatically dropped when the handler will be called on EXIT (before calling the corresponding Exit() member function).

See scip/type_event.h for the list of possible events. This function corresponds to SCIPcatchEvent().

Todo
(user): Support Var and Row events.
Todo
(user): Support registering events in the EVENTINITSOL callback, which would cause them to be trapped only after presolve.

Definition at line 121 of file gscip_event_handler.cc.

◆ Execute()

virtual SCIP_RETCODE operations_research::GScipEventHandler::Execute ( GScipEventHandlerContext context)
inlinevirtual

Called when a caught event is emitted.

Return SCIP_OKAY, or use SCIP_CALL macro to wraps SCIP calls to properly propagate errors.

Definition at line 126 of file gscip_event_handler.h.

◆ Exit()

virtual SCIP_RETCODE operations_research::GScipEventHandler::Exit ( GScip * gscip)
inlinevirtual

Deinitialization of the event handler.

Called before the transformed problem is freed and after all the events specified in CatchEvent() have been dropped (thus there is no need to implement this function to drop these events since this would have already been done).

Return SCIP_OKAY, or use SCIP_CALL macro to wraps SCIP calls to properly propagate errors.

Definition at line 139 of file gscip_event_handler.h.

◆ Init()

virtual SCIP_RETCODE operations_research::GScipEventHandler::Init ( GScip * gscip)
inlinevirtual

Initialization of the event handler. Called after the problem was transformed.

The implementation should use the CatchEvent() method to register to global events.

Return SCIP_OKAY, or use SCIP_CALL macro to wraps SCIP calls to properly propagate errors.

Definition at line 120 of file gscip_event_handler.h.

◆ operator=()

GScipEventHandler & operations_research::GScipEventHandler::operator= ( const GScipEventHandler & )
delete

◆ Register()

absl::Status operations_research::GScipEventHandler::Register ( GScip * gscip)

Registers this event handler to the given GScip.

This function returns an internal Status error if this handler has already been registered.

The given GScip won't own this handler but will keep a pointer to it that will be used during the solve.

event_handler_data is freed in EventFree.

This is only defensive: SCIP should return a SCIP error above instead.

Definition at line 92 of file gscip_event_handler.cc.

Friends And Related Symbol Documentation

◆ DropAllEvents

SCIP_RETCODE DropAllEvents ( GScipEventHandler & handler)
friend

Calls SCIPdropEvent() for all events in caught_events_ and clear this collection.

This is not a member function since it needs to be visible to the SCIP Exit callback function.

Definition at line 133 of file gscip_event_handler.cc.


The documentation for this class was generated from the following files: