1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*                  This file is part of the program and library             */
4 /*         SCIP --- Solving Constraint Integer Programs                      */
5 /*                                                                           */
6 /*    Copyright (C) 2002-2021 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 scipopt.org.         */
13 /*                                                                           */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file   cons_linking.h
17  * @ingroup CONSHDLRS
18  * @brief  constraint handler for linking binary variables to a linking (continuous or integer) variable
19  * @author Stefan Heinz
20  * @author Jens Schulz
21  *
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #ifndef __SCIP_CONS_LINKING_H__
27 #define __SCIP_CONS_LINKING_H__
28 
29 
30 #include "scip/def.h"
31 #include "scip/type_cons.h"
32 #include "scip/type_retcode.h"
33 #include "scip/type_scip.h"
34 #include "scip/type_var.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /** creates the handler for linking constraints and includes it in SCIP
41  *
42  * @ingroup ConshdlrIncludes
43  * */
44 SCIP_EXPORT
45 SCIP_RETCODE SCIPincludeConshdlrLinking(
46    SCIP*                 scip                /**< SCIP data structure */
47    );
48 
49 /**@addtogroup CONSHDLRS
50  *
51  * @{
52  *
53  * @name Linking Constraints
54  *
55  * @{
56  *
57  * The constraints handler stores linking constraints between a linking variable (continuous or integer) and an array of binary variables. Such
58  * a linking constraint has the form:
59  * \f[
60  * y = \sum_{i=1}^n {c_i * x_i}
61  * \f]
62  * with linking variable (continuous or integer) \f$ y \f$, binary variables \f$ x_1, \dots, x_n \f$ and offset \f$b \in Q\f$, and
63  * with the additional side condition that exactly one binary variable has to be one (set partitioning condition).
64  *
65  * This constraint can be created only with the linking variable, if it is an integer variable. In this case the binary variables are only created on
66  * demand. That is, whenever someone asks for the binary variables. Therefore, such constraints can be used to get a
67  * "binary representation" of the domain of the linking variable which will be dynamically created.
68  */
69 
70 /** creates and captures a linking constraint
71  *
72  *  @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
73  */
74 SCIP_EXPORT
75 SCIP_RETCODE SCIPcreateConsLinking(
76    SCIP*                 scip,               /**< SCIP data structure */
77    SCIP_CONS**           cons,               /**< pointer to hold the created constraint */
78    const char*           name,               /**< name of constraint */
79    SCIP_VAR*             linkvar,            /**< linking variable (continuous or integer) which should be linked */
80    SCIP_VAR**            binvars,            /**< binary variables */
81    SCIP_Real*            vals,               /**< coefficients of the binary variables */
82    int                   nbinvars,           /**< number of binary starting variables */
83    SCIP_Bool             initial,            /**< should the LP relaxation of constraint be in the initial LP?
84                                               *   Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
85    SCIP_Bool             separate,           /**< should the constraint be separated during LP processing?
86                                               *   Usually set to TRUE. */
87    SCIP_Bool             enforce,            /**< should the constraint be enforced during node processing?
88                                               *   TRUE for model constraints, FALSE for additional, redundant constraints. */
89    SCIP_Bool             check,              /**< should the constraint be checked for feasibility?
90                                               *   TRUE for model constraints, FALSE for additional, redundant constraints. */
91    SCIP_Bool             propagate,          /**< should the constraint be propagated during node processing?
92                                               *   Usually set to TRUE. */
93    SCIP_Bool             local,              /**< is constraint only valid locally?
94                                               *   Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
95    SCIP_Bool             modifiable,         /**< is constraint modifiable (subject to column generation)?
96                                               *   Usually set to FALSE. In column generation applications, set to TRUE if pricing
97                                               *   adds coefficients to this constraint. */
98    SCIP_Bool             dynamic,            /**< is constraint subject to aging?
99                                               *   Usually set to FALSE. Set to TRUE for own cuts which
100                                               *   are separated as constraints. */
101    SCIP_Bool             removable,          /**< should the relaxation be removed from the LP due to aging or cleanup?
102                                               *   Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
103    SCIP_Bool             stickingatnode      /**< should the constraint always be kept at the node where it was added, even
104                                               *   if it may be moved to a more global node?
105                                               *   Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
106    );
107 
108 /** creates and captures a linking constraint
109  *  in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
110  *  method SCIPcreateConsLinking(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
111  *
112  *  @see SCIPcreateConsLinking() for information about the basic constraint flag configuration
113  *
114  *  @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
115  */
116 SCIP_EXPORT
117 SCIP_RETCODE SCIPcreateConsBasicLinking(
118    SCIP*                 scip,               /**< SCIP data structure */
119    SCIP_CONS**           cons,               /**< pointer to hold the created constraint */
120    const char*           name,               /**< name of constraint */
121    SCIP_VAR*             linkvar,            /**< linking variable (continuous or integer) which should be linked */
122    SCIP_VAR**            binvars,            /**< binary variables, or NULL */
123    SCIP_Real*            vals,               /**< coefficients of the binary variables */
124    int                   nbinvars            /**< number of binary variables */
125    );
126 
127 
128 /** checks if for the given linking variable (continuous or integer) a linking constraint exists */
129 SCIP_EXPORT
130 SCIP_Bool SCIPexistsConsLinking(
131    SCIP*                 scip,               /**< SCIP data structure */
132    SCIP_VAR*             linkvar             /**< linking variable (continuous or integer) which should be linked */
133    );
134 
135 /** returns the linking constraint belonging the given linking variable (continuous or integer) or NULL if it does not exist yet */
136 SCIP_EXPORT
137 SCIP_CONS* SCIPgetConsLinking(
138    SCIP*                 scip,               /**< SCIP data structure */
139    SCIP_VAR*             linkvar             /**< linking variable (continuous or integer) which should be linked */
140    );
141 
142 /** returns the linking variable (continuous or integer) of the linking constraint */
143 SCIP_EXPORT
144 SCIP_VAR* SCIPgetLinkvarLinking(
145    SCIP*                 scip,               /**< SCIP data structure */
146    SCIP_CONS*            cons                /**< linking constraint */
147    );
148 
149 /** returns the binary variables of the linking constraint */
150 SCIP_EXPORT
151 SCIP_RETCODE SCIPgetBinvarsLinking(
152    SCIP*                 scip,               /**< SCIP data structure */
153    SCIP_CONS*            cons,               /**< linking constraint */
154    SCIP_VAR***           binvars,            /**< pointer to store the binary variables array pointer */
155    int*                  nbinvars            /**< pointer to store the number of returned binary variables */
156    );
157 
158 /** returns the number of binary variables of the linking constraint */
159 SCIP_EXPORT
160 int SCIPgetNBinvarsLinking(
161    SCIP*                 scip,               /**< SCIP data structure */
162    SCIP_CONS*            cons                /**< linking constraint */
163    );
164 
165 /** returns the coefficients of the binary variables */
166 SCIP_EXPORT
167 SCIP_Real* SCIPgetValsLinking(
168    SCIP*                 scip,               /**< SCIP data structure */
169    SCIP_CONS*            cons                /**< linking constraint */
170    );
171 
172 /** return all binary variable information of the linking constraint */
173 SCIP_EXPORT
174 SCIP_RETCODE SCIPgetBinvarsDataLinking(
175    SCIP_CONS*            cons,               /**< linking constraint */
176    SCIP_VAR***           binvars,            /**< pointer to store binary variables, or NULL */
177    SCIP_Real**           vals,               /**< pointer to store the binary coefficients, or NULL */
178    int*                  nbinvars            /**< pointer to store the number of binary variables, or NULL */
179    );
180 
181 /** @} */
182 
183 /** @} */
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
190