Scippy

SCIP

Solving Constraint Integer Programs

scip_relax.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2018 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_relax.c
17  * @brief public methods for relaxator plugins
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include <ctype.h>
36 #include <stdarg.h>
37 #include <assert.h>
38 #include <string.h>
39 #if defined(_WIN32) || defined(_WIN64)
40 #else
41 #include <strings.h> /*lint --e{766}*/
42 #endif
43 
44 
45 #include "lpi/lpi.h"
46 #include "nlpi/exprinterpret.h"
47 #include "nlpi/nlpi.h"
48 #include "scip/benders.h"
49 #include "scip/benderscut.h"
50 #include "scip/branch.h"
51 #include "scip/branch_nodereopt.h"
52 #include "scip/clock.h"
53 #include "scip/compr.h"
54 #include "scip/concsolver.h"
55 #include "scip/concurrent.h"
56 #include "scip/conflict.h"
57 #include "scip/conflictstore.h"
58 #include "scip/cons.h"
59 #include "scip/cons_linear.h"
60 #include "scip/cutpool.h"
61 #include "scip/cuts.h"
62 #include "scip/debug.h"
63 #include "scip/def.h"
64 #include "scip/dialog.h"
65 #include "scip/dialog_default.h"
66 #include "scip/disp.h"
67 #include "scip/event.h"
68 #include "scip/heur.h"
69 #include "scip/heur_ofins.h"
70 #include "scip/heur_reoptsols.h"
72 #include "scip/heuristics.h"
73 #include "scip/history.h"
74 #include "scip/implics.h"
75 #include "scip/interrupt.h"
76 #include "scip/lp.h"
77 #include "scip/mem.h"
78 #include "scip/message_default.h"
79 #include "scip/misc.h"
80 #include "scip/nlp.h"
81 #include "scip/nodesel.h"
82 #include "scip/paramset.h"
83 #include "scip/presol.h"
84 #include "scip/presolve.h"
85 #include "scip/pricer.h"
86 #include "scip/pricestore.h"
87 #include "scip/primal.h"
88 #include "scip/prob.h"
89 #include "scip/prop.h"
90 #include "scip/reader.h"
91 #include "scip/relax.h"
92 #include "scip/reopt.h"
93 #include "scip/retcode.h"
94 #include "scip/scipbuildflags.h"
95 #include "scip/scipcoreplugins.h"
96 #include "scip/scipgithash.h"
97 #include "scip/sepa.h"
98 #include "scip/sepastore.h"
99 #include "scip/set.h"
100 #include "scip/sol.h"
101 #include "scip/solve.h"
102 #include "scip/stat.h"
103 #include "scip/syncstore.h"
104 #include "scip/table.h"
105 #include "scip/tree.h"
106 #include "scip/var.h"
107 #include "scip/visual.h"
108 #include "xml/xml.h"
109 
110 #include "scip/scip_relax.h"
111 
112 #include "scip/pub_message.h"
113 
114 
115 /* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
116  * this structure except the interface methods in scip.c.
117  * In optimized mode, the structure is included in scip.h, because some of the methods
118  * are implemented as defines for performance reasons (e.g. the numerical comparisons)
119  */
120 #ifndef NDEBUG
121 #include "scip/struct_scip.h"
122 #endif
123 
124 /** creates a relaxation handler and includes it in SCIP
125  *
126  * @note method has all relaxation handler callbacks as arguments and is thus changed every time a new
127  * callback is added
128  * in future releases; consider using SCIPincludeRelaxBasic() and setter functions
129  * if you seek for a method which is less likely to change in future releases
130  */
132  SCIP* scip, /**< SCIP data structure */
133  const char* name, /**< name of relaxation handler */
134  const char* desc, /**< description of relaxation handler */
135  int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
136  int freq, /**< frequency for calling relaxation handler */
137  SCIP_DECL_RELAXCOPY ((*relaxcopy)), /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
138  SCIP_DECL_RELAXFREE ((*relaxfree)), /**< destructor of relaxation handler */
139  SCIP_DECL_RELAXINIT ((*relaxinit)), /**< initialize relaxation handler */
140  SCIP_DECL_RELAXEXIT ((*relaxexit)), /**< deinitialize relaxation handler */
141  SCIP_DECL_RELAXINITSOL((*relaxinitsol)), /**< solving process initialization method of relaxation handler */
142  SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), /**< solving process deinitialization method of relaxation handler */
143  SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
144  SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
145  )
146 {
147  SCIP_RELAX* relax;
148 
149  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeRelax", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
150 
151  /* check whether relaxation handler is already present */
152  if( SCIPfindRelax(scip, name) != NULL )
153  {
154  SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
155  return SCIP_INVALIDDATA;
156  }
157 
158  SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
159  name, desc, priority, freq, relaxcopy,
160  relaxfree, relaxinit, relaxexit, relaxinitsol, relaxexitsol, relaxexec, relaxdata) );
161  SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
162 
163  return SCIP_OKAY;
164 }
165 
166 /** creates a relaxation handler and includes it in SCIP. All non fundamental
167  * (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL.
168  * Optional callbacks can be set via specific setter functions, see SCIPsetRelaxInit(), SCIPsetRelaxExit(),
169  * SCIPsetRelaxCopy(), SCIPsetRelaxFree(), SCIPsetRelaxInitsol(), and SCIPsetRelaxExitsol()
170  *
171  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeRelax() instead
172  */
174  SCIP* scip, /**< SCIP data structure */
175  SCIP_RELAX** relaxptr, /**< reference to relaxation pointer, or NULL */
176  const char* name, /**< name of relaxation handler */
177  const char* desc, /**< description of relaxation handler */
178  int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
179  int freq, /**< frequency for calling relaxation handler */
180  SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
181  SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
182  )
183 {
184  SCIP_RELAX* relax;
185 
186  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeRelaxBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
187 
188  /* check whether relaxation handler is already present */
189  if( SCIPfindRelax(scip, name) != NULL )
190  {
191  SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
192  return SCIP_INVALIDDATA;
193  }
194 
195  SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
196  name, desc, priority, freq,
197  NULL, NULL, NULL, NULL, NULL, NULL, relaxexec, relaxdata) );
198  SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
199 
200  if( relaxptr != NULL )
201  *relaxptr = relax;
202 
203  return SCIP_OKAY;
204 }
205 
206 /** sets copy method of relaxation handler */
208  SCIP* scip, /**< SCIP data structure */
209  SCIP_RELAX* relax, /**< relaxation handler */
210  SCIP_DECL_RELAXCOPY ((*relaxcopy)) /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
211  )
212 {
213  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
214 
215  assert(relax != NULL);
216 
217  SCIPrelaxSetCopy(relax, relaxcopy);
218 
219  return SCIP_OKAY;
220 }
221 
222 /** sets destructor method of relaxation handler */
224  SCIP* scip, /**< SCIP data structure */
225  SCIP_RELAX* relax, /**< relaxation handler */
226  SCIP_DECL_RELAXFREE ((*relaxfree)) /**< destructor of relaxation handler */
227  )
228 {
229  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
230 
231  assert(relax != NULL);
232 
233  SCIPrelaxSetFree(relax, relaxfree);
234 
235  return SCIP_OKAY;
236 }
237 
238 /** sets initialization method of relaxation handler */
240  SCIP* scip, /**< SCIP data structure */
241  SCIP_RELAX* relax, /**< relaxation handler */
242  SCIP_DECL_RELAXINIT ((*relaxinit)) /**< initialize relaxation handler */
243  )
244 {
245  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
246 
247  assert(relax != NULL);
248 
249  SCIPrelaxSetInit(relax, relaxinit);
250 
251  return SCIP_OKAY;
252 }
253 
254 /** sets deinitialization method of relaxation handler */
256  SCIP* scip, /**< SCIP data structure */
257  SCIP_RELAX* relax, /**< relaxation handler */
258  SCIP_DECL_RELAXEXIT ((*relaxexit)) /**< deinitialize relaxation handler */
259  )
260 {
261  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
262 
263  assert(relax != NULL);
264 
265  SCIPrelaxSetExit(relax, relaxexit);
266 
267  return SCIP_OKAY;
268 }
269 
270 /** sets solving process initialization method of relaxation handler */
272  SCIP* scip, /**< SCIP data structure */
273  SCIP_RELAX* relax, /**< relaxation handler */
274  SCIP_DECL_RELAXINITSOL((*relaxinitsol)) /**< solving process initialization method of relaxation handler */
275  )
276 {
277  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
278 
279  assert(relax != NULL);
280 
281  SCIPrelaxSetInitsol(relax, relaxinitsol);
282 
283  return SCIP_OKAY;
284 }
285 
286 /** sets solving process deinitialization method of relaxation handler */
288  SCIP* scip, /**< SCIP data structure */
289  SCIP_RELAX* relax, /**< relaxation handler */
290  SCIP_DECL_RELAXEXITSOL((*relaxexitsol)) /**< solving process deinitialization method of relaxation handler */
291  )
292 {
293  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
294 
295  assert(relax != NULL);
296 
297  SCIPrelaxSetExitsol(relax, relaxexitsol);
298 
299  return SCIP_OKAY;
300 }
301 
302 
303 /** returns the relaxation handler of the given name, or NULL if not existing */
305  SCIP* scip, /**< SCIP data structure */
306  const char* name /**< name of relaxation handler */
307  )
308 {
309  assert(scip != NULL);
310  assert(scip->set != NULL);
311  assert(name != NULL);
312 
313  return SCIPsetFindRelax(scip->set, name);
314 }
315 
316 /** returns the array of currently available relaxation handlers */
318  SCIP* scip /**< SCIP data structure */
319  )
320 {
321  assert(scip != NULL);
322  assert(scip->set != NULL);
323 
324  SCIPsetSortRelaxs(scip->set);
325 
326  return scip->set->relaxs;
327 }
328 
329 /** returns the number of currently available relaxation handlers */
331  SCIP* scip /**< SCIP data structure */
332  )
333 {
334  assert(scip != NULL);
335  assert(scip->set != NULL);
336 
337  return scip->set->nrelaxs;
338 }
339 
340 /** sets the priority of a relaxation handler */
342  SCIP* scip, /**< SCIP data structure */
343  SCIP_RELAX* relax, /**< relaxation handler */
344  int priority /**< new priority of the relaxation handler */
345  )
346 {
347  assert(scip != NULL);
348  assert(scip->set != NULL);
349 
350  SCIPrelaxSetPriority(relax, scip->set, priority);
351 
352  return SCIP_OKAY;
353 }
internal methods for separators
#define SCIP_DECL_RELAXFREE(x)
Definition: type_relax.h:55
SCIP_RETCODE SCIPsetRelaxCopy(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
Definition: scip_relax.c:207
#define NULL
Definition: def.h:239
internal methods for managing events
default message handler
public methods for relaxator plugins
trivialnegation primal heuristic
internal methods for storing primal CIP solutions
methods to interpret (evaluate) an expression tree "fast"
internal methods for branch and bound tree
int SCIPgetNRelaxs(SCIP *scip)
Definition: scip_relax.c:330
methods for implications, variable bounds, and cliques
internal methods for clocks and timing issues
SCIP_RETCODE SCIPsetIncludeRelax(SCIP_SET *set, SCIP_RELAX *relax)
Definition: set.c:4047
SCIP_RETCODE SCIPsetRelaxInit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
Definition: scip_relax.c:239
SCIP_RELAX ** SCIPgetRelaxs(SCIP *scip)
Definition: scip_relax.c:317
internal methods for NLPI solver interfaces
void SCIPrelaxSetPriority(SCIP_RELAX *relax, SCIP_SET *set, int priority)
Definition: relax.c:510
interface methods for specific LP solvers
internal methods for displaying statistics tables
SCIP_RETCODE SCIPsetRelaxExitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
Definition: scip_relax.c:287
#define FALSE
Definition: def.h:65
methods for the aggregation rows
SCIP_RETCODE SCIPincludeRelaxBasic(SCIP *scip, SCIP_RELAX **relaxptr, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: scip_relax.c:173
#define SCIP_DECL_RELAXINIT(x)
Definition: type_relax.h:63
#define SCIP_DECL_RELAXINITSOL(x)
Definition: type_relax.h:82
internal methods for Benders&#39; decomposition
#define TRUE
Definition: def.h:64
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
methods commonly used by primal heuristics
SCIP_RETCODE SCIPincludeRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: scip_relax.c:131
void SCIPrelaxSetCopy(SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
Definition: relax.c:414
internal methods for branching rules and branching candidate storage
datastructures for concurrent solvers
internal methods for handling parameter settings
methods for creating output for visualization tools (VBC, BAK)
nodereopt branching rule
SCIP_RELAX ** relaxs
Definition: struct_set.h:76
internal methods for LP management
internal methods for branching and inference history
internal methods for collecting primal CIP solutions and primal informations
internal methods for propagators
SCIP_RETCODE SCIPsetRelaxFree(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
Definition: scip_relax.c:223
SCIP_MEM * mem
Definition: struct_scip.h:61
#define SCIP_DECL_RELAXEXIT(x)
Definition: type_relax.h:71
void SCIPrelaxSetFree(SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
Definition: relax.c:425
git hash methods
SCIP_RETCODE SCIPrelaxCreate(SCIP_RELAX **relax, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: relax.c:154
internal methods for storing and manipulating the main problem
#define SCIPerrorMessage
Definition: pub_message.h:45
methods for block memory pools and memory buffers
register additional core functionality that is designed as plugins
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:1933
internal methods for presolvers
SCIP_RELAX * SCIPsetFindRelax(SCIP_SET *set, const char *name)
Definition: set.c:4071
internal methods for NLP management
internal miscellaneous methods
#define SCIP_DECL_RELAXCOPY(x)
Definition: type_relax.h:47
int nrelaxs
Definition: struct_set.h:108
void SCIPrelaxSetInitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
Definition: relax.c:458
void SCIPrelaxSetExitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
Definition: relax.c:469
internal methods for node selectors and node priority queues
internal methods for variable pricers
internal methods for global SCIP settings
internal methods for storing conflicts
#define SCIP_CALL(x)
Definition: def.h:351
SCIP main data structure.
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
internal methods for storing priced variables
internal methods for relaxators
SCIP_RETCODE SCIPsetRelaxPriority(SCIP *scip, SCIP_RELAX *relax, int priority)
Definition: scip_relax.c:341
internal methods for storing separated cuts
void SCIPsetSortRelaxs(SCIP_SET *set)
Definition: set.c:4091
SCIP_RETCODE SCIPsetRelaxExit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
Definition: scip_relax.c:255
methods commonly used for presolving
methods for catching the user CTRL-C interrupt
internal methods for problem variables
data structures and methods for collecting reoptimization information
the function declarations for the synchronization store
internal methods for user interface dialog
internal methods for input file readers
methods for debugging
reoptsols primal heuristic
internal methods for storing cuts in a cut pool
Constraint handler for linear constraints in their most general form, .
helper functions for concurrent scip solvers
internal methods for return codes for SCIP methods
struct SCIP_RelaxData SCIP_RELAXDATA
Definition: type_relax.h:38
#define SCIP_DECL_RELAXEXEC(x)
Definition: type_relax.h:118
internal methods for conflict analysis
internal methods for tree compressions
internal methods for main solving loop and node processing
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
default user interface dialog
internal methods for problem statistics
internal methods for constraints and constraint handlers
declarations for XML parsing
build flags methods
#define SCIP_DECL_RELAXEXITSOL(x)
Definition: type_relax.h:93
common defines and data types used in all packages of SCIP
internal methods for primal heuristics
void SCIPrelaxSetExit(SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
Definition: relax.c:447
internal methods for Benders&#39; decomposition cuts
SCIP_RETCODE SCIPsetRelaxInitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
Definition: scip_relax.c:271
void SCIPrelaxSetInit(SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
Definition: relax.c:436
SCIP_RELAX * SCIPfindRelax(SCIP *scip, const char *name)
Definition: scip_relax.c:304
internal methods for displaying runtime statistics
OFINS - Objective Function Induced Neighborhood Search - a primal heuristic for reoptimization.