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   pub_sol.h
17  * @ingroup PUBLICCOREAPI
18  * @brief  public methods for primal CIP solutions
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  */
22 
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24 
25 #ifndef __SCIP_PUB_SOL_H__
26 #define __SCIP_PUB_SOL_H__
27 
28 
29 #include "scip/def.h"
30 #include "scip/type_sol.h"
31 #include "scip/type_heur.h"
32 #include "scip/type_relax.h"
33 
34 #ifdef NDEBUG
35 #include "scip/struct_sol.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**@addtogroup PublicSolutionMethods
43  *
44  * @{
45  */
46 
47 
48 /** gets origin of solution */
49 SCIP_EXPORT
50 SCIP_SOLORIGIN SCIPsolGetOrigin(
51    SCIP_SOL*             sol                 /**< primal CIP solution */
52    );
53 
54 /** returns whether the given solution is defined on original variables */
55 SCIP_EXPORT
56 SCIP_Bool SCIPsolIsOriginal(
57    SCIP_SOL*             sol                 /**< primal CIP solution */
58    );
59 
60 /** returns whether the given solution is partial */
61 SCIP_EXPORT
62 SCIP_Bool SCIPsolIsPartial(
63    SCIP_SOL*             sol                 /**< primal CIP solution */
64    );
65 
66 /** gets objective value of primal CIP solution which lives in the original problem space */
67 SCIP_EXPORT
68 SCIP_Real SCIPsolGetOrigObj(
69    SCIP_SOL*             sol                 /**< primal CIP solution */
70    );
71 
72 /** gets clock time, when this solution was found */
73 SCIP_EXPORT
74 SCIP_Real SCIPsolGetTime(
75    SCIP_SOL*             sol                 /**< primal CIP solution */
76    );
77 
78 /** gets branch and bound run number, where this solution was found */
79 SCIP_EXPORT
80 int SCIPsolGetRunnum(
81    SCIP_SOL*             sol                 /**< primal CIP solution */
82    );
83 
84 /** gets node number of the specific branch and bound run, where this solution was found */
85 SCIP_EXPORT
86 SCIP_Longint SCIPsolGetNodenum(
87    SCIP_SOL*             sol                 /**< primal CIP solution */
88    );
89 
90 /** gets node's depth, where this solution was found */
91 SCIP_EXPORT
92 int SCIPsolGetDepth(
93    SCIP_SOL*             sol                 /**< primal CIP solution */
94    );
95 
96 /** gets information if solution was found by the LP, a primal heuristic, or a custom relaxator */
97 SCIP_EXPORT
98 SCIP_SOLTYPE SCIPsolGetType(
99    SCIP_SOL*             sol                 /**< primal CIP solution */
100    );
101 
102 /** gets heuristic that found this solution, or NULL if solution has type different than SCIP_SOLTYPE_HEUR */
103 SCIP_EXPORT
104 SCIP_HEUR* SCIPsolGetHeur(
105    SCIP_SOL*             sol                 /**< primal CIP solution */
106    );
107 
108 /** gets relaxation handler that found this solution, or NULL if solution has different type than SCIP_SOLTYPE_RELAX */
109 SCIP_EXPORT
110 SCIP_RELAX* SCIPsolGetRelax(
111    SCIP_SOL*             sol                 /**< primal CIP solution */
112    );
113 
114 /** informs the solution that it now belongs to the given primal heuristic. For convenience and backwards compatibility,
115  *  the method accepts NULL as input for \p heur, in which case the solution type is set to SCIP_SOLTYPE_LPRELAX.
116  *
117  *  @note Relaxation handlers should use SCIPsolSetRelax() instead.
118  */
119 SCIP_EXPORT
120 void SCIPsolSetHeur(
121    SCIP_SOL*             sol,                /**< primal CIP solution */
122    SCIP_HEUR*            heur                /**< primal heuristic that found the solution, or NULL for LP solutions */
123    );
124 
125 /** informs the solution that it now belongs to the given relaxation handler */
126 SCIP_EXPORT
127 void SCIPsolSetRelax(
128    SCIP_SOL*             sol,                /**< primal CIP solution */
129    SCIP_RELAX*           relax               /**< relaxator that found the solution */
130    );
131 
132 /** informs the solution that it is an LP relaxation solution */
133 SCIP_EXPORT
134 void SCIPsolSetLPRelaxation(
135    SCIP_SOL*             sol                 /**< primal CIP solution */
136    );
137 
138 /** informs the solution that it is a solution found during strong branching */
139 SCIP_EXPORT
140 void SCIPsolSetStrongbranching(
141    SCIP_SOL*             sol                 /**< primal CIP solution */
142    );
143 
144 /** informs the solution that it originates from a pseudo solution */
145 SCIP_EXPORT
146 void SCIPsolSetPseudo(
147    SCIP_SOL*             sol                 /**< primal CIP solution */
148    );
149 
150 /** returns unique index of given solution */
151 SCIP_EXPORT
152 int SCIPsolGetIndex(
153    SCIP_SOL*             sol                 /**< primal CIP solution */
154    );
155 
156 /** get maximum absolute bound violation of solution */
157 SCIP_EXPORT
158 SCIP_Real SCIPsolGetAbsBoundViolation(
159    SCIP_SOL*             sol                 /**< primal CIP solution */
160    );
161 
162 /** get maximum relative bound violation of solution */
163 SCIP_EXPORT
164 SCIP_Real SCIPsolGetRelBoundViolation(
165    SCIP_SOL*             sol                 /**< primal CIP solution */
166    );
167 
168 /** get maximum absolute integrality violation of solution */
169 SCIP_EXPORT
170 SCIP_Real SCIPsolGetAbsIntegralityViolation(
171    SCIP_SOL*             sol                 /**< primal CIP solution */
172    );
173 
174 /** get maximum absolute LP row violation of solution */
175 SCIP_EXPORT
176 SCIP_Real SCIPsolGetAbsLPRowViolation(
177    SCIP_SOL*             sol                 /**< primal CIP solution */
178    );
179 
180 /** get maximum relative LP row violation of solution */
181 SCIP_EXPORT
182 SCIP_Real SCIPsolGetRelLPRowViolation(
183    SCIP_SOL*             sol                 /**< primal CIP solution */
184    );
185 
186 /** get maximum absolute constraint violation of solution */
187 SCIP_EXPORT
188 SCIP_Real SCIPsolGetAbsConsViolation(
189    SCIP_SOL*             sol                 /**< primal CIP solution */
190    );
191 
192 /** get maximum relative constraint violation of solution */
193 SCIP_EXPORT
194 SCIP_Real SCIPsolGetRelConsViolation(
195    SCIP_SOL*             sol                 /**< primal CIP solution */
196    );
197 
198 #ifdef NDEBUG
199 
200 /* In optimized mode, the function calls are overwritten by defines to reduce the number of function calls and
201  * speed up the algorithms.
202  */
203 
204 #define SCIPsolGetOrigin(sol)           ((sol)->solorigin)
205 #define SCIPsolIsOriginal(sol)          ((sol)->solorigin == SCIP_SOLORIGIN_ORIGINAL || (sol)->solorigin == SCIP_SOLORIGIN_PARTIAL)
206 #define SCIPsolGetOrigObj(sol)          (sol)->obj
207 #define SCIPsolGetTime(sol)             (sol)->time
208 #define SCIPsolGetNodenum(sol)          (sol)->nodenum
209 #define SCIPsolGetRunnum(sol)           (sol)->runnum
210 #define SCIPsolGetDepth(sol)            (sol)->depth
211 #define SCIPsolGetHeur(sol)             ((sol)->type == SCIP_SOLTYPE_HEUR ? (sol)->creator.heur : NULL)
212 #define SCIPsolGetRelax(sol)            ((sol)->type == SCIP_SOLTYPE_RELAX ? (sol)->creator.relax : NULL)
213 #define SCIPsolGetIndex(sol)            (sol)->index
214 #define SCIPsolGetType(sol)             (sol)->type
215 #define SCIPsolSetLPRelaxation(sol)     ((sol)->type = SCIP_SOLTYPE_LPRELAX)
216 #define SCIPsolSetStrongbranching(sol)  ((sol)->type = SCIP_SOLTYPE_STRONGBRANCH)
217 #define SCIPsolSetPseudo(sol)           ((sol)->type = SCIP_SOLTYPE_PSEUDO)
218 #endif
219 
220 /** @} */
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif
227