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