Scippy

SCIP

Solving Constraint Integer Programs

objrelax.cpp
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-2016 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objrelax.cpp
17  * @brief C++ wrapper for relaxators
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objrelax.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** relaxator data */
35 struct SCIP_RelaxData
36 {
37  scip::ObjRelax* objrelax; /**< relaxator object */
38  SCIP_Bool deleteobject; /**< should the relaxator object be deleted when relaxator is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of relaxator
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for relaxator plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_RELAXCOPY(relaxCopyObj)
54 { /*lint --e{715}*/
55  SCIP_RELAXDATA* relaxdata;
56 
57  assert(scip != NULL);
58 
59  relaxdata = SCIPrelaxGetData(relax);
60  assert(relaxdata != NULL);
61  assert(relaxdata->objrelax != NULL);
62  assert(relaxdata->objrelax->scip_ != scip);
63 
64  if( relaxdata->objrelax->iscloneable() )
65  {
66  scip::ObjRelax* newobjrelax;
67  newobjrelax = dynamic_cast<scip::ObjRelax*> (relaxdata->objrelax->clone(scip));
68 
69  /* call include method of relaxator object */
70  SCIP_CALL( SCIPincludeObjRelax(scip, newobjrelax, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of relaxator to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_RELAXFREE(relaxFreeObj)
79 { /*lint --e{715}*/
80  SCIP_RELAXDATA* relaxdata;
81 
82  relaxdata = SCIPrelaxGetData(relax);
83  assert(relaxdata != NULL);
84  assert(relaxdata->objrelax != NULL);
85  assert(relaxdata->objrelax->scip_ == scip);
86 
87  /* call virtual method of relax object */
88  SCIP_CALL( relaxdata->objrelax->scip_free(scip, relax) );
89 
90  /* free relax object */
91  if( relaxdata->deleteobject )
92  delete relaxdata->objrelax;
93 
94  /* free relax data */
95  delete relaxdata;
96  SCIPrelaxSetData(relax, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** initialization method of relaxator (called after problem was transformed) */
103 static
104 SCIP_DECL_RELAXINIT(relaxInitObj)
105 { /*lint --e{715}*/
106  SCIP_RELAXDATA* relaxdata;
107 
108  relaxdata = SCIPrelaxGetData(relax);
109  assert(relaxdata != NULL);
110  assert(relaxdata->objrelax != NULL);
111  assert(relaxdata->objrelax->scip_ == scip);
112 
113  /* call virtual method of relax object */
114  SCIP_CALL( relaxdata->objrelax->scip_init(scip, relax) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** deinitialization method of relaxator (called before transformed problem is freed) */
121 static
122 SCIP_DECL_RELAXEXIT(relaxExitObj)
123 { /*lint --e{715}*/
124  SCIP_RELAXDATA* relaxdata;
125 
126  relaxdata = SCIPrelaxGetData(relax);
127  assert(relaxdata != NULL);
128  assert(relaxdata->objrelax != NULL);
129 
130  /* call virtual method of relax object */
131  SCIP_CALL( relaxdata->objrelax->scip_exit(scip, relax) );
132 
133  return SCIP_OKAY;
134 }
135 
136 
137 /** solving process initialization method of relaxator (called when branch and bound process is about to begin) */
138 static
139 SCIP_DECL_RELAXINITSOL(relaxInitsolObj)
140 { /*lint --e{715}*/
141  SCIP_RELAXDATA* relaxdata;
142 
143  relaxdata = SCIPrelaxGetData(relax);
144  assert(relaxdata != NULL);
145  assert(relaxdata->objrelax != NULL);
146 
147  /* call virtual method of relax object */
148  SCIP_CALL( relaxdata->objrelax->scip_initsol(scip, relax) );
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /** solving process deinitialization method of relaxator (called before branch and bound process data is freed) */
155 static
156 SCIP_DECL_RELAXEXITSOL(relaxExitsolObj)
157 { /*lint --e{715}*/
158  SCIP_RELAXDATA* relaxdata;
159 
160  relaxdata = SCIPrelaxGetData(relax);
161  assert(relaxdata != NULL);
162  assert(relaxdata->objrelax != NULL);
163 
164  /* call virtual method of relax object */
165  SCIP_CALL( relaxdata->objrelax->scip_exitsol(scip, relax) );
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /** execution method of relaxator */
172 static
173 SCIP_DECL_RELAXEXEC(relaxExecObj)
174 { /*lint --e{715}*/
175  SCIP_RELAXDATA* relaxdata;
176 
177  relaxdata = SCIPrelaxGetData(relax);
178  assert(relaxdata != NULL);
179  assert(relaxdata->objrelax != NULL);
180 
181  /* call virtual method of relax object */
182  SCIP_CALL( relaxdata->objrelax->scip_exec(scip, relax, lowerbound, result) );
183 
184  return SCIP_OKAY;
185 }
186 }
187 
188 
189 
190 /*
191  * relaxator specific interface methods
192  */
193 
194 /** creates the relaxator for the given relaxator object and includes it in SCIP */
196  SCIP* scip, /**< SCIP data structure */
197  scip::ObjRelax* objrelax, /**< relaxator object */
198  SCIP_Bool deleteobject /**< should the relaxator object be deleted when relaxator is freed? */
199  )
200 {
201  SCIP_RELAXDATA* relaxdata;
202 
203  assert(scip != NULL);
204  assert(objrelax != NULL);
205 
206  /* create relaxator data */
207  relaxdata = new SCIP_RELAXDATA;
208  relaxdata->objrelax = objrelax;
209  relaxdata->deleteobject = deleteobject;
210 
211  /* include relaxator */
212  SCIP_CALL( SCIPincludeRelax(scip, objrelax->scip_name_, objrelax->scip_desc_,
213  objrelax->scip_priority_, objrelax->scip_freq_,
214  relaxCopyObj,
215  relaxFreeObj, relaxInitObj, relaxExitObj,
216  relaxInitsolObj, relaxExitsolObj, relaxExecObj,
217  relaxdata) ); /*lint !e429*/
218 
219  return SCIP_OKAY; /*lint !e429*/
220 }
221 
222 /** returns the relax object of the given name, or 0 if not existing */
224  SCIP* scip, /**< SCIP data structure */
225  const char* name /**< name of relaxator */
226  )
227 {
228  SCIP_RELAX* relax;
229  SCIP_RELAXDATA* relaxdata;
230 
231  relax = SCIPfindRelax(scip, name);
232  if( relax == NULL )
233  return 0;
234 
235  relaxdata = SCIPrelaxGetData(relax);
236  assert(relaxdata != NULL);
237 
238  return relaxdata->objrelax;
239 }
240 
241 /** returns the relax object for the given relaxator */
243  SCIP* scip, /**< SCIP data structure */
244  SCIP_RELAX* relax /**< relaxator */
245  )
246 {
247  SCIP_RELAXDATA* relaxdata;
248 
249  relaxdata = SCIPrelaxGetData(relax);
250  assert(relaxdata != NULL);
251 
252  return relaxdata->objrelax;
253 }
#define NULL
Definition: lpi_spx.cpp:130
static SCIP_DECL_RELAXEXEC(relaxExecObj)
Definition: objrelax.cpp:173
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
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.c:6380
static SCIP_DECL_RELAXCOPY(relaxCopyObj)
Definition: objrelax.cpp:53
static SCIP_DECL_RELAXFREE(relaxFreeObj)
Definition: objrelax.cpp:78
scip::ObjRelax * SCIPfindObjRelax(SCIP *scip, const char *name)
Definition: objrelax.cpp:223
char * scip_desc_
Definition: objrelax.h:54
SCIP_RETCODE SCIPincludeObjRelax(SCIP *scip, scip::ObjRelax *objrelax, SCIP_Bool deleteobject)
Definition: objrelax.cpp:195
#define SCIP_Bool
Definition: def.h:53
static SCIP_DECL_RELAXINIT(relaxInitObj)
Definition: objrelax.cpp:104
static SCIP_DECL_RELAXINITSOL(relaxInitsolObj)
Definition: objrelax.cpp:139
char * scip_name_
Definition: objrelax.h:51
static SCIP_DECL_RELAXEXITSOL(relaxExitsolObj)
Definition: objrelax.cpp:156
struct SCIP_RelaxData SCIP_RELAXDATA
Definition: type_relax.h:38
scip::ObjRelax * SCIPgetObjRelax(SCIP *scip, SCIP_RELAX *relax)
Definition: objrelax.cpp:242
const int scip_freq_
Definition: objrelax.h:60
const int scip_priority_
Definition: objrelax.h:57
C++ wrapper for relaxation handlers.
Definition: objrelax.h:42
SCIP_RELAXDATA * SCIPrelaxGetData(SCIP_RELAX *relax)
Definition: relax.c:354
static SCIP_DECL_RELAXEXIT(relaxExitObj)
Definition: objrelax.cpp:122
C++ wrapper for relaxation handlers.
SCIP_RELAX * SCIPfindRelax(SCIP *scip, const char *name)
Definition: scip.c:6554
void SCIPrelaxSetData(SCIP_RELAX *relax, SCIP_RELAXDATA *relaxdata)
Definition: relax.c:364