Scippy

SCIP

Solving Constraint Integer Programs

cons_linear.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-2019 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cons_linear.h
17  * @ingroup CONSHDLRS
18  * @brief Constraint handler for linear constraints in their most general form, \f$lhs <= a^T x <= rhs\f$.
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Marc Pfetsch
22  * @author Kati Wolter
23  *
24  */
25 
26 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
27 
28 #ifndef __SCIP_CONS_LINEAR_H__
29 #define __SCIP_CONS_LINEAR_H__
30 
31 #include "scip/def.h"
32 #include "scip/type_cons.h"
33 #include "scip/type_lp.h"
34 #include "scip/type_misc.h"
35 #include "scip/type_retcode.h"
36 #include "scip/type_scip.h"
37 #include "scip/type_sol.h"
38 #include "scip/type_var.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 
45 
46 /*
47  * constraint specific interface methods
48  */
49 
50 /** creates the handler for linear constraints and includes it in SCIP
51  *
52  * @ingroup ConshdlrIncludes
53  * */
54 extern
56  SCIP* scip /**< SCIP data structure */
57  );
58 
59 /**@addtogroup CONSHDLRS
60  *
61  * @{
62  *
63  * @name Linear Constraints
64  *
65  * This constraint handler handles linear constraints in their most general form. That is,
66  * \f[
67  * lhs \leq \sum_{i=1}^n a_i x_i \leq rhs
68  * \f]
69  * with \f$a_i \in Q, i = 1,\dots,n\f$, \f$lhs\in Q \cup \{-\infty\}\f$, \f$rhs\in Q \cup \{\infty\}\f$,
70  * and decision variables \f$x_i, i = 1,\dots,n\f$ which can be binary, integer, or continuous.
71  *
72  * Furthermore, this header offers the upgrade functionality of a general linear constraint into a more specific
73  * constraint, such as a knapsack constraint, via SCIP_DECL_LINCONSUPGD() and SCIPincludeLinconsUpgrade()
74  *
75  * @{
76  */
77 
78 typedef struct SCIP_LinConsUpgrade SCIP_LINCONSUPGRADE; /**< linear constraint update method */
79 
80 /** upgrading method for linear constraints into more specific constraints
81  *
82  * input:
83  * - scip : SCIP main data structure
84  * - cons : the linear constraint to upgrade
85  * - nvars : number of variables in the constraint
86  * - vars : array with constraint variables
87  * - vals : array with constraint coefficients
88  * - lhs : left hand side of linear constraint
89  * - rhs : right hand side of linear constraint
90  * - nposbin : number of binary variables with positive coefficient
91  * - nnegbin : number of binary variables with negative coefficient
92  * - nposint : number of integer variables with positive coefficient
93  * - nnegint : number of integer variables with negative coefficient
94  * - nposimpl : number of implicit integer variables with positive coefficient (including implicit binary variables)
95  * - nnegimpl : number of implicit integer variables with negative coefficient (including implicit binary variables)
96  * - nposimplbin : number of implicit binary variables with positive coefficient
97  * - nnegimplbin : number of implicit binary variables with negative coefficient
98  * - nposcont : number of continuous variables with positive coefficient
99  * - nnegcont : number of continuous variables with negative coefficient
100  * - ncoeffspone : number of +1 coefficients
101  * - ncoeffsnone : number of -1 coefficients
102  * - ncoeffspint : number of positive integral coefficients other than +1
103  * - ncoeffsnint : number of negative integral coefficients other than -1
104  * - ncoeffspfrac : number of positive fractional coefficients
105  * - ncoeffsnfrac : number of negative fractional coefficients
106  * - poscoeffsum : sum of all positive coefficients
107  * - negcoeffsum : sum of all negative coefficients
108  * - integral : TRUE iff constraints activity value is always integral
109  * - upgdcons : pointer to store the upgraded constraint
110  */
111 #define SCIP_DECL_LINCONSUPGD(x) SCIP_RETCODE x (SCIP* scip, SCIP_CONS* cons, int nvars, SCIP_VAR** vars, SCIP_Real* vals, SCIP_Real lhs, SCIP_Real rhs, \
112  int nposbin, int nnegbin, int nposint, int nnegint, int nposimpl, int nnegimpl, int nposimplbin, int nnegimplbin, int nposcont, int nnegcont, \
113  int ncoeffspone, int ncoeffsnone, int ncoeffspint, int ncoeffsnint, int ncoeffspfrac, int ncoeffsnfrac, \
114  SCIP_Real poscoeffsum, SCIP_Real negcoeffsum, SCIP_Bool integral, SCIP_CONS** upgdcons)
115 
116 /** includes a linear constraint update method into the linear constraint handler */
117 extern
119  SCIP* scip, /**< SCIP data structure */
120  SCIP_DECL_LINCONSUPGD((*linconsupgd)), /**< method to call for upgrading linear constraint */
121  int priority, /**< priority of upgrading method */
122  const char* conshdlrname /**< name of the constraint handler */
123  );
124 
125 /** creates and captures a linear constraint
126  *
127  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
128  */
129 extern
131  SCIP* scip, /**< SCIP data structure */
132  SCIP_CONS** cons, /**< pointer to hold the created constraint */
133  const char* name, /**< name of constraint */
134  int nvars, /**< number of nonzeros in the constraint */
135  SCIP_VAR** vars, /**< array with variables of constraint entries */
136  SCIP_Real* vals, /**< array with coefficients of constraint entries */
137  SCIP_Real lhs, /**< left hand side of constraint */
138  SCIP_Real rhs, /**< right hand side of constraint */
139  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
140  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
141  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
142  * Usually set to TRUE. */
143  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
144  * TRUE for model constraints, FALSE for additional, redundant constraints. */
145  SCIP_Bool check, /**< should the constraint be checked for feasibility?
146  * TRUE for model constraints, FALSE for additional, redundant constraints. */
147  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
148  * Usually set to TRUE. */
149  SCIP_Bool local, /**< is constraint only valid locally?
150  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
151  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
152  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
153  * adds coefficients to this constraint. */
154  SCIP_Bool dynamic, /**< is constraint subject to aging?
155  * Usually set to FALSE. Set to TRUE for own cuts which
156  * are separated as constraints. */
157  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
158  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
159  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
160  * if it may be moved to a more global node?
161  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
162  );
163 
164 /** creates and captures a linear constraint
165  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
166  * method SCIPcreateConsLinear(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
167  *
168  * @see SCIPcreateConsLinear() for information about the basic constraint flag configuration
169  *
170  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
171  */
172 extern
174  SCIP* scip, /**< SCIP data structure */
175  SCIP_CONS** cons, /**< pointer to hold the created constraint */
176  const char* name, /**< name of constraint */
177  int nvars, /**< number of nonzeros in the constraint */
178  SCIP_VAR** vars, /**< array with variables of constraint entries */
179  SCIP_Real* vals, /**< array with coefficients of constraint entries */
180  SCIP_Real lhs, /**< left hand side of constraint */
181  SCIP_Real rhs /**< right hand side of constraint */
182  );
183 
184 /** creates by copying and captures a linear constraint */
185 extern
187  SCIP* scip, /**< target SCIP data structure */
188  SCIP_CONS** cons, /**< pointer to store the created target constraint */
189  SCIP* sourcescip, /**< source SCIP data structure */
190  const char* name, /**< name of constraint */
191  int nvars, /**< number of variables in source variable array */
192  SCIP_VAR** sourcevars, /**< source variables of the linear constraints */
193  SCIP_Real* sourcecoefs, /**< coefficient array of the linear constraint, or NULL if all coefficients are one */
194  SCIP_Real lhs, /**< left hand side of the linear constraint */
195  SCIP_Real rhs, /**< right hand side of the linear constraint */
196  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to corresponding
197  * variables of the target SCIP */
198  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
199  * target constraints */
200  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? */
201  SCIP_Bool separate, /**< should the constraint be separated during LP processing? */
202  SCIP_Bool enforce, /**< should the constraint be enforced during node processing? */
203  SCIP_Bool check, /**< should the constraint be checked for feasibility? */
204  SCIP_Bool propagate, /**< should the constraint be propagated during node processing? */
205  SCIP_Bool local, /**< is constraint only valid locally? */
206  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)? */
207  SCIP_Bool dynamic, /**< is constraint subject to aging? */
208  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? */
209  SCIP_Bool stickingatnode, /**< should the constraint always be kept at the node where it was added, even
210  * if it may be moved to a more global node? */
211  SCIP_Bool global, /**< create a global or a local copy? */
212  SCIP_Bool* valid /**< pointer to store if the copying was valid */
213  );
214 
215 /** adds coefficient to linear constraint (if it is not zero) */
216 extern
218  SCIP* scip, /**< SCIP data structure */
219  SCIP_CONS* cons, /**< constraint data */
220  SCIP_VAR* var, /**< variable of constraint entry */
221  SCIP_Real val /**< coefficient of constraint entry */
222  );
223 
224 /** changes coefficient of variable in linear constraint; deletes the variable if coefficient is zero; adds variable if
225  * not yet contained in the constraint
226  *
227  * @note This method may only be called during problem creation stage for an original constraint and variable.
228  *
229  * @note This method requires linear time to search for occurences of the variable in the constraint data.
230  */
231 extern
233  SCIP* scip, /**< SCIP data structure */
234  SCIP_CONS* cons, /**< constraint data */
235  SCIP_VAR* var, /**< variable of constraint entry */
236  SCIP_Real val /**< new coefficient of constraint entry */
237  );
238 
239 /** deletes variable from linear constraint
240  *
241  * @note This method may only be called during problem creation stage for an original constraint and variable.
242  *
243  * @note This method requires linear time to search for occurences of the variable in the constraint data.
244  */
245 extern
247  SCIP* scip, /**< SCIP data structure */
248  SCIP_CONS* cons, /**< constraint data */
249  SCIP_VAR* var /**< variable of constraint entry */
250  );
251 
252 /** gets left hand side of linear constraint */
253 extern
255  SCIP* scip, /**< SCIP data structure */
256  SCIP_CONS* cons /**< constraint data */
257  );
258 
259 /** gets right hand side of linear constraint */
260 extern
262  SCIP* scip, /**< SCIP data structure */
263  SCIP_CONS* cons /**< constraint data */
264  );
265 
266 /** changes left hand side of linear constraint */
267 extern
269  SCIP* scip, /**< SCIP data structure */
270  SCIP_CONS* cons, /**< constraint data */
271  SCIP_Real lhs /**< new left hand side */
272  );
273 
274 /** changes right hand side of linear constraint */
275 extern
277  SCIP* scip, /**< SCIP data structure */
278  SCIP_CONS* cons, /**< constraint data */
279  SCIP_Real rhs /**< new right hand side */
280  );
281 
282 /** gets the number of variables in the linear constraint */
283 extern
285  SCIP* scip, /**< SCIP data structure */
286  SCIP_CONS* cons /**< constraint data */
287  );
288 
289 /** gets the array of variables in the linear constraint; the user must not modify this array! */
290 extern
292  SCIP* scip, /**< SCIP data structure */
293  SCIP_CONS* cons /**< constraint data */
294  );
295 
296 /** gets the array of coefficient values in the linear constraint; the user must not modify this array! */
297 extern
299  SCIP* scip, /**< SCIP data structure */
300  SCIP_CONS* cons /**< constraint data */
301  );
302 
303 /** gets the activity of the linear constraint in the given solution
304  *
305  * @note if the solution contains values at infinity, this method will return SCIP_INVALID in case the activity
306  * comprises positive and negative infinity contributions
307  */
308 extern
310  SCIP* scip, /**< SCIP data structure */
311  SCIP_CONS* cons, /**< constraint data */
312  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
313  );
314 
315 /** gets the feasibility of the linear constraint in the given solution */
316 extern
318  SCIP* scip, /**< SCIP data structure */
319  SCIP_CONS* cons, /**< constraint data */
320  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
321  );
322 
323 /** gets the dual solution of the linear constraint in the current LP */
324 extern
326  SCIP* scip, /**< SCIP data structure */
327  SCIP_CONS* cons /**< constraint data */
328  );
329 
330 /** gets the dual Farkas value of the linear constraint in the current infeasible LP */
331 extern
333  SCIP* scip, /**< SCIP data structure */
334  SCIP_CONS* cons /**< constraint data */
335  );
336 
337 /** returns the linear relaxation of the given linear constraint; may return NULL if no LP row was yet created;
338  * the user must not modify the row!
339  */
340 extern
342  SCIP* scip, /**< SCIP data structure */
343  SCIP_CONS* cons /**< constraint data */
344  );
345 
346 /** tries to automatically convert a linear constraint into a more specific and more specialized constraint */
347 extern
349  SCIP* scip, /**< SCIP data structure */
350  SCIP_CONS* cons, /**< source constraint to try to convert */
351  SCIP_CONS** upgdcons /**< pointer to store upgraded constraint, or NULL if not successful */
352  );
353 
354 /** performs linear constraint type classification as used for MIPLIB
355  *
356  * iterates through all linear constraints and stores relevant statistics in the linear constraint statistics \p linconsstats.
357  *
358  * @note only constraints are iterated that belong to the linear constraint handler. If the problem has been presolved already,
359  * constraints that were upgraded to more special types such as, e.g., varbound constraints, will not be shown correctly anymore.
360  * Similarly, if specialized constraints were created through the API, these are currently not present.
361  */
362 extern
364  SCIP* scip, /**< SCIP data structure */
365  SCIP_LINCONSSTATS* linconsstats /**< linear constraint type classification */
366  );
367 
368 
369 /* @} */
370 
371 /* @} */
372 
373 #ifdef __cplusplus
374 }
375 #endif
376 
377 #endif
#define SCIP_DECL_LINCONSUPGD(x)
Definition: cons_linear.h:111
SCIP_Real SCIPgetActivityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
SCIP_RETCODE SCIPincludeConshdlrLinear(SCIP *scip)
type definitions for miscellaneous datastructures
SCIP_RETCODE SCIPcreateConsBasicLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs)
SCIP_RETCODE SCIPcopyConsLinear(SCIP *scip, SCIP_CONS **cons, SCIP *sourcescip, const char *name, int nvars, SCIP_VAR **sourcevars, SCIP_Real *sourcecoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, 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_Bool global, SCIP_Bool *valid)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_ROW * SCIPgetRowLinear(SCIP *scip, SCIP_CONS *cons)
type definitions for return codes for SCIP methods
SCIP_RETCODE SCIPdelCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
type definitions for LP management
SCIP_Real SCIPgetDualsolLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPupgradeConsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_CONS **upgdcons)
type definitions for SCIP&#39;s main datastructure
type definitions for problem variables
SCIP_Real SCIPgetDualfarkasLinear(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Bool
Definition: def.h:69
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
SCIP_Real SCIPgetFeasibilityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
SCIP_RETCODE SCIPclassifyConstraintTypesLinear(SCIP *scip, SCIP_LINCONSSTATS *linconsstats)
type definitions for storing primal CIP solutions
SCIP_RETCODE SCIPincludeLinconsUpgrade(SCIP *scip, SCIP_DECL_LINCONSUPGD((*linconsupgd)), int priority, const char *conshdlrname)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, 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 ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Real
Definition: def.h:157
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPchgLhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real lhs)
common defines and data types used in all packages of SCIP
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
type definitions for constraints and constraint handlers
SCIP_RETCODE SCIPchgCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)