Scippy

SCIP

Solving Constraint Integer Programs

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