Scippy

SCIP

Solving Constraint Integer Programs

cons_knapsack.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_knapsack.h
17  * @ingroup CONSHDLRS
18  * @brief Constraint handler for knapsack constraints of the form \f$a^T x \le b\f$, x binary and \f$a \ge 0\f$.
19  * @author Tobias Achterberg
20  * @author Kati Wolter
21  * @author Michael Winkler
22  *
23  */
24 
25 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
26 
27 #ifndef __SCIP_CONS_KNAPSACK_H__
28 #define __SCIP_CONS_KNAPSACK_H__
29 
30 #include "scip/scip.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /** creates the handler for knapsack constraints and includes it in SCIP
37  *
38  * @ingroup ConshdlrIncludes
39  * */
40 extern
42  SCIP* scip /**< SCIP data structure */
43  );
44 
45 /**@addtogroup CONSHDLRS
46  *
47  * @{
48  *
49  * @name Knapsack Constraints
50  *
51  * @{
52  *
53  * This constraint handler handles a special type of linear constraints, namely knapsack constraints.
54  * A knapsack constraint has the form
55  * \f[
56  * \sum_{i=1}^n a_i x_i \leq b
57  * \f]
58  * with non-negative integer coefficients \f$a_i\f$, integer right-hand side \f$b\f$, and binary variables \f$x_i\f$.
59  */
60 
61 /** creates and captures a knapsack constraint
62  *
63  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
64  */
65 extern
67  SCIP* scip, /**< SCIP data structure */
68  SCIP_CONS** cons, /**< pointer to hold the created constraint */
69  const char* name, /**< name of constraint */
70  int nvars, /**< number of items in the knapsack */
71  SCIP_VAR** vars, /**< array with item variables */
72  SCIP_Longint* weights, /**< array with item weights */
73  SCIP_Longint capacity, /**< capacity of knapsack (right hand side of inequality) */
74  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
75  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
76  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
77  * Usually set to TRUE. */
78  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
79  * TRUE for model constraints, FALSE for additional, redundant constraints. */
80  SCIP_Bool check, /**< should the constraint be checked for feasibility?
81  * TRUE for model constraints, FALSE for additional, redundant constraints. */
82  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
83  * Usually set to TRUE. */
84  SCIP_Bool local, /**< is constraint only valid locally?
85  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
86  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
87  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
88  * adds coefficients to this constraint. */
89  SCIP_Bool dynamic, /**< is constraint subject to aging?
90  * Usually set to FALSE. Set to TRUE for own cuts which
91  * are separated as constraints. */
92  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
93  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
94  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
95  * if it may be moved to a more global node?
96  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
97  );
98 
99 /** creates and captures a knapsack constraint
100  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
101  * method SCIPcreateConsKnapsack(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
102  *
103  * @see SCIPcreateConsKnapsack() for information about the basic constraint flag configuration
104  *
105  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
106  */
107 extern
109  SCIP* scip, /**< SCIP data structure */
110  SCIP_CONS** cons, /**< pointer to hold the created constraint */
111  const char* name, /**< name of constraint */
112  int nvars, /**< number of items in the knapsack */
113  SCIP_VAR** vars, /**< array with item variables */
114  SCIP_Longint* weights, /**< array with item weights */
115  SCIP_Longint capacity /**< capacity of knapsack */
116  );
117 
118 /** adds new item to knapsack constraint */
119 extern
121  SCIP* scip, /**< SCIP data structure */
122  SCIP_CONS* cons, /**< constraint data */
123  SCIP_VAR* var, /**< item variable */
124  SCIP_Longint weight /**< item weight */
125  );
126 
127 /** gets the capacity of the knapsack constraint */
128 extern
130  SCIP* scip, /**< SCIP data structure */
131  SCIP_CONS* cons /**< constraint data */
132  );
133 
134 /** changes capacity of the knapsack constraint
135  *
136  * @note This method can only be called during problem creation stage (SCIP_STAGE_PROBLEM)
137  */
138 extern
140  SCIP* scip, /**< SCIP data structure */
141  SCIP_CONS* cons, /**< constraint data */
142  SCIP_Longint capacity /**< new capacity of knapsack */
143  );
144 
145 /** gets the number of items in the knapsack constraint */
146 extern
148  SCIP* scip, /**< SCIP data structure */
149  SCIP_CONS* cons /**< constraint data */
150  );
151 
152 /** gets the array of variables in the knapsack constraint; the user must not modify this array! */
153 extern
155  SCIP* scip, /**< SCIP data structure */
156  SCIP_CONS* cons /**< constraint data */
157  );
158 
159 /** gets the array of weights in the knapsack constraint; the user must not modify this array! */
160 extern
162  SCIP* scip, /**< SCIP data structure */
163  SCIP_CONS* cons /**< constraint data */
164  );
165 
166 /** gets the dual solution of the knapsack constraint in the current LP */
167 extern
169  SCIP* scip, /**< SCIP data structure */
170  SCIP_CONS* cons /**< constraint data */
171  );
172 
173 /** gets the dual Farkas value of the knapsack constraint in the current infeasible LP */
174 extern
176  SCIP* scip, /**< SCIP data structure */
177  SCIP_CONS* cons /**< constraint data */
178  );
179 
180 /** returns the linear relaxation of the given knapsack constraint; may return NULL if no LP row was yet created;
181  * the user must not modify the row!
182  */
183 extern
185  SCIP* scip, /**< SCIP data structure */
186  SCIP_CONS* cons /**< constraint data */
187  );
188 
189 /** solves knapsack problem in maximization form exactly using dynamic programming;
190  * if needed, one can provide arrays to store all selected items and all not selected items
191  */
192 extern
194  SCIP* scip, /**< SCIP data structure */
195  int nitems, /**< number of available items */
196  SCIP_Longint* weights, /**< item weights */
197  SCIP_Real* profits, /**< item profits */
198  SCIP_Longint capacity, /**< capacity of knapsack */
199  int* items, /**< item numbers */
200  int* solitems, /**< array to store items in solution, or NULL */
201  int* nonsolitems, /**< array to store items not in solution, or NULL */
202  int* nsolitems, /**< pointer to store number of items in solution, or NULL */
203  int* nnonsolitems, /**< pointer to store number of items not in solution, or NULL */
204  SCIP_Real* solval, /**< pointer to store optimal solution value, or NULL */
205  SCIP_Bool* success /**< pointer to store if an error occured during solving
206  * (normally a memory problem) */
207  );
208 
209 /** solves knapsack problem in maximization form approximately by solving the LP-relaxation of the problem using Dantzig's
210  * method and rounding down the solution; if needed, one can provide arrays to store all selected items and all not
211  * selected items
212  */
213 extern
215  SCIP* scip, /**< SCIP data structure */
216  int nitems, /**< number of available items */
217  SCIP_Longint* weights, /**< item weights */
218  SCIP_Real* profits, /**< item profits */
219  SCIP_Longint capacity, /**< capacity of knapsack */
220  int* items, /**< item numbers */
221  int* solitems, /**< array to store items in solution, or NULL */
222  int* nonsolitems, /**< array to store items not in solution, or NULL */
223  int* nsolitems, /**< pointer to store number of items in solution, or NULL */
224  int* nnonsolitems, /**< pointer to store number of items not in solution, or NULL */
225  SCIP_Real* solval /**< pointer to store optimal solution value, or NULL */
226  );
227 
228 /** separates different classes of valid inequalities for the 0-1 knapsack problem */
229 extern
231  SCIP* scip, /**< SCIP data structure */
232  SCIP_CONS* cons, /**< originating constraint of the knapsack problem, or NULL */
233  SCIP_SEPA* sepa, /**< originating separator of the knapsack problem, or NULL */
234  SCIP_VAR** vars, /**< variables in knapsack constraint */
235  int nvars, /**< number of variables in knapsack constraint */
236  SCIP_Longint* weights, /**< weights of variables in knapsack constraint */
237  SCIP_Longint capacity, /**< capacity of knapsack */
238  SCIP_SOL* sol, /**< primal SCIP solution to separate, NULL for current LP solution */
239  SCIP_Bool usegubs, /**< should GUB information be used for separation? */
240  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff has been detected */
241  int* ncuts /**< pointer to add up the number of found cuts */
242  );
243 
244 /* relaxes given general linear constraint into a knapsack constraint and separates lifted knapsack cover inequalities */
245 extern
247  SCIP* scip, /**< SCIP data structure */
248  SCIP_CONS* cons, /**< originating constraint of the knapsack problem, or NULL */
249  SCIP_SEPA* sepa, /**< originating separator of the knapsack problem, or NULL */
250  int nknapvars, /**< number of variables in the continuous knapsack constraint */
251  SCIP_VAR** knapvars, /**< variables in the continuous knapsack constraint */
252  SCIP_Real* knapvals, /**< coefficients of the variables in the continuous knapsack constraint */
253  SCIP_Real valscale, /**< -1.0 if lhs of row is used as rhs of c. k. constraint, +1.0 otherwise */
254  SCIP_Real rhs, /**< right hand side of the continuous knapsack constraint */
255  SCIP_SOL* sol, /**< primal CIP solution, NULL for current LP solution */
256  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff was found */
257  int* ncuts /**< pointer to add up the number of found cuts */
258  );
259 
260 /* @} */
261 
262 /* @} */
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif
SCIP_RETCODE SCIPsolveKnapsackExactly(SCIP *scip, int nitems, SCIP_Longint *weights, SCIP_Real *profits, SCIP_Longint capacity, int *items, int *solitems, int *nonsolitems, int *nsolitems, int *nnonsolitems, SCIP_Real *solval, SCIP_Bool *success)
SCIP_RETCODE SCIPseparateKnapsackCuts(SCIP *scip, SCIP_CONS *cons, SCIP_SEPA *sepa, SCIP_VAR **vars, int nvars, SCIP_Longint *weights, SCIP_Longint capacity, SCIP_SOL *sol, SCIP_Bool usegubs, SCIP_Bool *cutoff, int *ncuts)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPsolveKnapsackApproximately(SCIP *scip, int nitems, SCIP_Longint *weights, SCIP_Real *profits, SCIP_Longint capacity, int *items, int *solitems, int *nonsolitems, int *nsolitems, int *nnonsolitems, SCIP_Real *solval)
SCIP_VAR ** SCIPgetVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualsolKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddCoefKnapsack(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Longint weight)
SCIP_RETCODE SCIPchgCapacityKnapsack(SCIP *scip, SCIP_CONS *cons, SCIP_Longint capacity)
SCIP_RETCODE SCIPcreateConsKnapsack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Longint *weights, SCIP_Longint capacity, 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_RETCODE SCIPcreateConsBasicKnapsack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Longint *weights, SCIP_Longint capacity)
SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Bool
Definition: def.h:61
SCIP_RETCODE SCIPincludeConshdlrKnapsack(SCIP *scip)
#define SCIP_Real
Definition: def.h:135
int SCIPgetNVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Longint
Definition: def.h:120
SCIP_Real SCIPgetDualfarkasKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_ROW * SCIPgetRowKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPseparateRelaxedKnapsack(SCIP *scip, SCIP_CONS *cons, SCIP_SEPA *sepa, int nknapvars, SCIP_VAR **knapvars, SCIP_Real *knapvals, SCIP_Real valscale, SCIP_Real rhs, SCIP_SOL *sol, SCIP_Bool *cutoff, int *ncuts)
SCIP callable library.