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-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_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/scip.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 
38 
39 /*
40  * constraint specific interface methods
41  */
42 
43 /** creates the handler for linear constraints and includes it in SCIP
44  *
45  * @ingroup ConshdlrIncludes
46  * */
47 extern
49  SCIP* scip /**< SCIP data structure */
50  );
51 
52 /**@addtogroup CONSHDLRS
53  *
54  * @{
55  *
56  * @name Linear Constraints
57  *
58  * This constraint handler handles linear constraints in their most general form. That is,
59  * \f[
60  * lhs \leq \sum_{i=1}^n a_i x_i \leq rhs
61  * \f]
62  * 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$,
63  * and decision variables \f$x_i, i = 1,\dots,n\f$ which can be binary, integer, or continuous.
64  *
65  * Furthermore, this header offers the upgrade functionality of a general linear constraint into a more specific
66  * constraint, such as a knapsack constraint, via SCIP_DECL_LINCONSUPGD() and SCIPincludeLinconsUpgrade()
67  *
68  * @{
69  */
70 
71 typedef struct SCIP_LinConsUpgrade SCIP_LINCONSUPGRADE; /**< linear constraint update method */
72 
73 /** upgrading method for linear constraints into more specific constraints
74  *
75  * input:
76  * - scip : SCIP main data structure
77  * - cons : the linear constraint to upgrade
78  * - nvars : number of variables in the constraint
79  * - vars : array with constraint variables
80  * - vals : array with constraint coefficients
81  * - lhs : left hand side of linear constraint
82  * - rhs : right hand side of linear constraint
83  * - nposbin : number of binary variables with positive coefficient
84  * - nnegbin : number of binary variables with negative coefficient
85  * - nposint : number of integer variables with positive coefficient
86  * - nnegint : number of integer variables with negative coefficient
87  * - nposimpl : number of implicit integer variables with positive coefficient (including implicit binary variables)
88  * - nnegimpl : number of implicit integer variables with negative coefficient (including implicit binary variables)
89  * - nposimplbin : number of implicit binary variables with positive coefficient
90  * - nnegimplbin : number of implicit binary variables with negative coefficient
91  * - nposcont : number of continuous variables with positive coefficient
92  * - nnegcont : number of continuous variables with negative coefficient
93  * - ncoeffspone : number of +1 coefficients
94  * - ncoeffsnone : number of -1 coefficients
95  * - ncoeffspint : number of positive integral coefficients other than +1
96  * - ncoeffsnint : number of negative integral coefficients other than -1
97  * - ncoeffspfrac : number of positive fractional coefficients
98  * - ncoeffsnfrac : number of negative fractional coefficients
99  * - poscoeffsum : sum of all positive coefficients
100  * - negcoeffsum : sum of all negative coefficients
101  * - integral : TRUE iff constraints activity value is always integral
102  * - upgdcons : pointer to store the upgraded constraint
103  */
104 #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, \
105  int nposbin, int nnegbin, int nposint, int nnegint, int nposimpl, int nnegimpl, int nposimplbin, int nnegimplbin, int nposcont, int nnegcont, \
106  int ncoeffspone, int ncoeffsnone, int ncoeffspint, int ncoeffsnint, int ncoeffspfrac, int ncoeffsnfrac, \
107  SCIP_Real poscoeffsum, SCIP_Real negcoeffsum, SCIP_Bool integral, SCIP_CONS** upgdcons)
108 
109 /** includes a linear constraint update method into the linear constraint handler */
110 extern
112  SCIP* scip, /**< SCIP data structure */
113  SCIP_DECL_LINCONSUPGD((*linconsupgd)), /**< method to call for upgrading linear constraint */
114  int priority, /**< priority of upgrading method */
115  const char* conshdlrname /**< name of the constraint handler */
116  );
117 
118 /** creates and captures a linear constraint
119  *
120  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
121  */
122 extern
124  SCIP* scip, /**< SCIP data structure */
125  SCIP_CONS** cons, /**< pointer to hold the created constraint */
126  const char* name, /**< name of constraint */
127  int nvars, /**< number of nonzeros in the constraint */
128  SCIP_VAR** vars, /**< array with variables of constraint entries */
129  SCIP_Real* vals, /**< array with coefficients of constraint entries */
130  SCIP_Real lhs, /**< left hand side of constraint */
131  SCIP_Real rhs, /**< right hand side of constraint */
132  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
133  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
134  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
135  * Usually set to TRUE. */
136  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
137  * TRUE for model constraints, FALSE for additional, redundant constraints. */
138  SCIP_Bool check, /**< should the constraint be checked for feasibility?
139  * TRUE for model constraints, FALSE for additional, redundant constraints. */
140  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
141  * Usually set to TRUE. */
142  SCIP_Bool local, /**< is constraint only valid locally?
143  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
144  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
145  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
146  * adds coefficients to this constraint. */
147  SCIP_Bool dynamic, /**< is constraint subject to aging?
148  * Usually set to FALSE. Set to TRUE for own cuts which
149  * are separated as constraints. */
150  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
151  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
152  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
153  * if it may be moved to a more global node?
154  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
155  );
156 
157 /** creates and captures a linear constraint
158  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
159  * method SCIPcreateConsLinear(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
160  *
161  * @see SCIPcreateConsLinear() for information about the basic constraint flag configuration
162  *
163  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
164  */
165 extern
167  SCIP* scip, /**< SCIP data structure */
168  SCIP_CONS** cons, /**< pointer to hold the created constraint */
169  const char* name, /**< name of constraint */
170  int nvars, /**< number of nonzeros in the constraint */
171  SCIP_VAR** vars, /**< array with variables of constraint entries */
172  SCIP_Real* vals, /**< array with coefficients of constraint entries */
173  SCIP_Real lhs, /**< left hand side of constraint */
174  SCIP_Real rhs /**< right hand side of constraint */
175  );
176 
177 /** creates by copying and captures a linear constraint */
178 extern
180  SCIP* scip, /**< target SCIP data structure */
181  SCIP_CONS** cons, /**< pointer to store the created target constraint */
182  SCIP* sourcescip, /**< source SCIP data structure */
183  const char* name, /**< name of constraint */
184  int nvars, /**< number of variables in source variable array */
185  SCIP_VAR** sourcevars, /**< source variables of the linear constraints */
186  SCIP_Real* sourcecoefs, /**< coefficient array of the linear constraint, or NULL if all coefficients are one */
187  SCIP_Real lhs, /**< left hand side of the linear constraint */
188  SCIP_Real rhs, /**< right hand side of the linear constraint */
189  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to corresponding
190  * variables of the target SCIP */
191  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
192  * target constraints */
193  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? */
194  SCIP_Bool separate, /**< should the constraint be separated during LP processing? */
195  SCIP_Bool enforce, /**< should the constraint be enforced during node processing? */
196  SCIP_Bool check, /**< should the constraint be checked for feasibility? */
197  SCIP_Bool propagate, /**< should the constraint be propagated during node processing? */
198  SCIP_Bool local, /**< is constraint only valid locally? */
199  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)? */
200  SCIP_Bool dynamic, /**< is constraint subject to aging? */
201  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? */
202  SCIP_Bool stickingatnode, /**< should the constraint always be kept at the node where it was added, even
203  * if it may be moved to a more global node? */
204  SCIP_Bool global, /**< create a global or a local copy? */
205  SCIP_Bool* valid /**< pointer to store if the copying was valid */
206  );
207 
208 /** adds coefficient to linear constraint (if it is not zero) */
209 extern
211  SCIP* scip, /**< SCIP data structure */
212  SCIP_CONS* cons, /**< constraint data */
213  SCIP_VAR* var, /**< variable of constraint entry */
214  SCIP_Real val /**< coefficient of constraint entry */
215  );
216 
217 /** changes coefficient of variable in linear constraint; deletes the variable if coefficient is zero; adds variable if
218  * not yet contained in the constraint
219  *
220  * @note This method may only be called during problem creation stage for an original constraint and variable.
221  *
222  * @note This method requires linear time to search for occurences of the variable in the constraint data.
223  */
224 extern
226  SCIP* scip, /**< SCIP data structure */
227  SCIP_CONS* cons, /**< constraint data */
228  SCIP_VAR* var, /**< variable of constraint entry */
229  SCIP_Real val /**< new coefficient of constraint entry */
230  );
231 
232 /** deletes variable from linear constraint
233  *
234  * @note This method may only be called during problem creation stage for an original constraint and variable.
235  *
236  * @note This method requires linear time to search for occurences of the variable in the constraint data.
237  */
238 extern
240  SCIP* scip, /**< SCIP data structure */
241  SCIP_CONS* cons, /**< constraint data */
242  SCIP_VAR* var /**< variable of constraint entry */
243  );
244 
245 /** gets left hand side of linear constraint */
246 extern
248  SCIP* scip, /**< SCIP data structure */
249  SCIP_CONS* cons /**< constraint data */
250  );
251 
252 /** gets right hand side of linear constraint */
253 extern
255  SCIP* scip, /**< SCIP data structure */
256  SCIP_CONS* cons /**< constraint data */
257  );
258 
259 /** changes left hand side of linear constraint */
260 extern
262  SCIP* scip, /**< SCIP data structure */
263  SCIP_CONS* cons, /**< constraint data */
264  SCIP_Real lhs /**< new left hand side */
265  );
266 
267 /** changes right hand side of linear constraint */
268 extern
270  SCIP* scip, /**< SCIP data structure */
271  SCIP_CONS* cons, /**< constraint data */
272  SCIP_Real rhs /**< new right hand side */
273  );
274 
275 /** gets the number of variables in the linear constraint */
276 extern
278  SCIP* scip, /**< SCIP data structure */
279  SCIP_CONS* cons /**< constraint data */
280  );
281 
282 /** gets the array of variables in the linear constraint; the user must not modify this array! */
283 extern
285  SCIP* scip, /**< SCIP data structure */
286  SCIP_CONS* cons /**< constraint data */
287  );
288 
289 /** gets the array of coefficient values 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 activity of the linear constraint in the given solution
297  *
298  * @note if the solution contains values at infinity, this method will return SCIP_INVALID in case the activity
299  * comprises positive and negative infinity contributions
300  */
301 extern
303  SCIP* scip, /**< SCIP data structure */
304  SCIP_CONS* cons, /**< constraint data */
305  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
306  );
307 
308 /** gets the feasibility of the linear constraint in the given solution */
309 extern
311  SCIP* scip, /**< SCIP data structure */
312  SCIP_CONS* cons, /**< constraint data */
313  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
314  );
315 
316 /** gets the dual solution of the linear constraint in the current LP */
317 extern
319  SCIP* scip, /**< SCIP data structure */
320  SCIP_CONS* cons /**< constraint data */
321  );
322 
323 /** gets the dual Farkas value of the linear constraint in the current infeasible LP */
324 extern
326  SCIP* scip, /**< SCIP data structure */
327  SCIP_CONS* cons /**< constraint data */
328  );
329 
330 /** returns the linear relaxation of the given linear constraint; may return NULL if no LP row was yet created;
331  * the user must not modify the row!
332  */
333 extern
335  SCIP* scip, /**< SCIP data structure */
336  SCIP_CONS* cons /**< constraint data */
337  );
338 
339 /** tries to automatically convert a linear constraint into a more specific and more specialized constraint */
340 extern
342  SCIP* scip, /**< SCIP data structure */
343  SCIP_CONS* cons, /**< source constraint to try to convert */
344  SCIP_CONS** upgdcons /**< pointer to store upgraded constraint, or NULL if not successful */
345  );
346 
347 
348 /* @} */
349 
350 /* @} */
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif
#define SCIP_DECL_LINCONSUPGD(x)
Definition: cons_linear.h:104
SCIP_Real SCIPgetActivityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
SCIP_RETCODE SCIPincludeConshdlrLinear(SCIP *scip)
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)
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)
SCIP_Real SCIPgetDualsolLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPupgradeConsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_CONS **upgdcons)
SCIP_Real SCIPgetDualfarkasLinear(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Bool
Definition: def.h:61
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
SCIP_Real SCIPgetFeasibilityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
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:135
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPchgLhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real lhs)
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP callable library.
SCIP_RETCODE SCIPchgCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)