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