Scippy

SCIP

Solving Constraint Integer Programs

objdisp.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-2014 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 objdisp.cpp
17  * @brief C++ wrapper for display column
18  * @author Kati Wolter
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objdisp.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** display column data */
35 struct SCIP_DispData
36 {
37  scip::ObjDisp* objdisp; /**< display column object */
38  SCIP_Bool deleteobject; /**< should the display column object be deleted when display column is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of display column
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for display column plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_DISPCOPY(dispCopyObj)
54 { /*lint --e{715}*/
55  SCIP_DISPDATA* dispdata;
56 
57  assert(scip != NULL);
58 
59  dispdata = SCIPdispGetData(disp);
60  assert(dispdata != NULL);
61  assert(dispdata->objdisp != NULL);
62  assert(dispdata->objdisp->scip_ != scip);
63 
64  if( dispdata->objdisp->iscloneable() )
65  {
66  scip::ObjDisp* newobjdisp;
67  newobjdisp = dynamic_cast<scip::ObjDisp*> (dispdata->objdisp->clone(scip));
68 
69  /* call include method of display column object */
70  SCIP_CALL( SCIPincludeObjDisp(scip, newobjdisp, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of display column to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_DISPFREE(dispFreeObj)
79 { /*lint --e{715}*/
80  SCIP_DISPDATA* dispdata;
81 
82  dispdata = SCIPdispGetData(disp);
83  assert(dispdata != NULL);
84  assert(dispdata->objdisp != NULL);
85  assert(dispdata->objdisp->scip_ == scip);
86 
87  /* call virtual method of display column object */
88  SCIP_CALL( dispdata->objdisp->scip_free(scip, disp) );
89 
90  /* free display column object */
91  if( dispdata->deleteobject )
92  delete dispdata->objdisp;
93 
94  /* free display column data */
95  delete dispdata;
96  SCIPdispSetData(disp, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** initialization method of display column (called after problem was transformed) */
103 static
104 SCIP_DECL_DISPINIT(dispInitObj)
105 { /*lint --e{715}*/
106  SCIP_DISPDATA* dispdata;
107 
108  dispdata = SCIPdispGetData(disp);
109  assert(dispdata != NULL);
110  assert(dispdata->objdisp != NULL);
111  assert(dispdata->objdisp->scip_ == scip);
112 
113  /* call virtual method of display column object */
114  SCIP_CALL( dispdata->objdisp->scip_init(scip, disp) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** deinitialization method of display column (called before transformed problem is freed) */
121 static
122 SCIP_DECL_DISPEXIT(dispExitObj)
123 { /*lint --e{715}*/
124  SCIP_DISPDATA* dispdata;
125 
126  dispdata = SCIPdispGetData(disp);
127  assert(dispdata != NULL);
128  assert(dispdata->objdisp != NULL);
129 
130  /* call virtual method of display column object */
131  SCIP_CALL( dispdata->objdisp->scip_exit(scip, disp) );
132 
133  return SCIP_OKAY;
134 }
135 
136 
137 /** solving process initialization method of display column (called when branch and bound process is about to begin) */
138 static
139 SCIP_DECL_DISPINITSOL(dispInitsolObj)
140 { /*lint --e{715}*/
141  SCIP_DISPDATA* dispdata;
142 
143  dispdata = SCIPdispGetData(disp);
144  assert(dispdata != NULL);
145  assert(dispdata->objdisp != NULL);
146 
147  /* call virtual method of display column object */
148  SCIP_CALL( dispdata->objdisp->scip_initsol(scip, disp) );
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /** solving process deinitialization method of display column (called before branch and bound process data is freed) */
155 static
156 SCIP_DECL_DISPEXITSOL(dispExitsolObj)
157 { /*lint --e{715}*/
158  SCIP_DISPDATA* dispdata;
159 
160  dispdata = SCIPdispGetData(disp);
161  assert(dispdata != NULL);
162  assert(dispdata->objdisp != NULL);
163 
164  /* call virtual method of display column object */
165  SCIP_CALL( dispdata->objdisp->scip_exitsol(scip, disp) );
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /** output method of display column to output file stream 'file' */
172 static
173 SCIP_DECL_DISPOUTPUT(dispOutputObj)
174 { /*lint --e{715}*/
175  SCIP_DISPDATA* dispdata;
176 
177  dispdata = SCIPdispGetData(disp);
178  assert(dispdata != NULL);
179  assert(dispdata->objdisp != NULL);
180 
181  /* call virtual method of display column object */
182  SCIP_CALL( dispdata->objdisp->scip_output(scip, disp, file) );
183 
184  return SCIP_OKAY;
185 }
186 }
187 
188 
189 
190 /*
191  * display column specific interface methods
192  */
193 
194 /** creates the display column for the given display column object and includes it in SCIP */
196  SCIP* scip, /**< SCIP data structure */
197  scip::ObjDisp* objdisp, /**< display column object */
198  SCIP_Bool deleteobject /**< should the display column object be deleted when display column is freed? */
199  )
200 {
201  SCIP_DISPDATA* dispdata;
202 
203  assert(scip != NULL);
204  assert(objdisp != NULL);
205 
206  /* create display column data */
207  dispdata = new SCIP_DISPDATA;
208  dispdata->objdisp = objdisp;
209  dispdata->deleteobject = deleteobject;
210 
211  /* include display column */
212  SCIP_CALL( SCIPincludeDisp(scip, objdisp->scip_name_, objdisp->scip_desc_,
214  dispCopyObj,
215  dispFreeObj, dispInitObj, dispExitObj, dispInitsolObj,
216  dispExitsolObj, dispOutputObj, dispdata, objdisp->scip_width_, objdisp->scip_priority_, objdisp->scip_position_,
217  objdisp->scip_stripline_) ); /*lint !e429*/
218 
219  return SCIP_OKAY; /*lint !e429*/
220 }
221 
222 /** returns the display column object of the given name, or 0 if not existing */
224  SCIP* scip, /**< SCIP data structure */
225  const char* name /**< name of display column */
226  )
227 {
228  SCIP_DISP* disp;
229  SCIP_DISPDATA* dispdata;
230 
231  disp = SCIPfindDisp(scip, name);
232  if( disp == NULL )
233  return 0;
234 
235  dispdata = SCIPdispGetData(disp);
236  assert(dispdata != NULL);
237 
238  return dispdata->objdisp;
239 }
240 
241 /** returns the display column object for the given display column */
243  SCIP* scip, /**< SCIP data structure */
244  SCIP_DISP* disp /**< display column */
245  )
246 {
247  SCIP_DISPDATA* dispdata;
248 
249  dispdata = SCIPdispGetData(disp);
250  assert(dispdata != NULL);
251 
252  return dispdata->objdisp;
253 }
254