SCIP

    Solving Constraint Integer Programs

    event_bestsol.c
    Go to the documentation of this file.
    1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    2/* */
    3/* This file is part of the program and library */
    4/* SCIP --- Solving Constraint Integer Programs */
    5/* */
    6/* Copyright (c) 2002-2026 Zuse Institute Berlin (ZIB) */
    7/* */
    8/* Licensed under the Apache License, Version 2.0 (the "License"); */
    9/* you may not use this file except in compliance with the License. */
    10/* You may obtain a copy of the License at */
    11/* */
    12/* http://www.apache.org/licenses/LICENSE-2.0 */
    13/* */
    14/* Unless required by applicable law or agreed to in writing, software */
    15/* distributed under the License is distributed on an "AS IS" BASIS, */
    16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
    17/* See the License for the specific language governing permissions and */
    18/* limitations under the License. */
    19/* */
    20/* You should have received a copy of the Apache-2.0 license */
    21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
    22/* */
    23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    24
    25/**@file examples/Eventhdlr/src/event_bestsol.c
    26 * @brief eventhdlr for best solution found
    27 * @author Stefan Heinz
    28 * @author Michael Winkler
    29 */
    30
    31/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    32
    33#include "event_bestsol.h"
    34
    35
    36#define EVENTHDLR_NAME "bestsol"
    37#define EVENTHDLR_DESC "event handler for best solutions found"
    38
    39/** copy method for event handler plugins (called when SCIP copies plugins) */
    40static
    41SCIP_DECL_EVENTCOPY(eventCopyBestsol)
    42{ /*lint --e{715}*/
    43 assert(scip != NULL);
    44 assert(eventhdlr != NULL);
    45
    47
    48 /* call inclusion method of event handler */
    50
    51 return SCIP_OKAY;
    52}
    53
    54/** initialization method of event handler (called after problem was transformed) */
    55static
    56SCIP_DECL_EVENTINIT(eventInitBestsol)
    57{ /*lint --e{715}*/
    58 assert(scip != NULL);
    59 assert(eventhdlr != NULL);
    60
    62
    63 /* notify SCIP that your event handler wants to react on the event type best solution found */
    65
    66 return SCIP_OKAY;
    67}
    68
    69/** deinitialization method of event handler (called before transformed problem is freed) */
    70static
    71SCIP_DECL_EVENTEXIT(eventExitBestsol)
    72{ /*lint --e{715}*/
    73 assert(scip != NULL);
    74 assert(eventhdlr != NULL);
    75
    77
    78 /* notify SCIP that your event handler wants to drop the event type best solution found */
    80
    81 return SCIP_OKAY;
    82}
    83
    84/** execution method of event handler */
    85static
    86SCIP_DECL_EVENTEXEC(eventExecBestsol)
    87{ /*lint --e{715}*/
    88 SCIP_SOL* bestsol;
    89 SCIP_Real solvalue;
    90
    91 assert(eventhdlr != NULL);
    92 assert(event != NULL);
    93 assert(scip != NULL);
    95
    97
    98 SCIPdebugMsg(scip, "exec method of event handler for best solution found\n");
    99
    100 bestsol = SCIPgetBestSol(scip);
    101 assert(bestsol != NULL);
    102 solvalue = SCIPgetSolOrigObj(scip, bestsol);
    103
    104 /* print best solution value */
    105 SCIPinfoMessage(scip, NULL, "found new best solution with solution value <%g> in SCIP <%s>\n",
    106 solvalue, SCIPgetProbName(scip) );
    107
    108 return SCIP_OKAY;
    109}
    110
    111/** includes event handler for best solution found */
    113 SCIP* scip /**< SCIP data structure */
    114 )
    115{
    116 SCIP_EVENTHDLRDATA* eventhdlrdata;
    117 SCIP_EVENTHDLR* eventhdlr;
    118 eventhdlrdata = NULL;
    119
    120 eventhdlr = NULL;
    121 /* create event handler for events on watched variables */
    122 SCIP_CALL( SCIPincludeEventhdlrBasic(scip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecBestsol, eventhdlrdata) );
    123 assert(eventhdlr != NULL);
    124
    125 SCIP_CALL( SCIPsetEventhdlrCopy(scip, eventhdlr, eventCopyBestsol) );
    126 SCIP_CALL( SCIPsetEventhdlrInit(scip, eventhdlr, eventInitBestsol) );
    127 SCIP_CALL( SCIPsetEventhdlrExit(scip, eventhdlr, eventExitBestsol) );
    128
    129 return SCIP_OKAY;
    130}
    #define NULL
    Definition: def.h:257
    #define SCIP_STRINGEQ(name, reference, retcode)
    Definition: def.h:454
    #define SCIP_Real
    Definition: def.h:165
    #define SCIP_CALL(x)
    Definition: def.h:364
    static SCIP_DECL_EVENTCOPY(eventCopyBestsol)
    Definition: event_bestsol.c:41
    SCIP_RETCODE SCIPincludeEventHdlrBestsol(SCIP *scip)
    static SCIP_DECL_EVENTINIT(eventInitBestsol)
    Definition: event_bestsol.c:56
    static SCIP_DECL_EVENTEXIT(eventExitBestsol)
    Definition: event_bestsol.c:71
    static SCIP_DECL_EVENTEXEC(eventExecBestsol)
    Definition: event_bestsol.c:86
    #define EVENTHDLR_DESC
    Definition: event_bestsol.c:37
    #define EVENTHDLR_NAME
    Definition: event_bestsol.c:36
    eventhdlr for best solution found
    const char * SCIPgetProbName(SCIP *scip)
    Definition: scip_prob.c:1242
    void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
    Definition: scip_message.c:208
    #define SCIPdebugMsg
    Definition: scip_message.h:78
    SCIP_RETCODE SCIPsetEventhdlrCopy(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTCOPY((*eventcopy)))
    Definition: scip_event.c:143
    SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
    Definition: scip_event.c:111
    const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
    Definition: event.c:396
    SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
    Definition: scip_event.c:185
    SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
    Definition: scip_event.c:171
    SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
    Definition: event.c:1194
    SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
    Definition: scip_event.c:293
    SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
    Definition: scip_event.c:333
    SCIP_SOL * SCIPgetBestSol(SCIP *scip)
    Definition: scip_sol.c:2986
    SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
    Definition: scip_sol.c:1890
    struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
    Definition: type_event.h:160
    #define SCIP_EVENTTYPE_BESTSOLFOUND
    Definition: type_event.h:106
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_INVALIDCALL
    Definition: type_retcode.h:51
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63