Scippy

    SCIP

    Solving Constraint Integer Programs

    cons_pseudoboolean.h
    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 cons_pseudoboolean.h
    26 * @ingroup CONSHDLRS
    27 * @brief constraint handler for pseudoboolean constraints
    28 * @author Stefan Heinz
    29 * @author Michael Winkler
    30 */
    31
    32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    33
    34#ifndef __SCIP_CONS_PSEUDOBOOLEAN_H__
    35#define __SCIP_CONS_PSEUDOBOOLEAN_H__
    36
    37
    38#include "scip/def.h"
    39#include "scip/type_cons.h"
    40#include "scip/type_retcode.h"
    41#include "scip/type_scip.h"
    42#include "scip/type_var.h"
    43
    44#ifdef __cplusplus
    45extern "C" {
    46#endif
    47
    48#define ARTIFICIALVARNAMEPREFIX "andresultant_"
    49
    50
    51
    52/** creates the handler for pseudoboolean constraints and includes it in SCIP
    53 *
    54 * @ingroup ConshdlrIncludes
    55 * */
    56SCIP_EXPORT
    58 SCIP* scip /**< SCIP data structure */
    59 );
    60
    61/**@addtogroup CONSHDLRS
    62 *
    63 * @{
    64 *
    65 * @name Pseudoboolean Constraints
    66 *
    67 * @{
    68 *
    69 * The constraint handler deals with pseudo boolean constraints. These are constraints of the form
    70 * \f[
    71 * \mbox{lhs} \leq \sum_{k=0}^m c_k \cdot x_k + \sum_{i=0}^n c_i \cdot \prod_{j \in I_i} x_j \leq \mbox{rhs}
    72 * \f]
    73 * where all \f$x\f$ are binary.
    74 */
    75
    76/** solution status after solving LP */
    78{
    79 SCIP_LINEARCONSTYPE_INVALIDCONS = -1, /**< this is no valid linear constraint type */
    80 SCIP_LINEARCONSTYPE_LINEAR = 0, /**< this is the common linear constraint */
    81 SCIP_LINEARCONSTYPE_LOGICOR = 1, /**< this is a logicor constraint */
    82 SCIP_LINEARCONSTYPE_KNAPSACK = 2, /**< this is a knapsack constraint */
    83#ifndef WITHEQKNAPSACK
    84 SCIP_LINEARCONSTYPE_SETPPC = 3 /**< this is a setppc constraint */
    85#else
    86 SCIP_LINEARCONSTYPE_SETPPC = 3, /**< this is a setppc constraint */
    87 SCIP_LINEARCONSTYPE_EQKNAPSACK = 4 /**< this is a equality knapsack constraint */
    88#endif
    89};
    91
    92/** creates and captures a pseudoboolean constraint, with given linear and and-constraints */
    93SCIP_EXPORT
    95 SCIP* scip, /**< SCIP data structure */
    96 SCIP_CONS** cons, /**< pointer to hold the created constraint */
    97 const char* name, /**< name of constraint */
    98 SCIP_CONS* lincons, /**< associated linear constraint */
    99 SCIP_LINEARCONSTYPE linconstype, /**< linear constraint type of associated linear constraint */
    100 SCIP_CONS** andconss, /**< associated and-constraints */
    101 SCIP_Real* andcoefs, /**< associated coefficients of and-constraints */
    102 int nandconss, /**< number of associated and-constraints */
    103 SCIP_VAR* indvar, /**< indicator variable if it's a soft constraint, or NULL */
    104 SCIP_Real weight, /**< weight of the soft constraint, if it is one */
    105 SCIP_Bool issoftcons, /**< is this a soft constraint */
    106 SCIP_Real lhs, /**< left hand side of constraint */
    107 SCIP_Real rhs, /**< right hand side of constraint */
    108 SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
    109 * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
    110 SCIP_Bool separate, /**< should the constraint be separated during LP processing?
    111 * Usually set to TRUE. */
    112 SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
    113 * TRUE for model constraints, FALSE for additional, redundant
    114 * constraints. */
    115 SCIP_Bool check, /**< should the constraint be checked for feasibility?
    116 * TRUE for model constraints, FALSE for additional, redundant
    117 * constraints. */
    118 SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
    119 * Usually set to TRUE. */
    120 SCIP_Bool local, /**< is constraint only valid locally?
    121 * Usually set to FALSE. Has to be set to TRUE, e.g., for branching
    122 * constraints. */
    123 SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
    124 * Usually set to FALSE. In column generation applications, set to TRUE if
    125 * pricing adds coefficients to this constraint. */
    126 SCIP_Bool dynamic, /**< is constraint subject to aging?
    127 * Usually set to FALSE. Set to TRUE for own cuts which are seperated as
    128 * constraints. */
    129 SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
    130 * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user
    131 * cuts'. */
    132 SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
    133 * if it may be moved to a more global node?
    134 * Usually set to FALSE. Set to TRUE to for constraints that represent
    135 * node data. */
    136 );
    137
    138/** creates and captures a pseudoboolean constraint
    139 *
    140 * @note linear and nonlinear terms can be added using SCIPaddCoefPseudoboolean() and SCIPaddTermPseudoboolean(),
    141 * respectively
    142 *
    143 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
    144 */
    145SCIP_EXPORT
    147 SCIP* scip, /**< SCIP data structure */
    148 SCIP_CONS** cons, /**< pointer to hold the created constraint */
    149 const char* name, /**< name of constraint */
    150 SCIP_VAR** linvars, /**< variables of the linear part, or NULL */
    151 int nlinvars, /**< number of variables of the linear part */
    152 SCIP_Real* linvals, /**< coefficients of linear part, or NULL */
    153 SCIP_VAR*** terms, /**< nonlinear terms of variables, or NULL */
    154 int nterms, /**< number of terms of variables of nonlinear term */
    155 int* ntermvars, /**< number of variables in nonlinear terms, or NULL */
    156 SCIP_Real* termvals, /**< coefficients of nonlinear parts, or NULL */
    157 SCIP_VAR* indvar, /**< indicator variable if it's a soft constraint, or NULL */
    158 SCIP_Real weight, /**< weight of the soft constraint, if it is one */
    159 SCIP_Bool issoftcons, /**< is this a soft constraint */
    160 SCIP_Real lhs, /**< left hand side of constraint */
    161 SCIP_Real rhs, /**< right hand side of constraint */
    162 SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
    163 * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
    164 SCIP_Bool separate, /**< should the constraint be separated during LP processing?
    165 * Usually set to TRUE. */
    166 SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
    167 * TRUE for model constraints, FALSE for additional, redundant constraints. */
    168 SCIP_Bool check, /**< should the constraint be checked for feasibility?
    169 * TRUE for model constraints, FALSE for additional, redundant constraints. */
    170 SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
    171 * Usually set to TRUE. */
    172 SCIP_Bool local, /**< is constraint only valid locally?
    173 * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
    174 SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
    175 * Usually set to FALSE. In column generation applications, set to TRUE if pricing
    176 * adds coefficients to this constraint. */
    177 SCIP_Bool dynamic, /**< is constraint subject to aging?
    178 * Usually set to FALSE. Set to TRUE for own cuts which
    179 * are separated as constraints. */
    180 SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
    181 * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
    182 SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
    183 * if it may be moved to a more global node?
    184 * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
    185 );
    186
    187/** creates and captures a pseudoboolean constraint
    188 * in its most basic variant, i. e., with all constraint flags set to their default values, which can be set
    189 * afterwards using SCIPsetConsFLAGNAME() in scip.h
    190 *
    191 * @see SCIPcreateConsPseudoboolean() for the default constraint flag configuration
    192 *
    193 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
    194 */
    195SCIP_EXPORT
    197 SCIP* scip, /**< SCIP data structure */
    198 SCIP_CONS** cons, /**< pointer to hold the created constraint */
    199 const char* name, /**< name of constraint */
    200 SCIP_VAR** linvars, /**< variables of the linear part, or NULL */
    201 int nlinvars, /**< number of variables of the linear part */
    202 SCIP_Real* linvals, /**< coefficients of linear part, or NULL */
    203 SCIP_VAR*** terms, /**< nonlinear terms of variables, or NULL */
    204 int nterms, /**< number of terms of variables of nonlinear term */
    205 int* ntermvars, /**< number of variables in nonlinear terms, or NULL */
    206 SCIP_Real* termvals, /**< coefficients of nonlinear parts, or NULL */
    207 SCIP_VAR* indvar, /**< indicator variable if it's a soft constraint, or NULL */
    208 SCIP_Real weight, /**< weight of the soft constraint, if it is one */
    209 SCIP_Bool issoftcons, /**< is this a soft constraint */
    210 SCIP_Real lhs, /**< left hand side of constraint */
    211 SCIP_Real rhs /**< right hand side of constraint */
    212 );
    213
    214/** adds a variable to the pseudo boolean constraint (if it is not zero)
    215 *
    216 * @note you can only add a coefficient if the special type of linear constraint won't changed
    217 *
    218 * @todo if adding a coefficient would change the type of the special linear constraint, we need to erase it and
    219 * create a new linear constraint
    220 */
    221SCIP_EXPORT
    223 SCIP*const scip, /**< SCIP data structure */
    224 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    225 SCIP_VAR* const var, /**< variable of constraint entry */
    226 SCIP_Real const val /**< coefficient of constraint entry */
    227 );
    228
    229/** adds nonlinear term to pseudo boolean constraint (if it is not zero)
    230 *
    231 * @note you can only add a coefficient if the special type of linear constraint won't changed
    232 *
    233 * @todo if adding a coefficient would change the type of the special linear constraint, we need to erase it and
    234 * create a new linear constraint
    235 */
    236SCIP_EXPORT
    238 SCIP*const scip, /**< SCIP data structure */
    239 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    240 SCIP_VAR**const vars, /**< variables of the nonlinear term */
    241 int const nvars, /**< number of variables of the nonlinear term */
    242 SCIP_Real const val /**< coefficient of constraint entry */
    243 );
    244
    245/** gets indicator variable of pseudoboolean constraint, or NULL if there is no */
    246SCIP_EXPORT
    248 SCIP*const scip, /**< SCIP data structure */
    249 SCIP_CONS*const cons /**< pseudoboolean constraint */
    250 );
    251
    252/** gets linear constraint of pseudoboolean constraint */
    253SCIP_EXPORT
    255 SCIP*const scip, /**< SCIP data structure */
    256 SCIP_CONS*const cons /**< pseudoboolean constraint */
    257 );
    258
    259/** gets type of linear constraint of pseudoboolean constraint */
    260SCIP_EXPORT
    262 SCIP*const scip, /**< SCIP data structure */
    263 SCIP_CONS*const cons /**< pseudoboolean constraint */
    264 );
    265
    266/** gets number of linear variables without artificial terms variables of pseudoboolean constraint */
    267SCIP_EXPORT
    269 SCIP*const scip, /**< SCIP data structure */
    270 SCIP_CONS*const cons /**< pseudoboolean constraint */
    271 );
    272
    273/** gets linear constraint of pseudoboolean constraint */
    274SCIP_EXPORT
    276 SCIP*const scip, /**< SCIP data structure */
    277 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    278 SCIP_VAR**const linvars, /**< array to store and-constraints */
    279 SCIP_Real*const lincoefs, /**< array to store and-coefficients */
    280 int*const nlinvars /**< pointer to store the required array size for and-constraints, have to
    281 * be initialized with size of given array */
    282 );
    283
    284/** gets and-constraints of pseudoboolean constraint */
    285SCIP_EXPORT
    287 SCIP*const scip, /**< SCIP data structure */
    288 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    289 SCIP_CONS**const andconss, /**< array to store and-constraints */
    290 SCIP_Real*const andcoefs, /**< array to store and-coefficients */
    291 int*const nandconss /**< pointer to store the required array size for and-constraints, have to
    292 * be initialized with size of given array */
    293 );
    294
    295/** gets number of and constraints of pseudoboolean constraint */
    296SCIP_EXPORT
    298 SCIP*const scip, /**< SCIP data structure */
    299 SCIP_CONS*const cons /**< pseudoboolean constraint */
    300 );
    301
    302/** changes left hand side of pseudoboolean constraint
    303 *
    304 * @note you can only change the left hand side if the special type of linear constraint won't changed
    305 *
    306 * @todo if changing the left hand side would change the type of the special linear constraint, we need to erase it
    307 * and create a new linear constraint
    308 */
    309SCIP_EXPORT
    311 SCIP*const scip, /**< SCIP data structure */
    312 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    313 SCIP_Real const lhs /**< new left hand side */
    314 );
    315
    316/** changes right hand side of pseudoboolean constraint
    317 *
    318 * @note you can only change the right hand side if the special type of linear constraint won't changed
    319 *
    320 * @todo if changing the right hand side would change the type of the special linear constraint, we need to erase it
    321 * and create a new linear constraint
    322 */
    323SCIP_EXPORT
    325 SCIP*const scip, /**< SCIP data structure */
    326 SCIP_CONS*const cons, /**< pseudoboolean constraint */
    327 SCIP_Real const rhs /**< new right hand side */
    328 );
    329
    330/** get left hand side of pseudoboolean constraint */
    331SCIP_EXPORT
    333 SCIP*const scip, /**< SCIP data structure */
    334 SCIP_CONS*const cons /**< pseudoboolean constraint */
    335 );
    336
    337/** get right hand side of pseudoboolean constraint */
    338SCIP_EXPORT
    340 SCIP*const scip, /**< SCIP data structure */
    341 SCIP_CONS*const cons /**< pseudoboolean constraint */
    342 );
    343
    344/** @} */
    345
    346/** @} */
    347
    348#ifdef __cplusplus
    349}
    350#endif
    351
    352#endif
    common defines and data types used in all packages of SCIP
    #define SCIP_Bool
    Definition: def.h:91
    #define SCIP_Real
    Definition: def.h:156
    SCIP_RETCODE SCIPchgLhsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_Real const lhs)
    SCIP_RETCODE SCIPcreateConsBasicPseudoboolean(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR **linvars, int nlinvars, SCIP_Real *linvals, SCIP_VAR ***terms, int nterms, int *ntermvars, SCIP_Real *termvals, SCIP_VAR *indvar, SCIP_Real weight, SCIP_Bool issoftcons, SCIP_Real lhs, SCIP_Real rhs)
    SCIP_RETCODE SCIPcreateConsPseudobooleanWithConss(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONS *lincons, SCIP_LINEARCONSTYPE linconstype, SCIP_CONS **andconss, SCIP_Real *andcoefs, int nandconss, SCIP_VAR *indvar, SCIP_Real weight, SCIP_Bool issoftcons, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
    SCIP_LINEARCONSTYPE SCIPgetLinearConsTypePseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    SCIP_LinearConsType
    SCIP_RETCODE SCIPaddCoefPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_VAR *const var, SCIP_Real const val)
    int SCIPgetNAndsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    int SCIPgetNLinVarsWithoutAndPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    SCIP_RETCODE SCIPgetLinDatasWithoutAndPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_VAR **const linvars, SCIP_Real *const lincoefs, int *const nlinvars)
    SCIP_Real SCIPgetLhsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    SCIP_VAR * SCIPgetIndVarPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    SCIP_RETCODE SCIPcreateConsPseudoboolean(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR **linvars, int nlinvars, SCIP_Real *linvals, SCIP_VAR ***terms, int nterms, int *ntermvars, SCIP_Real *termvals, SCIP_VAR *indvar, SCIP_Real weight, SCIP_Bool issoftcons, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
    SCIP_RETCODE SCIPaddTermPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_VAR **const vars, int const nvars, SCIP_Real const val)
    SCIP_RETCODE SCIPchgRhsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_Real const rhs)
    SCIP_RETCODE SCIPgetAndDatasPseudoboolean(SCIP *const scip, SCIP_CONS *const cons, SCIP_CONS **const andconss, SCIP_Real *const andcoefs, int *const nandconss)
    SCIP_CONS * SCIPgetLinearConsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    enum SCIP_LinearConsType SCIP_LINEARCONSTYPE
    SCIP_Real SCIPgetRhsPseudoboolean(SCIP *const scip, SCIP_CONS *const cons)
    @ SCIP_LINEARCONSTYPE_LINEAR
    @ SCIP_LINEARCONSTYPE_INVALIDCONS
    @ SCIP_LINEARCONSTYPE_LOGICOR
    @ SCIP_LINEARCONSTYPE_KNAPSACK
    @ SCIP_LINEARCONSTYPE_SETPPC
    SCIP_RETCODE SCIPincludeConshdlrPseudoboolean(SCIP *scip)
    static volatile int nterms
    Definition: interrupt.c:47
    static SCIP_RETCODE separate(SCIP *scip, SCIP_SEPA *sepa, SCIP_SOL *sol, SCIP_RESULT *result)
    Main separation function.
    Definition: sepa_flower.c:1221
    type definitions for constraints and constraint handlers
    type definitions for return codes for SCIP methods
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63
    type definitions for SCIP's main datastructure
    type definitions for problem variables