Scippy

SCIP

Solving Constraint Integer Programs

cons_cardinality.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-2024 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file cons_cardinality.h
26 * @ingroup CONSHDLRS
27 * @brief constraint handler for cardinality constraints
28 * @author Tobias Fischer
29 *
30 */
31
32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
33
34#ifndef __SCIP_CONS_CARDINALITY_H__
35#define __SCIP_CONS_CARDINALITY_H__
36
37
38#include "scip/def.h"
39#include "scip/type_cons.h"
40#include "scip/type_retcode.h"
41#include "scip/type_scip.h"
42#include "scip/type_var.h"
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/** creates the handler for cardinality constraints and includes it in SCIP
49 *
50 * @ingroup ConshdlrIncludes
51 * */
52SCIP_EXPORT
54 SCIP* scip /**< SCIP data structure */
55 );
56
57/**@addtogroup CONSHDLRS
58 *
59 * @{
60 *
61 * @name Cardinality Constraints
62 *
63 * @{
64 *
65 * This constraint handler handles cardinality constraints of the form
66 * \f[
67 * |\mbox{supp}(x)| \leq b
68 * \f]
69 * with integer right-hand side \f$b\f$. Here, \f$|\mbox{supp}(x)|\f$ denotes the number of nonzero entries of the
70 * vector \f$x\f$.
71 *
72 * Cardinality constraints generalize special ordered set of type one (SOS1) constraints in which \f$b = 1\f$.
73 */
74
75/** creates and captures an cardinality constraint
76 *
77 * We set the constraint to not be modifable. If the weights are non
78 * NULL, the variables are ordered according to these weights (in
79 * ascending order).
80 *
81 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
82 */
83SCIP_EXPORT
85 SCIP* scip, /**< SCIP data structure */
86 SCIP_CONS** cons, /**< pointer to hold the created constraint */
87 const char* name, /**< name of constraint */
88 int nvars, /**< number of variables in the constraint */
89 SCIP_VAR** vars, /**< array with variables of constraint entries */
90 int cardval, /**< number of variables allowed to be nonzero */
91 SCIP_VAR** indvars, /**< indicator variables to indicate which variables may be treated as nonzero
92 * in cardinality constraint, or NULL if indicator variables should be
93 * created automatically */
94 SCIP_Real* weights, /**< weights determining the variable order, or NULL if variables should be
95 * ordered in the same way they were added to the constraint */
96 SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
97 * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
98 SCIP_Bool separate, /**< should the constraint be separated during LP processing?
99 * Usually set to TRUE. */
100 SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
101 * TRUE for model constraints, FALSE for additional, redundant constraints. */
102 SCIP_Bool check, /**< should the constraint be checked for feasibility?
103 * TRUE for model constraints, FALSE for additional, redundant constraints. */
104 SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
105 * Usually set to TRUE. */
106 SCIP_Bool local, /**< is constraint only valid locally?
107 * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
108 SCIP_Bool dynamic, /**< is constraint subject to aging?
109 * Usually set to FALSE. Set to TRUE for own cuts which
110 * are separated as constraints. */
111 SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
112 * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
113 SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
114 * if it may be moved to a more global node?
115 * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
116 );
117
118/** creates and captures an cardinality constraint
119 * in its most basic variant, i. e., with all constraint flags set to their default values, which can be set
120 * afterwards using SCIPsetConsFLAGNAME() in scip.h
121 *
122 * @see SCIPcreateConsCardinality() for the default constraint flag configuration
123 *
124 * @warning Do NOT set the constraint to be modifiable manually, because this might lead
125 * to wrong results as the variable array will not be resorted
126 *
127 * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
128 */
129SCIP_EXPORT
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 variables in the constraint */
135 SCIP_VAR** vars, /**< array with variables of constraint entries */
136 int cardval, /**< number of variables allowed to be nonzero */
137 SCIP_VAR** indvars, /**< indicator variables to indicate which variables may be treated as nonzero
138 * in cardinality constraint, or NULL if indicator variables should be
139 * created automatically */
140 SCIP_Real* weights /**< weights determining the variable order, or NULL if variables should be
141 * ordered in the same way they were added to the constraint */
142 );
143
144/** changes cardinality value of cardinality constraint (i.e., right hand side of cardinality constraint) */
145SCIP_EXPORT
147 SCIP* scip, /**< SCIP data structure */
148 SCIP_CONS* cons, /**< pointer to hold the created constraint */
149 int cardval /**< number of variables allowed to be nonzero */
150 );
151
152/** adds variable to cardinality constraint, the position is determined by the given weight */
153SCIP_EXPORT
155 SCIP* scip, /**< SCIP data structure */
156 SCIP_CONS* cons, /**< constraint */
157 SCIP_VAR* var, /**< variable to add to the constraint */
158 SCIP_VAR* indvar, /**< indicator variable to indicate whether variable may be treated as nonzero
159 * in cardinality constraint (or NULL if this variable should be created
160 * automatically) */
161 SCIP_Real weight /**< weight determining position of variable */
162 );
163
164/** appends variable to cardinality constraint */
165SCIP_EXPORT
167 SCIP* scip, /**< SCIP data structure */
168 SCIP_CONS* cons, /**< constraint */
169 SCIP_VAR* var, /**< variable to add to the constraint */
170 SCIP_VAR* indvar /**< indicator variable to indicate whether variable may be treated as nonzero
171 * in cardinality constraint (or NULL if this variable should be created
172 * automatically) */
173 );
174
175/** gets number of variables in cardinality constraint */
176SCIP_EXPORT
178 SCIP* scip, /**< SCIP data structure */
179 SCIP_CONS* cons /**< constraint */
180 );
181
182/** gets array of variables in cardinality constraint */
183SCIP_EXPORT
185 SCIP* scip, /**< SCIP data structure */
186 SCIP_CONS* cons /**< constraint data */
187 );
188
189/** gets cardinality value of cardinality constraint (i.e., right hand side of cardinality constraint) */
190SCIP_EXPORT
192 SCIP* scip, /**< SCIP data structure */
193 SCIP_CONS* cons /**< constraint data */
194 );
195
196/** gets array of weights in cardinality constraint (or NULL if not existent) */
197SCIP_EXPORT
199 SCIP* scip, /**< SCIP data structure */
200 SCIP_CONS* cons /**< constraint data */
201 );
202
203/** @} */
204
205/** @} */
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif
common defines and data types used in all packages of SCIP
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:173
SCIP_Real * SCIPgetWeightsCardinality(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateConsCardinality(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, int cardval, SCIP_VAR **indvars, SCIP_Real *weights, 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_RETCODE SCIPcreateConsBasicCardinality(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, int cardval, SCIP_VAR **indvars, SCIP_Real *weights)
int SCIPgetCardvalCardinality(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPappendVarCardinality(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar)
SCIP_RETCODE SCIPaddVarCardinality(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar, SCIP_Real weight)
int SCIPgetNVarsCardinality(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsCardinality(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPchgCardvalCardinality(SCIP *scip, SCIP_CONS *cons, int cardval)
SCIP_RETCODE SCIPincludeConshdlrCardinality(SCIP *scip)
type definitions for constraints and constraint handlers
type definitions for return codes for SCIP methods
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
type definitions for SCIP's main datastructure
type definitions for problem variables