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   scip_solve.h
17  * @ingroup PUBLICCOREAPI
18  * @brief  public solving methods
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Thorsten Koch
22  * @author Alexander Martin
23  * @author Marc Pfetsch
24  * @author Kati Wolter
25  * @author Gregor Hendel
26  * @author Leona Gottwald
27  */
28 
29 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
30 
31 #ifndef __SCIP_SCIP_SOLVE_H__
32 #define __SCIP_SCIP_SOLVE_H__
33 
34 
35 #include "scip/def.h"
36 #include "scip/type_retcode.h"
37 #include "scip/type_scip.h"
38 #include "scip/type_sol.h"
39 #include "scip/type_tree.h"
40 #include "scip/type_var.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**@addtogroup PublicSolveMethods
47  *
48  * @{
49  */
50 
51 /** initializes solving data structures and transforms problem
52  *
53  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
54  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
55  *
56  *  @pre This method can be called if @p scip is in one of the following stages:
57  *       - \ref SCIP_STAGE_PROBLEM
58  *       - \ref SCIP_STAGE_TRANSFORMED
59  *       - \ref SCIP_STAGE_INITPRESOLVE
60  *       - \ref SCIP_STAGE_PRESOLVING
61  *       - \ref SCIP_STAGE_EXITPRESOLVE
62  *       - \ref SCIP_STAGE_PRESOLVED
63  *       - \ref SCIP_STAGE_INITSOLVE
64  *       - \ref SCIP_STAGE_SOLVING
65  *       - \ref SCIP_STAGE_SOLVED
66  *       - \ref SCIP_STAGE_EXITSOLVE
67  *       - \ref SCIP_STAGE_FREETRANS
68  *       - \ref SCIP_STAGE_FREE
69  *
70  *  @post When calling this method in the \ref SCIP_STAGE_PROBLEM stage, the \SCIP stage is changed to \ref
71  *        SCIP_STAGE_TRANSFORMED; otherwise, the stage is not changed
72  *
73  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
74  */
75 SCIP_EXPORT
76 SCIP_RETCODE SCIPtransformProb(
77    SCIP*                 scip                /**< SCIP data structure */
78    );
79 
80 /** transforms and presolves problem
81  *
82  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
83  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
84  *
85  *  @pre This method can be called if @p scip is in one of the following stages:
86  *       - \ref SCIP_STAGE_PROBLEM
87  *       - \ref SCIP_STAGE_TRANSFORMED
88  *       - \ref SCIP_STAGE_PRESOLVING
89  *       - \ref SCIP_STAGE_PRESOLVED
90  *       - \ref SCIP_STAGE_SOLVED
91  *
92  *  @post After calling this method \SCIP reaches one of the following stages:
93  *        - \ref SCIP_STAGE_PRESOLVING if the presolving process was interrupted
94  *        - \ref SCIP_STAGE_PRESOLVED if the presolving process was finished and did not solve the problem
95  *        - \ref SCIP_STAGE_SOLVED if the problem was solved during presolving
96  *
97  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
98  */
99 SCIP_EXPORT
100 SCIP_RETCODE SCIPpresolve(
101    SCIP*                 scip                /**< SCIP data structure */
102    );
103 
104 /** transforms, presolves, and solves problem
105  *
106  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
107  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
108  *
109  *  @pre This method can be called if @p scip is in one of the following stages:
110  *       - \ref SCIP_STAGE_PROBLEM
111  *       - \ref SCIP_STAGE_TRANSFORMED
112  *       - \ref SCIP_STAGE_PRESOLVING
113  *       - \ref SCIP_STAGE_PRESOLVED
114  *       - \ref SCIP_STAGE_SOLVING
115  *       - \ref SCIP_STAGE_SOLVED
116  *
117  *  @post After calling this method \SCIP reaches one of the following stages depending on if and when the solution
118  *        process was interrupted:
119 
120  *        - \ref SCIP_STAGE_PRESOLVING if the solution process was interrupted during presolving
121  *        - \ref SCIP_STAGE_SOLVING if the solution process was interrupted during the tree search
122  *        - \ref SCIP_STAGE_SOLVED if the solving process was not interrupted
123  *
124  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
125  */
126 SCIP_EXPORT
127 SCIP_RETCODE SCIPsolve(
128    SCIP*                 scip                /**< SCIP data structure */
129    );
130 
131 /** transforms, presolves, and solves problem using additional solvers which emphasize on
132  *  finding solutions.
133  *
134  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
135  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
136  *
137  *  @pre This method can be called if @p scip is in one of the following stages:
138  *       - \ref SCIP_STAGE_PROBLEM
139  *       - \ref SCIP_STAGE_TRANSFORMED
140  *       - \ref SCIP_STAGE_PRESOLVING
141  *       - \ref SCIP_STAGE_PRESOLVED
142  *       - \ref SCIP_STAGE_SOLVING
143  *       - \ref SCIP_STAGE_SOLVED
144  *
145  *  @post After calling this method \SCIP reaches one of the following stages depending on if and when the solution
146  *        process was interrupted:
147  *        - \ref SCIP_STAGE_PRESOLVING if the solution process was interrupted during presolving
148  *        - \ref SCIP_STAGE_SOLVING if the solution process was interrupted during the tree search
149  *        - \ref SCIP_STAGE_SOLVED if the solving process was not interrupted
150  *
151  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
152  *
153  *  @deprecated Please use SCIPsolveConcurrent() instead.
154  */
155 SCIP_EXPORT
156 SCIP_RETCODE SCIPsolveParallel(
157    SCIP*                 scip                /**< SCIP data structure */
158    );
159 
160 /** transforms, presolves, and solves problem using additional solvers which emphasize on
161  *  finding solutions.
162  *
163  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
164  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
165  *
166  *  @pre This method can be called if @p scip is in one of the following stages:
167  *       - \ref SCIP_STAGE_PROBLEM
168  *       - \ref SCIP_STAGE_TRANSFORMED
169  *       - \ref SCIP_STAGE_PRESOLVING
170  *       - \ref SCIP_STAGE_PRESOLVED
171  *       - \ref SCIP_STAGE_SOLVING
172  *       - \ref SCIP_STAGE_SOLVED
173  *
174  *  @post After calling this method \SCIP reaches one of the following stages depending on if and when the solution
175  *        process was interrupted:
176  *        - \ref SCIP_STAGE_PRESOLVING if the solution process was interrupted during presolving
177  *        - \ref SCIP_STAGE_SOLVING if the solution process was interrupted during the tree search
178  *        - \ref SCIP_STAGE_SOLVED if the solving process was not interrupted
179  *
180  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
181  */
182 SCIP_EXPORT
183 SCIP_RETCODE SCIPsolveConcurrent(
184    SCIP*                 scip                /**< SCIP data structure */
185    );
186 
187 /** frees branch and bound tree and all solution process data; statistics, presolving data and transformed problem is
188  *  preserved
189  *
190  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
191  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
192  *
193  *  @pre This method can be called if @p scip is in one of the following stages:
194  *       - \ref SCIP_STAGE_INIT
195  *       - \ref SCIP_STAGE_PROBLEM
196  *       - \ref SCIP_STAGE_TRANSFORMED
197  *       - \ref SCIP_STAGE_PRESOLVING
198  *       - \ref SCIP_STAGE_PRESOLVED
199  *       - \ref SCIP_STAGE_SOLVING
200  *       - \ref SCIP_STAGE_SOLVED
201  *
202  *  @post If this method is called in \SCIP stage \ref SCIP_STAGE_INIT or \ref SCIP_STAGE_PROBLEM, the stage of
203  *        \SCIP is not changed; otherwise, the \SCIP stage is changed to \ref SCIP_STAGE_TRANSFORMED
204  *
205  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
206  */
207 SCIP_EXPORT
208 SCIP_RETCODE SCIPfreeSolve(
209    SCIP*                 scip,               /**< SCIP data structure */
210    SCIP_Bool             restart             /**< should certain data be preserved for improved restarting? */
211    );
212 
213 /** frees branch and bound tree and all solution process data; statistics, presolving data and transformed problem is
214  *  preserved
215  *
216  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
217  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
218  *
219  *  @pre This method can be called if @p scip is in one of the following stages:
220  *       - \ref SCIP_STAGE_INIT
221  *       - \ref SCIP_STAGE_PROBLEM
222  *       - \ref SCIP_STAGE_TRANSFORMED
223  *       - \ref SCIP_STAGE_PRESOLVING
224  *       - \ref SCIP_STAGE_PRESOLVED
225  *       - \ref SCIP_STAGE_SOLVING
226  *       - \ref SCIP_STAGE_SOLVED
227  *
228  *  @post If this method is called in \SCIP stage \ref SCIP_STAGE_INIT or \ref SCIP_STAGE_PROBLEM, the stage of
229  *        \SCIP is not changed; otherwise, the \SCIP stage is changed to \ref SCIP_STAGE_PRESOLVED.
230  *
231  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
232  */
233 SCIP_EXPORT
234 SCIP_RETCODE SCIPfreeReoptSolve(
235    SCIP*                 scip                /**< SCIP data structure */
236    );
237 
238 /** frees all solution process data including presolving and transformed problem, only original problem is kept
239  *
240  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
241  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
242  *
243  *  @pre This method can be called if @p scip is in one of the following stages:
244  *       - \ref SCIP_STAGE_INIT
245  *       - \ref SCIP_STAGE_PROBLEM
246  *       - \ref SCIP_STAGE_TRANSFORMED
247  *       - \ref SCIP_STAGE_PRESOLVING
248  *       - \ref SCIP_STAGE_PRESOLVED
249  *       - \ref SCIP_STAGE_SOLVING
250  *       - \ref SCIP_STAGE_SOLVED
251  *
252  *  @post After calling this method \SCIP reaches one of the following stages:
253  *        - \ref SCIP_STAGE_INIT if the method was called from \SCIP stage \ref SCIP_STAGE_INIT
254  *        - \ref SCIP_STAGE_PROBLEM if the method was called from any other of the allowed stages
255  *
256  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
257  */
258 SCIP_EXPORT
259 SCIP_RETCODE SCIPfreeTransform(
260    SCIP*                 scip                /**< SCIP data structure */
261    );
262 
263 /** informs \SCIP that the solving process should be interrupted as soon as possible (e.g., after the current node has
264  *   been solved)
265  *
266  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
267  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
268  *
269  *  @pre This method can be called if @p scip is in one of the following stages:
270  *       - \ref SCIP_STAGE_PROBLEM
271  *       - \ref SCIP_STAGE_TRANSFORMING
272  *       - \ref SCIP_STAGE_TRANSFORMED
273  *       - \ref SCIP_STAGE_INITPRESOLVE
274  *       - \ref SCIP_STAGE_PRESOLVING
275  *       - \ref SCIP_STAGE_EXITPRESOLVE
276  *       - \ref SCIP_STAGE_PRESOLVED
277  *       - \ref SCIP_STAGE_SOLVING
278  *       - \ref SCIP_STAGE_SOLVED
279  *       - \ref SCIP_STAGE_EXITSOLVE
280  *       - \ref SCIP_STAGE_FREETRANS
281  *
282  *  @note the \SCIP stage does not get changed
283  */
284 SCIP_EXPORT
285 SCIP_RETCODE SCIPinterruptSolve(
286    SCIP*                 scip                /**< SCIP data structure */
287    );
288 
289 /** informs SCIP that the solving process should be restarted as soon as possible (e.g., after the current node has
290  *  been solved)
291  *
292  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
293  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
294  *
295  *  @pre This method can be called if @p scip is in one of the following stages:
296  *       - \ref SCIP_STAGE_INITPRESOLVE
297  *       - \ref SCIP_STAGE_PRESOLVING
298  *       - \ref SCIP_STAGE_EXITPRESOLVE
299  *       - \ref SCIP_STAGE_SOLVING
300  *
301  *  @note the \SCIP stage does not get changed
302  */
303 SCIP_EXPORT
304 SCIP_RETCODE SCIPrestartSolve(
305    SCIP*                 scip                /**< SCIP data structure */
306    );
307 
308 /** include specific heuristics and branching rules for reoptimization
309  *
310  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
311  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
312  *
313  *  @pre This method can be called if @p scip is in one of the following stages:
314  *       - \ref SCIP_STAGE_PROBLEM
315  */
316 SCIP_EXPORT
317 SCIP_RETCODE SCIPenableReoptimization(
318    SCIP*                 scip,               /**< SCIP data structure */
319    SCIP_Bool             enable              /**< enable reoptimization (TRUE) or disable it (FALSE) */
320    );
321 
322 /** returns whether reoptimization is enabled or not */
323 SCIP_EXPORT
324 SCIP_Bool SCIPisReoptEnabled(
325    SCIP*                 scip                /**< SCIP data structure */
326    );
327 
328 /** returns the stored solutions corresponding to a given run */
329 SCIP_EXPORT
330 SCIP_RETCODE SCIPgetReoptSolsRun(
331    SCIP*                 scip,               /**< SCIP data structue */
332    int                   run,                /**< number of the run */
333    SCIP_SOL**            sols,               /**< array to store solutions */
334    int                   allocmem,           /**< allocated size of the array */
335    int*                  nsols               /**< number of solutions */
336    );
337 
338 /** mark all stored solutions as not updated */
339 SCIP_EXPORT
340 void SCIPresetReoptSolMarks(
341    SCIP*                 scip                /**< SCIP data structure */
342    );
343 
344 /** check if the reoptimization process should be restarted
345  *
346  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
347  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
348  *
349  *  @pre This method can be called if @p scip is in one of the following stages:
350  *       - \ref SCIP_STAGE_TRANSFORMED
351  *       - \ref SCIP_STAGE_SOLVING
352  */
353 SCIP_EXPORT
354 SCIP_RETCODE SCIPcheckReoptRestart(
355    SCIP*                 scip,               /**< SCIP data structure */
356    SCIP_NODE*            node,               /**< current node of the branch and bound tree (or NULL) */
357    SCIP_Bool*            restart             /**< pointer to store of the reoptimitation process should be restarted */
358    );
359 
360 /** save bound change based on dual information in the reoptimization tree
361  *
362  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
363  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
364  *
365  *  @pre This method can be called if @p scip is in one of the following stages:
366  *       - \ref SCIP_STAGE_SOLVING
367  *       - \ref SCIP_STAGE_SOLVED
368  */
369 SCIP_EXPORT
370 SCIP_RETCODE SCIPaddReoptDualBndchg(
371    SCIP*                 scip,               /**< SCIP data structure */
372    SCIP_NODE*            node,               /**< node of the search tree */
373    SCIP_VAR*             var,                /**< variable whose bound changed */
374    SCIP_Real             newbound,           /**< new bound of the variable */
375    SCIP_Real             oldbound            /**< old bound of the variable */
376    );
377 
378 /** returns the optimal solution of the last iteration or NULL of none exists */
379 SCIP_EXPORT
380 SCIP_SOL* SCIPgetReoptLastOptSol(
381    SCIP*                 scip                /**< SCIP data structure */
382    );
383 
384 /** returns the objective coefficent of a given variable in a previous iteration
385  *
386  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
387  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
388  *
389  *  @pre This method can be called if @p scip is in one of the following stages:
390  *       - \ref SCIP_STAGE_PRESOLVING
391  *       - \ref SCIP_STAGE_SOLVING
392  */
393 SCIP_EXPORT
394 SCIP_RETCODE SCIPgetReoptOldObjCoef(
395    SCIP*                 scip,               /**< SCIP data structure */
396    SCIP_VAR*             var,                /**< variable */
397    int                   run,                /**< number of the run */
398    SCIP_Real*            objcoef             /**< pointer to store the objective coefficient */
399    );
400 
401 /** returns whether we are in the restarting phase
402  *
403  *  @return TRUE, if we are in the restarting phase; FALSE, otherwise
404  *
405  *  @pre This method can be called if @p scip is in one of the following stages:
406  *       - \ref SCIP_STAGE_INITPRESOLVE
407  *       - \ref SCIP_STAGE_PRESOLVING
408  *       - \ref SCIP_STAGE_EXITPRESOLVE
409  *       - \ref SCIP_STAGE_PRESOLVED
410  *       - \ref SCIP_STAGE_INITSOLVE
411  *       - \ref SCIP_STAGE_SOLVING
412  *       - \ref SCIP_STAGE_SOLVED
413  *       - \ref SCIP_STAGE_EXITSOLVE
414  *       - \ref SCIP_STAGE_FREETRANS
415  */
416 SCIP_EXPORT
417 SCIP_Bool SCIPisInRestart(
418    SCIP*                 scip                /**< SCIP data structure */
419    );
420 
421 /**@} */
422 
423 #ifdef __cplusplus
424 }
425 #endif
426 
427 #endif
428