Scippy

SCIP

Solving Constraint Integer Programs

cons_indicator.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-2022 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_indicator.h
17  * @ingroup CONSHDLRS
18  * @brief constraint handler for indicator constraints
19  * @author Marc Pfetsch
20  *
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #ifndef __SCIP_CONS_INDICATOR_H__
26 #define __SCIP_CONS_INDICATOR_H__
27 
28 
29 #include "scip/def.h"
30 #include "scip/type_cons.h"
31 #include "scip/type_lp.h"
32 #include "scip/type_retcode.h"
33 #include "scip/type_scip.h"
34 #include "scip/type_sol.h"
35 #include "scip/type_var.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /** creates the handler for indicator constraints and includes it in SCIP
42  *
43  * @ingroup ConshdlrIncludes
44  * */
45 SCIP_EXPORT
47  SCIP* scip /**< SCIP data structure */
48  );
49 
50 /**@addtogroup CONSHDLRS
51  *
52  * @{
53  *
54  * @name Indicator Constraints
55  *
56  * @{
57  *
58  * An indicator constraint is given by a binary variable \f$z\f$ and an inequality \f$ax \leq
59  * b\f$. It states that if \f$z = 1\f$ then \f$ax \leq b\f$ holds.
60  *
61  * This constraint is handled by adding a slack variable \f$s:\; ax - s \leq b\f$ with \f$s \geq
62  * 0\f$. The constraint is enforced by fixing \f$s\f$ to 0 if \f$z = 1\f$.
63  *
64  * @note The constraint only implements an implication not an equivalence, i.e., it does not ensure
65  * that \f$z = 1\f$ if \f$ax \leq b\f$ or equivalently if \f$s = 0\f$ holds.
66  *
67  * This constraint is equivalent to a linear constraint \f$ax - s \leq b\f$ and an SOS1 constraint on
68  * \f$z\f$ and \f$s\f$ (at most one should be nonzero). In the indicator context we can, however,
69  * separate more inequalities.
70  */
71 
72 /** creates and captures an indicator constraint
73  *
74  * @note @a binvar is checked to be binary only later. This enables a change of the type in
75  * procedures reading an instance.
76  *
77  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
78  */
79 SCIP_EXPORT
81  SCIP* scip, /**< SCIP data structure */
82  SCIP_CONS** cons, /**< pointer to hold the created constraint (indicator or quadratic) */
83  const char* name, /**< name of constraint */
84  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
85  int nvars, /**< number of variables in the inequality */
86  SCIP_VAR** vars, /**< array with variables of inequality (or NULL) */
87  SCIP_Real* vals, /**< values of variables in inequality (or NULL) */
88  SCIP_Real rhs, /**< rhs of the inequality */
89  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
90  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
91  * Usually set to TRUE. */
92  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
93  * TRUE for model constraints, FALSE for additional, redundant constraints. */
94  SCIP_Bool check, /**< should the constraint be checked for feasibility?
95  * TRUE for model constraints, FALSE for additional, redundant constraints. */
96  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
97  * Usually set to TRUE. */
98  SCIP_Bool local, /**< is constraint only valid locally?
99  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
100  SCIP_Bool dynamic, /**< is constraint subject to aging?
101  * Usually set to FALSE. Set to TRUE for own cuts which
102  * are separated as constraints. */
103  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
104  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
105  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
106  * if it may be moved to a more global node?
107  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
108  );
109 
110 /** creates and captures an indicator constraint in its most basic version, i. e., all constraint flags are set to their
111  * basic value as explained for the method SCIPcreateConsIndicator(); all flags can be set via
112  * SCIPsetConsFLAGNAME-methods in scip.h
113  *
114  * @see SCIPcreateConsIndicator() for information about the basic constraint flag configuration
115  *
116  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
117  */
118 SCIP_EXPORT
120  SCIP* scip, /**< SCIP data structure */
121  SCIP_CONS** cons, /**< pointer to hold the created constraint (indicator or quadratic) */
122  const char* name, /**< name of constraint */
123  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
124  int nvars, /**< number of variables in the inequality */
125  SCIP_VAR** vars, /**< array with variables of inequality (or NULL) */
126  SCIP_Real* vals, /**< values of variables in inequality (or NULL) */
127  SCIP_Real rhs /**< rhs of the inequality */
128  );
129 
130 /** creates and captures a indicator constraint in a more generic version.
131  *
132  * The key difference from SCIPcreateConsIndicator() is the activeone and lessthanineq Booleans.
133  * If \f$z = o\f$, with \f$o\f$ the activeone flag, then:
134  * if lessthanineq then \f$a^T x \leq b\f$ holds, else the passed vectors are assumed to be of the form \f$a^T x \geq b\f$.
135  * The underlying linear constraint is always created as a less-than inequality.
136  */
137 SCIP_EXPORT
139  SCIP* scip, /**< SCIP data structure */
140  SCIP_CONS** cons, /**< pointer to hold the created constraint (indicator or quadratic) */
141  const char* name, /**< name of constraint */
142  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
143  int nvars, /**< number of variables in the inequality */
144  SCIP_VAR** vars, /**< array with variables of inequality (or NULL) */
145  SCIP_Real* vals, /**< values of variables in inequality (or NULL) */
146  SCIP_Real rhs, /**< rhs of the inequality */
147  SCIP_Bool activeone, /**< is the constraint active when the binary is 1? */
148  SCIP_Bool lessthanineq, /**< is the linear constraint a less than RHS (TRUE) or greater than RHS (FALSE)? */
149  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
150  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
151  * Usually set to TRUE. */
152  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
153  * TRUE for model constraints, FALSE for additional, redundant constraints. */
154  SCIP_Bool check, /**< should the constraint be checked for feasibility?
155  * TRUE for model constraints, FALSE for additional, redundant constraints. */
156  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
157  * Usually set to TRUE. */
158  SCIP_Bool local, /**< is constraint only valid locally?
159  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
160  SCIP_Bool dynamic, /**< is constraint subject to aging?
161  * Usually set to FALSE. Set to TRUE for own cuts which
162  * are separated as constraints. */
163  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
164  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
165  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
166  * if it may be moved to a more global node?
167  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
168  );
169 
170 /** creates and captures an indicator constraint with given linear constraint and slack variable
171  *
172  * @note @a binvar is checked to be binary only later. This enables a change of the type in
173  * procedures reading an instance.
174  *
175  * @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
176  * the role of a slack variable!
177  *
178  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
179  */
180 SCIP_EXPORT
182  SCIP* scip, /**< SCIP data structure */
183  SCIP_CONS** cons, /**< pointer to hold the created constraint */
184  const char* name, /**< name of constraint */
185  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
186  SCIP_CONS* lincons, /**< linear constraint */
187  SCIP_VAR* slackvar, /**< slack variable */
188  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
189  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
190  * Usually set to TRUE. */
191  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
192  * TRUE for model constraints, FALSE for additional, redundant constraints. */
193  SCIP_Bool check, /**< should the constraint be checked for feasibility?
194  * TRUE for model constraints, FALSE for additional, redundant constraints. */
195  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
196  * Usually set to TRUE. */
197  SCIP_Bool local, /**< is constraint only valid locally?
198  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
199  SCIP_Bool dynamic, /**< is constraint subject to aging?
200  * Usually set to FALSE. Set to TRUE for own cuts which
201  * are separated as constraints. */
202  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
203  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
204  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
205  * if it may be moved to a more global node?
206  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
207  );
208 
209 /** creates and captures an indicator constraint with given linear constraint and slack variable
210  * in a generic version, i. e., with a flag activeone indicating whether the constraint is active on
211  * value 1 or 0 of the binary variable.
212 
213  * @note @a binvar is checked to be binary only later. This enables a change of the type in
214  * procedures reading an instance.
215  *
216  * @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
217  * the role of a slack variable!
218  *
219  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
220  *
221  * @see SCIPcreateConsIndicatorLinCons() for information about the basic constraint flag configuration
222  */
223 SCIP_EXPORT
225  SCIP* scip, /**< SCIP data structure */
226  SCIP_CONS** cons, /**< pointer to hold the created constraint */
227  const char* name, /**< name of constraint */
228  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
229  SCIP_CONS* lincons, /**< linear constraint */
230  SCIP_VAR* slackvar, /**< slack variable */
231  SCIP_Bool activeone, /**< is the constraint active when the binary is 1? */
232  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
233  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
234  * Usually set to TRUE. */
235  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
236  * TRUE for model constraints, FALSE for additional, redundant constraints. */
237  SCIP_Bool check, /**< should the constraint be checked for feasibility?
238  * TRUE for model constraints, FALSE for additional, redundant constraints. */
239  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
240  * Usually set to TRUE. */
241  SCIP_Bool local, /**< is constraint only valid locally?
242  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
243  SCIP_Bool dynamic, /**< is constraint subject to aging?
244  * Usually set to FALSE. Set to TRUE for own cuts which
245  * are separated as constraints. */
246  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
247  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
248  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
249  * if it may be moved to a more global node?
250  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
251  );
252 
253 /** creates and captures an indicator constraint with given linear constraint and slack variable
254  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
255  * method SCIPcreateConsIndicator(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
256 
257  * @note @a binvar is checked to be binary only later. This enables a change of the type in
258  * procedures reading an instance.
259  *
260  * @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
261  * the role of a slack variable!
262  *
263  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
264  *
265  * @see SCIPcreateConsIndicatorLinCons() for information about the basic constraint flag configuration
266  *
267  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
268  */
269 SCIP_EXPORT
271  SCIP* scip, /**< SCIP data structure */
272  SCIP_CONS** cons, /**< pointer to hold the created constraint */
273  const char* name, /**< name of constraint */
274  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
275  SCIP_CONS* lincons, /**< linear constraint */
276  SCIP_VAR* slackvar /**< slack variable */
277  );
278 
279 /** adds variable to the inequality of the indicator constraint */
280 SCIP_EXPORT
282  SCIP* scip, /**< SCIP data structure */
283  SCIP_CONS* cons, /**< indicator constraint */
284  SCIP_VAR* var, /**< variable to add to the inequality */
285  SCIP_Real val /**< value of variable */
286  );
287 
288 /** gets the linear constraint corresponding to the indicator constraint (may be NULL) */
289 SCIP_EXPORT
291  SCIP_CONS* cons /**< indicator constraint */
292  );
293 
294 /** sets the linear constraint corresponding to the indicator constraint (may be NULL) */
295 SCIP_EXPORT
297  SCIP* scip, /**< SCIP data structure */
298  SCIP_CONS* cons, /**< indicator constraint */
299  SCIP_CONS* lincons /**< linear constraint */
300  );
301 
302 /** sets binary indicator variable for indicator constraint */
303 SCIP_EXPORT
305  SCIP* scip, /**< SCIP data structure */
306  SCIP_CONS* cons, /**< indicator constraint */
307  SCIP_VAR* binvar /**< binary variable to add to the inequality */
308  );
309 
310 /** gets activation value of an indicator constraint, TRUE for active on 1, FALSE for active on 0 */
311 SCIP_EXPORT
313  SCIP_CONS* cons /**< indicator constraint */
314  );
315 
316 /** gets binary variable corresponding to indicator constraint. Returns the negative of the original binary variable if activeone was set to false */
317 SCIP_EXPORT
319  SCIP_CONS* cons /**< indicator constraint */
320  );
321 
322 /** similar to SCIPgetBinaryVarIndicator but returns the original binary variable passed by the user. */
323 SCIP_EXPORT
325  SCIP_CONS* cons /**< indicator constraint */
326  );
327 
328 /** gets slack variable corresponding to indicator constraint */
329 SCIP_EXPORT
331  SCIP_CONS* cons /**< indicator constraint */
332  );
333 
334 /** sets upper bound for slack variable corresponding to indicator constraint
335  *
336  * Use with care if you know that the maximal violation of the corresponding constraint is at most @p ub. This bound
337  * might be improved automatically during the solution process.
338  *
339  * @pre This method should only be called if SCIP is in one of the following stages:
340  * - \ref SCIP_STAGE_INIT
341  * - \ref SCIP_STAGE_PROBLEM
342  */
343 SCIP_EXPORT
345  SCIP* scip, /**< SCIP data structure */
346  SCIP_CONS* cons, /**< indicator constraint */
347  SCIP_Real ub /**< upper bound for slack variable */
348  );
349 
350 /** checks whether indicator constraint is violated w.r.t. sol */
351 SCIP_EXPORT
353  SCIP* scip, /**< SCIP data structure */
354  SCIP_CONS* cons, /**< indicator constraint */
355  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
356  );
357 
358 /** based on values of other variables, computes slack and binary variable to turn constraint feasible */
359 SCIP_EXPORT
361  SCIP* scip, /**< SCIP data structure */
362  SCIP_CONS* cons, /**< indicator constraint */
363  SCIP_SOL* sol, /**< solution */
364  SCIP_Bool* changed /**< pointer to store whether the solution has been changed */
365  );
366 
367 /** based on values of other variables, computes slack and binary variable to turn all constraints feasible */
368 SCIP_EXPORT
370  SCIP* scip, /**< SCIP data structure */
371  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
372  SCIP_SOL* sol, /**< solution */
373  SCIP_Bool* changed /**< pointer to store whether the solution has been changed */
374  );
375 
376 /** adds additional linear constraint that is not connected with an indicator constraint, but can be used for separation */
377 SCIP_EXPORT
379  SCIP* scip, /**< SCIP data structure */
380  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
381  SCIP_CONS* lincons /**< linear constraint */
382  );
383 
384 /** adds additional globally valid row that is not connected with an indicator constraint, but can be used for separation */
385 SCIP_EXPORT
387  SCIP* scip, /**< SCIP data structure */
388  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
389  SCIP_ROW* row /**< row to add */
390  );
391 
392 /** @} */
393 
394 /** @} */
395 
396 #ifdef __cplusplus
397 }
398 #endif
399 
400 #endif
SCIP_Bool SCIPisViolatedIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
SCIP_RETCODE SCIPaddVarIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsIndicatorGeneric(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs, SCIP_Bool activeone, SCIP_Bool lessthanineq, 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 SCIPsetSlackVarUb(SCIP *scip, SCIP_CONS *cons, SCIP_Real ub)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_RETCODE SCIPsetLinearConsIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_CONS *lincons)
SCIP_RETCODE SCIPmakeIndicatorFeasible(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_Bool *changed)
type definitions for return codes for SCIP methods
type definitions for LP management
SCIP_VAR * SCIPgetSlackVarIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateConsBasicIndicator(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs)
type definitions for SCIP&#39;s main datastructure
SCIP_VAR * SCIPgetBinaryVarIndicatorGeneric(SCIP_CONS *cons)
type definitions for problem variables
SCIP_RETCODE SCIPaddLinearConsIndicator(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *lincons)
#define SCIP_Bool
Definition: def.h:84
SCIP_RETCODE SCIPcreateConsIndicatorLinCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, SCIP_CONS *lincons, SCIP_VAR *slackvar, 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_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
type definitions for storing primal CIP solutions
SCIP_Bool SCIPgetActiveOnIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPincludeConshdlrIndicator(SCIP *scip)
SCIP_RETCODE SCIPsetBinaryVarIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *binvar)
SCIP_RETCODE SCIPcreateConsIndicator(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs, 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 SCIPcreateConsIndicatorGenericLinCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, SCIP_CONS *lincons, SCIP_VAR *slackvar, SCIP_Bool activeone, 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)
#define SCIP_Real
Definition: def.h:177
SCIP_RETCODE SCIPaddRowIndicator(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_ROW *row)
SCIP_RETCODE SCIPcreateConsBasicIndicatorLinCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, SCIP_CONS *lincons, SCIP_VAR *slackvar)
SCIP_RETCODE SCIPmakeIndicatorsFeasible(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_Bool *changed)
common defines and data types used in all packages of SCIP
SCIP_CONS * SCIPgetLinearConsIndicator(SCIP_CONS *cons)
type definitions for constraints and constraint handlers