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 event_bestsol.c
    26 * @brief eventhdlr to print the best solution value
    27 * @author Alexander Hoen
    28 * @author Gioni Mexi
    29 * @author Dominik Kamp
    30 */
    31
    32/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    33
    34#include "message_pb.h"
    35#include "event_bestsol.h"
    36
    37
    38#define EVENTHDLR_NAME "bestsol"
    39#define EVENTHDLR_DESC "event handler for best solutions found"
    40
    41
    42/** initialization method of event handler (called after problem was transformed) */
    43static
    44SCIP_DECL_EVENTINIT(eventInitBestsol)
    45{ /*lint --e{715}*/
    46 assert(scip != NULL);
    47 assert(eventhdlr != NULL);
    48
    50
    52
    53 return SCIP_OKAY;
    54}
    55
    56/** deinitialization method of event handler (called before transformed problem is freed) */
    57static
    58SCIP_DECL_EVENTEXIT(eventExitBestsol)
    59{ /*lint --e{715}*/
    60 assert(scip != NULL);
    61 assert(eventhdlr != NULL);
    62
    64
    66
    67 return SCIP_OKAY;
    68}
    69
    70/** frees specific event data */
    71static
    72SCIP_DECL_EVENTDELETE(eventDeleteBestsol)
    73{ /*lint --e{715}*/
    74 assert(scip != NULL);
    75 assert(eventhdlr != NULL);
    76 assert(eventdata != NULL);
    77 assert(*eventdata != NULL);
    78
    80
    81 SCIPfreeMemory(scip, eventdata);
    82
    83 return SCIP_OKAY;
    84}
    85
    86/** execution method of event handler */
    87static
    88SCIP_DECL_EVENTEXEC(eventExecBestsol)
    89{ /*lint --e{715}*/
    90 SCIP_MESSAGEHDLR* messagehdlr;
    91 SCIP_MESSAGEHDLRDATA* messagehdlrdata;
    92 SCIP_Real solval;
    93 SCIP_Bool quiet;
    94 SCIP_Bool comment;
    95
    96 assert(scip != NULL);
    97 assert(eventhdlr != NULL);
    98 assert(event != NULL);
    100
    102
    103 SCIPdebugMessage("exec method of best solution event of pbsolver\n");
    104
    105 /* get best solution value */
    107 assert(!SCIPisHugeValue(scip, ABS(solval)));
    108
    109 messagehdlr = SCIPgetMessagehdlr(scip);
    110 assert(messagehdlr != NULL);
    111 messagehdlrdata = SCIPmessagehdlrGetData(messagehdlr);
    112 assert(messagehdlrdata != NULL);
    113
    114 /* store old quiet and comment value of message handler */
    115 quiet = SCIPmessagehdlrIsQuiet(messagehdlr);
    116 comment = messagehdlrdata->comment;
    117
    118 /* turn on message handler */
    119 SCIPmessagehdlrSetQuiet(messagehdlr, FALSE);
    120 messagehdlrdata->comment = FALSE;
    121
    122 /* print best solution value */
    123 SCIPinfoMessage(scip, NULL, "o %.0lf\n", -solval != 0.0 ? solval : 0.0); /*lint !e777*/
    124
    125 /* reset old values of message handler data */
    126 SCIPmessagehdlrSetQuiet(messagehdlr, quiet);
    127 messagehdlrdata->comment = comment;
    128
    129 return SCIP_OKAY;
    130}
    131
    132/** creates event handler for best solution found */
    134 SCIP* scip /**< SCIP data structure */
    135 )
    136{
    137 /* create event handler for events on best solutions */
    139 NULL, NULL, eventInitBestsol, eventExitBestsol, NULL, NULL, eventDeleteBestsol, eventExecBestsol, NULL) );
    140
    141 return SCIP_OKAY;
    142}
    static SCIP_DECL_EVENTDELETE(eventDeleteBestsol)
    Definition: event_bestsol.c:72
    SCIP_RETCODE SCIPcreateEventHdlrBestsol(SCIP *scip)
    static SCIP_DECL_EVENTINIT(eventInitBestsol)
    Definition: event_bestsol.c:44
    static SCIP_DECL_EVENTEXIT(eventExitBestsol)
    Definition: event_bestsol.c:58
    static SCIP_DECL_EVENTEXEC(eventExecBestsol)
    Definition: event_bestsol.c:88
    #define EVENTHDLR_DESC
    Definition: event_bestsol.c:39
    #define EVENTHDLR_NAME
    Definition: event_bestsol.c:38
    #define NULL
    Definition: def.h:257
    #define SCIP_Bool
    Definition: def.h:100
    #define SCIP_STRINGEQ(name, reference, retcode)
    Definition: def.h:454
    #define SCIP_Real
    Definition: def.h:165
    #define ABS(x)
    Definition: def.h:225
    #define FALSE
    Definition: def.h:103
    #define SCIP_CALL(x)
    Definition: def.h:364
    eventhdlr for best solution found
    void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
    Definition: scip_message.c:208
    SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
    Definition: scip_message.c:88
    SCIP_RETCODE SCIPincludeEventhdlr(SCIP *scip, const char *name, const char *desc, SCIP_DECL_EVENTCOPY((*eventcopy)), SCIP_DECL_EVENTFREE((*eventfree)), SCIP_DECL_EVENTINIT((*eventinit)), SCIP_DECL_EVENTEXIT((*eventexit)), SCIP_DECL_EVENTINITSOL((*eventinitsol)), SCIP_DECL_EVENTEXITSOL((*eventexitsol)), SCIP_DECL_EVENTDELETE((*eventdelete)), SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
    Definition: scip_event.c:66
    const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
    Definition: event.c:396
    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
    #define SCIPfreeMemory(scip, ptr)
    Definition: scip_mem.h:78
    SCIP_SOL * SCIPgetBestSol(SCIP *scip)
    Definition: scip_sol.c:2986
    SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
    Definition: scip_sol.c:1890
    SCIP_Bool SCIPisHugeValue(SCIP *scip, SCIP_Real val)
    SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
    SCIP_MESSAGEHDLRDATA * SCIPmessagehdlrGetData(SCIP_MESSAGEHDLR *messagehdlr)
    Definition: message.c:887
    void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
    Definition: message.c:411
    SCIP_Bool SCIPmessagehdlrIsQuiet(SCIP_MESSAGEHDLR *messagehdlr)
    Definition: message.c:910
    messagehdlr for the Pseudo-Boolean output format
    #define SCIPdebugMessage
    Definition: pub_message.h:96
    #define SCIP_EVENTTYPE_BESTSOLFOUND
    Definition: type_event.h:106
    struct SCIP_MessagehdlrData SCIP_MESSAGEHDLRDATA
    Definition: type_message.h:67
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    @ SCIP_INVALIDCALL
    Definition: type_retcode.h:51
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63