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-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_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/scip.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /** creates the handler for indicator 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 Indicator Constraints
49  *
50  * @{
51  *
52  * An indicator constraint is given by a binary variable \f$z\f$ and an inequality \f$ax \leq
53  * b\f$. It states that if \f$z = 1\f$ then \f$ax \leq b\f$ holds.
54  *
55  * This constraint is handled by adding a slack variable \f$s:\; ax - s \leq b\f$ with \f$s \geq
56  * 0\f$. The constraint is enforced by fixing \f$s\f$ to 0 if \f$z = 1\f$.
57  *
58  * @note The constraint only implements an implication not an equivalence, i.e., it does not ensure
59  * that \f$z = 1\f$ if \f$ax \leq b\f$ or equivalently if \f$s = 0\f$ holds.
60  *
61  * This constraint is equivalent to a linear constraint \f$ax - s \leq b\f$ and an SOS1 constraint on
62  * \f$z\f$ and \f$s\f$ (at most one should be nonzero). In the indicator context we can, however,
63  * separate more inequalities.
64  */
65 
66 /** creates and captures an indicator constraint
67  *
68  * @note @a binvar is checked to be binary only later. This enables a change of the type in
69  * procedures reading an instance.
70  *
71  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
72  */
73 extern
75  SCIP* scip, /**< SCIP data structure */
76  SCIP_CONS** cons, /**< pointer to hold the created constraint (indicator or quadratic) */
77  const char* name, /**< name of constraint */
78  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
79  int nvars, /**< number of variables in the inequality */
80  SCIP_VAR** vars, /**< array with variables of inequality (or NULL) */
81  SCIP_Real* vals, /**< values of variables in inequality (or NULL) */
82  SCIP_Real rhs, /**< rhs of the inequality */
83  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
84  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
85  * Usually set to TRUE. */
86  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
87  * TRUE for model constraints, FALSE for additional, redundant constraints. */
88  SCIP_Bool check, /**< should the constraint be checked for feasibility?
89  * TRUE for model constraints, FALSE for additional, redundant constraints. */
90  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
91  * Usually set to TRUE. */
92  SCIP_Bool local, /**< is constraint only valid locally?
93  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
94  SCIP_Bool dynamic, /**< is constraint subject to aging?
95  * Usually set to FALSE. Set to TRUE for own cuts which
96  * are separated as constraints. */
97  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
98  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
99  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
100  * if it may be moved to a more global node?
101  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
102  );
103 
104 /** creates and captures an indicator constraint in its most basic version, i. e., all constraint flags are set to their
105  * basic value as explained for the method SCIPcreateConsIndicator(); all flags can be set via
106  * SCIPsetConsFLAGNAME-methods in scip.h
107  *
108  * @see SCIPcreateConsIndicator() for information about the basic constraint flag configuration
109  *
110  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
111  */
112 extern
114  SCIP* scip, /**< SCIP data structure */
115  SCIP_CONS** cons, /**< pointer to hold the created constraint (indicator or quadratic) */
116  const char* name, /**< name of constraint */
117  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
118  int nvars, /**< number of variables in the inequality */
119  SCIP_VAR** vars, /**< array with variables of inequality (or NULL) */
120  SCIP_Real* vals, /**< values of variables in inequality (or NULL) */
121  SCIP_Real rhs /**< rhs of the inequality */
122  );
123 
124 /** creates and captures an indicator constraint with given linear constraint and slack variable
125  *
126  * @note @a binvar is checked to be binary only later. This enables a change of the type in
127  * procedures reading an instance.
128  *
129  * @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
130  * the role of a slack variable!
131  *
132  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
133  */
134 extern
136  SCIP* scip, /**< SCIP data structure */
137  SCIP_CONS** cons, /**< pointer to hold the created constraint */
138  const char* name, /**< name of constraint */
139  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
140  SCIP_CONS* lincons, /**< linear constraint */
141  SCIP_VAR* slackvar, /**< slack variable */
142  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? Usually set to TRUE. */
143  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
144  * Usually set to TRUE. */
145  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
146  * TRUE for model constraints, FALSE for additional, redundant constraints. */
147  SCIP_Bool check, /**< should the constraint be checked for feasibility?
148  * TRUE for model constraints, FALSE for additional, redundant constraints. */
149  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
150  * Usually set to TRUE. */
151  SCIP_Bool local, /**< is constraint only valid locally?
152  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
153  SCIP_Bool dynamic, /**< is constraint subject to aging?
154  * Usually set to FALSE. Set to TRUE for own cuts which
155  * are separated as constraints. */
156  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
157  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
158  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
159  * if it may be moved to a more global node?
160  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
161  );
162 
163 /** creates and captures an indicator constraint with given linear constraint and slack variable
164  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
165  * method SCIPcreateConsIndicator(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
166 
167  * @note @a binvar is checked to be binary only later. This enables a change of the type in
168  * procedures reading an instance.
169  *
170  * @note we assume that @a slackvar actually appears in @a lincons and we also assume that it takes
171  * the role of a slack variable!
172  *
173  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
174  *
175  * @see SCIPcreateConsIndicatorLinCons() for information about the basic constraint flag configuration
176  *
177  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
178  */
179 extern
181  SCIP* scip, /**< SCIP data structure */
182  SCIP_CONS** cons, /**< pointer to hold the created constraint */
183  const char* name, /**< name of constraint */
184  SCIP_VAR* binvar, /**< binary indicator variable (or NULL) */
185  SCIP_CONS* lincons, /**< linear constraint */
186  SCIP_VAR* slackvar /**< slack variable */
187  );
188 
189 /** adds variable to the inequality of the indicator constraint */
190 extern
192  SCIP* scip, /**< SCIP data structure */
193  SCIP_CONS* cons, /**< indicator constraint */
194  SCIP_VAR* var, /**< variable to add to the inequality */
195  SCIP_Real val /**< value of variable */
196  );
197 
198 /** gets the linear constraint corresponding to the indicator constraint (may be NULL) */
199 extern
201  SCIP_CONS* cons /**< indicator constraint */
202  );
203 
204 /** sets the linear constraint corresponding to the indicator constraint (may be NULL) */
205 extern
207  SCIP* scip, /**< SCIP data structure */
208  SCIP_CONS* cons, /**< indicator constraint */
209  SCIP_CONS* lincons /**< linear constraint */
210  );
211 
212 /** sets binary indicator variable for indicator constraint */
213 extern
215  SCIP* scip, /**< SCIP data structure */
216  SCIP_CONS* cons, /**< indicator constraint */
217  SCIP_VAR* binvar /**< binary variable to add to the inequality */
218  );
219 
220 /** gets binary variable corresponding to indicator constraint */
221 extern
223  SCIP_CONS* cons /**< indicator constraint */
224  );
225 
226 /** gets slack variable corresponding to indicator constraint */
227 extern
229  SCIP_CONS* cons /**< indicator constraint */
230  );
231 
232 /** checks whether indicator constraint is violated w.r.t. sol */
233 extern
235  SCIP* scip, /**< SCIP data structure */
236  SCIP_CONS* cons, /**< indicator constraint */
237  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
238  );
239 
240 /** based on values of other variables, computes slack and binary variable to turn constraint feasible */
241 extern
243  SCIP* scip, /**< SCIP data structure */
244  SCIP_CONS* cons, /**< indicator constraint */
245  SCIP_SOL* sol, /**< solution */
246  SCIP_Bool* changed /**< pointer to store whether the solution has been changed */
247  );
248 
249 /** based on values of other variables, computes slack and binary variable to turn all constraints feasible */
250 extern
252  SCIP* scip, /**< SCIP data structure */
253  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
254  SCIP_SOL* sol, /**< solution */
255  SCIP_Bool* changed /**< pointer to store whether the solution has been changed */
256  );
257 
258 /** adds additional linear constraint that is not connected with an indicator constraint, but can be used for separation */
259 extern
261  SCIP* scip, /**< SCIP data structure */
262  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
263  SCIP_CONS* lincons /**< linear constraint */
264  );
265 
266 /** adds additional globally valid row that is not connected with an indicator constraint, but can be used for separation */
267 extern
269  SCIP* scip, /**< SCIP data structure */
270  SCIP_CONSHDLR* conshdlr, /**< indicator constraint handler */
271  SCIP_ROW* row /**< row to add */
272  );
273 
274 /* @} */
275 
276 /* @} */
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #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)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
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)
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)
SCIP_RETCODE SCIPaddLinearConsIndicator(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *lincons)
#define SCIP_Bool
Definition: def.h:61
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)
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)
#define SCIP_Real
Definition: def.h:135
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)
SCIP_CONS * SCIPgetLinearConsIndicator(SCIP_CONS *cons)
SCIP callable library.