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