1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the program and library */ 4 /* SCIP --- Solving Constraint Integer Programs */ 5 /* */ 6 /* Copyright (C) 2002-2021 Konrad-Zuse-Zentrum */ 7 /* fuer Informationstechnik Berlin */ 8 /* */ 9 /* SCIP is distributed under the terms of the ZIB Academic License. */ 10 /* */ 11 /* You should have received a copy of the ZIB Academic License */ 12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */ 13 /* */ 14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 15 16 /**@file cons_cardinality.h 17 * @ingroup CONSHDLRS 18 * @brief constraint handler for cardinality constraints 19 * @author Tobias Fischer 20 * 21 */ 22 23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 24 25 #ifndef __SCIP_CONS_CARDINALITY_H__ 26 #define __SCIP_CONS_CARDINALITY_H__ 27 28 29 #include "scip/def.h" 30 #include "scip/type_cons.h" 31 #include "scip/type_retcode.h" 32 #include "scip/type_scip.h" 33 #include "scip/type_var.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /** creates the handler for cardinality constraints and includes it in SCIP 40 * 41 * @ingroup ConshdlrIncludes 42 * */ 43 SCIP_EXPORT 44 SCIP_RETCODE SCIPincludeConshdlrCardinality( 45 SCIP* scip /**< SCIP data structure */ 46 ); 47 48 /**@addtogroup CONSHDLRS 49 * 50 * @{ 51 * 52 * @name Cardinality Constraints 53 * 54 * @{ 55 * 56 * This constraint handler handles cardinality constraints of the form 57 * \f[ 58 * |\mbox{supp}(x)| \leq b 59 * \f] 60 * with integer right-hand side \f$b\f$. Here, \f$|\mbox{supp}(x)|\f$ denotes the number of nonzero entries of the 61 * vector \f$x\f$. 62 * 63 * Cardinality constraints generalize special ordered set of type one (SOS1) constraints in which \f$b = 1\f$. 64 */ 65 66 /** creates and captures an cardinality constraint 67 * 68 * We set the constraint to not be modifable. If the weights are non 69 * NULL, the variables are ordered according to these weights (in 70 * ascending order). 71 * 72 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons() 73 */ 74 SCIP_EXPORT 75 SCIP_RETCODE SCIPcreateConsCardinality( 76 SCIP* scip, /**< SCIP data structure */ 77 SCIP_CONS** cons, /**< pointer to hold the created constraint */ 78 const char* name, /**< name of constraint */ 79 int nvars, /**< number of variables in the constraint */ 80 SCIP_VAR** vars, /**< array with variables of constraint entries */ 81 int cardval, /**< number of variables allowed to be nonzero */ 82 SCIP_VAR** indvars, /**< indicator variables to indicate which variables may be treated as nonzero 83 * in cardinality constraint, or NULL if indicator variables should be 84 * created automatically */ 85 SCIP_Real* weights, /**< weights determining the variable order, or NULL if variables should be 86 * ordered in the same way they were added to the constraint */ 87 SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? 88 * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */ 89 SCIP_Bool separate, /**< should the constraint be separated during LP processing? 90 * Usually set to TRUE. */ 91 SCIP_Bool enforce, /**< should the constraint be enforced during node processing? 92 * TRUE for model constraints, FALSE for additional, redundant constraints. */ 93 SCIP_Bool check, /**< should the constraint be checked for feasibility? 94 * TRUE for model constraints, FALSE for additional, redundant constraints. */ 95 SCIP_Bool propagate, /**< should the constraint be propagated during node processing? 96 * Usually set to TRUE. */ 97 SCIP_Bool local, /**< is constraint only valid locally? 98 * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */ 99 SCIP_Bool dynamic, /**< is constraint subject to aging? 100 * Usually set to FALSE. Set to TRUE for own cuts which 101 * are separated as constraints. */ 102 SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? 103 * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */ 104 SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even 105 * if it may be moved to a more global node? 106 * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */ 107 ); 108 109 /** creates and captures an cardinality constraint 110 * in its most basic variant, i. e., with all constraint flags set to their default values, which can be set 111 * afterwards using SCIPsetConsFLAGNAME() in scip.h 112 * 113 * @see SCIPcreateConsCardinality() for the default constraint flag configuration 114 * 115 * @warning Do NOT set the constraint to be modifiable manually, because this might lead 116 * to wrong results as the variable array will not be resorted 117 * 118 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons() 119 */ 120 SCIP_EXPORT 121 SCIP_RETCODE SCIPcreateConsBasicCardinality( 122 SCIP* scip, /**< SCIP data structure */ 123 SCIP_CONS** cons, /**< pointer to hold the created constraint */ 124 const char* name, /**< name of constraint */ 125 int nvars, /**< number of variables in the constraint */ 126 SCIP_VAR** vars, /**< array with variables of constraint entries */ 127 int cardval, /**< number of variables allowed to be nonzero */ 128 SCIP_VAR** indvars, /**< indicator variables to indicate which variables may be treated as nonzero 129 * in cardinality constraint, or NULL if indicator variables should be 130 * created automatically */ 131 SCIP_Real* weights /**< weights determining the variable order, or NULL if variables should be 132 * ordered in the same way they were added to the constraint */ 133 ); 134 135 /** changes cardinality value of cardinality constraint (i.e., right hand side of cardinality constraint) */ 136 SCIP_EXPORT 137 SCIP_RETCODE SCIPchgCardvalCardinality( 138 SCIP* scip, /**< SCIP data structure */ 139 SCIP_CONS* cons, /**< pointer to hold the created constraint */ 140 int cardval /**< number of variables allowed to be nonzero */ 141 ); 142 143 /** adds variable to cardinality constraint, the position is determined by the given weight */ 144 SCIP_EXPORT 145 SCIP_RETCODE SCIPaddVarCardinality( 146 SCIP* scip, /**< SCIP data structure */ 147 SCIP_CONS* cons, /**< constraint */ 148 SCIP_VAR* var, /**< variable to add to the constraint */ 149 SCIP_VAR* indvar, /**< indicator variable to indicate whether variable may be treated as nonzero 150 * in cardinality constraint (or NULL if this variable should be created 151 * automatically) */ 152 SCIP_Real weight /**< weight determining position of variable */ 153 ); 154 155 /** appends variable to cardinality constraint */ 156 SCIP_EXPORT 157 SCIP_RETCODE SCIPappendVarCardinality( 158 SCIP* scip, /**< SCIP data structure */ 159 SCIP_CONS* cons, /**< constraint */ 160 SCIP_VAR* var, /**< variable to add to the constraint */ 161 SCIP_VAR* indvar /**< indicator variable to indicate whether variable may be treated as nonzero 162 * in cardinality constraint (or NULL if this variable should be created 163 * automatically) */ 164 ); 165 166 /** gets number of variables in cardinality constraint */ 167 SCIP_EXPORT 168 int SCIPgetNVarsCardinality( 169 SCIP* scip, /**< SCIP data structure */ 170 SCIP_CONS* cons /**< constraint */ 171 ); 172 173 /** gets array of variables in cardinality constraint */ 174 SCIP_EXPORT 175 SCIP_VAR** SCIPgetVarsCardinality( 176 SCIP* scip, /**< SCIP data structure */ 177 SCIP_CONS* cons /**< constraint data */ 178 ); 179 180 /** gets cardinality value of cardinality constraint (i.e., right hand side of cardinality constraint) */ 181 SCIP_EXPORT 182 int SCIPgetCardvalCardinality( 183 SCIP* scip, /**< SCIP data structure */ 184 SCIP_CONS* cons /**< constraint data */ 185 ); 186 187 /** gets array of weights in cardinality constraint (or NULL if not existent) */ 188 SCIP_EXPORT 189 SCIP_Real* SCIPgetWeightsCardinality( 190 SCIP* scip, /**< SCIP data structure */ 191 SCIP_CONS* cons /**< constraint data */ 192 ); 193 194 /** @} */ 195 196 /** @} */ 197 198 #ifdef __cplusplus 199 } 200 #endif 201 202 #endif 203