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_lp.c
17  * @ingroup OTHER_CFILES
18  * @brief  public methods for the LP relaxation, rows and columns
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "blockmemshell/memory.h"
37 #include "lpi/lpi.h"
38 #include "scip/conflict.h"
39 #include "scip/debug.h"
40 #include "scip/lp.h"
41 #include "scip/prob.h"
42 #include "scip/pub_lp.h"
43 #include "scip/pub_message.h"
44 #include "scip/pub_tree.h"
45 #include "scip/scip_lp.h"
46 #include "scip/scip_mem.h"
47 #include "scip/scip_numerics.h"
48 #include "scip/scip_sol.h"
49 #include "scip/scip_solvingstats.h"
50 #include "scip/scip_tree.h"
51 #include "scip/scip_var.h"
52 #include "scip/set.h"
53 #include "scip/solve.h"
54 #include "scip/struct_lp.h"
55 #include "scip/struct_mem.h"
56 #include "scip/struct_primal.h"
57 #include "scip/struct_prob.h"
58 #include "scip/struct_scip.h"
59 #include "scip/struct_set.h"
60 #include "scip/struct_stat.h"
61 #include "scip/struct_tree.h"
62 #include "scip/tree.h"
63 #include "scip/var.h"
64 
65 /** returns, whether the LP was or is to be solved in the current node
66  *
67  *  @return whether the LP was or is to be solved in the current node.
68  *
69  *  @pre This method can be called if @p scip is in one of the following stages:
70  *       - \ref SCIP_STAGE_SOLVING
71  *
72  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
73  */
SCIPhasCurrentNodeLP(SCIP * scip)74 SCIP_Bool SCIPhasCurrentNodeLP(
75    SCIP*                 scip                /**< SCIP data structure */
76    )
77 {
78    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPhasCurrentNodeLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
79 
80    return SCIPtreeHasCurrentNodeLP(scip->tree);
81 }
82 
83 /** returns, whether the LP of the current node is already constructed
84  *
85  *  @return whether the LP of the current node is already constructed.
86  *
87  *  @pre This method can be called if @p scip is in one of the following stages:
88  *       - \ref SCIP_STAGE_SOLVING
89  *
90  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
91  */
SCIPisLPConstructed(SCIP * scip)92 SCIP_Bool SCIPisLPConstructed(
93    SCIP*                 scip                /**< SCIP data structure */
94    )
95 {
96    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisLPConstructed", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
97 
98    return SCIPtreeIsFocusNodeLPConstructed(scip->tree);
99 }
100 
101 /** makes sure that the LP of the current node is loaded and may be accessed through the LP information methods
102  *
103  *  @warning Contructing the LP might change the amount of variables known in the transformed problem and therefore also
104  *           the variables array of SCIP (returned by SCIPgetVars() and SCIPgetVarsData()), so it might be necessary to
105  *           call one of the later method after this one
106  *
107  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
108  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
109  *
110  *  @pre This method can be called if @p scip is in one of the following stages:
111  *       - \ref SCIP_STAGE_SOLVING
112  *
113  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
114  */
SCIPconstructLP(SCIP * scip,SCIP_Bool * cutoff)115 SCIP_RETCODE SCIPconstructLP(
116    SCIP*                 scip,               /**< SCIP data structure */
117    SCIP_Bool*            cutoff              /**< pointer to store whether the node can be cut off */
118    )
119 {
120    SCIP_CALL( SCIPcheckStage(scip, "SCIPconstructLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
121 
122    SCIP_CALL( SCIPconstructCurrentLP(scip->mem->probmem, scip->set, scip->stat, scip->transprob, scip->origprob,
123          scip->tree, scip->reopt, scip->lp, scip->pricestore, scip->sepastore, scip->cutpool, scip->branchcand,
124          scip->eventqueue, scip->eventfilter, scip->cliquetable, FALSE, cutoff) );
125 
126    return SCIP_OKAY;
127 }
128 
129 /** makes sure that the LP of the current node is flushed
130  *
131  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
132  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
133  *
134  *  @pre This method can be called if @p scip is in one of the following stages:
135  *       - \ref SCIP_STAGE_SOLVING
136  *
137  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
138  */
SCIPflushLP(SCIP * scip)139 SCIP_RETCODE SCIPflushLP(
140    SCIP*                 scip                /**< SCIP data structure */
141    )
142 {
143    SCIP_CALL( SCIPcheckStage(scip, "SCIPflushLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
144 
145    SCIP_CALL( SCIPlpFlush(scip->lp, scip->mem->probmem, scip->set, scip->eventqueue) );
146 
147    return SCIP_OKAY;
148 }
149 
150 /** gets solution status of current LP
151  *
152  *  @return the solution status of current LP.
153  *
154  *  @pre This method can be called if @p scip is in one of the following stages:
155  *       - \ref SCIP_STAGE_SOLVING
156  *
157  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
158  */
SCIPgetLPSolstat(SCIP * scip)159 SCIP_LPSOLSTAT SCIPgetLPSolstat(
160    SCIP*                 scip                /**< SCIP data structure */
161    )
162 {
163    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPSolstat", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
164 
165    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
166       return SCIPlpGetSolstat(scip->lp);
167    else
168       return SCIP_LPSOLSTAT_NOTSOLVED;
169 }
170 
171 /** returns whether the current LP solution passed the primal feasibility check
172  *
173  *  @return whether the current LP solution passed the primal feasibility check.
174  *
175  *  @pre This method can be called if @p scip is in one of the following stages:
176  *       - \ref SCIP_STAGE_SOLVING
177  *
178  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
179  */
SCIPisLPPrimalReliable(SCIP * scip)180 SCIP_Bool SCIPisLPPrimalReliable(
181    SCIP*                 scip                /**< SCIP data structure */
182    )
183 {
184    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisLPPrimalReliable", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
185 
186    return SCIPlpIsPrimalReliable(scip->lp);
187 }
188 
189 /** returns whether the current LP solution passed the dual feasibility check
190  *
191  *  @returns whether the current LP solution passed the dual feasibility check.
192  *
193  *  @pre This method can be called if @p scip is in one of the following stages:
194  *       - \ref SCIP_STAGE_SOLVING
195  *
196  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
197  */
SCIPisLPDualReliable(SCIP * scip)198 SCIP_Bool SCIPisLPDualReliable(
199    SCIP*                 scip                /**< SCIP data structure */
200    )
201 {
202    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisLPDualReliable", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
203 
204    return SCIPlpIsDualReliable(scip->lp);
205 }
206 
207 /** returns whether the current lp is a relaxation of the current problem and its optimal objective value is a local lower bound
208  *
209  *  @return whether the current lp is a relaxation of the current problem and its optimal objective value is a local lower bound.
210  *
211  *  @pre This method can be called if @p scip is in one of the following stages:
212  *       - \ref SCIP_STAGE_SOLVING
213  *
214  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
215  */
SCIPisLPRelax(SCIP * scip)216 SCIP_Bool SCIPisLPRelax(
217    SCIP*                 scip                /**< SCIP data structure */
218    )
219 {
220    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisLPRelax", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
221 
222    return SCIPlpIsRelax(scip->lp);
223 }
224 
225 /** gets objective value of current LP (which is the sum of column and loose objective value)
226  *
227  *  @return the objective value of current LP (which is the sum of column and loose objective value).
228  *
229  *  @pre This method can be called if @p scip is in one of the following stages:
230  *       - \ref SCIP_STAGE_SOLVING
231  *
232  *  @note This method returns the objective value of the current LP solution, which might be primal or dual infeasible
233  *        if a limit was hit during solving. It must not be used as a dual bound if the LP solution status returned by
234  *        SCIPgetLPSolstat() is SCIP_LPSOLSTAT_ITERLIMIT or SCIP_LPSOLSTAT_TIMELIMIT.
235  *
236  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
237  */
SCIPgetLPObjval(SCIP * scip)238 SCIP_Real SCIPgetLPObjval(
239    SCIP*                 scip                /**< SCIP data structure */
240    )
241 {
242    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPObjval", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
243 
244    return SCIPlpGetObjval(scip->lp, scip->set, scip->transprob);
245 }
246 
247 /** gets part of objective value of current LP that results from COLUMN variables only
248  *
249  *  @return the part of objective value of current LP that results from COLUMN variables only.
250  *
251  *  @pre This method can be called if @p scip is in one of the following stages:
252  *       - \ref SCIP_STAGE_SOLVING
253  *
254  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
255  */
SCIPgetLPColumnObjval(SCIP * scip)256 SCIP_Real SCIPgetLPColumnObjval(
257    SCIP*                 scip                /**< SCIP data structure */
258    )
259 {
260    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPColumnObjval", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
261 
262    return SCIPlpGetColumnObjval(scip->lp);
263 }
264 
265 /** gets part of objective value of current LP that results from LOOSE variables only
266  *
267  *  @return part of objective value of current LP that results from LOOSE variables only.
268  *
269  *  @pre This method can be called if @p scip is in one of the following stages:
270  *       - \ref SCIP_STAGE_SOLVING
271  *
272  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
273  */
SCIPgetLPLooseObjval(SCIP * scip)274 SCIP_Real SCIPgetLPLooseObjval(
275    SCIP*                 scip                /**< SCIP data structure */
276    )
277 {
278    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPLooseObjval", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
279 
280    return SCIPlpGetLooseObjval(scip->lp, scip->set, scip->transprob);
281 }
282 
283 /** gets the global pseudo objective value; that is all variables set to their best  (w.r.t. the objective
284  *  function) global bound
285  *
286  *  @return the global pseudo objective value; that is all variables set to their best  (w.r.t. the objective
287  *  function) global bound.
288  *
289  *  @pre This method can be called if @p scip is in one of the following stages:
290  *       - \ref SCIP_STAGE_INITPRESOLVE
291  *       - \ref SCIP_STAGE_PRESOLVING
292  *       - \ref SCIP_STAGE_EXITPRESOLVE
293  *       - \ref SCIP_STAGE_PRESOLVED
294  *       - \ref SCIP_STAGE_INITSOLVE
295  *       - \ref SCIP_STAGE_SOLVING
296  *
297  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
298  */
SCIPgetGlobalPseudoObjval(SCIP * scip)299 SCIP_Real SCIPgetGlobalPseudoObjval(
300    SCIP*                 scip                /**< SCIP data structure */
301    )
302 {
303    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetGlobalPseudoObjval", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
304 
305    return SCIPlpGetGlobalPseudoObjval(scip->lp, scip->set, scip->transprob);
306 }
307 
308 /** gets the pseudo objective value for the current search node; that is all variables set to their best (w.r.t. the
309  *  objective function) local bound
310  *
311  *  @return the pseudo objective value for the current search node; that is all variables set to their best (w.r.t. the
312  *  objective function) local bound.
313  *
314  *  @pre This method can be called if @p scip is in one of the following stages:
315  *       - \ref SCIP_STAGE_INITPRESOLVE
316  *       - \ref SCIP_STAGE_PRESOLVING
317  *       - \ref SCIP_STAGE_EXITPRESOLVE
318  *       - \ref SCIP_STAGE_PRESOLVED
319  *       - \ref SCIP_STAGE_INITSOLVE
320  *       - \ref SCIP_STAGE_SOLVING
321  *
322  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
323  */
SCIPgetPseudoObjval(SCIP * scip)324 SCIP_Real SCIPgetPseudoObjval(
325    SCIP*                 scip                /**< SCIP data structure */
326    )
327 {
328    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetPseudoObjval", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
329 
330    return SCIPlpGetPseudoObjval(scip->lp, scip->set, scip->transprob);
331 }
332 
333 /** returns whether the root lp is a relaxation of the problem and its optimal objective value is a global lower bound
334  *
335  *  @return whether the root lp is a relaxation of the problem and its optimal objective value is a global lower bound.
336  *
337  *  @pre This method can be called if @p scip is in one of the following stages:
338  *       - \ref SCIP_STAGE_SOLVING
339  *
340  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
341  */
SCIPisRootLPRelax(SCIP * scip)342 SCIP_Bool SCIPisRootLPRelax(
343    SCIP*                 scip                /**< SCIP data structure */
344    )
345 {
346    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisRootLPRelax", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
347 
348    return SCIPlpIsRootLPRelax(scip->lp);
349 }
350 
351 /** gets the objective value of the root node LP or SCIP_INVALID if the root node LP was not (yet) solved
352  *
353  *  @return the objective value of the root node LP or SCIP_INVALID if the root node LP was not (yet) solved.
354  *
355  *  @pre This method can be called if @p scip is in one of the following stages:
356  *       - \ref SCIP_STAGE_INITPRESOLVE
357  *       - \ref SCIP_STAGE_PRESOLVING
358  *       - \ref SCIP_STAGE_EXITPRESOLVE
359  *       - \ref SCIP_STAGE_SOLVING
360  *
361  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
362  */
SCIPgetLPRootObjval(SCIP * scip)363 SCIP_Real SCIPgetLPRootObjval(
364    SCIP*                 scip                /**< SCIP data structure */
365    )
366 {
367    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPRootObjval", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
368 
369    return SCIPlpGetRootObjval(scip->lp);
370 }
371 
372 /** gets part of the objective value of the root node LP that results from COLUMN variables only;
373  *  returns SCIP_INVALID if the root node LP was not (yet) solved
374  *
375  *  @return the part of the objective value of the root node LP that results from COLUMN variables only;
376  *  or SCIP_INVALID if the root node LP was not (yet) solved.
377  *
378  *  @pre This method can be called if @p scip is in one of the following stages:
379  *       - \ref SCIP_STAGE_INITPRESOLVE
380  *       - \ref SCIP_STAGE_PRESOLVING
381  *       - \ref SCIP_STAGE_EXITPRESOLVE
382  *       - \ref SCIP_STAGE_SOLVING
383  *
384  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
385  */
SCIPgetLPRootColumnObjval(SCIP * scip)386 SCIP_Real SCIPgetLPRootColumnObjval(
387    SCIP*                 scip                /**< SCIP data structure */
388    )
389 {
390    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPRootColumnObjval", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
391 
392    return SCIPlpGetRootColumnObjval(scip->lp);
393 }
394 
395 /** gets part of the objective value of the root node LP that results from LOOSE variables only;
396  *  returns SCIP_INVALID if the root node LP was not (yet) solved
397  *
398  *  @return the part of the objective value of the root node LP that results from LOOSE variables only;
399  *  or SCIP_INVALID if the root node LP was not (yet) solved.
400  *
401  *  @pre This method can be called if @p scip is in one of the following stages:
402  *       - \ref SCIP_STAGE_INITPRESOLVE
403  *       - \ref SCIP_STAGE_PRESOLVING
404  *       - \ref SCIP_STAGE_EXITPRESOLVE
405  *       - \ref SCIP_STAGE_SOLVING
406  *
407  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
408  */
SCIPgetLPRootLooseObjval(SCIP * scip)409 SCIP_Real SCIPgetLPRootLooseObjval(
410    SCIP*                 scip                /**< SCIP data structure */
411    )
412 {
413    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPRootLooseObjval", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
414 
415    return SCIPlpGetRootLooseObjval(scip->lp);
416 }
417 
418 /** gets current primal feasibility tolerance of LP */
SCIPgetLPFeastol(SCIP * scip)419 SCIP_Real SCIPgetLPFeastol(
420    SCIP*                 scip                /**< SCIP data structure */
421    )
422 {
423    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPFeastol", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
424 
425    return SCIPlpGetFeastol(scip->lp);
426 }
427 
428 /** sets primal feasibility tolerance of LP */
SCIPsetLPFeastol(SCIP * scip,SCIP_Real newfeastol)429 void SCIPsetLPFeastol(
430    SCIP*                 scip,               /**< SCIP data structure */
431    SCIP_Real             newfeastol          /**< new primal feasibility tolerance for LP */
432    )
433 {
434    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPsetLPFeastol", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
435 
436    SCIPlpSetFeastol(scip->lp, scip->set, newfeastol);
437 }
438 
439 /** resets primal feasibility tolerance of LP
440  *
441  * Sets primal feasibility tolerance to min of numerics/lpfeastolfactor * numerics/feastol and relaxfeastol.
442  */
SCIPresetLPFeastol(SCIP * scip)443 void SCIPresetLPFeastol(
444    SCIP*                 scip                /**< SCIP data structure */
445    )
446 {
447    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPresetLPFeastol", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
448 
449    SCIPlpResetFeastol(scip->lp, scip->set);
450 }
451 
452 /** gets current LP columns along with the current number of LP columns
453  *
454  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
455  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
456  *
457  *  @pre This method can be called if @p scip is in one of the following stages:
458  *       - \ref SCIP_STAGE_SOLVING
459  *
460  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
461  */
SCIPgetLPColsData(SCIP * scip,SCIP_COL *** cols,int * ncols)462 SCIP_RETCODE SCIPgetLPColsData(
463    SCIP*                 scip,               /**< SCIP data structure */
464    SCIP_COL***           cols,               /**< pointer to store the array of LP columns, or NULL */
465    int*                  ncols               /**< pointer to store the number of LP columns, or NULL */
466    )
467 {
468    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPColsData", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
469 
470    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
471    {
472       if( cols != NULL )
473          *cols = SCIPlpGetCols(scip->lp);
474       if( ncols != NULL )
475          *ncols = SCIPlpGetNCols(scip->lp);
476    }
477    else
478    {
479       if( cols != NULL )
480          *cols = NULL;
481       if( ncols != NULL )
482          *ncols = 0;
483    }
484 
485    return SCIP_OKAY;
486 }
487 
488 /** gets current LP columns
489  *
490  *  @return the current LP columns.
491  *
492  *  @pre This method can be called if @p scip is in one of the following stages:
493  *       - \ref SCIP_STAGE_SOLVING
494  *
495  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
496  */
SCIPgetLPCols(SCIP * scip)497 SCIP_COL** SCIPgetLPCols(
498    SCIP*                 scip                /**< SCIP data structure */
499    )
500 {
501    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPCols", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
502 
503    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
504       return SCIPlpGetCols(scip->lp);
505    else
506       return NULL;
507 }
508 
509 /** gets current number of LP columns
510  *
511  *  @return the current number of LP columns.
512  *
513  *  @pre This method can be called if @p scip is in one of the following stages:
514  *       - \ref SCIP_STAGE_SOLVING
515  *
516  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
517  */
SCIPgetNLPCols(SCIP * scip)518 int SCIPgetNLPCols(
519    SCIP*                 scip                /**< SCIP data structure */
520    )
521 {
522    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetNLPCols", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
523 
524    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
525       return SCIPlpGetNCols(scip->lp);
526    else
527       return 0;
528 }
529 
530 /** gets current LP rows along with the current number of LP rows
531  *
532  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
533  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
534  *
535  *  @pre This method can be called if @p scip is in one of the following stages:
536  *       - \ref SCIP_STAGE_SOLVING
537  *
538  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
539  */
SCIPgetLPRowsData(SCIP * scip,SCIP_ROW *** rows,int * nrows)540 SCIP_RETCODE SCIPgetLPRowsData(
541    SCIP*                 scip,               /**< SCIP data structure */
542    SCIP_ROW***           rows,               /**< pointer to store the array of LP rows, or NULL */
543    int*                  nrows               /**< pointer to store the number of LP rows, or NULL */
544    )
545 {
546    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPRowsData", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
547 
548    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
549    {
550       if( rows != NULL )
551          *rows = SCIPlpGetRows(scip->lp);
552       if( nrows != NULL )
553          *nrows = SCIPlpGetNRows(scip->lp);
554    }
555    else
556    {
557       if( rows != NULL )
558          *rows = NULL;
559       if( nrows != NULL )
560          *nrows = 0;
561    }
562 
563    return SCIP_OKAY;
564 }
565 
566 /** gets current LP rows
567  *
568  *  @return the current LP rows.
569  *
570  *  @pre This method can be called if @p scip is in one of the following stages:
571  *       - \ref SCIP_STAGE_SOLVING
572  *
573  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
574  */
SCIPgetLPRows(SCIP * scip)575 SCIP_ROW** SCIPgetLPRows(
576    SCIP*                 scip                /**< SCIP data structure */
577    )
578 {
579    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLPRows", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
580 
581    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
582       return SCIPlpGetRows(scip->lp);
583    else
584       return NULL;
585 }
586 
587 /** gets current number of LP rows
588  *
589  *  @return the current number of LP rows.
590  *
591  *  @pre This method can be called if @p scip is in one of the following stages:
592  *       - \ref SCIP_STAGE_SOLVING
593  *
594  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
595  */
SCIPgetNLPRows(SCIP * scip)596 int SCIPgetNLPRows(
597    SCIP*                 scip                /**< SCIP data structure */
598    )
599 {
600    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetNLPRows", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
601 
602    if( SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
603       return SCIPlpGetNRows(scip->lp);
604    else
605       return 0;
606 }
607 
608 /** returns TRUE iff all columns, i.e. every variable with non-empty column w.r.t. all ever created rows, are present
609  *  in the LP, and FALSE, if there are additional already existing columns, that may be added to the LP in pricing
610  *
611  *  @return TRUE iff all columns, i.e. every variable with non-empty column w.r.t. all ever created rows, are present
612  *  in the LP, and FALSE, if there are additional already existing columns, that may be added to the LP in pricing.
613  *
614  *  @pre This method can be called if @p scip is in one of the following stages:
615  *       - \ref SCIP_STAGE_SOLVING
616  *
617  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
618  */
SCIPallColsInLP(SCIP * scip)619 SCIP_Bool SCIPallColsInLP(
620    SCIP*                 scip                /**< SCIP data structure */
621    )
622 {
623    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPallColsInLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
624 
625    return SCIPprobAllColsInLP(scip->transprob, scip->set, scip->lp);
626 }
627 
628 /** returns whether the current LP solution is basic, i.e. is defined by a valid simplex basis
629  *
630  *  @return whether the current LP solution is basic, i.e. is defined by a valid simplex basis.
631  *
632  *  @pre This method can be called if @p scip is in one of the following stages:
633  *       - \ref SCIP_STAGE_SOLVING
634  *
635  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
636  */
SCIPisLPSolBasic(SCIP * scip)637 SCIP_Bool SCIPisLPSolBasic(
638    SCIP*                 scip                /**< SCIP data structure */
639    )
640 {
641    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisLPSolBasic", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
642 
643    return SCIPlpIsSolBasic(scip->lp);
644 }
645 
646 /** gets all indices of basic columns and rows: index i >= 0 corresponds to column i, index i < 0 to row -i-1
647  *
648  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
649  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
650  *
651  *  @pre This method can be called if @p scip is in one of the following stages:
652  *       - \ref SCIP_STAGE_SOLVING
653  *
654  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
655  */
SCIPgetLPBasisInd(SCIP * scip,int * basisind)656 SCIP_RETCODE SCIPgetLPBasisInd(
657    SCIP*                 scip,               /**< SCIP data structure */
658    int*                  basisind            /**< pointer to store basis indices ready to keep number of rows entries */
659    )
660 {
661    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPBasisInd", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
662 
663    if( !SCIPlpIsSolBasic(scip->lp) )
664    {
665       SCIPerrorMessage("current LP solution is not basic\n");
666       return SCIP_INVALIDCALL;
667    }
668 
669    SCIP_CALL( SCIPlpGetBasisInd(scip->lp, basisind) );
670 
671    return SCIP_OKAY;
672 }
673 
674 /** gets a row from the inverse basis matrix B^-1
675  *
676  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
677  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
678  *
679  *  @pre This method can be called if @p scip is in one of the following stages:
680  *       - \ref SCIP_STAGE_SOLVING
681  *
682  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
683  */
SCIPgetLPBInvRow(SCIP * scip,int r,SCIP_Real * coefs,int * inds,int * ninds)684 SCIP_RETCODE SCIPgetLPBInvRow(
685    SCIP*                 scip,               /**< SCIP data structure */
686    int                   r,                  /**< row number */
687    SCIP_Real*            coefs,              /**< array to store the coefficients of the row */
688    int*                  inds,               /**< array to store the non-zero indices, or NULL */
689    int*                  ninds               /**< pointer to store the number of non-zero indices, or NULL
690                                               *  (-1: if we do not store sparsity informations) */
691    )
692 {
693    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPBInvRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
694 
695    if( !SCIPlpIsSolBasic(scip->lp) )
696    {
697       SCIPerrorMessage("current LP solution is not basic\n");
698       return SCIP_INVALIDCALL;
699    }
700 
701    SCIP_CALL( SCIPlpGetBInvRow(scip->lp, r, coefs, inds, ninds) );
702 
703    /* debug check if the coef is the r-th line of the inverse matrix B^-1 */
704    SCIP_CALL( SCIPdebugCheckBInvRow(scip, r, coefs) ); /*lint !e506 !e774*/
705 
706    return SCIP_OKAY;
707 }
708 
709 /** gets a column from the inverse basis matrix B^-1
710  *
711  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
712  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
713  *
714  *  @pre This method can be called if @p scip is in one of the following stages:
715  *       - \ref SCIP_STAGE_SOLVING
716  *
717  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
718  */
SCIPgetLPBInvCol(SCIP * scip,int c,SCIP_Real * coefs,int * inds,int * ninds)719 SCIP_RETCODE SCIPgetLPBInvCol(
720    SCIP*                 scip,               /**< SCIP data structure */
721    int                   c,                  /**< column number of B^-1; this is NOT the number of the column in the LP
722                                               *   returned by SCIPcolGetLPPos(); you have to call SCIPgetBasisInd()
723                                               *   to get the array which links the B^-1 column numbers to the row and
724                                               *   column numbers of the LP! c must be between 0 and nrows-1, since the
725                                               *   basis has the size nrows * nrows */
726    SCIP_Real*            coefs,              /**< array to store the coefficients of the column */
727    int*                  inds,               /**< array to store the non-zero indices, or NULL */
728    int*                  ninds               /**< pointer to store the number of non-zero indices, or NULL
729                                               *  (-1: if we do not store sparsity informations) */
730    )
731 {
732    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPBInvCol", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
733 
734    if( !SCIPlpIsSolBasic(scip->lp) )
735    {
736       SCIPerrorMessage("current LP solution is not basic\n");
737       return SCIP_INVALIDCALL;
738    }
739 
740    SCIP_CALL( SCIPlpGetBInvCol(scip->lp, c, coefs, inds, ninds) );
741 
742    return SCIP_OKAY;
743 }
744 
745 /** gets a row from the product of inverse basis matrix B^-1 and coefficient matrix A (i.e. from B^-1 * A)
746  *
747  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
748  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
749  *
750  *  @pre This method can be called if @p scip is in one of the following stages:
751  *       - \ref SCIP_STAGE_SOLVING
752  *
753  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
754  */
SCIPgetLPBInvARow(SCIP * scip,int r,SCIP_Real * binvrow,SCIP_Real * coefs,int * inds,int * ninds)755 SCIP_RETCODE SCIPgetLPBInvARow(
756    SCIP*                 scip,               /**< SCIP data structure */
757    int                   r,                  /**< row number */
758    SCIP_Real*            binvrow,            /**< row in B^-1 from prior call to SCIPgetLPBInvRow(), or NULL */
759    SCIP_Real*            coefs,              /**< array to store the coefficients of the row */
760    int*                  inds,               /**< array to store the non-zero indices, or NULL */
761    int*                  ninds               /**< pointer to store the number of non-zero indices, or NULL
762                                               *  (-1: if we do not store sparsity informations) */
763    )
764 {
765    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPBInvARow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
766 
767    if( !SCIPlpIsSolBasic(scip->lp) )
768    {
769       SCIPerrorMessage("current LP solution is not basic\n");
770       return SCIP_INVALIDCALL;
771    }
772 
773    SCIP_CALL( SCIPlpGetBInvARow(scip->lp, r, binvrow, coefs, inds, ninds) );
774 
775    return SCIP_OKAY;
776 }
777 
778 /** gets a column from the product of inverse basis matrix B^-1 and coefficient matrix A (i.e. from B^-1 * A),
779  *  i.e., it computes B^-1 * A_c with A_c being the c'th column of A
780  *
781  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
782  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
783  *
784  *  @pre This method can be called if @p scip is in one of the following stages:
785  *       - \ref SCIP_STAGE_SOLVING
786  *
787  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
788  */
SCIPgetLPBInvACol(SCIP * scip,int c,SCIP_Real * coefs,int * inds,int * ninds)789 SCIP_RETCODE SCIPgetLPBInvACol(
790    SCIP*                 scip,               /**< SCIP data structure */
791    int                   c,                  /**< column number which can be accessed by SCIPcolGetLPPos() */
792    SCIP_Real*            coefs,              /**< array to store the coefficients of the column */
793    int*                  inds,               /**< array to store the non-zero indices, or NULL */
794    int*                  ninds               /**< pointer to store the number of non-zero indices, or NULL
795                                               *  (-1: if we do not store sparsity informations) */
796    )
797 {
798    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPBInvACol", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
799 
800    if( !SCIPlpIsSolBasic(scip->lp) )
801    {
802       SCIPerrorMessage("current LP solution is not basic\n");
803       return SCIP_INVALIDCALL;
804    }
805 
806    SCIP_CALL( SCIPlpGetBInvACol(scip->lp, c, coefs, inds, ninds) );
807 
808    return SCIP_OKAY;
809 }
810 
811 /** calculates a weighted sum of all LP rows; for negative weights, the left and right hand side of the corresponding
812  *  LP row are swapped in the summation
813  *
814  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
815  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
816  *
817  *  @pre This method can be called if @p scip is in one of the following stages:
818  *       - \ref SCIP_STAGE_SOLVING
819  *
820  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
821  */
SCIPsumLPRows(SCIP * scip,SCIP_Real * weights,SCIP_REALARRAY * sumcoef,SCIP_Real * sumlhs,SCIP_Real * sumrhs)822 SCIP_RETCODE SCIPsumLPRows(
823    SCIP*                 scip,               /**< SCIP data structure */
824    SCIP_Real*            weights,            /**< row weights in row summation */
825    SCIP_REALARRAY*       sumcoef,            /**< array to store sum coefficients indexed by variables' probindex */
826    SCIP_Real*            sumlhs,             /**< pointer to store the left hand side of the row summation */
827    SCIP_Real*            sumrhs              /**< pointer to store the right hand side of the row summation */
828    )
829 {
830    SCIP_CALL( SCIPcheckStage(scip, "SCIPsumLPRows", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
831 
832    SCIP_CALL( SCIPlpSumRows(scip->lp, scip->set, scip->transprob, weights, sumcoef, sumlhs, sumrhs) );
833 
834    return SCIP_OKAY;
835 }
836 
837 /** writes current LP to a file
838  *
839  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
840  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
841  *
842  *  @pre This method can be called if @p scip is in one of the following stages:
843  *       - \ref SCIP_STAGE_SOLVING
844  *
845  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
846  */
SCIPwriteLP(SCIP * scip,const char * filename)847 SCIP_RETCODE SCIPwriteLP(
848    SCIP*                 scip,               /**< SCIP data structure */
849    const char*           filename            /**< file name */
850    )
851 {
852    SCIP_Bool cutoff;
853 
854    SCIP_CALL( SCIPcheckStage(scip, "SCIPwriteLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
855 
856    if( !SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
857    {
858       SCIP_CALL( SCIPconstructCurrentLP(scip->mem->probmem, scip->set, scip->stat, scip->transprob, scip->origprob,
859             scip->tree, scip->reopt, scip->lp, scip->pricestore, scip->sepastore, scip->cutpool, scip->branchcand,
860             scip->eventqueue, scip->eventfilter, scip->cliquetable, FALSE, &cutoff) );
861    }
862 
863    /* we need a flushed lp to write the current lp */
864    SCIP_CALL( SCIPlpFlush(scip->lp, scip->mem->probmem, scip->set, scip->eventqueue) );
865 
866    SCIP_CALL( SCIPlpWrite(scip->lp, filename) );
867 
868    return SCIP_OKAY;
869 }
870 
871 /** writes MIP relaxation of the current branch-and-bound node to a file
872  *
873  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
874  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
875  *
876  *  @pre This method can be called if @p scip is in one of the following stages:
877  *       - \ref SCIP_STAGE_SOLVING
878  *
879  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
880  */
SCIPwriteMIP(SCIP * scip,const char * filename,SCIP_Bool genericnames,SCIP_Bool origobj,SCIP_Bool lazyconss)881 SCIP_RETCODE SCIPwriteMIP(
882    SCIP*                 scip,               /**< SCIP data structure */
883    const char*           filename,           /**< file name */
884    SCIP_Bool             genericnames,       /**< should generic names like x_i and row_j be used in order to avoid
885                                               *   troubles with reserved symbols? */
886    SCIP_Bool             origobj,            /**< should the original objective function be used? */
887    SCIP_Bool             lazyconss           /**< output removable rows as lazy constraints? */
888    )
889 {
890    SCIP_CALL( SCIPcheckStage(scip, "SCIPwriteMIP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
891 
892    /* we need a flushed lp to write the current mip */
893    SCIP_CALL( SCIPlpFlush(scip->lp, scip->mem->probmem, scip->set, scip->eventqueue) );
894 
895    SCIP_CALL( SCIPlpWriteMip(scip->lp, scip->set, scip->messagehdlr, filename, genericnames,
896          origobj, scip->origprob->objsense, scip->transprob->objscale, scip->transprob->objoffset, lazyconss) );
897 
898    return SCIP_OKAY;
899 }
900 
901 /** gets the LP interface of SCIP;
902  *  with the LPI you can use all of the methods defined in lpi/lpi.h;
903  *
904  *  @warning You have to make sure, that the full internal state of the LPI does not change or is recovered completely
905  *           after the end of the method that uses the LPI. In particular, if you manipulate the LP or its solution
906  *           (e.g. by calling one of the SCIPlpiAdd...() or one of the SCIPlpiSolve...() methods), you have to check in
907  *           advance with SCIPlpiWasSolved() whether the LP is currently solved. If this is the case, you have to make
908  *           sure, the internal solution status is recovered completely at the end of your method. This can be achieved
909  *           by getting the LPI state before applying any LPI manipulations with SCIPlpiGetState() and restoring it
910  *           afterwards with SCIPlpiSetState() and SCIPlpiFreeState(). Additionally you have to resolve the LP with the
911  *           appropriate SCIPlpiSolve...() call in order to reinstall the internal solution status.
912  *
913  *  @warning Make also sure, that all parameter values that you have changed are set back to their original values.
914  *
915  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
916  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
917  *
918  *  @pre This method can be called if @p scip is in one of the following stages:
919  *       - \ref SCIP_STAGE_TRANSFORMED
920  *       - \ref SCIP_STAGE_INITPRESOLVE
921  *       - \ref SCIP_STAGE_PRESOLVING
922  *       - \ref SCIP_STAGE_EXITPRESOLVE
923  *       - \ref SCIP_STAGE_PRESOLVED
924  *       - \ref SCIP_STAGE_INITSOLVE
925  *       - \ref SCIP_STAGE_SOLVING
926  *       - \ref SCIP_STAGE_SOLVED
927  *       - \ref SCIP_STAGE_EXITSOLVE
928  *
929  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
930  */
SCIPgetLPI(SCIP * scip,SCIP_LPI ** lpi)931 SCIP_RETCODE SCIPgetLPI(
932    SCIP*                 scip,               /**< SCIP data structure */
933    SCIP_LPI**            lpi                 /**< pointer to store the LP interface */
934    )
935 {
936    assert(lpi != NULL);
937 
938    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPI", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE) );
939 
940    *lpi = SCIPlpGetLPI(scip->lp);
941 
942    return SCIP_OKAY;
943 }
944 
945 /** displays quality information about the current LP solution. An LP solution need to be available; information printed
946  *  is subject to what the LP solver supports
947  *
948  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
949  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
950  *
951  *  @pre This method can be called if @p scip is in one of the following stages:
952  *       - \ref SCIP_STAGE_INIT
953  *       - \ref SCIP_STAGE_PROBLEM
954  *       - \ref SCIP_STAGE_TRANSFORMED
955  *       - \ref SCIP_STAGE_INITPRESOLVE
956  *       - \ref SCIP_STAGE_PRESOLVING
957  *       - \ref SCIP_STAGE_EXITPRESOLVE
958  *       - \ref SCIP_STAGE_PRESOLVED
959  *       - \ref SCIP_STAGE_SOLVING
960  *       - \ref SCIP_STAGE_SOLVED
961  *       - \ref SCIP_STAGE_FREE
962  *
963  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
964  *
965  *  @note The printing process is done via the message handler system.
966  */
SCIPprintLPSolutionQuality(SCIP * scip,FILE * file)967 SCIP_RETCODE SCIPprintLPSolutionQuality(
968    SCIP*                 scip,               /**< SCIP data structure */
969    FILE*                 file                /**< output file (or NULL for standard output) */
970    )
971 {
972    SCIP_LPI* lpi;
973    SCIP_Real quality;
974 
975    SCIP_CALL( SCIPcheckStage(scip, "SCIPprintLPSolutionQuality", TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE) );
976 
977    switch( scip->set->stage )
978    {
979       case SCIP_STAGE_INIT:
980       case SCIP_STAGE_PROBLEM:
981       case SCIP_STAGE_TRANSFORMED:
982       case SCIP_STAGE_INITPRESOLVE:
983    case SCIP_STAGE_PRESOLVING:
984    case SCIP_STAGE_EXITPRESOLVE:
985       case SCIP_STAGE_PRESOLVED:
986          SCIPmessageFPrintInfo(scip->messagehdlr, file, "Problem not solving yet, no LP available.\n");
987          return SCIP_OKAY;
988 
989       case SCIP_STAGE_SOLVING:
990       case SCIP_STAGE_SOLVED:
991          break;
992 
993       default:
994          SCIPerrorMessage("invalid SCIP stage <%d>\n", scip->set->stage);
995          return SCIP_INVALIDCALL;
996    }  /*lint !e788*/
997 
998    /* note that after diving mode, the LPI may only have the basis information, but SCIPlpiWasSolved() can be false; in
999     * this case, we will (depending on the LP solver) probably not obtain the quality measure; one solution would be to
1000     * store the results of SCIPlpiGetRealSolQuality() within the SCIP_LP after each LP solve; this would have the added
1001     * advantage, that we reduce direct access to the LPI, but it sounds potentially expensive
1002     */
1003    lpi = SCIPlpGetLPI(scip->lp);
1004    assert(lpi != NULL);
1005 
1006    SCIP_CALL( SCIPlpiGetRealSolQuality(lpi, SCIP_LPSOLQUALITY_ESTIMCONDITION, &quality) );
1007    SCIPmessageFPrintInfo(scip->messagehdlr, file, "Basis matrix condition (estimated): ");
1008    if( quality != SCIP_INVALID ) /*lint !e777*/
1009       SCIPmessageFPrintInfo(scip->messagehdlr, file, "%.6e\n", quality);
1010    else
1011       SCIPmessageFPrintInfo(scip->messagehdlr, file, "not available\n");
1012 
1013    SCIP_CALL( SCIPlpiGetRealSolQuality(lpi, SCIP_LPSOLQUALITY_EXACTCONDITION, &quality) );
1014    SCIPmessageFPrintInfo(scip->messagehdlr, file, "Basis matrix condition (exact):     ");
1015    if( quality != SCIP_INVALID ) /*lint !e777*/
1016       SCIPmessageFPrintInfo(scip->messagehdlr, file, "%.6e\n", quality);
1017    else
1018       SCIPmessageFPrintInfo(scip->messagehdlr, file, "not available\n");
1019 
1020    return SCIP_OKAY;
1021 }
1022 
1023 /** compute relative interior point to current LP
1024  *  @see SCIPlpComputeRelIntPoint
1025  *
1026  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1027  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1028  *
1029  *  @pre This method can be called if @p scip is in one of the following stages:
1030  *       - \ref SCIP_STAGE_TRANSFORMED
1031  *       - \ref SCIP_STAGE_INITPRESOLVE
1032  *       - \ref SCIP_STAGE_PRESOLVING
1033  *       - \ref SCIP_STAGE_EXITPRESOLVE
1034  *       - \ref SCIP_STAGE_PRESOLVED
1035  *       - \ref SCIP_STAGE_SOLVING
1036  *       - \ref SCIP_STAGE_SOLVED
1037  *
1038  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1039  */
SCIPcomputeLPRelIntPoint(SCIP * scip,SCIP_Bool relaxrows,SCIP_Bool inclobjcutoff,SCIP_Real timelimit,int iterlimit,SCIP_SOL ** point)1040 SCIP_RETCODE SCIPcomputeLPRelIntPoint(
1041    SCIP*                 scip,               /**< SCIP data structure */
1042    SCIP_Bool             relaxrows,          /**< should the rows be relaxed */
1043    SCIP_Bool             inclobjcutoff,      /**< should a row for the objective cutoff be included */
1044    SCIP_Real             timelimit,          /**< time limit for LP solver */
1045    int                   iterlimit,          /**< iteration limit for LP solver */
1046    SCIP_SOL**            point               /**< relative interior point on exit */
1047    )
1048 {
1049    SCIP_Real* pointvals;
1050    SCIP_Bool success;
1051 
1052    SCIP_CALL( SCIPcheckStage(scip, "SCIPcomputeLPRelIntPoint", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1053 
1054    assert(scip != NULL);
1055    assert(scip->lp != NULL);
1056    assert(point != NULL);
1057 
1058    *point = NULL;
1059 
1060    SCIP_CALL( SCIPallocBufferArray(scip, &pointvals, SCIPlpGetNCols(scip->lp)) );
1061 
1062    SCIP_CALL( SCIPlpComputeRelIntPoint(scip->set, scip->messagehdlr, scip->lp, scip->transprob,
1063          relaxrows, inclobjcutoff, timelimit, iterlimit, pointvals, &success) );
1064 
1065    /* if successful, create new solution with point values */
1066    if( success )
1067    {
1068       int i;
1069 
1070       SCIP_CALL( SCIPcreateSol(scip, point, NULL) );
1071 
1072       for( i = 0; i < SCIPlpGetNCols(scip->lp); ++i )
1073       {
1074          SCIP_CALL( SCIPsetSolVal(scip, *point, SCIPcolGetVar(SCIPlpGetCols(scip->lp)[i]), pointvals[i]) );
1075       }
1076    }
1077 
1078    SCIPfreeBufferArray(scip, &pointvals);
1079 
1080    return SCIP_OKAY;
1081 }
1082 
1083 /*
1084  * LP column methods
1085  */
1086 
1087 /** returns the reduced costs of a column in the last (feasible) LP
1088  *
1089  *  @return the reduced costs of a column in the last (feasible) LP
1090  *
1091  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1092  *       - \ref SCIP_STAGE_SOLVING
1093  *       - \ref SCIP_STAGE_SOLVED
1094  *
1095  *  @note calling this method in SCIP_STAGE_SOLVED is only recommended to experienced users and should only be called
1096  *        for pure LP instances (without presolving)
1097  *
1098  *  @note The return value of this method should be used carefully if the dual feasibility check was explictely disabled.
1099  */
SCIPgetColRedcost(SCIP * scip,SCIP_COL * col)1100 SCIP_Real SCIPgetColRedcost(
1101    SCIP*                 scip,               /**< SCIP data structure */
1102    SCIP_COL*             col                 /**< LP column */
1103    )
1104 {
1105    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetColRedcost", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1106 
1107    if( !SCIPtreeHasCurrentNodeLP(scip->tree) )
1108    {
1109       SCIPerrorMessage("cannot get reduced costs, because node LP is not processed\n");
1110       SCIPABORT();
1111       return 0.0; /*lint !e527*/
1112    }
1113 
1114    return SCIPcolGetRedcost(col, scip->stat, scip->lp);
1115 }
1116 
1117 
1118 /** returns the Farkas coefficient of a column in the last (infeasible) LP
1119  *
1120  *  @return the Farkas coefficient of a column in the last (infeasible) LP
1121  *
1122  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1123  *       - \ref SCIP_STAGE_SOLVING
1124  *       - \ref SCIP_STAGE_SOLVED
1125  */
SCIPgetColFarkasCoef(SCIP * scip,SCIP_COL * col)1126 SCIP_Real SCIPgetColFarkasCoef(
1127    SCIP*                 scip,               /**< SCIP data structure */
1128    SCIP_COL*             col                 /**< LP column */
1129    )
1130 {
1131    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetColFarkasCoef", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1132 
1133    if( !SCIPtreeHasCurrentNodeLP(scip->tree) )
1134    {
1135       SCIPerrorMessage("cannot get Farkas coeff, because node LP is not processed\n");
1136       SCIPABORT();
1137       return 0.0; /*lint !e527*/
1138    }
1139 
1140    return SCIPcolGetFarkasCoef(col, scip->stat, scip->lp);
1141 }
1142 
1143 /** marks a column to be not removable from the LP in the current node
1144  *
1145  *  @pre this method can be called in the following stage of the SCIP solving process:
1146  *       - \ref SCIP_STAGE_SOLVING
1147  */
SCIPmarkColNotRemovableLocal(SCIP * scip,SCIP_COL * col)1148 void SCIPmarkColNotRemovableLocal(
1149    SCIP*                 scip,               /**< SCIP data structure */
1150    SCIP_COL*             col                 /**< LP column */
1151    )
1152 {
1153    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPmarkColNotRemovableLocal", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1154 
1155    SCIPcolMarkNotRemovableLocal(col, scip->stat);
1156 }
1157 
1158 /*
1159  * LP row methods
1160  */
1161 
1162 /** creates and captures an LP row from a constraint handler
1163  *
1164  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1165  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1166  *
1167  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1168  *       - \ref SCIP_STAGE_INITSOLVE
1169  *       - \ref SCIP_STAGE_SOLVING
1170  */
SCIPcreateRowConshdlr(SCIP * scip,SCIP_ROW ** row,SCIP_CONSHDLR * conshdlr,const char * name,int len,SCIP_COL ** cols,SCIP_Real * vals,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1171 SCIP_RETCODE SCIPcreateRowConshdlr(
1172    SCIP*                 scip,               /**< SCIP data structure */
1173    SCIP_ROW**            row,                /**< pointer to row */
1174    SCIP_CONSHDLR*        conshdlr,           /**< constraint handler that creates the row */
1175    const char*           name,               /**< name of row */
1176    int                   len,                /**< number of nonzeros in the row */
1177    SCIP_COL**            cols,               /**< array with columns of row entries */
1178    SCIP_Real*            vals,               /**< array with coefficients of row entries */
1179    SCIP_Real             lhs,                /**< left hand side of row */
1180    SCIP_Real             rhs,                /**< right hand side of row */
1181    SCIP_Bool             local,              /**< is row only valid locally? */
1182    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1183    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1184    )
1185 {
1186    assert(conshdlr != NULL);
1187 
1188    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateRowConshdlr", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1189 
1190    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1191          name, len, cols, vals, lhs, rhs, SCIP_ROWORIGINTYPE_CONSHDLR, (void*) conshdlr, local, modifiable, removable) );
1192 
1193    return SCIP_OKAY;
1194 }
1195 
1196 /** creates and captures an LP row from a constraint
1197  *
1198  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1199  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1200  *
1201  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1202  *       - \ref SCIP_STAGE_INITSOLVE
1203  *       - \ref SCIP_STAGE_SOLVING
1204  */
SCIPcreateRowCons(SCIP * scip,SCIP_ROW ** row,SCIP_CONS * cons,const char * name,int len,SCIP_COL ** cols,SCIP_Real * vals,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1205 SCIP_RETCODE SCIPcreateRowCons(
1206    SCIP*                 scip,               /**< SCIP data structure */
1207    SCIP_ROW**            row,                /**< pointer to row */
1208    SCIP_CONS*            cons,               /**< constraint that creates the row */
1209    const char*           name,               /**< name of row */
1210    int                   len,                /**< number of nonzeros in the row */
1211    SCIP_COL**            cols,               /**< array with columns of row entries */
1212    SCIP_Real*            vals,               /**< array with coefficients of row entries */
1213    SCIP_Real             lhs,                /**< left hand side of row */
1214    SCIP_Real             rhs,                /**< right hand side of row */
1215    SCIP_Bool             local,              /**< is row only valid locally? */
1216    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1217    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1218    )
1219 {
1220    assert(cons != NULL);
1221 
1222    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateRowCons", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1223 
1224    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1225          name, len, cols, vals, lhs, rhs, SCIP_ROWORIGINTYPE_CONS, (void*) cons, local, modifiable, removable) );
1226 
1227    return SCIP_OKAY;
1228 }
1229 
1230 /** creates and captures an LP row from a separator
1231  *
1232  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1233  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1234  *
1235  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1236  *       - \ref SCIP_STAGE_INITSOLVE
1237  *       - \ref SCIP_STAGE_SOLVING
1238  */
SCIPcreateRowSepa(SCIP * scip,SCIP_ROW ** row,SCIP_SEPA * sepa,const char * name,int len,SCIP_COL ** cols,SCIP_Real * vals,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1239 SCIP_RETCODE SCIPcreateRowSepa(
1240    SCIP*                 scip,               /**< SCIP data structure */
1241    SCIP_ROW**            row,                /**< pointer to row */
1242    SCIP_SEPA*            sepa,               /**< separator that creates the row */
1243    const char*           name,               /**< name of row */
1244    int                   len,                /**< number of nonzeros in the row */
1245    SCIP_COL**            cols,               /**< array with columns of row entries */
1246    SCIP_Real*            vals,               /**< array with coefficients of row entries */
1247    SCIP_Real             lhs,                /**< left hand side of row */
1248    SCIP_Real             rhs,                /**< right hand side of row */
1249    SCIP_Bool             local,              /**< is row only valid locally? */
1250    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1251    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1252    )
1253 {
1254    assert(sepa != NULL);
1255 
1256    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateRowSepa", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1257 
1258    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1259          name, len, cols, vals, lhs, rhs, SCIP_ROWORIGINTYPE_SEPA, (void*) sepa, local, modifiable, removable) );
1260 
1261    return SCIP_OKAY;
1262 }
1263 
1264 /** creates and captures an LP row from an unspecified source
1265  *
1266  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1267  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1268  *
1269  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1270  *       - \ref SCIP_STAGE_INITSOLVE
1271  *       - \ref SCIP_STAGE_SOLVING
1272  */
SCIPcreateRowUnspec(SCIP * scip,SCIP_ROW ** row,const char * name,int len,SCIP_COL ** cols,SCIP_Real * vals,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1273 SCIP_RETCODE SCIPcreateRowUnspec(
1274    SCIP*                 scip,               /**< SCIP data structure */
1275    SCIP_ROW**            row,                /**< pointer to row */
1276    const char*           name,               /**< name of row */
1277    int                   len,                /**< number of nonzeros in the row */
1278    SCIP_COL**            cols,               /**< array with columns of row entries */
1279    SCIP_Real*            vals,               /**< array with coefficients of row entries */
1280    SCIP_Real             lhs,                /**< left hand side of row */
1281    SCIP_Real             rhs,                /**< right hand side of row */
1282    SCIP_Bool             local,              /**< is row only valid locally? */
1283    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1284    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1285    )
1286 {
1287    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateRowUnspec", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1288 
1289    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1290          name, len, cols, vals, lhs, rhs, SCIP_ROWORIGINTYPE_UNSPEC, NULL, local, modifiable, removable) );
1291 
1292    return SCIP_OKAY;
1293 }
1294 
1295 /** creates and captures an LP row
1296  *
1297  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1298  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1299  *
1300  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1301  *       - \ref SCIP_STAGE_INITSOLVE
1302  *       - \ref SCIP_STAGE_SOLVING
1303  *
1304  *  @deprecated Please use SCIPcreateRowConshdlr() or SCIPcreateRowSepa() when calling from a constraint handler or separator in order
1305  *              to facilitate correct statistics. If the call is from neither a constraint handler or separator, use SCIPcreateRowUnspec().
1306  */
SCIPcreateRow(SCIP * scip,SCIP_ROW ** row,const char * name,int len,SCIP_COL ** cols,SCIP_Real * vals,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1307 SCIP_RETCODE SCIPcreateRow(
1308    SCIP*                 scip,               /**< SCIP data structure */
1309    SCIP_ROW**            row,                /**< pointer to row */
1310    const char*           name,               /**< name of row */
1311    int                   len,                /**< number of nonzeros in the row */
1312    SCIP_COL**            cols,               /**< array with columns of row entries */
1313    SCIP_Real*            vals,               /**< array with coefficients of row entries */
1314    SCIP_Real             lhs,                /**< left hand side of row */
1315    SCIP_Real             rhs,                /**< right hand side of row */
1316    SCIP_Bool             local,              /**< is row only valid locally? */
1317    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1318    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1319    )
1320 {
1321    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1322 
1323    SCIP_CALL( SCIPcreateRowUnspec(scip, row, name, len, cols, vals, lhs, rhs, local, modifiable, removable) );
1324 
1325    return SCIP_OKAY;
1326 }
1327 
1328 /** creates and captures an LP row without any coefficients from a constraint handler
1329  *
1330  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1331  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1332  *
1333  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1334  *       - \ref SCIP_STAGE_INITSOLVE
1335  *       - \ref SCIP_STAGE_SOLVING
1336  */
SCIPcreateEmptyRowConshdlr(SCIP * scip,SCIP_ROW ** row,SCIP_CONSHDLR * conshdlr,const char * name,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1337 SCIP_RETCODE SCIPcreateEmptyRowConshdlr(
1338    SCIP*                 scip,               /**< SCIP data structure */
1339    SCIP_ROW**            row,                /**< pointer to row */
1340    SCIP_CONSHDLR*        conshdlr,           /**< constraint handler that creates the row */
1341    const char*           name,               /**< name of row */
1342    SCIP_Real             lhs,                /**< left hand side of row */
1343    SCIP_Real             rhs,                /**< right hand side of row */
1344    SCIP_Bool             local,              /**< is row only valid locally? */
1345    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1346    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1347    )
1348 {
1349    assert(conshdlr != NULL);
1350 
1351    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateEmptyRowConshdlr", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1352 
1353    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1354          name, 0, NULL, NULL, lhs, rhs, SCIP_ROWORIGINTYPE_CONSHDLR, (void*) conshdlr, local, modifiable, removable) );
1355 
1356    return SCIP_OKAY;
1357 }
1358 
1359 /** creates and captures an LP row without any coefficients from a constraint
1360  *
1361  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1362  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1363  *
1364  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1365  *       - \ref SCIP_STAGE_INITSOLVE
1366  *       - \ref SCIP_STAGE_SOLVING
1367  */
SCIPcreateEmptyRowCons(SCIP * scip,SCIP_ROW ** row,SCIP_CONS * cons,const char * name,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1368 SCIP_RETCODE SCIPcreateEmptyRowCons(
1369    SCIP*                 scip,               /**< SCIP data structure */
1370    SCIP_ROW**            row,                /**< pointer to row */
1371    SCIP_CONS*            cons,               /**< constraint that creates the row */
1372    const char*           name,               /**< name of row */
1373    SCIP_Real             lhs,                /**< left hand side of row */
1374    SCIP_Real             rhs,                /**< right hand side of row */
1375    SCIP_Bool             local,              /**< is row only valid locally? */
1376    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1377    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1378    )
1379 {
1380    assert(cons != NULL);
1381 
1382    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateEmptyRowCons", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1383 
1384    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1385          name, 0, NULL, NULL, lhs, rhs, SCIP_ROWORIGINTYPE_CONS, (void*) cons, local, modifiable, removable) );
1386 
1387    return SCIP_OKAY;
1388 }
1389 
1390 /** creates and captures an LP row without any coefficients from a separator
1391  *
1392  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1393  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1394  *
1395  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1396  *       - \ref SCIP_STAGE_INITSOLVE
1397  *       - \ref SCIP_STAGE_SOLVING
1398  */
SCIPcreateEmptyRowSepa(SCIP * scip,SCIP_ROW ** row,SCIP_SEPA * sepa,const char * name,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1399 SCIP_RETCODE SCIPcreateEmptyRowSepa(
1400    SCIP*                 scip,               /**< SCIP data structure */
1401    SCIP_ROW**            row,                /**< pointer to row */
1402    SCIP_SEPA*            sepa,               /**< separator that creates the row */
1403    const char*           name,               /**< name of row */
1404    SCIP_Real             lhs,                /**< left hand side of row */
1405    SCIP_Real             rhs,                /**< right hand side of row */
1406    SCIP_Bool             local,              /**< is row only valid locally? */
1407    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1408    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1409    )
1410 {
1411    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateEmptyRowSepa", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1412 
1413    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1414          name, 0, NULL, NULL, lhs, rhs, SCIP_ROWORIGINTYPE_SEPA, (void*) sepa, local, modifiable, removable) );
1415 
1416    return SCIP_OKAY;
1417 }
1418 
1419 /** creates and captures an LP row without any coefficients from an unspecified source
1420  *
1421  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1422  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1423  *
1424  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1425  *       - \ref SCIP_STAGE_INITSOLVE
1426  *       - \ref SCIP_STAGE_SOLVING
1427  */
SCIPcreateEmptyRowUnspec(SCIP * scip,SCIP_ROW ** row,const char * name,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1428 SCIP_RETCODE SCIPcreateEmptyRowUnspec(
1429    SCIP*                 scip,               /**< SCIP data structure */
1430    SCIP_ROW**            row,                /**< pointer to row */
1431    const char*           name,               /**< name of row */
1432    SCIP_Real             lhs,                /**< left hand side of row */
1433    SCIP_Real             rhs,                /**< right hand side of row */
1434    SCIP_Bool             local,              /**< is row only valid locally? */
1435    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1436    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1437    )
1438 {
1439    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateEmptyRowUnspec", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1440 
1441    SCIP_CALL( SCIProwCreate(row, scip->mem->probmem, scip->set, scip->stat,
1442          name, 0, NULL, NULL, lhs, rhs, SCIP_ROWORIGINTYPE_UNSPEC, NULL, local, modifiable, removable) );
1443 
1444    return SCIP_OKAY;
1445 }
1446 
1447 /** creates and captures an LP row without any coefficients
1448  *
1449  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1450  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1451  *
1452  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1453  *       - \ref SCIP_STAGE_INITSOLVE
1454  *       - \ref SCIP_STAGE_SOLVING
1455  *
1456  *  @deprecated Please use SCIPcreateEmptyRowConshdlr() or SCIPcreateEmptyRowSepa() when calling from a constraint handler or separator in order
1457  *              to facilitate correct statistics. If the call is from neither a constraint handler or separator, use SCIPcreateEmptyRowUnspec().
1458  */
SCIPcreateEmptyRow(SCIP * scip,SCIP_ROW ** row,const char * name,SCIP_Real lhs,SCIP_Real rhs,SCIP_Bool local,SCIP_Bool modifiable,SCIP_Bool removable)1459 SCIP_RETCODE SCIPcreateEmptyRow(
1460    SCIP*                 scip,               /**< SCIP data structure */
1461    SCIP_ROW**            row,                /**< pointer to row */
1462    const char*           name,               /**< name of row */
1463    SCIP_Real             lhs,                /**< left hand side of row */
1464    SCIP_Real             rhs,                /**< right hand side of row */
1465    SCIP_Bool             local,              /**< is row only valid locally? */
1466    SCIP_Bool             modifiable,         /**< is row modifiable during node processing (subject to column generation)? */
1467    SCIP_Bool             removable           /**< should the row be removed from the LP due to aging or cleanup? */
1468    )
1469 {
1470    SCIP_CALL( SCIPcheckStage(scip, "SCIPcreateEmptyRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1471 
1472    SCIP_CALL( SCIPcreateEmptyRowUnspec(scip, row, name, lhs, rhs, local, modifiable, removable) );
1473 
1474    return SCIP_OKAY;
1475 }
1476 
1477 /** increases usage counter of LP row
1478  *
1479  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1480  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1481  *
1482  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1483  *       - \ref SCIP_STAGE_INITSOLVE
1484  *       - \ref SCIP_STAGE_SOLVING
1485  */
SCIPcaptureRow(SCIP * scip,SCIP_ROW * row)1486 SCIP_RETCODE SCIPcaptureRow(
1487    SCIP*                 scip,               /**< SCIP data structure */
1488    SCIP_ROW*             row                 /**< row to capture */
1489    )
1490 {
1491    SCIP_CALL( SCIPcheckStage(scip, "SCIPcaptureRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1492 
1493    SCIProwCapture(row);
1494 
1495    return SCIP_OKAY;
1496 }
1497 
1498 /** decreases usage counter of LP row, and frees memory if necessary
1499  *
1500  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1501  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1502  *
1503  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1504  *       - \ref SCIP_STAGE_INITSOLVE
1505  *       - \ref SCIP_STAGE_SOLVING
1506  *       - \ref SCIP_STAGE_EXITSOLVE
1507  */
SCIPreleaseRow(SCIP * scip,SCIP_ROW ** row)1508 SCIP_RETCODE SCIPreleaseRow(
1509    SCIP*                 scip,               /**< SCIP data structure */
1510    SCIP_ROW**            row                 /**< pointer to LP row */
1511    )
1512 {
1513    SCIP_CALL( SCIPcheckStage(scip, "SCIPreleaseRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE) );
1514 
1515    SCIP_CALL( SCIProwRelease(row, scip->mem->probmem, scip->set, scip->lp) );
1516 
1517    return SCIP_OKAY;
1518 }
1519 
1520 /** changes left hand side of LP row
1521  *
1522  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1523  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1524  *
1525  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1526  *       - \ref SCIP_STAGE_INITSOLVE
1527  *       - \ref SCIP_STAGE_SOLVING
1528  */
SCIPchgRowLhs(SCIP * scip,SCIP_ROW * row,SCIP_Real lhs)1529 SCIP_RETCODE SCIPchgRowLhs(
1530    SCIP*                 scip,               /**< SCIP data structure */
1531    SCIP_ROW*             row,                /**< LP row */
1532    SCIP_Real             lhs                 /**< new left hand side */
1533    )
1534 {
1535    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgRowLhs", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1536 
1537    assert(!SCIPlpDiving(scip->lp) || (row->lppos == -1));
1538 
1539    SCIP_CALL( SCIProwChgLhs(row, scip->mem->probmem, scip->set, scip->eventqueue, scip->lp, lhs) );
1540 
1541    return SCIP_OKAY;
1542 }
1543 
1544 /** changes right hand side of LP row
1545  *
1546  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1547  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1548  *
1549  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1550  *       - \ref SCIP_STAGE_INITSOLVE
1551  *       - \ref SCIP_STAGE_SOLVING
1552  */
SCIPchgRowRhs(SCIP * scip,SCIP_ROW * row,SCIP_Real rhs)1553 SCIP_RETCODE SCIPchgRowRhs(
1554    SCIP*                 scip,               /**< SCIP data structure */
1555    SCIP_ROW*             row,                /**< LP row */
1556    SCIP_Real             rhs                 /**< new right hand side */
1557    )
1558 {
1559    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgRowRhs", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1560 
1561    assert(!SCIPlpDiving(scip->lp) || (row->lppos == -1));
1562 
1563    SCIP_CALL( SCIProwChgRhs(row, scip->mem->probmem, scip->set, scip->eventqueue, scip->lp, rhs) );
1564 
1565    return SCIP_OKAY;
1566 }
1567 
1568 /** informs row, that all subsequent additions of variables to the row should be cached and not directly applied;
1569  *  after all additions were applied, SCIPflushRowExtensions() must be called;
1570  *  while the caching of row extensions is activated, information methods of the row give invalid results;
1571  *  caching should be used, if a row is build with SCIPaddVarToRow() calls variable by variable to increase
1572  *  the performance
1573  *
1574  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1575  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1576  *
1577  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1578  *       - \ref SCIP_STAGE_INITSOLVE
1579  *       - \ref SCIP_STAGE_SOLVING
1580  */
SCIPcacheRowExtensions(SCIP * scip,SCIP_ROW * row)1581 SCIP_RETCODE SCIPcacheRowExtensions(
1582    SCIP*                 scip,               /**< SCIP data structure */
1583    SCIP_ROW*             row                 /**< LP row */
1584    )
1585 {
1586    SCIP_CALL( SCIPcheckStage(scip, "SCIPcacheRowExtensions", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1587 
1588    /* delay the row sorting */
1589    SCIProwDelaySort(row);
1590 
1591    return SCIP_OKAY;
1592 }
1593 
1594 /** flushes all cached row extensions after a call of SCIPcacheRowExtensions() and merges coefficients with
1595  *  equal columns into a single coefficient
1596  *
1597  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1598  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1599  *
1600  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1601  *       - \ref SCIP_STAGE_INITSOLVE
1602  *       - \ref SCIP_STAGE_SOLVING
1603  */
SCIPflushRowExtensions(SCIP * scip,SCIP_ROW * row)1604 SCIP_RETCODE SCIPflushRowExtensions(
1605    SCIP*                 scip,               /**< SCIP data structure */
1606    SCIP_ROW*             row                 /**< LP row */
1607    )
1608 {
1609    SCIP_CALL( SCIPcheckStage(scip, "SCIPflushRowExtensions", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1610 
1611    /* force the row sorting, and merge equal column entries */
1612    SCIProwForceSort(row, scip->set);
1613 
1614    return SCIP_OKAY;
1615 }
1616 
1617 /** resolves variable to columns and adds them with the coefficient to the row
1618  *
1619  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1620  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1621  *
1622  *  @attention If the absolute value of val is below the SCIP epsilon tolerance, the variable will not added.
1623  *
1624  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1625  *       - \ref SCIP_STAGE_INITSOLVE
1626  *       - \ref SCIP_STAGE_SOLVING
1627  *
1628  *  @note In case calling this method in the enforcement process of an lp solution, it might be that some variables,
1629  *        that were not yet in the LP (e.g. dynamic columns) will change their lp solution value returned by SCIP.
1630  *        For example, a variable, which has a negative objective value, that has no column in the lp yet, is in the lp solution
1631  *        on its upper bound (variables with status SCIP_VARSTATUS_LOOSE are in an lp solution on it's best bound), but
1632  *        creating the column, changes the solution value (variable than has status SCIP_VARSTATUS_COLUMN, and the
1633  *        initialization sets the lp solution value) to 0.0. (This leads to the conclusion that, if a constraint was
1634  *        violated, the linear relaxation might not be violated anymore.)
1635  *
1636  *  @note If the variable being added is FIXED (as given by the status SCIP_VARSTATUS_FIXED), then the variable is not
1637  *        added to the row, but the corresponding constant is added. Similarly, if the input variable is aggregated (as
1638  *        given by the status SCIP_VARSTATUS_AGGREGATED), then the input variable is substituted with its aggregation.
1639  *        For other cases, and to better understand the function behavior, please check the code of SCIPvarAddToRow.
1640  */
SCIPaddVarToRow(SCIP * scip,SCIP_ROW * row,SCIP_VAR * var,SCIP_Real val)1641 SCIP_RETCODE SCIPaddVarToRow(
1642    SCIP*                 scip,               /**< SCIP data structure */
1643    SCIP_ROW*             row,                /**< LP row */
1644    SCIP_VAR*             var,                /**< problem variable */
1645    SCIP_Real             val                 /**< value of coefficient */
1646    )
1647 {
1648    SCIP_CALL( SCIPcheckStage(scip, "SCIPaddVarToRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1649 
1650    SCIP_CALL( SCIPvarAddToRow(var, scip->mem->probmem, scip->set, scip->stat, scip->eventqueue, scip->transprob, scip->lp, row, val) );
1651 
1652    return SCIP_OKAY;
1653 }
1654 
1655 /** resolves variables to columns and adds them with the coefficients to the row;
1656  *  this method caches the row extensions and flushes them afterwards to gain better performance
1657  *
1658  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1659  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1660  *
1661  *  @attention If a coefficients absolute value is below the SCIP epsilon tolerance, the variable with its value is not added.
1662  *
1663  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1664  *       - \ref SCIP_STAGE_INITSOLVE
1665  *       - \ref SCIP_STAGE_SOLVING
1666  */
SCIPaddVarsToRow(SCIP * scip,SCIP_ROW * row,int nvars,SCIP_VAR ** vars,SCIP_Real * vals)1667 SCIP_RETCODE SCIPaddVarsToRow(
1668    SCIP*                 scip,               /**< SCIP data structure */
1669    SCIP_ROW*             row,                /**< LP row */
1670    int                   nvars,              /**< number of variables to add to the row */
1671    SCIP_VAR**            vars,               /**< problem variables to add */
1672    SCIP_Real*            vals                /**< values of coefficients */
1673    )
1674 {
1675    int v;
1676 
1677    assert(nvars == 0 || vars != NULL);
1678    assert(nvars == 0 || vals != NULL);
1679 
1680    SCIP_CALL( SCIPcheckStage(scip, "SCIPaddVarsToRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1681 
1682    /* resize the row to be able to store all variables (at least, if they are COLUMN variables) */
1683    SCIP_CALL( SCIProwEnsureSize(row, scip->mem->probmem, scip->set, SCIProwGetNNonz(row) + nvars) );
1684 
1685    /* delay the row sorting */
1686    SCIProwDelaySort(row);
1687 
1688    /* add the variables to the row */
1689    for( v = 0; v < nvars; ++v )
1690    {
1691       SCIP_CALL( SCIPvarAddToRow(vars[v], scip->mem->probmem, scip->set, scip->stat, scip->eventqueue, scip->transprob, scip->lp,
1692             row, vals[v]) );
1693    }
1694 
1695    /* force the row sorting */
1696    SCIProwForceSort(row, scip->set);
1697 
1698    return SCIP_OKAY;
1699 }
1700 
1701 /** resolves variables to columns and adds them with the same single coefficient to the row;
1702  *  this method caches the row extensions and flushes them afterwards to gain better performance
1703  *
1704  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1705  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1706  *
1707  *  @attention If the absolute value of val is below the SCIP epsilon tolerance, the variables will not added.
1708  *
1709  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1710  *       - \ref SCIP_STAGE_INITSOLVE
1711  *       - \ref SCIP_STAGE_SOLVING
1712  */
SCIPaddVarsToRowSameCoef(SCIP * scip,SCIP_ROW * row,int nvars,SCIP_VAR ** vars,SCIP_Real val)1713 SCIP_RETCODE SCIPaddVarsToRowSameCoef(
1714    SCIP*                 scip,               /**< SCIP data structure */
1715    SCIP_ROW*             row,                /**< LP row */
1716    int                   nvars,              /**< number of variables to add to the row */
1717    SCIP_VAR**            vars,               /**< problem variables to add */
1718    SCIP_Real             val                 /**< unique value of all coefficients */
1719    )
1720 {
1721    int v;
1722 
1723    assert(nvars == 0 || vars != NULL);
1724 
1725    SCIP_CALL( SCIPcheckStage(scip, "SCIPaddVarsToRowSameCoef", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1726 
1727    /* resize the row to be able to store all variables (at least, if they are COLUMN variables) */
1728    SCIP_CALL( SCIProwEnsureSize(row, scip->mem->probmem, scip->set, SCIProwGetNNonz(row) + nvars) );
1729 
1730    /* delay the row sorting */
1731    SCIProwDelaySort(row);
1732 
1733    /* add the variables to the row */
1734    for( v = 0; v < nvars; ++v )
1735    {
1736       SCIP_CALL( SCIPvarAddToRow(vars[v], scip->mem->probmem, scip->set, scip->stat, scip->eventqueue, scip->transprob, scip->lp,
1737             row, val) );
1738    }
1739 
1740    /* force the row sorting */
1741    SCIProwForceSort(row, scip->set);
1742 
1743    return SCIP_OKAY;
1744 }
1745 
1746 /** tries to find a value, such that all row coefficients, if scaled with this value become integral
1747  *
1748  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1749  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1750  *
1751  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1752  *       - \ref SCIP_STAGE_INITSOLVE
1753  *       - \ref SCIP_STAGE_SOLVING
1754  */
SCIPcalcRowIntegralScalar(SCIP * scip,SCIP_ROW * row,SCIP_Real mindelta,SCIP_Real maxdelta,SCIP_Longint maxdnom,SCIP_Real maxscale,SCIP_Bool usecontvars,SCIP_Real * intscalar,SCIP_Bool * success)1755 SCIP_RETCODE SCIPcalcRowIntegralScalar(
1756    SCIP*                 scip,               /**< SCIP data structure */
1757    SCIP_ROW*             row,                /**< LP row */
1758    SCIP_Real             mindelta,           /**< minimal relative allowed difference of scaled coefficient s*c and integral i */
1759    SCIP_Real             maxdelta,           /**< maximal relative allowed difference of scaled coefficient s*c and integral i */
1760    SCIP_Longint          maxdnom,            /**< maximal denominator allowed in rational numbers */
1761    SCIP_Real             maxscale,           /**< maximal allowed scalar */
1762    SCIP_Bool             usecontvars,        /**< should the coefficients of the continuous variables also be made integral? */
1763    SCIP_Real*            intscalar,          /**< pointer to store scalar that would make the coefficients integral, or NULL */
1764    SCIP_Bool*            success             /**< stores whether returned value is valid */
1765    )
1766 {
1767    SCIP_CALL( SCIPcheckStage(scip, "SCIPcalcRowIntegralScalar", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1768 
1769    SCIP_CALL( SCIProwCalcIntegralScalar(row, scip->set, mindelta, maxdelta, maxdnom, maxscale,
1770          usecontvars, intscalar, success) );
1771 
1772    return SCIP_OKAY;
1773 }
1774 
1775 /** tries to scale row, s.t. all coefficients (of integer variables) become integral
1776  *
1777  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1778  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1779  *
1780  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1781  *       - \ref SCIP_STAGE_INITSOLVE
1782  *       - \ref SCIP_STAGE_SOLVING
1783  */
SCIPmakeRowIntegral(SCIP * scip,SCIP_ROW * row,SCIP_Real mindelta,SCIP_Real maxdelta,SCIP_Longint maxdnom,SCIP_Real maxscale,SCIP_Bool usecontvars,SCIP_Bool * success)1784 SCIP_RETCODE SCIPmakeRowIntegral(
1785    SCIP*                 scip,               /**< SCIP data structure */
1786    SCIP_ROW*             row,                /**< LP row */
1787    SCIP_Real             mindelta,           /**< minimal relative allowed difference of scaled coefficient s*c and integral i */
1788    SCIP_Real             maxdelta,           /**< maximal relative allowed difference of scaled coefficient s*c and integral i */
1789    SCIP_Longint          maxdnom,            /**< maximal denominator allowed in rational numbers */
1790    SCIP_Real             maxscale,           /**< maximal value to scale row with */
1791    SCIP_Bool             usecontvars,        /**< should the coefficients of the continuous variables also be made integral? */
1792    SCIP_Bool*            success             /**< stores whether row could be made rational */
1793    )
1794 {
1795    SCIP_CALL( SCIPcheckStage(scip, "SCIPmakeRowIntegral", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1796 
1797    SCIP_CALL( SCIProwMakeIntegral(row, scip->mem->probmem, scip->set, scip->eventqueue, scip->stat, scip->lp, mindelta, maxdelta, maxdnom, maxscale,
1798          usecontvars, success) );
1799 
1800    return SCIP_OKAY;
1801 }
1802 
1803 /** marks a row to be not removable from the LP in the current node
1804  *
1805  *  @pre this method can be called in the following stage of the SCIP solving process:
1806  *       - \ref SCIP_STAGE_SOLVING
1807  */
SCIPmarkRowNotRemovableLocal(SCIP * scip,SCIP_ROW * row)1808 void SCIPmarkRowNotRemovableLocal(
1809    SCIP*                 scip,               /**< SCIP data structure */
1810    SCIP_ROW*             row                 /**< LP row */
1811    )
1812 {
1813    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPmarkRowNotRemovableLocal", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1814 
1815    SCIProwMarkNotRemovableLocal(row, scip->stat);
1816 }
1817 
1818 /** returns number of integral columns in the row
1819  *
1820  *  @return number of integral columns in the row
1821  *
1822  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1823  *       - \ref SCIP_STAGE_INITSOLVE
1824  *       - \ref SCIP_STAGE_SOLVING
1825  */
SCIPgetRowNumIntCols(SCIP * scip,SCIP_ROW * row)1826 int SCIPgetRowNumIntCols(
1827    SCIP*                 scip,               /**< SCIP data structure */
1828    SCIP_ROW*             row                 /**< LP row */
1829    )
1830 {
1831    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowNumIntCols", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1832 
1833    return SCIProwGetNumIntCols(row, scip->set);
1834 }
1835 
1836 /** returns minimal absolute value of row vector's non-zero coefficients
1837  *
1838  *  @return minimal absolute value of row vector's non-zero coefficients
1839  *
1840  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1841  *       - \ref SCIP_STAGE_INITSOLVE
1842  *       - \ref SCIP_STAGE_SOLVING
1843  */
SCIPgetRowMinCoef(SCIP * scip,SCIP_ROW * row)1844 SCIP_Real SCIPgetRowMinCoef(
1845    SCIP*                 scip,               /**< SCIP data structure */
1846    SCIP_ROW*             row                 /**< LP row */
1847    )
1848 {
1849    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowMinCoef", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1850 
1851    return SCIProwGetMinval(row, scip->set);
1852 }
1853 
1854 /** returns maximal absolute value of row vector's non-zero coefficients
1855  *
1856  *  @return maximal absolute value of row vector's non-zero coefficients
1857  *
1858  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1859  *       - \ref SCIP_STAGE_INITSOLVE
1860  *       - \ref SCIP_STAGE_SOLVING
1861  */
SCIPgetRowMaxCoef(SCIP * scip,SCIP_ROW * row)1862 SCIP_Real SCIPgetRowMaxCoef(
1863    SCIP*                 scip,               /**< SCIP data structure */
1864    SCIP_ROW*             row                 /**< LP row */
1865    )
1866 {
1867    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowMaxCoef", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1868 
1869    return SCIProwGetMaxval(row, scip->set);
1870 }
1871 
1872 /** returns the minimal activity of a row w.r.t. the column's bounds
1873  *
1874  *  @return the minimal activity of a row w.r.t. the column's bounds
1875  *
1876  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1877  *       - \ref SCIP_STAGE_SOLVING
1878  */
SCIPgetRowMinActivity(SCIP * scip,SCIP_ROW * row)1879 SCIP_Real SCIPgetRowMinActivity(
1880    SCIP*                 scip,               /**< SCIP data structure */
1881    SCIP_ROW*             row                 /**< LP row */
1882    )
1883 {
1884    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowMinActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1885 
1886    return SCIProwGetMinActivity(row, scip->set, scip->stat);
1887 }
1888 
1889 /** returns the maximal activity of a row w.r.t. the column's bounds
1890  *
1891  *  @return the maximal activity of a row w.r.t. the column's bounds
1892  *
1893  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1894  *       - \ref SCIP_STAGE_SOLVING
1895  */
SCIPgetRowMaxActivity(SCIP * scip,SCIP_ROW * row)1896 SCIP_Real SCIPgetRowMaxActivity(
1897    SCIP*                 scip,               /**< SCIP data structure */
1898    SCIP_ROW*             row                 /**< LP row */
1899    )
1900 {
1901    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowMaxActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1902 
1903    return SCIProwGetMaxActivity(row, scip->set, scip->stat);
1904 }
1905 
1906 /** recalculates the activity of a row in the last LP solution
1907  *
1908  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1909  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1910  *
1911  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1912  *       - \ref SCIP_STAGE_SOLVING
1913  */
SCIPrecalcRowLPActivity(SCIP * scip,SCIP_ROW * row)1914 SCIP_RETCODE SCIPrecalcRowLPActivity(
1915    SCIP*                 scip,               /**< SCIP data structure */
1916    SCIP_ROW*             row                 /**< LP row */
1917    )
1918 {
1919    SCIP_CALL( SCIPcheckStage(scip, "SCIPrecalcRowLPActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1920 
1921    SCIProwRecalcLPActivity(row, scip->stat);
1922 
1923    return SCIP_OKAY;
1924 }
1925 
1926 /** returns the activity of a row in the last LP solution
1927  *
1928  *  @return activity of a row in the last LP solution
1929  *
1930  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1931  *       - \ref SCIP_STAGE_SOLVING
1932  */
SCIPgetRowLPActivity(SCIP * scip,SCIP_ROW * row)1933 SCIP_Real SCIPgetRowLPActivity(
1934    SCIP*                 scip,               /**< SCIP data structure */
1935    SCIP_ROW*             row                 /**< LP row */
1936    )
1937 {
1938    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowLPActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1939 
1940    return SCIProwGetLPActivity(row, scip->set, scip->stat, scip->lp);
1941 }
1942 
1943 /** returns the feasibility of a row in the last LP solution
1944  *
1945  *  @return the feasibility of a row in the last LP solution: negative value means infeasibility
1946  *
1947  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1948  *       - \ref SCIP_STAGE_SOLVING
1949  */
SCIPgetRowLPFeasibility(SCIP * scip,SCIP_ROW * row)1950 SCIP_Real SCIPgetRowLPFeasibility(
1951    SCIP*                 scip,               /**< SCIP data structure */
1952    SCIP_ROW*             row                 /**< LP row */
1953    )
1954 {
1955    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowLPFeasibility", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1956 
1957    return SCIProwGetLPFeasibility(row, scip->set, scip->stat, scip->lp);
1958 }
1959 
1960 /** recalculates the activity of a row for the current pseudo solution
1961  *
1962  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1963  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1964  *
1965  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1966  *       - \ref SCIP_STAGE_SOLVING
1967  */
SCIPrecalcRowPseudoActivity(SCIP * scip,SCIP_ROW * row)1968 SCIP_RETCODE SCIPrecalcRowPseudoActivity(
1969    SCIP*                 scip,               /**< SCIP data structure */
1970    SCIP_ROW*             row                 /**< LP row */
1971    )
1972 {
1973    SCIP_CALL( SCIPcheckStage(scip, "SCIPrecalcRowPseudoActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1974 
1975    SCIProwRecalcPseudoActivity(row, scip->stat);
1976 
1977    return SCIP_OKAY;
1978 }
1979 
1980 /** returns the activity of a row for the current pseudo solution
1981  *
1982  *  @return the activity of a row for the current pseudo solution
1983  *
1984  *  @pre this method can be called in one of the following stages of the SCIP solving process:
1985  *       - \ref SCIP_STAGE_SOLVING
1986  */
SCIPgetRowPseudoActivity(SCIP * scip,SCIP_ROW * row)1987 SCIP_Real SCIPgetRowPseudoActivity(
1988    SCIP*                 scip,               /**< SCIP data structure */
1989    SCIP_ROW*             row                 /**< LP row */
1990    )
1991 {
1992    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowPseudoActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1993 
1994    return SCIProwGetPseudoActivity(row, scip->set, scip->stat);
1995 }
1996 
1997 /** returns the feasibility of a row for the current pseudo solution: negative value means infeasibility
1998  *
1999  *  @return the feasibility of a row for the current pseudo solution: negative value means infeasibility
2000  *
2001  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2002  *       - \ref SCIP_STAGE_SOLVING
2003  */
SCIPgetRowPseudoFeasibility(SCIP * scip,SCIP_ROW * row)2004 SCIP_Real SCIPgetRowPseudoFeasibility(
2005    SCIP*                 scip,               /**< SCIP data structure */
2006    SCIP_ROW*             row                 /**< LP row */
2007    )
2008 {
2009    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowPseudoFeasibility", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2010 
2011    return SCIProwGetPseudoFeasibility(row, scip->set, scip->stat);
2012 }
2013 
2014 /** recalculates the activity of a row in the last LP or pseudo solution
2015  *
2016  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2017  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2018  *
2019  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2020  *       - \ref SCIP_STAGE_SOLVING
2021  */
SCIPrecalcRowActivity(SCIP * scip,SCIP_ROW * row)2022 SCIP_RETCODE SCIPrecalcRowActivity(
2023    SCIP*                 scip,               /**< SCIP data structure */
2024    SCIP_ROW*             row                 /**< LP row */
2025    )
2026 {
2027    SCIP_CALL( SCIPcheckStage(scip, "SCIPrecalcRowActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2028 
2029    if( SCIPtreeHasCurrentNodeLP(scip->tree) )
2030       SCIProwRecalcLPActivity(row, scip->stat);
2031    else
2032       SCIProwRecalcPseudoActivity(row, scip->stat);
2033 
2034    return SCIP_OKAY;
2035 }
2036 
2037 /** returns the activity of a row in the last LP or pseudo solution
2038  *
2039  *  @return the activity of a row in the last LP or pseudo solution
2040  *
2041  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2042  *       - \ref SCIP_STAGE_SOLVING
2043  */
SCIPgetRowActivity(SCIP * scip,SCIP_ROW * row)2044 SCIP_Real SCIPgetRowActivity(
2045    SCIP*                 scip,               /**< SCIP data structure */
2046    SCIP_ROW*             row                 /**< LP row */
2047    )
2048 {
2049    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2050 
2051    if( SCIPtreeHasCurrentNodeLP(scip->tree) )
2052       return SCIProwGetLPActivity(row, scip->set, scip->stat, scip->lp);
2053    else
2054       return SCIProwGetPseudoActivity(row, scip->set, scip->stat);
2055 }
2056 
2057 /** returns the feasibility of a row in the last LP or pseudo solution
2058  *
2059  *  @return the feasibility of a row in the last LP or pseudo solution
2060  *
2061  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2062  *       - \ref SCIP_STAGE_SOLVING
2063  */
SCIPgetRowFeasibility(SCIP * scip,SCIP_ROW * row)2064 SCIP_Real SCIPgetRowFeasibility(
2065    SCIP*                 scip,               /**< SCIP data structure */
2066    SCIP_ROW*             row                 /**< LP row */
2067    )
2068 {
2069    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowFeasibility", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2070 
2071    if( SCIPtreeHasCurrentNodeLP(scip->tree) )
2072       return SCIProwGetLPFeasibility(row, scip->set, scip->stat, scip->lp);
2073    else
2074       return SCIProwGetPseudoFeasibility(row, scip->set, scip->stat);
2075 }
2076 
2077 /** returns the activity of a row for the given primal solution
2078  *
2079  *  @return the activitiy of a row for the given primal solution
2080  *
2081  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2082  *       - \ref SCIP_STAGE_SOLVING
2083  */
SCIPgetRowSolActivity(SCIP * scip,SCIP_ROW * row,SCIP_SOL * sol)2084 SCIP_Real SCIPgetRowSolActivity(
2085    SCIP*                 scip,               /**< SCIP data structure */
2086    SCIP_ROW*             row,                /**< LP row */
2087    SCIP_SOL*             sol                 /**< primal CIP solution */
2088    )
2089 {
2090    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowSolActivity", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2091 
2092    if( sol != NULL )
2093       return SCIProwGetSolActivity(row, scip->set, scip->stat, sol);
2094    else if( SCIPtreeHasCurrentNodeLP(scip->tree) )
2095       return SCIProwGetLPActivity(row, scip->set, scip->stat, scip->lp);
2096    else
2097       return SCIProwGetPseudoActivity(row, scip->set, scip->stat);
2098 }
2099 
2100 /** returns the feasibility of a row for the given primal solution
2101  *
2102  *  @return the feasibility of a row for the given primal solution
2103  *
2104  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2105  *       - \ref SCIP_STAGE_SOLVING
2106  */
SCIPgetRowSolFeasibility(SCIP * scip,SCIP_ROW * row,SCIP_SOL * sol)2107 SCIP_Real SCIPgetRowSolFeasibility(
2108    SCIP*                 scip,               /**< SCIP data structure */
2109    SCIP_ROW*             row,                /**< LP row */
2110    SCIP_SOL*             sol                 /**< primal CIP solution */
2111    )
2112 {
2113    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowSolFeasibility", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2114 
2115    if( sol != NULL )
2116       return SCIProwGetSolFeasibility(row, scip->set, scip->stat, sol);
2117    else if( SCIPtreeHasCurrentNodeLP(scip->tree) )
2118       return SCIProwGetLPFeasibility(row, scip->set, scip->stat, scip->lp);
2119    else
2120       return SCIProwGetPseudoFeasibility(row, scip->set, scip->stat);
2121 }
2122 
2123 /** returns the parallelism of row with objective function
2124  *
2125  *  @return 1 is returned if the row is parallel to the objective function and 0 if it is orthogonal
2126  *
2127  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2128  *       - \ref SCIP_STAGE_SOLVING
2129  */
SCIPgetRowObjParallelism(SCIP * scip,SCIP_ROW * row)2130 SCIP_Real SCIPgetRowObjParallelism(
2131    SCIP*                 scip,               /**< SCIP data structure */
2132    SCIP_ROW*             row                 /**< LP row */
2133    )
2134 {
2135    assert(row != NULL);
2136 
2137    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetRowObjParallelism", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2138 
2139    return SCIProwGetObjParallelism(row, scip->set, scip->lp);
2140 }
2141 
2142 /** output row to file stream via the message handler system
2143  *
2144  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2145  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2146  *
2147  *  @pre this method can be called in one of the following stages of the SCIP solving process:
2148  *       - \ref SCIP_STAGE_SOLVING
2149  *       - \ref SCIP_STAGE_SOLVED
2150  *       - \ref SCIP_STAGE_EXITSOLVE
2151  */
SCIPprintRow(SCIP * scip,SCIP_ROW * row,FILE * file)2152 SCIP_RETCODE SCIPprintRow(
2153    SCIP*                 scip,               /**< SCIP data structure */
2154    SCIP_ROW*             row,                /**< LP row */
2155    FILE*                 file                /**< output file (or NULL for standard output) */
2156    )
2157 {
2158    assert(row != NULL);
2159 
2160    SCIP_CALL( SCIPcheckStage(scip, "SCIPprintRow", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE) );
2161 
2162    SCIProwPrint(row, scip->messagehdlr, file);
2163 
2164    return SCIP_OKAY;
2165 }
2166 
2167 /** initiates LP diving, making methods SCIPchgVarObjDive(), SCIPchgVarLbDive(), and SCIPchgVarUbDive() available
2168  *
2169  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2170  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2171  *
2172  *  @pre This method can be called if @p scip is in one of the following stages:
2173  *       - \ref SCIP_STAGE_SOLVING
2174  *
2175  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2176  *
2177  *  @note diving is allowed even if the current LP is not flushed, not solved, or not solved to optimality; be aware
2178  *  that solving the (first) diving LP may take longer than expect and that the latter two cases could stem from
2179  *  numerical troubles during the last LP solve; because of this, most users will want to call this method only if
2180  *  SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL
2181  */
SCIPstartDive(SCIP * scip)2182 SCIP_RETCODE SCIPstartDive(
2183    SCIP*                 scip                /**< SCIP data structure */
2184    )
2185 {
2186    assert(scip != NULL);
2187 
2188    SCIP_CALL( SCIPcheckStage(scip, "SCIPstartDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2189    assert(SCIPnodeGetType(SCIPgetCurrentNode(scip)) == SCIP_NODETYPE_FOCUSNODE);
2190 
2191    if( SCIPlpDiving(scip->lp) )
2192    {
2193       SCIPerrorMessage("already in diving mode\n");
2194       return SCIP_INVALIDCALL;
2195    }
2196 
2197    if( SCIPtreeProbing(scip->tree) )
2198    {
2199       SCIPerrorMessage("cannot start diving while being in probing mode\n");
2200       return SCIP_INVALIDCALL;
2201    }
2202 
2203    if( !SCIPtreeIsFocusNodeLPConstructed(scip->tree) )
2204    {
2205       SCIPerrorMessage("cannot start diving if LP has not been constructed\n");
2206       return SCIP_INVALIDCALL;
2207    }
2208    assert(SCIPtreeHasCurrentNodeLP(scip->tree));
2209 
2210    SCIP_CALL( SCIPlpStartDive(scip->lp, scip->mem->probmem, scip->set, scip->stat) );
2211 
2212    /* remember the relaxation solution to reset it later */
2213    if( SCIPisRelaxSolValid(scip) )
2214    {
2215       SCIP_CALL( SCIPtreeStoreRelaxSol(scip->tree, scip->set, scip->relaxation, scip->transprob) );
2216    }
2217 
2218    return SCIP_OKAY;
2219 }
2220 
2221 /** quits LP diving and resets bounds and objective values of columns to the current node's values
2222  *
2223  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2224  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2225  *
2226  *  @pre This method can be called if @p scip is in one of the following stages:
2227  *       - \ref SCIP_STAGE_SOLVING
2228  *
2229  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2230  */
SCIPendDive(SCIP * scip)2231 SCIP_RETCODE SCIPendDive(
2232    SCIP*                 scip                /**< SCIP data structure */
2233    )
2234 {
2235    assert(scip != NULL);
2236 
2237    SCIP_CALL( SCIPcheckStage(scip, "SCIPendDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2238 
2239    if( !SCIPlpDiving(scip->lp) )
2240    {
2241       SCIPerrorMessage("not in diving mode\n");
2242       return SCIP_INVALIDCALL;
2243    }
2244 
2245    /* unmark the diving flag in the LP and reset all variables' objective and bound values */
2246    SCIP_CALL( SCIPlpEndDive(scip->lp, scip->mem->probmem, scip->set, scip->messagehdlr, scip->stat, scip->eventqueue, scip->eventfilter,
2247          scip->transprob, scip->transprob->vars, scip->transprob->nvars) );
2248 
2249    /* the lower bound may have changed slightly due to LP resolve in SCIPlpEndDive() */
2250    if( !scip->lp->resolvelperror && scip->tree->focusnode != NULL && SCIPlpIsRelax(scip->lp) && SCIPlpIsSolved(scip->lp) )
2251    {
2252       assert(SCIPtreeIsFocusNodeLPConstructed(scip->tree));
2253       SCIP_CALL( SCIPnodeUpdateLowerboundLP(scip->tree->focusnode, scip->set, scip->stat, scip->tree, scip->transprob,
2254             scip->origprob, scip->lp) );
2255    }
2256    /* reset the probably changed LP's cutoff bound */
2257    SCIP_CALL( SCIPlpSetCutoffbound(scip->lp, scip->set, scip->transprob, scip->primal->cutoffbound) );
2258    assert(scip->lp->cutoffbound == scip->primal->cutoffbound); /*lint !e777*/
2259 
2260    /* if a new best solution was created, the cutoff of the tree was delayed due to diving;
2261     * the cutoff has to be done now.
2262     */
2263    if( scip->tree->cutoffdelayed )
2264    {
2265       SCIP_CALL( SCIPtreeCutoff(scip->tree, scip->reopt, scip->mem->probmem, scip->set, scip->stat, scip->eventfilter,
2266             scip->eventqueue, scip->lp, scip->primal->cutoffbound) );
2267    }
2268 
2269    /* if a relaxation was stored before diving, restore it now */
2270    if( scip->tree->probdiverelaxstored )
2271    {
2272       SCIP_CALL( SCIPtreeRestoreRelaxSol(scip->tree, scip->set, scip->relaxation, scip->transprob) );
2273    }
2274 
2275    return SCIP_OKAY;
2276 }
2277 
2278 /** changes cutoffbound in current dive
2279  *
2280  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2281  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2282  *
2283  *  @pre This method can be called if @p scip is in one of the following stages:
2284  *       - \ref SCIP_STAGE_SOLVING
2285  *
2286  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2287  */
SCIPchgCutoffboundDive(SCIP * scip,SCIP_Real newcutoffbound)2288 SCIP_RETCODE SCIPchgCutoffboundDive(
2289    SCIP*                 scip,               /**< SCIP data structure */
2290    SCIP_Real             newcutoffbound      /**< new cutoffbound */
2291    )
2292 {
2293    assert(scip != NULL);
2294 
2295    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgCutoffboundDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2296 
2297    if( !SCIPlpDiving(scip->lp) )
2298    {
2299       SCIPerrorMessage("not in diving mode\n");
2300       return SCIP_INVALIDCALL;
2301    }
2302 
2303    SCIP_CALL( SCIPlpSetCutoffbound(scip->lp, scip->set, scip->transprob, newcutoffbound) );
2304 
2305    return SCIP_OKAY;
2306 }
2307 
2308 /** changes variable's objective value in current dive
2309  *
2310  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2311  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2312  *
2313  *  @pre This method can be called if @p scip is in one of the following stages:
2314  *       - \ref SCIP_STAGE_SOLVING
2315  *
2316  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2317  */
SCIPchgVarObjDive(SCIP * scip,SCIP_VAR * var,SCIP_Real newobj)2318 SCIP_RETCODE SCIPchgVarObjDive(
2319    SCIP*                 scip,               /**< SCIP data structure */
2320    SCIP_VAR*             var,                /**< variable to change the objective value for */
2321    SCIP_Real             newobj              /**< new objective value */
2322    )
2323 {
2324    assert(scip != NULL);
2325    assert(var != NULL);
2326 
2327    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgVarObjDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2328 
2329    if( !SCIPlpDiving(scip->lp) )
2330    {
2331       SCIPerrorMessage("not in diving mode\n");
2332       return SCIP_INVALIDCALL;
2333    }
2334 
2335    /* invalidate the LP's cutoff bound, since this has nothing to do with the current objective value anymore;
2336     * the cutoff bound is reset in SCIPendDive()
2337     */
2338    SCIP_CALL( SCIPlpSetCutoffbound(scip->lp, scip->set, scip->transprob, SCIPsetInfinity(scip->set)) );
2339 
2340    /* mark the LP's objective function invalid */
2341    SCIPlpMarkDivingObjChanged(scip->lp);
2342 
2343    /* change the objective value of the variable in the diving LP */
2344    SCIP_CALL( SCIPvarChgObjDive(var, scip->set, scip->lp, newobj) );
2345 
2346    return SCIP_OKAY;
2347 }
2348 
2349 /** changes variable's lower bound in current dive
2350  *
2351  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2352  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2353  *
2354  *  @pre This method can be called if @p scip is in one of the following stages:
2355  *       - \ref SCIP_STAGE_SOLVING
2356  *
2357  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2358  */
SCIPchgVarLbDive(SCIP * scip,SCIP_VAR * var,SCIP_Real newbound)2359 SCIP_RETCODE SCIPchgVarLbDive(
2360    SCIP*                 scip,               /**< SCIP data structure */
2361    SCIP_VAR*             var,                /**< variable to change the bound for */
2362    SCIP_Real             newbound            /**< new value for bound */
2363    )
2364 {
2365    assert(scip != NULL);
2366    assert(var != NULL);
2367 
2368    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgVarLbDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2369 
2370    if( !SCIPlpDiving(scip->lp) )
2371    {
2372       SCIPerrorMessage("not in diving mode\n");
2373       return SCIP_INVALIDCALL;
2374    }
2375 
2376    SCIP_CALL( SCIPvarChgLbDive(var, scip->set, scip->lp, newbound) );
2377 
2378    return SCIP_OKAY;
2379 }
2380 
2381 /** changes variable's upper bound in current dive
2382  *
2383  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2384  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2385  *
2386  *  @pre This method can be called if @p scip is in one of the following stages:
2387  *       - \ref SCIP_STAGE_SOLVING
2388  *
2389  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2390  */
SCIPchgVarUbDive(SCIP * scip,SCIP_VAR * var,SCIP_Real newbound)2391 SCIP_RETCODE SCIPchgVarUbDive(
2392    SCIP*                 scip,               /**< SCIP data structure */
2393    SCIP_VAR*             var,                /**< variable to change the bound for */
2394    SCIP_Real             newbound            /**< new value for bound */
2395    )
2396 {
2397    assert(scip != NULL);
2398    assert(var != NULL);
2399 
2400    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgVarUbDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2401 
2402    if( !SCIPlpDiving(scip->lp) )
2403    {
2404       SCIPerrorMessage("not in diving mode\n");
2405       return SCIP_INVALIDCALL;
2406    }
2407 
2408    SCIP_CALL( SCIPvarChgUbDive(var, scip->set, scip->lp, newbound) );
2409 
2410    return SCIP_OKAY;
2411 }
2412 
2413 /** adds a row to the LP in current dive
2414  *
2415  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2416  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2417  *
2418  *  @pre This method can be called if @p scip is in one of the following stages:
2419  *       - \ref SCIP_STAGE_SOLVING
2420  *
2421  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2422  */
SCIPaddRowDive(SCIP * scip,SCIP_ROW * row)2423 SCIP_RETCODE SCIPaddRowDive(
2424    SCIP*                 scip,               /**< SCIP data structure */
2425    SCIP_ROW*             row                 /**< row to be added */
2426    )
2427 {
2428    SCIP_NODE* node;
2429    int depth;
2430 
2431    assert(scip != NULL);
2432    assert(row != NULL);
2433 
2434    SCIP_CALL( SCIPcheckStage(scip, "SCIPaddRowDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2435 
2436    if( !SCIPlpDiving(scip->lp) )
2437    {
2438       SCIPerrorMessage("not in diving mode\n");
2439       return SCIP_INVALIDCALL;
2440    }
2441 
2442    /* get depth of current node */
2443    node = SCIPtreeGetCurrentNode(scip->tree);
2444    assert(node != NULL);
2445    depth = SCIPnodeGetDepth(node);
2446 
2447    SCIP_CALL( SCIPlpAddRow(scip->lp, scip->mem->probmem, scip->set, scip->eventqueue, scip->eventfilter, row, depth) );
2448 
2449    return SCIP_OKAY;
2450 }
2451 
2452 /** changes row lhs in current dive, change will be undone after diving ends, for permanent changes use SCIPchgRowLhs()
2453  *
2454  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2455  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2456  *
2457  *  @pre This method can be called if @p scip is in one of the following stages:
2458  *       - \ref SCIP_STAGE_SOLVING
2459  *
2460  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2461  */
SCIPchgRowLhsDive(SCIP * scip,SCIP_ROW * row,SCIP_Real newlhs)2462 SCIP_RETCODE SCIPchgRowLhsDive(
2463    SCIP*                 scip,               /**< SCIP data structure */
2464    SCIP_ROW*             row,                /**< row to change the lhs for */
2465    SCIP_Real             newlhs              /**< new value for lhs */
2466    )
2467 {
2468    assert(scip != NULL);
2469    assert(row != NULL);
2470 
2471    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgRowLhsDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2472 
2473    if( !SCIPlpDiving(scip->lp) )
2474    {
2475       SCIPerrorMessage("not in diving mode\n");
2476       return SCIP_INVALIDCALL;
2477    }
2478 
2479    SCIP_CALL( SCIPlpRecordOldRowSideDive(scip->lp, row, SCIP_SIDETYPE_LEFT) );
2480    SCIP_CALL( SCIProwChgLhs(row, scip->mem->probmem, scip->set, scip->eventqueue, scip->lp, newlhs) );
2481 
2482    return SCIP_OKAY;
2483 }
2484 
2485 /** changes row rhs in current dive, change will be undone after diving ends, for permanent changes use SCIPchgRowRhs()
2486  *
2487  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2488  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2489  *
2490  *  @pre This method can be called if @p scip is in one of the following stages:
2491  *       - \ref SCIP_STAGE_SOLVING
2492  *
2493  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2494  */
SCIPchgRowRhsDive(SCIP * scip,SCIP_ROW * row,SCIP_Real newrhs)2495 SCIP_RETCODE SCIPchgRowRhsDive(
2496    SCIP*                 scip,               /**< SCIP data structure */
2497    SCIP_ROW*             row,                /**< row to change the lhs for */
2498    SCIP_Real             newrhs              /**< new value for rhs */
2499    )
2500 {
2501    assert(scip != NULL);
2502    assert(row != NULL);
2503 
2504    SCIP_CALL( SCIPcheckStage(scip, "SCIPchgRowRhsDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2505 
2506    if( !SCIPlpDiving(scip->lp) )
2507    {
2508       SCIPerrorMessage("not in diving mode\n");
2509       return SCIP_INVALIDCALL;
2510    }
2511 
2512    SCIP_CALL( SCIPlpRecordOldRowSideDive(scip->lp, row, SCIP_SIDETYPE_RIGHT) );
2513    SCIP_CALL( SCIProwChgRhs(row, scip->mem->probmem, scip->set, scip->eventqueue, scip->lp, newrhs) );
2514 
2515    return SCIP_OKAY;
2516 }
2517 
2518 /** gets variable's objective value in current dive
2519  *
2520  *  @return the variable's objective value in current dive.
2521  *
2522  *  @pre This method can be called if @p scip is in one of the following stages:
2523  *       - \ref SCIP_STAGE_SOLVING
2524  *
2525  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2526  */
SCIPgetVarObjDive(SCIP * scip,SCIP_VAR * var)2527 SCIP_Real SCIPgetVarObjDive(
2528    SCIP*                 scip,               /**< SCIP data structure */
2529    SCIP_VAR*             var                 /**< variable to get the bound for */
2530    )
2531 {
2532    assert(scip != NULL);
2533    assert(var != NULL);
2534 
2535    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetVarObjDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2536 
2537    if( !SCIPlpDiving(scip->lp) )
2538    {
2539       SCIPerrorMessage("not in diving mode\n");
2540       SCIPABORT();
2541       return SCIP_INVALID; /*lint !e527*/
2542    }
2543 
2544    return SCIPvarGetObjLP(var);
2545 }
2546 
2547 /** gets variable's lower bound in current dive
2548  *
2549  *  @return the variable's lower bound in current dive.
2550  *
2551  *  @pre This method can be called if @p scip is in one of the following stages:
2552  *       - \ref SCIP_STAGE_SOLVING
2553  *
2554  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2555  */
SCIPgetVarLbDive(SCIP * scip,SCIP_VAR * var)2556 SCIP_Real SCIPgetVarLbDive(
2557    SCIP*                 scip,               /**< SCIP data structure */
2558    SCIP_VAR*             var                 /**< variable to get the bound for */
2559    )
2560 {
2561    assert(scip != NULL);
2562    assert(var != NULL);
2563 
2564    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetVarLbDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2565 
2566    if( !SCIPlpDiving(scip->lp) )
2567    {
2568       SCIPerrorMessage("not in diving mode\n");
2569       SCIPABORT();
2570       return SCIP_INVALID; /*lint !e527*/
2571    }
2572 
2573    return SCIPvarGetLbLP(var, scip->set);
2574 }
2575 
2576 /** gets variable's upper bound in current dive
2577  *
2578  *  @return the variable's upper bound in current dive.
2579  *
2580  *  @pre This method can be called if @p scip is in one of the following stages:
2581  *       - \ref SCIP_STAGE_SOLVING
2582  *
2583  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2584  */
SCIPgetVarUbDive(SCIP * scip,SCIP_VAR * var)2585 SCIP_Real SCIPgetVarUbDive(
2586    SCIP*                 scip,               /**< SCIP data structure */
2587    SCIP_VAR*             var                 /**< variable to get the bound for */
2588    )
2589 {
2590    assert(scip != NULL);
2591    assert(var != NULL);
2592 
2593    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetVarUbDive", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2594 
2595    if( !SCIPlpDiving(scip->lp) )
2596    {
2597       SCIPerrorMessage("not in diving mode\n");
2598       SCIPABORT();
2599       return SCIP_INVALID; /*lint !e527*/
2600    }
2601 
2602    return SCIPvarGetUbLP(var, scip->set);
2603 }
2604 
2605 /** solves the LP of the current dive; no separation or pricing is applied
2606  *
2607  *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2608  *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2609  *
2610  *  @pre This method can be called if @p scip is in one of the following stages:
2611  *       - \ref SCIP_STAGE_SOLVING
2612  *
2613  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2614  *
2615  *  @note be aware that the LP solve may take longer than expected if SCIPgetLPSolstat(scip) != SCIP_LPSOLSTAT_OPTIMAL,
2616  *  compare the explanation of SCIPstartDive()
2617  */
SCIPsolveDiveLP(SCIP * scip,int itlim,SCIP_Bool * lperror,SCIP_Bool * cutoff)2618 SCIP_RETCODE SCIPsolveDiveLP(
2619    SCIP*                 scip,               /**< SCIP data structure */
2620    int                   itlim,              /**< maximal number of LP iterations to perform, or -1 for no limit */
2621    SCIP_Bool*            lperror,            /**< pointer to store whether an unresolved LP error occurred */
2622    SCIP_Bool*            cutoff              /**< pointer to store whether the diving LP was infeasible or the objective
2623                                               *   limit was reached (or NULL, if not needed) */
2624    )
2625 {
2626    assert(scip != NULL);
2627 
2628    SCIP_CALL( SCIPcheckStage(scip, "SCIPsolveDiveLP", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2629 
2630    if( !SCIPlpDiving(scip->lp) )
2631    {
2632       SCIPerrorMessage("not in diving mode\n");
2633       return SCIP_INVALIDCALL;
2634    }
2635 
2636    if( cutoff != NULL )
2637       *cutoff = FALSE;
2638 
2639    /* solve diving LP */
2640    SCIP_CALL( SCIPlpSolveAndEval(scip->lp, scip->set, scip->messagehdlr, scip->mem->probmem, scip->stat,
2641          scip->eventqueue, scip->eventfilter, scip->transprob, (SCIP_Longint)itlim, FALSE, FALSE, FALSE, lperror) );
2642 
2643    /* the LP is infeasible or the objective limit was reached */
2644    if( SCIPlpGetSolstat(scip->lp) == SCIP_LPSOLSTAT_INFEASIBLE || SCIPlpGetSolstat(scip->lp) == SCIP_LPSOLSTAT_OBJLIMIT
2645       || (SCIPlpGetSolstat(scip->lp) == SCIP_LPSOLSTAT_OPTIMAL &&
2646          SCIPisGE(scip, SCIPgetLPObjval(scip), SCIPgetCutoffbound(scip))) )
2647    {
2648       /* analyze the infeasible LP (only if the objective was not changed, all columns are in the LP, and no external
2649        * pricers exist) */
2650       if( !scip->set->misc_exactsolve && !(SCIPlpDivingObjChanged(scip->lp) || SCIPlpDivingRowsChanged(scip->lp))
2651          && SCIPprobAllColsInLP(scip->transprob, scip->set, scip->lp) )
2652       {
2653          SCIP_CALL( SCIPconflictAnalyzeLP(scip->conflict, scip->conflictstore, scip->mem->probmem, scip->set, scip->stat, scip->transprob,
2654                scip->origprob, scip->tree, scip->reopt, scip->lp, scip->branchcand, scip->eventqueue, scip->cliquetable, NULL) );
2655       }
2656 
2657       if( cutoff != NULL )
2658          *cutoff = TRUE;
2659    }
2660 
2661    return SCIP_OKAY;
2662 }
2663 
2664 /** returns the number of the node in the current branch and bound run, where the last LP was solved in diving
2665  *  or probing mode
2666  *
2667  *  @return the number of the node in the current branch and bound run, where the last LP was solved in diving
2668  *  or probing mode.
2669  *
2670  *  @pre This method can be called if @p scip is in one of the following stages:
2671  *       - \ref SCIP_STAGE_TRANSFORMING
2672  *       - \ref SCIP_STAGE_TRANSFORMED
2673  *       - \ref SCIP_STAGE_INITPRESOLVE
2674  *       - \ref SCIP_STAGE_PRESOLVING
2675  *       - \ref SCIP_STAGE_EXITPRESOLVE
2676  *       - \ref SCIP_STAGE_PRESOLVED
2677  *       - \ref SCIP_STAGE_INITSOLVE
2678  *       - \ref SCIP_STAGE_SOLVING
2679  *       - \ref SCIP_STAGE_SOLVED
2680  *       - \ref SCIP_STAGE_EXITSOLVE
2681  *       - \ref SCIP_STAGE_FREETRANS
2682  *
2683  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2684  */
SCIPgetLastDivenode(SCIP * scip)2685 SCIP_Longint SCIPgetLastDivenode(
2686    SCIP*                 scip                /**< SCIP data structure */
2687    )
2688 {
2689    assert(scip != NULL);
2690 
2691    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetLastDivenode", FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
2692 
2693    return scip->stat->lastdivenode;
2694 }
2695 
2696 /** returns whether we are in diving mode
2697  *
2698  *  @return whether we are in diving mode.
2699  *
2700  *  @pre This method can be called if @p scip is in one of the following stages:
2701  *       - \ref SCIP_STAGE_TRANSFORMING
2702  *       - \ref SCIP_STAGE_TRANSFORMED
2703  *       - \ref SCIP_STAGE_INITPRESOLVE
2704  *       - \ref SCIP_STAGE_PRESOLVING
2705  *       - \ref SCIP_STAGE_EXITPRESOLVE
2706  *       - \ref SCIP_STAGE_PRESOLVED
2707  *       - \ref SCIP_STAGE_INITSOLVE
2708  *       - \ref SCIP_STAGE_SOLVING
2709  *       - \ref SCIP_STAGE_SOLVED
2710  *       - \ref SCIP_STAGE_EXITSOLVE
2711  *       - \ref SCIP_STAGE_FREETRANS
2712  *
2713  *  See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2714  */
SCIPinDive(SCIP * scip)2715 SCIP_Bool SCIPinDive(
2716    SCIP*                 scip                /**< SCIP data structure */
2717    )
2718 {
2719    assert(scip != NULL);
2720 
2721    SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPinDive", FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
2722 
2723    return SCIPlpDiving(scip->lp);
2724 }
2725 
2726 /** computes the changes to the problem when fixing to the optimal face
2727  *
2728  *  returns the degeneracy rate, i.e., the number of nonbasic variables with reduced cost 0
2729  *  and the variable constraint ratio, i.e., the number of unfixed variables in relation to the basis size
2730  */
SCIPgetLPDegeneracy(SCIP * scip,SCIP_Real * degeneracy,SCIP_Real * varconsratio)2731 SCIP_RETCODE SCIPgetLPDegeneracy(
2732    SCIP*                 scip,               /**< SCIP data structure */
2733    SCIP_Real*            degeneracy,         /**< pointer to store degeneracy share */
2734    SCIP_Real*            varconsratio        /**< pointer to store variable constraint ratio */
2735    )
2736 {
2737    assert(scip != NULL);
2738    assert(degeneracy != NULL);
2739    assert(varconsratio != NULL);
2740 
2741    SCIP_CALL( SCIPcheckStage(scip, "SCIPgetLPDegeneracy", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2742 
2743    SCIP_CALL( SCIPlpGetDegeneracy(scip->lp, scip->set, scip->stat, degeneracy, varconsratio) );
2744 
2745    return SCIP_OKAY;
2746 }
2747