Scippy

SCIP

Solving Constraint Integer Programs

objsepa.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-2024 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file objsepa.cpp
26  * @brief C++ wrapper for cut separators
27  * @author Tobias Achterberg
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #include <cassert>
33 
34 #include "objsepa.h"
35 
36 
37 
38 
39 /*
40  * Data structures
41  */
42 
43 /** cut separator data */
44 struct SCIP_SepaData
45 {
46  scip::ObjSepa* objsepa; /**< cut separator object */
47  SCIP_Bool deleteobject; /**< should the cut separator object be deleted when cut separator is freed? */
48 };
49 
50 
51 
52 /*
53  * Callback methods of cut separator
54  */
55 
56 extern "C"
57 {
58 
59 /** copy method for separator plugins (called when SCIP copies plugins) */
60 static
61 SCIP_DECL_SEPACOPY(sepaCopyObj)
62 { /*lint --e{715}*/
63  SCIP_SEPADATA* sepadata;
64 
65  assert(scip != NULL);
66 
67  sepadata = SCIPsepaGetData(sepa);
68  assert(sepadata != NULL);
69  assert(sepadata->objsepa != NULL);
70  assert(sepadata->objsepa->scip_ != scip);
71 
72  if( sepadata->objsepa->iscloneable() )
73  {
74  scip::ObjSepa* newobjsepa;
75  newobjsepa = dynamic_cast<scip::ObjSepa*> (sepadata->objsepa->clone(scip));
76 
77  /* call include method of separator object */
78  SCIP_CALL( SCIPincludeObjSepa(scip, newobjsepa, TRUE) );
79  }
80 
81  return SCIP_OKAY;
82 }
83 
84 /** destructor of cut separator to free user data (called when SCIP is exiting) */
85 static
86 SCIP_DECL_SEPAFREE(sepaFreeObj)
87 { /*lint --e{715}*/
88  SCIP_SEPADATA* sepadata;
89 
90  sepadata = SCIPsepaGetData(sepa);
91  assert(sepadata != NULL);
92  assert(sepadata->objsepa != NULL);
93  assert(sepadata->objsepa->scip_ == scip);
94 
95  /* call virtual method of sepa object */
96  SCIP_CALL( sepadata->objsepa->scip_free(scip, sepa) );
97 
98  /* free sepa object */
99  if( sepadata->deleteobject )
100  delete sepadata->objsepa;
101 
102  /* free sepa data */
103  delete sepadata;
104  SCIPsepaSetData(sepa, NULL); /*lint !e64*/
105 
106  return SCIP_OKAY;
107 }
108 
109 
110 /** initialization method of cut separator (called after problem was transformed) */
111 static
112 SCIP_DECL_SEPAINIT(sepaInitObj)
113 { /*lint --e{715}*/
114  SCIP_SEPADATA* sepadata;
115 
116  sepadata = SCIPsepaGetData(sepa);
117  assert(sepadata != NULL);
118  assert(sepadata->objsepa != NULL);
119  assert(sepadata->objsepa->scip_ == scip);
120 
121  /* call virtual method of sepa object */
122  SCIP_CALL( sepadata->objsepa->scip_init(scip, sepa) );
123 
124  return SCIP_OKAY;
125 }
126 
127 
128 /** deinitialization method of cut separator (called before transformed problem is freed) */
129 static
130 SCIP_DECL_SEPAEXIT(sepaExitObj)
131 { /*lint --e{715}*/
132  SCIP_SEPADATA* sepadata;
133 
134  sepadata = SCIPsepaGetData(sepa);
135  assert(sepadata != NULL);
136  assert(sepadata->objsepa != NULL);
137 
138  /* call virtual method of sepa object */
139  SCIP_CALL( sepadata->objsepa->scip_exit(scip, sepa) );
140 
141  return SCIP_OKAY;
142 }
143 
144 
145 /** solving process initialization method of separator (called when branch and bound process is about to begin) */
146 static
147 SCIP_DECL_SEPAINITSOL(sepaInitsolObj)
148 { /*lint --e{715}*/
149  SCIP_SEPADATA* sepadata;
150 
151  sepadata = SCIPsepaGetData(sepa);
152  assert(sepadata != NULL);
153  assert(sepadata->objsepa != NULL);
154 
155  /* call virtual method of sepa object */
156  SCIP_CALL( sepadata->objsepa->scip_initsol(scip, sepa) );
157 
158  return SCIP_OKAY;
159 }
160 
161 
162 /** solving process deinitialization method of separator (called before branch and bound process data is freed) */
163 static
164 SCIP_DECL_SEPAEXITSOL(sepaExitsolObj)
165 { /*lint --e{715}*/
166  SCIP_SEPADATA* sepadata;
167 
168  sepadata = SCIPsepaGetData(sepa);
169  assert(sepadata != NULL);
170  assert(sepadata->objsepa != NULL);
171 
172  /* call virtual method of sepa object */
173  SCIP_CALL( sepadata->objsepa->scip_exitsol(scip, sepa) );
174 
175  return SCIP_OKAY;
176 }
177 
178 
179 /** LP solution separation method of separator */
180 static
181 SCIP_DECL_SEPAEXECLP(sepaExeclpObj)
182 { /*lint --e{715}*/
183  SCIP_SEPADATA* sepadata;
184 
185  sepadata = SCIPsepaGetData(sepa);
186  assert(sepadata != NULL);
187  assert(sepadata->objsepa != NULL);
188 
189  /* call virtual method of sepa object */
190  SCIP_CALL( sepadata->objsepa->scip_execlp(scip, sepa, result, allowlocal, depth) );
191 
192  return SCIP_OKAY;
193 }
194 
195 
196 /** arbitrary primal solution separation method of separator */
197 static
198 SCIP_DECL_SEPAEXECSOL(sepaExecsolObj)
199 { /*lint --e{715}*/
200  SCIP_SEPADATA* sepadata;
201 
202  sepadata = SCIPsepaGetData(sepa);
203  assert(sepadata != NULL);
204  assert(sepadata->objsepa != NULL);
205 
206  /* call virtual method of sepa object */
207  SCIP_CALL( sepadata->objsepa->scip_execsol(scip, sepa, sol, result, allowlocal, depth) );
208 
209  return SCIP_OKAY;
210 }
211 }
212 
213 
214 
215 /*
216  * cut separator specific interface methods
217  */
218 
219 /** creates the cut separator for the given cut separator object and includes it in SCIP */
221  SCIP* scip, /**< SCIP data structure */
222  scip::ObjSepa* objsepa, /**< cut separator object */
223  SCIP_Bool deleteobject /**< should the cut separator object be deleted when cut separator is freed? */
224  )
225 {
226  SCIP_SEPADATA* sepadata;
227 
228  assert(scip != NULL);
229  assert(objsepa != NULL);
230 
231  /* create cut separator data */
232  sepadata = new SCIP_SEPADATA;
233  sepadata->objsepa = objsepa;
234  sepadata->deleteobject = deleteobject;
235 
236  /* include cut separator */
237  SCIP_CALL( SCIPincludeSepa(scip, objsepa->scip_name_, objsepa->scip_desc_, objsepa->scip_priority_,
238  objsepa->scip_freq_, objsepa->scip_maxbounddist_, objsepa->scip_usessubscip_, objsepa->scip_delay_,
239  sepaCopyObj, sepaFreeObj, sepaInitObj, sepaExitObj, sepaInitsolObj, sepaExitsolObj,
240  sepaExeclpObj, sepaExecsolObj,
241  sepadata) ); /*lint !e429*/
242 
243  return SCIP_OKAY; /*lint !e429*/
244 }
245 
246 /** returns the sepa object of the given name, or 0 if not existing */
248  SCIP* scip, /**< SCIP data structure */
249  const char* name /**< name of cut separator */
250  )
251 {
252  SCIP_SEPA* sepa;
253  SCIP_SEPADATA* sepadata;
254 
255  sepa = SCIPfindSepa(scip, name);
256  if( sepa == NULL )
257  return 0;
258 
259  sepadata = SCIPsepaGetData(sepa);
260  assert(sepadata != NULL);
261 
262  return sepadata->objsepa;
263 }
264 
265 /** returns the sepa object for the given cut separator */
267  SCIP* scip, /**< SCIP data structure */
268  SCIP_SEPA* sepa /**< cut separator */
269  )
270 {
271  SCIP_SEPADATA* sepadata;
272 
273  assert(scip != NULL);
274  sepadata = SCIPsepaGetData(sepa);
275  assert(sepadata != NULL);
276 
277  return sepadata->objsepa;
278 }
static SCIP_DECL_SEPACOPY(sepaCopyObj)
Definition: objsepa.cpp:61
static SCIP_DECL_SEPAEXIT(sepaExitObj)
Definition: objsepa.cpp:130
#define NULL
Definition: def.h:267
const SCIP_Real scip_maxbounddist_
Definition: objsepa.h:75
SCIP_SEPA * SCIPfindSepa(SCIP *scip, const char *name)
Definition: scip_sepa.c:247
char * scip_name_
Definition: objsepa.h:61
#define TRUE
Definition: def.h:93
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
static SCIP_DECL_SEPAINIT(sepaInitObj)
Definition: objsepa.cpp:112
static SCIP_DECL_SEPAEXECSOL(sepaExecsolObj)
Definition: objsepa.cpp:198
static SCIP_DECL_SEPAEXECLP(sepaExeclpObj)
Definition: objsepa.cpp:181
SCIP_SEPADATA * SCIPsepaGetData(SCIP_SEPA *sepa)
Definition: sepa.c:633
static SCIP_DECL_SEPAFREE(sepaFreeObj)
Definition: objsepa.cpp:86
SCIP_RETCODE SCIPincludeSepa(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPACOPY((*sepacopy)), SCIP_DECL_SEPAFREE((*sepafree)), SCIP_DECL_SEPAINIT((*sepainit)), SCIP_DECL_SEPAEXIT((*sepaexit)), SCIP_DECL_SEPAINITSOL((*sepainitsol)), SCIP_DECL_SEPAEXITSOL((*sepaexitsol)), SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:62
scip::ObjSepa * SCIPgetObjSepa(SCIP *scip, SCIP_SEPA *sepa)
Definition: objsepa.cpp:266
void SCIPsepaSetData(SCIP_SEPA *sepa, SCIP_SEPADATA *sepadata)
Definition: sepa.c:643
#define SCIP_CALL(x)
Definition: def.h:380
const SCIP_Bool scip_delay_
Definition: objsepa.h:81
char * scip_desc_
Definition: objsepa.h:64
#define SCIP_Bool
Definition: def.h:91
const SCIP_Bool scip_usessubscip_
Definition: objsepa.h:78
SCIP_RETCODE SCIPincludeObjSepa(SCIP *scip, scip::ObjSepa *objsepa, SCIP_Bool deleteobject)
Definition: objsepa.cpp:220
scip::ObjSepa * SCIPfindObjSepa(SCIP *scip, const char *name)
Definition: objsepa.cpp:247
static SCIP_DECL_SEPAEXITSOL(sepaExitsolObj)
Definition: objsepa.cpp:164
static SCIP_DECL_SEPAINITSOL(sepaInitsolObj)
Definition: objsepa.cpp:147
const int scip_priority_
Definition: objsepa.h:67
const int scip_freq_
Definition: objsepa.h:70
C++ wrapper for cut separators.
Definition: objsepa.h:52
C++ wrapper for cut separators.
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:52