Scippy

SCIP

Solving Constraint Integer Programs

type_benders.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-2025 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 type_benders.h
26 * @ingroup TYPEDEFINITIONS
27 * @brief type definitions for Benders' decomposition methods
28 * @author Stephen J. Maher
29 */
30
31/** @defgroup DEFPLUGINS_BENDERS Default Benders handler plugins
32 * @ingroup DEFPLUGINS
33 * @brief implementation files (.c files) of the default benders handler plugins of SCIP
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37
38#ifndef __SCIP_TYPE_BENDERS_H__
39#define __SCIP_TYPE_BENDERS_H__
40
41#include "scip/def.h"
42#include "scip/type_retcode.h"
43#include "scip/type_scip.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
50{
51 SCIP_BENDERSENFOTYPE_LP = 1, /**< the Benders' subproblems are solved during the enforcement of an LP solution */
52 SCIP_BENDERSENFOTYPE_RELAX = 2, /**< the Benders' subproblems are solved during the enforcement of a relaxation solution */
53 SCIP_BENDERSENFOTYPE_PSEUDO = 3, /**< the Benders' subproblems are solved during the enforcement of a pseudo solution */
54 SCIP_BENDERSENFOTYPE_CHECK = 4 /**< the Benders' subproblems are solved during the checking of a solution for feasibility */
55};
56typedef enum SCIP_BendersEnfoType SCIP_BENDERSENFOTYPE; /**< indicates the callback in cons_benders and cons_benderslp that triggered the subproblem solve */
57
59{
60 SCIP_BENDERSSOLVELOOP_CONVEX = 0, /**< the relaxation is solved in this iteration of the loop */
61 SCIP_BENDERSSOLVELOOP_CIP = 1, /**< the CIP is solved in this iteration of the loop */
62 SCIP_BENDERSSOLVELOOP_USERCONVEX = 2, /**< the user defined solve function is called */
63 SCIP_BENDERSSOLVELOOP_USERCIP = 3 /**< the user defined solve function is called */
64};
65typedef enum SCIP_BendersSolveLoop SCIP_BENDERSSOLVELOOP; /**< identifies the type of problem solved in each solve loop */
66
68{
69 SCIP_BENDERSSUBSTATUS_UNKNOWN = 0, /**< the subsystem status is unknown */
70 SCIP_BENDERSSUBSTATUS_OPTIMAL = 1, /**< the subsystem is solved to be optimal */
71 SCIP_BENDERSSUBSTATUS_AUXVIOL = 2, /**< the subproblem is optimal, but the auxiliary variable is violated */
72 SCIP_BENDERSSUBSTATUS_INFEAS = 3 /**< the subproblem is solved to be infeasible */
73};
75
77{
78 SCIP_BENDERSSUBTYPE_CONVEXCONT = 0, /**< the subproblem has convex constraints and continuous variables */
79 SCIP_BENDERSSUBTYPE_CONVEXDIS = 1, /**< the subproblem has convex constraints and discrete variables */
80 SCIP_BENDERSSUBTYPE_NONCONVEXCONT = 2, /**< the subproblem has non-convex constraints and continuous variables */
81 SCIP_BENDERSSUBTYPE_NONCONVEXDIS = 3, /**< the subproblem has non-convex constraints and discrete variables */
82 SCIP_BENDERSSUBTYPE_UNKNOWN = 4, /**< the default type before the type is known */
83};
85
86typedef struct SCIP_Benders SCIP_BENDERS; /**< Benders' decomposition data */
87typedef struct SCIP_BendersData SCIP_BENDERSDATA; /**< locally defined Benders' decomposition data */
88typedef struct SCIP_SubproblemSolveStat SCIP_SUBPROBLEMSOLVESTAT; /**< the solving statistics of the subproblems */
89
90
91/** copy method for Benders' decomposition plugins (called when SCIP copies plugins). If there is an active Benders'
92 * decomposition, all copies are not valid. As such, there is no valid parameter that is passed to the callback
93 * function
94 *
95 * input:
96 * - scip : SCIP main data structure
97 * - benders : the Benders' decomposition itself
98 * - threadsafe : must the Benders' decomposition copy be thread safe
99 */
100#define SCIP_DECL_BENDERSCOPY(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_Bool threadsafe)
101
102/** destructor of Benders' decomposition to free user data (called when SCIP is exiting)
103 *
104 * input:
105 * - scip : SCIP main data structure
106 * - benders : the Benders' decomposition itself
107 */
108#define SCIP_DECL_BENDERSFREE(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
109
110/** initialization method of Benders' decomposition (called after problem was transformed and the Benders' decomposition
111 * is active)
112 *
113 * input:
114 * - scip : SCIP main data structure
115 * - benders : the Benders' decomposition itself
116 */
117#define SCIP_DECL_BENDERSINIT(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
118
119/** deinitialization method of Benders' decomposition (called before transformed problem is freed and the Benders'
120 * decomposition is active)
121 *
122 * input:
123 * - scip : SCIP main data structure
124 * - benders : the Benders' decomposition itself
125 */
126#define SCIP_DECL_BENDERSEXIT(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
127
128/** presolving initialization method of the Benders' decomposition (called when presolving is about to begin)
129 *
130 * This function is called immediately after the auxiliary variables are created in the master problem. The callback
131 * provides the user an opportunity to add variable data to the auxiliary variables.
132 *
133 * input:
134 * - scip : SCIP main data structure
135 * - benders : the Benders' decomposition itself
136 */
137#define SCIP_DECL_BENDERSINITPRE(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
138
139/** presolving deinitialization method of the Benders' decomposition (called after presolving has been finished)
140 *
141 * input:
142 * - scip : SCIP main data structure
143 * - benders : the Benders' decomposition itself
144 */
145#define SCIP_DECL_BENDERSEXITPRE(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
146
147/** solving process initialization method of Benders' decomposition (called when branch and bound process is about to begin)
148 *
149 * This method is called when the presolving was finished and the branch and bound process is about to begin.
150 * The Benders' decomposition may use this call to initialize its branch and bound specific data.
151 *
152 * input:
153 * - scip : SCIP main data structure
154 * - benders : the Benders' decomposition itself
155 */
156#define SCIP_DECL_BENDERSINITSOL(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
157
158/** solving process deinitialization method of Benders' decomposition (called before branch and bound process data is freed)
159 *
160 * This method is called before the branch and bound process is freed.
161 * The Benders' decomposition should use this call to clean up its branch and bound data.
162 *
163 * input:
164 * - scip : SCIP main data structure
165 * - benders : the Benders' decomposition itself
166 */
167#define SCIP_DECL_BENDERSEXITSOL(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders)
168
169/** the method for creating the Benders' decomposition subproblem. This method is called during the initialisation stage
170 * (after the master problem was transformed).
171 *
172 * @note When the create subproblem callback is invoked, the mapping between the master problem and subproblem
173 * variables must be available. The create subproblem callback is invoked immediately after BENDERSINIT. So, it is
174 * possible to construct the variable mapping within the BENDERSINIT callback.
175 *
176 * This method must register the SCIP instance for the subproblem with the Benders' decomposition core by calling
177 * SCIPaddBendersSubproblem. Typically, the user must create the SCIP instances for the subproblems. These can be
178 * created within a reader or probdata and then registered with the Benders' decomposition core during the call of this
179 * callback. If there are any settings required for solving the subproblems, then they should be set here. However,
180 * some settings will be overridden by the standard solving method included in the Benders' decomposition framework.
181 * If a special solving method is desired, the user can implement the bendersSolvesubXyz callback. In this latter case,
182 * it is possible to provide a NULL pointer to SCIPaddBendersSubproblem. This will ensure that no internal solving
183 * methods available within the Benders' decomposition core are invoked during the solving process.
184 *
185 * If the user defines a subproblem solving method, then in BENDERSCREATESUB, the user must explicitly specify the
186 * subproblem type. This is necessary because the dual solutions from convex problems can be used to generate cuts.
187 * The classical Benders' optimality and feasibility cuts require that the subproblems are convex. The subproblem type
188 * is specified by calling SCIPbendersSetSubproblemType. The available subproblem types are defined in
189 * SCIP_BENDERSSUBTYPE.
190 *
191 * If the user does NOT implement a subproblem solving method, then the convexity of the problem is determined
192 * internally.
193 *
194 * input:
195 * - scip : SCIP main data structure
196 * - benders : the Benders' decomposition data structure
197 * - probnumber : the subproblem problem number
198 */
199#define SCIP_DECL_BENDERSCREATESUB(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, int probnumber)
200
201/** called before the subproblem solving loop for Benders' decomposition. The pre subproblem solve function gives the
202 * user an oppportunity to perform any global set up for the Benders' decomposition.
203 *
204 * input:
205 * - scip : SCIP main data structure
206 * - benders : the Benders' decomposition data structure
207 * - sol : the solution that will be checked in the subproblem. Can be NULL.
208 * - type : the enforcement type that called the Benders' decomposition solve.
209 * - checkint : should the integer subproblems be checked.
210 * - infeasible : flag to return whether the master problem in infeasible with respect to the added cuts
211 * - auxviol : set to TRUE only if the solution is feasible but the aux vars are violated
212 * - skipsolve : flag to return whether the current subproblem solving loop should be skipped
213 * - result : a result to be returned to the Benders' constraint handler if the solve is skipped. If the
214 * solve is not skipped, then the returned result is ignored.
215 *
216 * possible return values for *result (if more than one applies, the first in the list should be used):
217 * - SCIP_DIDNOTRUN : the subproblem was not solved in this iteration. Other decompositions will be checked.
218 * - SCIP_CONSADDED : a constraint has been added to the master problem. No other decompositions will be checked.
219 * - SCIP_SEPARATED : a cut has been added to the master problem. No other decompositions will be checked.
220 * - SCIP_FEASIBLE : feasibility of the solution is reported to SCIP. Other decompositions will be checked.
221 * - SCIP_INFEASIBLE : infeasibility of the solution is reported to SCIP. No other decompositions will be checked.
222 */
223#define SCIP_DECL_BENDERSPRESUBSOLVE(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,\
224 SCIP_BENDERSENFOTYPE type, SCIP_Bool checkint, SCIP_Bool* infeasible, SCIP_Bool* auxviol, SCIP_Bool* skipsolve,\
225 SCIP_RESULT* result)
226
227/** the solving method for a convex Benders' decomposition subproblem. This call back is provided to solve problems
228 * for which the dual soluitons are used to generate Benders' decomposition cuts. In the classical Benders'
229 * decomposition implementation, this would be an LP. However, it can be any convex problem where the dual solutions
230 * are given by a single vector of reals.
231 *
232 * In the Benders' decomposition subproblem solving process, there are two solving loops. The first is where the convex
233 * subproblems, and the convex relaxations of subproblems, are solved. If no cuts are generated after this solving
234 * loop, then the second loop solves subproblems defined as CIPs. This callback is executed during the FIRST solving
235 * loop only.
236 *
237 * In the classical Benders' decomposition implementation, if the subproblems are all LPs the only the
238 * BENDERSSOLVESUBCONVEX need to be implemented. If the subproblems are MIPs, then it is useful to only implement a
239 * single SCIP instance for the subproblem and then change the variable types of the appropriate variables to
240 * CONTINUOUS for the CONVEX subproblem solve and to INTEGER for the CIP subproblem solve.
241 *
242 * The solving methods are separated so that they can be called in parallel.
243 *
244 * NOTE: The solving methods must be thread safe.
245 *
246 * This method is called from within the execution method.
247 *
248 * input:
249 * - scip : SCIP main data structure
250 * - benders : the Benders' decomposition data structure
251 * - sol : the solution that will be checked in the subproblem. Can be NULL.
252 * - probnumber : the subproblem problem number
253 * - onlyconvexcheck : flag to indicate that only the convex relaxations will be checked in this solving loop. This is
254 * a feature of the Large Neighbourhood Benders' Search
255 * - objective : variable to return the objective function value of the subproblem
256 * - result : the result from solving the subproblem
257 *
258 * possible return values for *result (if more than one applies, the first in the list should be used):
259 * - SCIP_DIDNOTRUN : the subproblem was not solved in this iteration
260 * - SCIP_FEASIBLE : the subproblem is solved and is feasible
261 * - SCIP_INFEASIBLE : the subproblem is solved and is infeasible
262 * - SCIP_UNBOUNDED : the subproblem is solved and is unbounded
263 */
264#define SCIP_DECL_BENDERSSOLVESUBCONVEX(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,\
265 int probnumber, SCIP_Bool onlyconvexcheck, SCIP_Real* objective, SCIP_RESULT* result)
266
267/** the solving method for a Benders' decomposition subproblem as a CIP. This call back is provided to solve problems
268 * for which the dual solutions are not well defined. In this case, the cuts are typically generated from the primal
269 * solution to the CIP. In the classical Benders' decomposition implementation, this would be a MIP. However, it can
270 * be any CIP.
271 *
272 * In the Benders' decomposition subproblem solving process, there are two solving loops. The first is where the convex
273 * subproblems, and the convex relaxations of subproblems, are solved. If no cuts are generated after this solving
274 * loop, then the second loop solves subproblems defined as CIPs. This callback is executed during the SECOND solving
275 * loop only.
276 *
277 * The solving methods are separated so that they can be called in parallel.
278 *
279 * NOTE: The solving methods must be thread safe.
280 *
281 * This method is called from within the execution method.
282 *
283 * input:
284 * - scip : SCIP main data structure
285 * - benders : the Benders' decomposition data structure
286 * - sol : the solution that will be checked in the subproblem. Can be NULL.
287 * - probnumber : the subproblem problem number
288 * - objective : variable to return the objective function value of the subproblem
289 * - result : the result from solving the subproblem
290 *
291 * possible return values for *result (if more than one applies, the first in the list should be used):
292 * - SCIP_DIDNOTRUN : the subproblem was not solved in this iteration
293 * - SCIP_FEASIBLE : the subproblem is solved and is feasible
294 * - SCIP_INFEASIBLE : the subproblem is solved and is infeasible
295 * - SCIP_UNBOUNDED : the subproblem is solved and is unbounded
296 */
297#define SCIP_DECL_BENDERSSOLVESUB(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol, int probnumber,\
298 SCIP_Real* objective, SCIP_RESULT* result)
299
300/** the post-solve method for Benders' decomposition. The post-solve method is called after the subproblems have
301 * been solved but before they have been freed. After the solving of the Benders' decomposition subproblems, the
302 * subproblem solving data is freed in the SCIP_DECL_BENDERSFREESUB callback. However, it is not necessary to implement
303 * SCIP_DECL_BENDERSFREESUB.
304 *
305 * If SCIP_DECL_BENDERSFREESUB is not implemented, then the Benders' decomposition framework will perform a default
306 * freeing of the subproblems. If a subproblem is an LP, then they will be in probing mode for the subproblem
307 * solve. So the freeing process involves ending the probing mode. If the subproblem is a MIP, then the subproblem is
308 * solved by calling SCIPsolve. As such, the transformed problem must be freed after each subproblem solve.
309 *
310 * This callback provides the opportunity for the user to clean up any data structures that should not exist beyond the current
311 * iteration.
312 * The user has full access to the master and subproblems in this callback. So it is possible to construct solution for
313 * the master problem in the method.
314 * Additionally, if there are any subproblems that are infeasibility and this can not be resolved, then the it is
315 * possible to merge these subproblems into the master problem. The subproblem indices are given in the mergecands
316 * array. The merging can be perform by a user defined function or by calling SCIPmergeBendersSubproblemIntoMaster. If a
317 * subproblem was merged into the master problem, then the merged flag must be set to TRUE.
318 *
319 * input:
320 * - scip : SCIP main data structure
321 * - benders : the Benders' decomposition data structure
322 * - sol : the solution that was checked by solving the subproblems. Can be NULL.
323 * - type : the enforcement type that called the Benders' decomposition solve.
324 * - mergecands : the subproblems that are candidates for merging into the master problem, the first
325 * npriomergecands are the priority candidates (they should be merged). The remaining
326 * (nmergecands - npriomergecands) are subproblems that could be merged if desired.
327 * - npriomergecands : the number of priority merge candidates.
328 * - nmergecands : the total number of subproblems that are candidates for merging into the master problem
329 * - checkint : should the integer subproblems be checked.
330 * - infeasible : indicates whether at least one subproblem is infeasible
331 * - merged : flag to indicate whether a subproblem was merged into the master problem.
332 */
333#define SCIP_DECL_BENDERSPOSTSOLVE(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,\
334 SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint,\
335 SCIP_Bool infeasible, SCIP_Bool* merged)
336
337/** frees the subproblem so that it can be resolved in the next iteration. As stated above, it is not necessary to
338 * implement this callback. If the callback is implemented, the subproblems should be freed by calling
339 * SCIPfreeTransform(). However, if the subproblems are LPs, then it could be more efficient to put the subproblem
340 * into probing mode prior to solving and then exiting the probing mode during the callback. To put the subproblem into
341 * probing mode, the subproblem must be in SCIP_STAGE_SOLVING. This can be achieved by using eventhandlers.
342 *
343 * If SCIP_DECL_BENDERSFREESUB is not implemented, then the Benders' decomposition framework will perform a default
344 * freeing of the subproblems. If a subproblem is an LP, then they will be in probing mode for the subproblem
345 * solve. So the freeing process involves ending the probing mode. If the subproblem is a MIP, then the subproblem is
346 * solved by calling SCIPsolve. As such, the transformed problem must be freed after each subproblem solve.
347 *
348 * NOTE: The freeing methods must be thread safe.
349 *
350 * input:
351 * - scip : SCIP main data structure
352 * - benders : the Benders' decomposition data structure
353 * - probnumber : the subproblem problem number
354 */
355#define SCIP_DECL_BENDERSFREESUB(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, int probnumber)
356
357/** the variable mapping from the subproblem to the master problem. It is neccessary to have a mapping between every
358 * master problem variable and its counterpart in the subproblem. This mapping must go both ways: from master to sub
359 * and sub to master.
360 *
361 * This method is called when generating the cuts. The cuts are generated by using the solution to the subproblem to
362 * eliminate a solution to the master problem.
363 *
364 * input:
365 * - scip : SCIP main data structure
366 * - benders : the Benders' decomposition structure
367 * - var : the variable for which the corresponding variable in the master or subproblem is required
368 * - mappedvar : pointer to store the variable that is mapped to var
369 * - probnumber : the number of the subproblem that the desired variable belongs to, -1 for the master problem
370 */
371#define SCIP_DECL_BENDERSGETVAR(x) SCIP_RETCODE x (SCIP* scip, SCIP_BENDERS* benders, SCIP_VAR* var,\
372 SCIP_VAR** mappedvar, int probnumber)
373
374#ifdef __cplusplus
375}
376#endif
377
378#endif
common defines and data types used in all packages of SCIP
SCIP_BendersEnfoType
Definition: type_benders.h:50
@ SCIP_BENDERSENFOTYPE_RELAX
Definition: type_benders.h:52
@ SCIP_BENDERSENFOTYPE_LP
Definition: type_benders.h:51
@ SCIP_BENDERSENFOTYPE_CHECK
Definition: type_benders.h:54
@ SCIP_BENDERSENFOTYPE_PSEUDO
Definition: type_benders.h:53
SCIP_BendersSubStatus
Definition: type_benders.h:68
@ SCIP_BENDERSSUBSTATUS_AUXVIOL
Definition: type_benders.h:71
@ SCIP_BENDERSSUBSTATUS_UNKNOWN
Definition: type_benders.h:69
@ SCIP_BENDERSSUBSTATUS_INFEAS
Definition: type_benders.h:72
@ SCIP_BENDERSSUBSTATUS_OPTIMAL
Definition: type_benders.h:70
SCIP_BendersSubType
Definition: type_benders.h:77
@ SCIP_BENDERSSUBTYPE_NONCONVEXDIS
Definition: type_benders.h:81
@ SCIP_BENDERSSUBTYPE_CONVEXCONT
Definition: type_benders.h:78
@ SCIP_BENDERSSUBTYPE_NONCONVEXCONT
Definition: type_benders.h:80
@ SCIP_BENDERSSUBTYPE_CONVEXDIS
Definition: type_benders.h:79
@ SCIP_BENDERSSUBTYPE_UNKNOWN
Definition: type_benders.h:82
enum SCIP_BendersSubType SCIP_BENDERSSUBTYPE
Definition: type_benders.h:84
SCIP_BendersSolveLoop
Definition: type_benders.h:59
@ SCIP_BENDERSSOLVELOOP_CIP
Definition: type_benders.h:61
@ SCIP_BENDERSSOLVELOOP_CONVEX
Definition: type_benders.h:60
@ SCIP_BENDERSSOLVELOOP_USERCONVEX
Definition: type_benders.h:62
@ SCIP_BENDERSSOLVELOOP_USERCIP
Definition: type_benders.h:63
enum SCIP_BendersSolveLoop SCIP_BENDERSSOLVELOOP
Definition: type_benders.h:65
enum SCIP_BendersEnfoType SCIP_BENDERSENFOTYPE
Definition: type_benders.h:56
enum SCIP_BendersSubStatus SCIP_BENDERSSUBSTATUS
Definition: type_benders.h:74
struct SCIP_BendersData SCIP_BENDERSDATA
Definition: type_benders.h:87
type definitions for return codes for SCIP methods
type definitions for SCIP's main datastructure