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   relax.h
17  * @ingroup INTERNALAPI
18  * @brief  internal methods for relaxators
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #ifndef __SCIP_RELAX_H__
25 #define __SCIP_RELAX_H__
26 
27 
28 #include "scip/def.h"
29 #include "blockmemshell/memory.h"
30 #include "scip/type_primal.h"
31 #include "scip/type_relax.h"
32 #include "scip/type_result.h"
33 #include "scip/type_retcode.h"
34 #include "scip/type_set.h"
35 #include "scip/type_sol.h"
36 #include "scip/type_stat.h"
37 #include "scip/type_tree.h"
38 #include "scip/type_var.h"
39 #include "scip/pub_relax.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /** copies the given relaxator to a new scip */
46 SCIP_RETCODE SCIPrelaxCopyInclude(
47    SCIP_RELAX*           relax,              /**< relaxator */
48    SCIP_SET*             set                 /**< SCIP_SET of SCIP to copy to */
49    );
50 
51 /** creates a relaxator */
52 SCIP_RETCODE SCIPrelaxCreate(
53    SCIP_RELAX**          relax,              /**< pointer to relaxator data structure */
54    SCIP_SET*             set,                /**< global SCIP settings */
55    SCIP_MESSAGEHDLR*     messagehdlr,        /**< message handler */
56    BMS_BLKMEM*           blkmem,             /**< block memory for parameter settings */
57    const char*           name,               /**< name of relaxator */
58    const char*           desc,               /**< description of relaxator */
59    int                   priority,           /**< priority of the relaxator (negative: after LP, non-negative: before LP) */
60    int                   freq,               /**< frequency for calling relaxator */
61    SCIP_DECL_RELAXCOPY   ((*relaxcopy)),     /**< copy method of relaxator or NULL if you don't want to copy your plugin into sub-SCIPs */
62    SCIP_DECL_RELAXFREE   ((*relaxfree)),     /**< destructor of relaxator */
63    SCIP_DECL_RELAXINIT   ((*relaxinit)),     /**< initialize relaxator */
64    SCIP_DECL_RELAXEXIT   ((*relaxexit)),     /**< deinitialize relaxator */
65    SCIP_DECL_RELAXINITSOL((*relaxinitsol)),  /**< solving process initialization method of relaxator */
66    SCIP_DECL_RELAXEXITSOL((*relaxexitsol)),  /**< solving process deinitialization method of relaxator */
67    SCIP_DECL_RELAXEXEC   ((*relaxexec)),     /**< execution method of relaxator */
68    SCIP_RELAXDATA*       relaxdata           /**< relaxator data */
69    );
70 
71 /** calls destructor and frees memory of relaxator */
72 SCIP_RETCODE SCIPrelaxFree(
73    SCIP_RELAX**          relax,              /**< pointer to relaxator data structure */
74    SCIP_SET*             set                 /**< global SCIP settings */
75    );
76 
77 /** initializes relaxator */
78 SCIP_RETCODE SCIPrelaxInit(
79    SCIP_RELAX*           relax,              /**< relaxator */
80    SCIP_SET*             set                 /**< global SCIP settings */
81    );
82 
83 /** calls exit method of relaxator */
84 SCIP_RETCODE SCIPrelaxExit(
85    SCIP_RELAX*           relax,              /**< relaxator */
86    SCIP_SET*             set                 /**< global SCIP settings */
87    );
88 
89 /** informs relaxator that the branch and bound process is being started */
90 SCIP_RETCODE SCIPrelaxInitsol(
91    SCIP_RELAX*           relax,              /**< relaxator */
92    SCIP_SET*             set                 /**< global SCIP settings */
93    );
94 
95 /** informs relaxator that the branch and bound process data is being freed */
96 SCIP_RETCODE SCIPrelaxExitsol(
97    SCIP_RELAX*           relax,              /**< relaxator */
98    SCIP_SET*             set                 /**< global SCIP settings */
99    );
100 
101 /** calls execution method of relaxator */
102 SCIP_RETCODE SCIPrelaxExec(
103    SCIP_RELAX*           relax,              /**< relaxator */
104    SCIP_SET*             set,                /**< global SCIP settings */
105    SCIP_TREE*            tree,               /**< branch and bound tree */
106    SCIP_STAT*            stat,               /**< dynamic problem statistics */
107    int                   depth,              /**< depth of current node */
108    SCIP_Real*            lowerbound,         /**< pointer to lower bound computed by the relaxator */
109    SCIP_RESULT*          result              /**< pointer to store the result of the callback method */
110    );
111 
112 /** sets priority of relaxator */
113 void SCIPrelaxSetPriority(
114    SCIP_RELAX*           relax,              /**< relaxator */
115    SCIP_SET*             set,                /**< global SCIP settings */
116    int                   priority            /**< new priority of the relaxator */
117    );
118 
119 /** set copy callback of relaxation handler */
120 void SCIPrelaxSetCopy(
121    SCIP_RELAX*           relax,              /**< relaxation handler  */
122    SCIP_DECL_RELAXCOPY   ((*relaxcopy))      /**< copy method of relaxation handler */
123    );
124 
125 /** set destructor callback of relaxation handler */
126 void SCIPrelaxSetFree(
127    SCIP_RELAX*           relax,              /**< relaxation handler  */
128    SCIP_DECL_RELAXFREE   ((*relaxfree))      /**< destructor of relaxation handler */
129    );
130 
131 /** set initialization callback of relaxation handler */
132 void SCIPrelaxSetInit(
133    SCIP_RELAX*           relax,              /**< relaxation handler  */
134    SCIP_DECL_RELAXINIT   ((*relaxinit))      /**< initialize relaxation handler */
135    );
136 
137 /** set deinitialization callback of relaxation handler */
138 void SCIPrelaxSetExit(
139    SCIP_RELAX*           relax,              /**< relaxation handler  */
140    SCIP_DECL_RELAXEXIT   ((*relaxexit))      /**< deinitialize relaxation handler */
141    );
142 
143 /** set solving process initialization callback of relaxation handler */
144 void SCIPrelaxSetInitsol(
145    SCIP_RELAX*           relax,              /**< relaxation handler  */
146    SCIP_DECL_RELAXINITSOL((*relaxinitsol))   /**< solving process initialization method of relaxation handler */
147    );
148 
149 /** set solving process deinitialization callback of relaxation handler */
150 void SCIPrelaxSetExitsol(
151    SCIP_RELAX*           relax,              /**< relaxation handler  */
152    SCIP_DECL_RELAXEXITSOL((*relaxexitsol))   /**< solving process deinitialization callback relaxation handler */
153    );
154 
155 /** returns whether the relaxation was completely solved at the current node */
156 SCIP_Bool SCIPrelaxIsSolved(
157    SCIP_RELAX*           relax,              /**< relaxator */
158    SCIP_STAT*            stat                /**< dynamic problem statistics */
159    );
160 
161 /*
162  *  methods for the global relaxation data
163  */
164 
165 /** enables or disables all clocks of \p relax, depending on the value of the flag */
166 void SCIPrelaxEnableOrDisableClocks(
167    SCIP_RELAX*           relax,              /**< the relaxation handler for which all clocks should be enabled or disabled */
168    SCIP_Bool             enable              /**< should the clocks of the relaxation handler be enabled? */
169    );
170 
171 /** creates global relaxation data */
172 SCIP_RETCODE SCIPrelaxationCreate(
173    SCIP_RELAXATION**     relaxation,         /**< global relaxation data */
174    BMS_BLKMEM*           blkmem,             /**< block memory */
175    SCIP_SET*             set,                /**< global SCIP settings */
176    SCIP_STAT*            stat,               /**< problem statistics data */
177    SCIP_PRIMAL*          primal,             /**< primal data */
178    SCIP_TREE*            tree                /**< branch and bound tree */
179    );
180 
181 /** frees global relaxation data */
182 SCIP_RETCODE SCIPrelaxationFree(
183    SCIP_RELAXATION**     relaxation          /**< global relaxation data */
184    );
185 
186 /** sets the relaxsolzero flag in the relaxation data to the given value */
187 void SCIPrelaxationSetSolZero(
188    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
189    SCIP_Bool             iszero              /**< are all values of the relaxation solution set to zero? */
190    );
191 
192 /** returns whether the global relaxation solution is cleared and all values are set to zero */
193 SCIP_Bool SCIPrelaxationIsSolZero(
194    SCIP_RELAXATION*      relaxation          /**< global relaxation data */
195    );
196 
197 /** sets the relaxsolvalid and includeslp flags in the relaxation data to the given values */
198 void SCIPrelaxationSetSolValid(
199    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
200    SCIP_Bool             isvalid,            /**< is the stored solution valid? */
201    SCIP_Bool             includeslp          /**< does the relaxator contain all cuts in the LP? */
202    );
203 
204 /** returns whether the global relaxation solution is valid */
205 SCIP_Bool SCIPrelaxationIsSolValid(
206    SCIP_RELAXATION*      relaxation          /**< global relaxation data */
207    );
208 
209 /** returns whether the global relaxation solution was computed by a relaxator which included all LP cuts */
210 SCIP_Bool SCIPrelaxationIsLpIncludedForSol(
211    SCIP_RELAXATION*      relaxation          /**< global relaxation data */
212    );
213 
214 /** sets the objective value of the global relaxation solution */
215 void SCIPrelaxationSetSolObj(
216    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
217    SCIP_Real             obj                 /**< objective value */
218    );
219 
220 /** returns the objective value of the global relaxation solution w.r.t. the transformed problem */
221 SCIP_Real SCIPrelaxationGetSolObj(
222    SCIP_RELAXATION*      relaxation          /**< global relaxation data */
223    );
224 
225 /** adds the given value to the global relaxation solution's objective value */
226 void SCIPrelaxationSolObjAdd(
227    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
228    SCIP_Real             val                 /**< value to add to the objective value */
229    );
230 
231 /** updates objective value of current relaxation solution after change of objective coefficient */
232 void SCIPrelaxationUpdateVarObj(
233    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
234    SCIP_SET*             set,                /**< global SCIP settings */
235    SCIP_VAR*             var,                /**< variable with changed objective coefficient */
236    SCIP_Real             oldobj,             /**< old objective coefficient */
237    SCIP_Real             newobj              /**< new objective coefficient */
238    );
239 
240 /** store the most recent relaxation handler \p relax responsible for the solution */
241 void SCIPrelaxationSetSolRelax(
242    SCIP_RELAXATION*      relaxation,         /**< global relaxation data */
243    SCIP_RELAX*           relax               /**< relaxation handler responsible for the most recent relaxation solution */
244    );
245 
246 /** returns the most recent relaxation handler responsible for the solution, or NULL if unspecified */
247 SCIP_RELAX* SCIPrelaxationGetSolRelax(
248    SCIP_RELAXATION*      relaxation          /**< global relaxation data */
249    );
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif
256