[Scip] New Solution Callback

Stefan Heinz heinz at zib.de
Wed Jul 21 21:45:42 MEST 2010


Hi

I try to explain shortly the reason why I put the SCPcatchEvent and
SCIPdropEvent calls in SCIP_DECL_EVENTINIT and SCIP_DECL_EVENTEXIT,
respectively.

At one point you have to tell SCIP, that you are interested in
watching/catching an event. In case for the solution events you should
install the event handler before the first solution is found. Which can be
easily realized within the callback SCIP_DECL_EVENTINIT since this method
is called after the problem was transformed. Note that there are
heuristics which are called before even the presolving starts
(heur_trivil.c). This explains the reason way I did not install the event
handler within the callback SCIP_DECL_EVENTINTSOL. This method is called
after presolving and before the branch-and-bound process starts. At that
point I might already missed some solutions.

The same hold for dropping the event handling. The easiest way is to do
this in SCIP_DECL_EVENTEXIT which is the counter part of
SCIP_DECL_EVENTINIT. Since the installation of the event handler takes
places in SCIP_DECL_EVENTINIT you should not drop the even handler in
SCIP_DECL_EVENTEXITSOL since this is the counter part to
SCIP_DECL_EVENTINTSOL and you can also miss solutions in case of a restart
where the branch-and-bound process is freed.

I hope that helps to understand it a little bit better. If there are more
questions about the event handling in SCIP, just post your questions to
the  mailing list and we will try answer them.

As Jakob suggested I will put the example into documentation. The new
documentation will be available with the next release in September.

Enjoy SCIP
Stefan



> Hi Stefan,
>
> thank you, this is a very helpful example. Up until now I wasn't sure,
> were to put the SCIPcatchEvent and SCIPdropEvent calls (I still don't
> understand why they belong in SCIP_DECL_EVENTINIT and
> SCIP_DECL_EVENTEXIT but I am happy to have the definite answer that they
> do).
> If you don't mind, I would like to ask you to make your example public
> in the online documentation and put a link to it on the HOWTO-page (
> http://scip.zib.de/doc/html/EVENT.html )
>
> Regards,
> Jakob Breier
>
> On 07/18/2010 09:55 PM, Stefan Heinz wrote:
>> Hi,
>>
>> I attached an event handler which checks for "best solution found". This
>> one
>> can be easily changed to "solution found" (Just replace
>> SCIP_EVENTTYPE_BESTSOLFOUND with SCIP_EVENTTYPE_SOLFOUND).
>>
>> The only thing you have to do, is to initialize the even handler before
>> you
>> call SCIPsolve() with the call
>> SCIP_CALL( SCIPcreateEventHdlrBestsol(scip) );
>>
>> The event handler is written in C which should be no problem with your
>> C++
>> project. You can also transform the C files into C++ file.
>>
>> Hope that helps
>> Stefan
>>
>>
>>
>>
>> Am Freitag 16 Juli 2010 22:28:19 schrieb Jakob Breier:
>>
>>> Hi,
>>>
>>> I am a student from the RWTH Aachen and I am working on a project using
>>> scip. I am working with the C++ Interface and I want to write out the
>>> currently best solutions every time a new solution is found, because
>>> the
>>> process crashes quite often (out of memory, system reboot, etc.). I
>>> believe the SOLFOUND event is the proper event to use (?).
>>> Unfortunately
>>> the following code does not work:
>>> =============SolFoundEventHandler.h=============
>>> #include "scip/scip.h"
>>> #include "objscip/objeventhdlr.h"
>>>
>>>
>>> class SolFoundEventHandler : public scip::ObjEventhdlr
>>> {
>>>
>>>           private:
>>>
>>>           public:
>>>                   SolFoundEventHandler();
>>>                   virtual SCIP_RETCODE scip_exec(
>>>                                        SCIP*              scip,
>>>                                        SCIP_EVENTHDLR*    eventhdlr,
>>>                                        SCIP_EVENT*        event,
>>>                                        SCIP_EVENTDATA*    eventdata
>>>                                        ) ;
>>>
>>>
>>> };
>>>
>>> ============SolFoundEventHandler.cpp============
>>> #include "SolFoundEventHandler.h"
>>>
>>>
>>> SolFoundEventHandler::SolFoundEventHandler() :
>>> ObjEventhdlr("SOLFOUND","desc")
>>> // As far as I understand the interface the above line should tell
>>> // scip that I want to catch the SOLFOUND event.
>>> {
>>>
>>> }
>>>
>>>
>>> SCIP_RETCODE SolFoundEventHandler::scip_exec(
>>>           SCIP*              scip,
>>>           SCIP_EVENTHDLR*    eventhdlr,
>>>           SCIP_EVENT*        event,
>>>           SCIP_EVENTDATA*    eventdata
>>>           )
>>> {
>>>
>>>           SCIPerrorMessage("This message will never be printed.");
>>>           SCIPABORT();
>>>
>>>           return SCIP_OKAY;
>>>
>>>
>>> }
>>>
>>> Also "SCIP_CALL_ABORT(SCIPincludeObjEventhdlr(scip_,
>>> &solFoundEventHandler, false));" is called before the solving begins
>>> (solFoundEventHandler is of course an object of type
>>> SolFoundEventHandler). Yet SCIP_RETCODE SolFoundEventHandler::scip_exec
>>> is never called.
>>> Do you know what I do wrong?
>>>
>>> Regards,
>>> Jakob Breier
>>> _______________________________________________
>>> Scip mailing list
>>> Scip at zib.de
>>> http://listserv.zib.de/mailman/listinfo/scip
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Scip mailing list
>>> Scip at zib.de
>>> http://listserv.zib.de/mailman/listinfo/scip
>>>
>
>



More information about the Scip mailing list