Scippy

    SCIP

    Solving Constraint Integer Programs

    objiisfinder.cpp
    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-2025 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 objiisfinder.cpp
    26 * @brief C++ wrapper for IIS finders
    27 * @author Mark Turner
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32#include <cassert>
    33
    34#include "objiisfinder.h"
    35
    36/*
    37 * Data structures
    38 */
    39
    40/** iis finder data */
    41struct SCIP_IISfinderData
    42{
    43 scip::ObjIISfinder* objiisfinder; /**< iis finder object */
    44 SCIP_Bool deleteobject; /**< should the iis finder object be deleted when iis finder is freed? */
    45};
    46
    47/*
    48 * Callback methods of iis finder
    49 */
    50
    51extern "C"
    52{
    53
    54/** copy method for iis finder plugins (called when SCIP copies plugins) */
    55static
    56SCIP_DECL_IISFINDERCOPY(iisfinderCopyObj)
    57{ /*lint --e{715}*/
    58 SCIP_IISFINDERDATA* iisfinderdata;
    59
    60 assert(scip != NULL);
    61
    62 iisfinderdata = SCIPiisfinderGetData(iisfinder);
    63 assert(iisfinderdata != NULL);
    64 assert(iisfinderdata->objiisfinder != NULL);
    65 assert(iisfinderdata->objiisfinder->scip_ != scip);
    66
    67 if( iisfinderdata->objiisfinder->iscloneable() )
    68 {
    69 scip::ObjIISfinder* newobjiisfinder;
    70 newobjiisfinder = dynamic_cast<scip::ObjIISfinder*> (iisfinderdata->objiisfinder->clone(scip));
    71
    72 /* call include method of iis finder object */
    73 SCIP_CALL( SCIPincludeObjIISfinder(scip, newobjiisfinder, TRUE) );
    74 }
    75
    76 return SCIP_OKAY;
    77}
    78
    79/** destructor of iis finder to free user data (called when SCIP is exiting) */
    80static
    81SCIP_DECL_IISFINDERFREE(iisfinderFreeObj)
    82{ /*lint --e{715}*/
    83 SCIP_IISFINDERDATA* iisfinderdata;
    84
    85 iisfinderdata = SCIPiisfinderGetData(iisfinder);
    86 assert(iisfinderdata != NULL);
    87 assert(iisfinderdata->objiisfinder != NULL);
    88 assert(iisfinderdata->objiisfinder->scip_ == scip);
    89
    90 /* call virtual method of iisfinder object */
    91 SCIP_CALL( iisfinderdata->objiisfinder->scip_free(scip, iisfinder) );
    92
    93 /* free iisfinder object */
    94 if( iisfinderdata->deleteobject )
    95 delete iisfinderdata->objiisfinder;
    96
    97 /* free iisfinder data */
    98 delete iisfinderdata;
    99 SCIPiisfinderSetData(iisfinder, NULL); /*lint !e64*/
    100
    101 return SCIP_OKAY;
    102}
    103
    104/** iis finder execution method of iisfinder */
    105static
    106SCIP_DECL_IISFINDEREXEC(iisfinderExecObj)
    107{ /*lint --e{715}*/
    108 SCIP_IISFINDERDATA* iisfinderdata;
    109
    110 iisfinderdata = SCIPiisfinderGetData(iisfinder);
    111 assert(iisfinderdata != NULL);
    112 assert(iisfinderdata->objiisfinder != NULL);
    113
    114 /* call virtual method of iisfinder object */
    115 SCIP_CALL( iisfinderdata->objiisfinder->scip_exec(iis, iisfinder, result) );
    116
    117 return SCIP_OKAY;
    118}
    119}
    120
    121/*
    122 * iis finder specific interface methods
    123 */
    124
    125/** creates the iis finder for the given iis finder object and includes it in SCIP */
    127 SCIP* scip, /**< SCIP data structure */
    128 scip::ObjIISfinder* objiisfinder, /**< iis finder object */
    129 SCIP_Bool deleteobject /**< should the iis finder object be deleted when iis finder is freed? */
    130 )
    131{
    132 SCIP_IISFINDERDATA* iisfinderdata;
    133
    134 assert(scip != NULL);
    135 assert(objiisfinder != NULL);
    136
    137 /* create iis finder data */
    138 iisfinderdata = new SCIP_IISFINDERDATA;
    139 iisfinderdata->objiisfinder = objiisfinder;
    140 iisfinderdata->deleteobject = deleteobject;
    141
    142 /* include iis finder */
    143 SCIP_CALL( SCIPincludeIISfinder(scip, objiisfinder->scip_name_, objiisfinder->scip_desc_,
    144 objiisfinder->scip_priority_,
    145 iisfinderCopyObj,
    146 iisfinderFreeObj,
    147 iisfinderExecObj,
    148 iisfinderdata) ); /*lint !e429*/
    149
    150 return SCIP_OKAY; /*lint !e429*/
    151}
    152
    153/** returns the iis finder object of the given name, or 0 if not existing */
    155 SCIP* scip, /**< SCIP data structure */
    156 const char* name /**< name of iis finder */
    157 )
    158{
    159 SCIP_IISFINDER * iisfinder;
    160 SCIP_IISFINDERDATA* iisfinderdata;
    161
    162 iisfinder = SCIPfindIISfinder(scip, name);
    163 if( iisfinder == NULL )
    164 return 0;
    165
    166 iisfinderdata = SCIPiisfinderGetData(iisfinder);
    167 assert(iisfinderdata != NULL);
    168
    169 return iisfinderdata->objiisfinder;
    170}
    171
    172/** returns the iis finder object for the given iis finder */
    174 SCIP* scip, /**< SCIP data structure */
    175 SCIP_IISFINDER* iisfinder /**< iis finder */
    176 )
    177{
    178 SCIP_IISFINDERDATA* iisfinderdata;
    179
    180 assert(scip != NULL);
    181 iisfinderdata = SCIPiisfinderGetData(iisfinder);
    182 assert(iisfinderdata != NULL);
    183
    184 return iisfinderdata->objiisfinder;
    185}
    C++ wrapper for iis finders.
    Definition: objiisfinder.h:53
    const int scip_priority_
    Definition: objiisfinder.h:67
    #define NULL
    Definition: def.h:248
    #define SCIP_Bool
    Definition: def.h:91
    #define TRUE
    Definition: def.h:93
    #define SCIP_CALL(x)
    Definition: def.h:355
    SCIP_IISFINDER * SCIPfindIISfinder(SCIP *scip, const char *name)
    SCIP_IISFINDERDATA * SCIPiisfinderGetData(SCIP_IISFINDER *iisfinder)
    Definition: iisfinder.c:625
    void SCIPiisfinderSetData(SCIP_IISFINDER *iisfinder, SCIP_IISFINDERDATA *iisfinderdata)
    Definition: iisfinder.c:635
    SCIP_RETCODE SCIPincludeIISfinder(SCIP *scip, const char *name, const char *desc, int priority, SCIP_DECL_IISFINDERCOPY((*iisfindercopy)), SCIP_DECL_IISFINDERFREE((*iisfinderfree)), SCIP_DECL_IISFINDEREXEC((*iisfinderexec)), SCIP_IISFINDERDATA *iisfinderdata)
    SCIP_RETCODE SCIPincludeObjIISfinder(SCIP *scip, scip::ObjIISfinder *objiisfinder, SCIP_Bool deleteobject)
    static SCIP_DECL_IISFINDEREXEC(iisfinderExecObj)
    scip::ObjIISfinder * SCIPgetObjIISfinder(SCIP *scip, SCIP_IISFINDER *iisfinder)
    scip::ObjIISfinder * SCIPfindObjIISfinder(SCIP *scip, const char *name)
    static SCIP_DECL_IISFINDERCOPY(iisfinderCopyObj)
    static SCIP_DECL_IISFINDERFREE(iisfinderFreeObj)
    C++ wrapper for iis finders.
    struct SCIP_IISfinderData SCIP_IISFINDERDATA
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63