1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the program and library             */
4    	/*         SCIP --- Solving Constraint Integer Programs                      */
5    	/*                                                                           */
6    	/*  Copyright (c) 2002-2023 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_sos1.h
26   	 * @ingroup CONSHDLRS
27   	 * @brief  constraint handler for SOS type 1 constraints
28   	 * @author Tobias Fischer
29   	 * @author Marc Pfetsch
30   	 *
31   	 */
32   	
33   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34   	
35   	#ifndef __SCIP_CONS_SOS1_H__
36   	#define __SCIP_CONS_SOS1_H__
37   	
38   	
39   	#include "scip/def.h"
40   	#include "scip/type_cons.h"
41   	#include "scip/type_misc.h"
42   	#include "scip/type_retcode.h"
43   	#include "scip/type_scip.h"
44   	#include "scip/type_sol.h"
45   	#include "scip/type_var.h"
46   	
47   	#ifdef __cplusplus
48   	extern "C" {
49   	#endif
50   	
51   	/** creates the handler for SOS1 constraints and includes it in SCIP
52   	 *
53   	 * @ingroup ConshdlrIncludes
54   	 * */
55   	SCIP_EXPORT
56   	SCIP_RETCODE SCIPincludeConshdlrSOS1(
57   	   SCIP*                 scip                /**< SCIP data structure */
58   	   );
59   	
60   	/**@addtogroup CONSHDLRS
61   	 *
62   	 * @{
63   	 *
64   	 * @name Specially Ordered Set (SOS) Type 1 Constraints
65   	 *
66   	 * @{
67   	 *
68   	 * A specially ordered set of type 1 (SOS1) is a sequence of variables such that at most one
69   	 * variable is nonzero. The special case of two variables arises, for instance, from equilibrium or
70   	 * complementary conditions like \f$x \cdot y = 0\f$. Note that it is in principle allowed that a
71   	 * variable appears twice, but it then can be fixed to 0.
72   	 */
73   	
74   	/** creates and captures an SOS1 constraint
75   	 *
76   	 *  We set the constraint to not be modifable. If the weights are non
77   	 *  NULL, the variables are ordered according to these weights (in
78   	 *  ascending order).
79   	 *
80   	 *  @note The constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons().
81   	 */
82   	SCIP_EXPORT
83   	SCIP_RETCODE SCIPcreateConsSOS1(
84   	   SCIP*                 scip,               /**< SCIP data structure */
85   	   SCIP_CONS**           cons,               /**< pointer to hold the created constraint */
86   	   const char*           name,               /**< name of constraint */
87   	   int                   nvars,              /**< number of variables in the constraint */
88   	   SCIP_VAR**            vars,               /**< array with variables of constraint entries */
89   	   SCIP_Real*            weights,            /**< weights determining the variable order, or NULL if natural order should be used */
90   	   SCIP_Bool             initial,            /**< should the LP relaxation of constraint be in the initial LP?
91   	                                              *   Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
92   	   SCIP_Bool             separate,           /**< should the constraint be separated during LP processing?
93   	                                              *   Usually set to TRUE. */
94   	   SCIP_Bool             enforce,            /**< should the constraint be enforced during node processing?
95   	                                              *   TRUE for model constraints, FALSE for additional, redundant constraints. */
96   	   SCIP_Bool             check,              /**< should the constraint be checked for feasibility?
97   	                                              *   TRUE for model constraints, FALSE for additional, redundant constraints. */
98   	   SCIP_Bool             propagate,          /**< should the constraint be propagated during node processing?
99   	                                              *   Usually set to TRUE. */
100  	   SCIP_Bool             local,              /**< is constraint only valid locally?
101  	                                              *   Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
102  	   SCIP_Bool             dynamic,            /**< is constraint subject to aging?
103  	                                              *   Usually set to FALSE. Set to TRUE for own cuts which
104  	                                              *   are separated as constraints. */
105  	   SCIP_Bool             removable,          /**< should the relaxation be removed from the LP due to aging or cleanup?
106  	                                              *   Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
107  	   SCIP_Bool             stickingatnode      /**< should the constraint always be kept at the node where it was added, even
108  	                                              *   if it may be moved to a more global node?
109  	                                              *   Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
110  	   );
111  	
112  	/** creates and captures an SOS1 constraint
113  	 *  in its most basic variant, i. e., with all constraint flags set to their default values, which can be set
114  	 *  afterwards using SCIPsetConsFLAGNAME() in scip.h
115  	 *
116  	 *  @see SCIPcreateConsSOS1() for the default constraint flag configuration
117  	 *
118  	 *  @warning Do NOT set the constraint to be modifiable manually, because this might lead
119  	 *  to wrong results as the variable array will not be resorted
120  	 *
121  	 *  @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
122  	 */
123  	SCIP_EXPORT
124  	SCIP_RETCODE SCIPcreateConsBasicSOS1(
125  	   SCIP*                 scip,               /**< SCIP data structure */
126  	   SCIP_CONS**           cons,               /**< pointer to hold the created constraint */
127  	   const char*           name,               /**< name of constraint */
128  	   int                   nvars,              /**< number of variables in the constraint */
129  	   SCIP_VAR**            vars,               /**< array with variables of constraint entries */
130  	   SCIP_Real*            weights             /**< weights determining the variable order, or NULL if natural order should be used */
131  	   );
132  	
133  	/** adds variable to SOS1 constraint, the position is determined by the given weight */
134  	SCIP_EXPORT
135  	SCIP_RETCODE SCIPaddVarSOS1(
136  	   SCIP*                 scip,               /**< SCIP data structure */
137  	   SCIP_CONS*            cons,               /**< constraint */
138  	   SCIP_VAR*             var,                /**< variable to add to the constraint */
139  	   SCIP_Real             weight              /**< weight determining position of variable */
140  	   );
141  	
142  	/** appends variable to SOS1 constraint */
143  	SCIP_EXPORT
144  	SCIP_RETCODE SCIPappendVarSOS1(
145  	   SCIP*                 scip,               /**< SCIP data structure */
146  	   SCIP_CONS*            cons,               /**< constraint */
147  	   SCIP_VAR*             var                 /**< variable to add to the constraint */
148  	   );
149  	
150  	/** gets number of variables in SOS1 constraint */
151  	SCIP_EXPORT
152  	int SCIPgetNVarsSOS1(
153  	   SCIP*                 scip,               /**< SCIP data structure */
154  	   SCIP_CONS*            cons                /**< constraint */
155  	   );
156  	
157  	/** gets array of variables in SOS1 constraint */
158  	SCIP_EXPORT
159  	SCIP_VAR** SCIPgetVarsSOS1(
160  	   SCIP*                 scip,               /**< SCIP data structure */
161  	   SCIP_CONS*            cons                /**< constraint data */
162  	   );
163  	
164  	/** gets array of weights in SOS1 constraint (or NULL if not existent) */
165  	SCIP_EXPORT
166  	SCIP_Real* SCIPgetWeightsSOS1(
167  	   SCIP*                 scip,               /**< SCIP data structure */
168  	   SCIP_CONS*            cons                /**< constraint data */
169  	   );
170  	
171  	/** gets conflict graph of SOS1 constraints (or NULL if not existent)
172  	 *
173  	 *  @note The conflict graph is globally valid; local changes are not taken into account.
174  	 */
175  	SCIP_EXPORT
176  	SCIP_DIGRAPH* SCIPgetConflictgraphSOS1(
177  	   SCIP_CONSHDLR*        conshdlr            /**< SOS1 constraint handler */
178  	   );
179  	
180  	/** gets number of problem variables that are part of the SOS1 conflict graph */
181  	SCIP_EXPORT
182  	int SCIPgetNSOS1Vars(
183  	   SCIP_CONSHDLR*        conshdlr            /**< SOS1 constraint handler */
184  	   );
185  	
186  	/** returns whether variable is part of the SOS1 conflict graph */
187  	SCIP_EXPORT
188  	SCIP_Bool SCIPvarIsSOS1(
189  	   SCIP_CONSHDLR*        conshdlr,           /**< SOS1 constraint handler */
190  	   SCIP_VAR*             var                 /**< variable */
191  	   );
192  	
193  	/** returns node of variable in the conflict graph or -1 if variable is not part of the SOS1 conflict graph */
194  	SCIP_EXPORT
195  	int SCIPvarGetNodeSOS1(
196  	   SCIP_CONSHDLR*        conshdlr,           /**< SOS1 constraint handler */
197  	   SCIP_VAR*             var                 /**< variable */
198  	   );
199  	
200  	/** returns variable that belongs to a given node from the conflict graph */
201  	SCIP_EXPORT
202  	SCIP_VAR* SCIPnodeGetVarSOS1(
203  	   SCIP_DIGRAPH*         conflictgraph,      /**< conflict graph */
204  	   int                   node                /**< node from the conflict graph */
205  	   );
206  	
207  	/** based on solution values of the variables, fixes variables to zero to turn all SOS1 constraints feasible  */
208  	SCIP_EXPORT
209  	SCIP_RETCODE SCIPmakeSOS1sFeasible(
210  	   SCIP*                 scip,               /**< SCIP pointer */
211  	   SCIP_CONSHDLR*        conshdlr,           /**< SOS1 constraint handler */
212  	   SCIP_SOL*             sol,                /**< solution */
213  	   SCIP_Bool*            changed,            /**< pointer to store whether the solution has been changed */
214  	   SCIP_Bool*            success             /**< pointer to store whether SOS1 constraints have been turned feasible and
215  	                                              *   solution was good enough */
216  	   );
217  	
218  	/** @} */
219  	
220  	/** @} */
221  	
222  	#ifdef __cplusplus
223  	}
224  	#endif
225  	
226  	#endif
227