Scippy

SCIP

Solving Constraint Integer Programs

objcutsel.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-2022 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 objcutsel.cpp
17  * @brief C++ wrapper for cut selectors
18  * @author Felipe Serrano
19  * @author Mark Turner
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <cassert>
25 
26 #include "objcutsel.h"
27 
28 
29 
30 
31 /*
32  * Data structures
33  */
34 
35 /** cut selector data */
36 struct SCIP_CutselData
37 {
38  scip::ObjCutsel* objcutsel; /**< cut selector object */
39  SCIP_Bool deleteobject; /**< should the cut selector object be deleted when cut selector is freed? */
40 };
41 
42 
43 
44 
45 /*
46  * Callback methods of cut selector
47  */
48 
49 extern "C"
50 {
51 
52 /** copy method for cut selector plugins (called when SCIP copies plugins) */
53 static
54 SCIP_DECL_CUTSELCOPY(cutselCopyObj)
55 { /*lint --e{715}*/
56  SCIP_CUTSELDATA* cutseldata;
57 
58  assert(scip != NULL);
59 
60  cutseldata = SCIPcutselGetData(cutsel);
61  assert(cutseldata != NULL);
62  assert(cutseldata->objcutsel != NULL);
63  assert(cutseldata->objcutsel->scip_ != scip);
64 
65  if( cutseldata->objcutsel->iscloneable() )
66  {
67  scip::ObjCutsel* newobjcutsel;
68  newobjcutsel = dynamic_cast<scip::ObjCutsel*> (cutseldata->objcutsel->clone(scip));
69 
70  /* call include method of cut selector object */
71  SCIP_CALL( SCIPincludeObjCutsel(scip, newobjcutsel, TRUE) );
72  }
73 
74  return SCIP_OKAY;
75 }
76 
77 /** destructor of cut selector to free user data (called when SCIP is exiting) */
78 static
79 SCIP_DECL_CUTSELFREE(cutselFreeObj)
80 { /*lint --e{715}*/
81  SCIP_CUTSELDATA* cutseldata;
82 
83  cutseldata = SCIPcutselGetData(cutsel);
84  assert(cutseldata != NULL);
85  assert(cutseldata->objcutsel != NULL);
86  assert(cutseldata->objcutsel->scip_ == scip);
87 
88  /* call virtual method of cutsel object */
89  SCIP_CALL( cutseldata->objcutsel->scip_free(scip, cutsel) );
90 
91  /* free cutsel object */
92  if( cutseldata->deleteobject )
93  delete cutseldata->objcutsel;
94 
95  /* free cutsel data */
96  delete cutseldata;
97  SCIPcutselSetData(cutsel, NULL); /*lint !e64*/
98 
99  return SCIP_OKAY;
100 }
101 
102 
103 /** initialization method of cut selector (called after problem was transformed) */
104 static
105 SCIP_DECL_CUTSELINIT(cutselInitObj)
106 { /*lint --e{715}*/
107  SCIP_CUTSELDATA* cutseldata;
108 
109  cutseldata = SCIPcutselGetData(cutsel);
110  assert(cutseldata != NULL);
111  assert(cutseldata->objcutsel != NULL);
112  assert(cutseldata->objcutsel->scip_ == scip);
113 
114  /* call virtual method of cutsel object */
115  SCIP_CALL( cutseldata->objcutsel->scip_init(scip, cutsel) );
116 
117  return SCIP_OKAY;
118 }
119 
120 
121 /** deinitialization method of cut selector (called before transformed problem is freed) */
122 static
123 SCIP_DECL_CUTSELEXIT(cutselExitObj)
124 { /*lint --e{715}*/
125  SCIP_CUTSELDATA* cutseldata;
126 
127  cutseldata = SCIPcutselGetData(cutsel);
128  assert(cutseldata != NULL);
129  assert(cutseldata->objcutsel != NULL);
130 
131  /* call virtual method of cutsel object */
132  SCIP_CALL( cutseldata->objcutsel->scip_exit(scip, cutsel) );
133 
134  return SCIP_OKAY;
135 }
136 
137 
138 /** solving process initialization method of cut selector (called when branch and bound process is about to begin) */
139 static
140 SCIP_DECL_CUTSELINITSOL(cutselInitsolObj)
141 { /*lint --e{715}*/
142  SCIP_CUTSELDATA* cutseldata;
143 
144  cutseldata = SCIPcutselGetData(cutsel);
145  assert(cutseldata != NULL);
146  assert(cutseldata->objcutsel != NULL);
147 
148  /* call virtual method of cutsel object */
149  SCIP_CALL( cutseldata->objcutsel->scip_initsol(scip, cutsel) );
150 
151  return SCIP_OKAY;
152 }
153 
154 
155 /** solving process deinitialization method of cut selector (called before branch and bound process data is freed) */
156 static
157 SCIP_DECL_CUTSELEXITSOL(cutselExitsolObj)
158 { /*lint --e{715}*/
159  SCIP_CUTSELDATA* cutseldata;
160 
161  cutseldata = SCIPcutselGetData(cutsel);
162  assert(cutseldata != NULL);
163  assert(cutseldata->objcutsel != NULL);
164 
165  /* call virtual method of cutsel object */
166  SCIP_CALL( cutseldata->objcutsel->scip_exitsol(scip, cutsel) );
167 
168  return SCIP_OKAY;
169 }
170 
171 
172 /** cut selection method of cut selector */
173 static
174 SCIP_DECL_CUTSELSELECT(cutselSelectObj)
175 { /*lint --e{715}*/
176  SCIP_CUTSELDATA* cutseldata;
177 
178  cutseldata = SCIPcutselGetData(cutsel);
179  assert(cutseldata != NULL);
180  assert(cutseldata->objcutsel != NULL);
181 
182  /* call virtual method of cutsel object */
183  SCIP_CALL( cutseldata->objcutsel->scip_select(scip, cutsel, cuts, ncuts, forcedcuts, nforcedcuts,
184  root, maxnselectedcuts, nselectedcuts, result) );
185 
186  return SCIP_OKAY;
187 }
188 }
189 
190 
191 
192 /*
193  * cut selector specific interface methods
194  */
195 
196 /** creates the cut selector for the given cut selector object and includes it in SCIP */
198  SCIP* scip, /**< SCIP data structure */
199  scip::ObjCutsel* objcutsel, /**< cut selector object */
200  SCIP_Bool deleteobject /**< should the cut selector object be deleted when cut selector is freed? */
201  )
202 {
203  SCIP_CUTSELDATA* cutseldata;
204 
205  assert(scip != NULL);
206  assert(objcutsel != NULL);
207 
208  /* create cut selector data */
209  cutseldata = new SCIP_CUTSELDATA;
210  cutseldata->objcutsel = objcutsel;
211  cutseldata->deleteobject = deleteobject;
212 
213  /* include cut selector */
214  SCIP_CALL( SCIPincludeCutsel(scip, objcutsel->scip_name_, objcutsel->scip_desc_,
215  objcutsel->scip_priority_,
216  cutselCopyObj,
217  cutselFreeObj, cutselInitObj, cutselExitObj,
218  cutselInitsolObj, cutselExitsolObj, cutselSelectObj,
219  cutseldata) ); /*lint !e429*/
220 
221  return SCIP_OKAY; /*lint !e429*/
222 }
223 
224 /** returns the cutsel object of the given name, or 0 if not existing */
226  SCIP* scip, /**< SCIP data structure */
227  const char* name /**< name of cut selector */
228  )
229 {
230  SCIP_CUTSEL* cutsel;
231  SCIP_CUTSELDATA* cutseldata;
232 
233  cutsel = SCIPfindCutsel(scip, name);
234  if( cutsel == NULL )
235  return 0;
236 
237  cutseldata = SCIPcutselGetData(cutsel);
238  assert(cutseldata != NULL);
239 
240  return cutseldata->objcutsel;
241 }
242 
243 /** returns the cutsel object for the given cut selector */
245  SCIP* scip, /**< SCIP data structure */
246  SCIP_CUTSEL* cutsel /**< cut selector */
247  )
248 {
249  SCIP_CUTSELDATA* cutseldata;
250 
251  assert(scip != NULL);
252  cutseldata = SCIPcutselGetData(cutsel);
253  assert(cutseldata != NULL);
254 
255  return cutseldata->objcutsel;
256 }
SCIP_CUTSELDATA * SCIPcutselGetData(SCIP_CUTSEL *cutsel)
Definition: cutsel.c:371
struct SCIP_CutselData SCIP_CUTSELDATA
Definition: type_cutsel.h:44
static SCIP_DECL_CUTSELEXIT(cutselExitObj)
Definition: objcutsel.cpp:123
const int scip_priority_
Definition: objcutsel.h:58
char * scip_name_
Definition: objcutsel.h:52
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
void SCIPcutselSetData(SCIP_CUTSEL *cutsel, SCIP_CUTSELDATA *cutseldata)
Definition: cutsel.c:381
static SCIP_DECL_CUTSELINIT(cutselInitObj)
Definition: objcutsel.cpp:105
C++ wrapper for cut selectors.
static SCIP_DECL_CUTSELEXITSOL(cutselExitsolObj)
Definition: objcutsel.cpp:157
SCIP_CUTSEL * SCIPfindCutsel(SCIP *scip, const char *name)
Definition: scip_cutsel.c:212
#define NULL
Definition: lpi_spx1.cpp:155
#define SCIP_CALL(x)
Definition: def.h:384
SCIP_RETCODE SCIPincludeObjCutsel(SCIP *scip, scip::ObjCutsel *objcutsel, SCIP_Bool deleteobject)
Definition: objcutsel.cpp:197
static SCIP_DECL_CUTSELFREE(cutselFreeObj)
Definition: objcutsel.cpp:79
#define SCIP_Bool
Definition: def.h:84
static SCIP_DECL_CUTSELCOPY(cutselCopyObj)
Definition: objcutsel.cpp:54
C++ wrapper for cut selectors.
Definition: objcutsel.h:43
static SCIP_DECL_CUTSELINITSOL(cutselInitsolObj)
Definition: objcutsel.cpp:140
SCIP_RETCODE SCIPincludeCutsel(SCIP *scip, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
Definition: scip_cutsel.c:41
char * scip_desc_
Definition: objcutsel.h:55
scip::ObjCutsel * SCIPfindObjCutsel(SCIP *scip, const char *name)
Definition: objcutsel.cpp:225
scip::ObjCutsel * SCIPgetObjCutsel(SCIP *scip, SCIP_CUTSEL *cutsel)
Definition: objcutsel.cpp:244
static SCIP_DECL_CUTSELSELECT(cutselSelectObj)
Definition: objcutsel.cpp:174