Scippy

SCIP

Solving Constraint Integer Programs

objdisp.h
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 2002-2022 Zuse Institute Berlin */
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.h
26  * @brief C++ wrapper for display columns
27  * @author Kati Wolter
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_OBJDISP_H__
33 #define __SCIP_OBJDISP_H__
34 
35 #include <cstring>
36 #include <utility>
37 
38 #include "scip/scip.h"
39 #include "objscip/objcloneable.h"
40 
41 namespace scip
42 {
43 
44 /**
45  * @brief C++ wrapper for display columns
46  *
47  * This class defines the interface for display columns implemented in C++. Note that there is a pure virtual function
48  * (this function has to be implemented). This function is: scip_output().
49  *
50  * - \ref DISP "Instructions for implementing a display column"
51  * - \ref DISPLAYS "List of available display columns"
52  * - \ref type_disp.h "Corresponding C interface"
53  */
54 class ObjDisp : public ObjCloneable
55 {
56 public:
57  /*lint --e{1540}*/
58 
59  /** SCIP data structure */
61 
62  /** name of the display column */
63  char* scip_name_;
64 
65  /** description of the display column */
66  char* scip_desc_;
67 
68  /** head line of the display column */
69  char* scip_header_;
70 
71  /** width of the display column (no. of chars used) */
72  const int scip_width_;
73 
74  /** priority of the display column */
75  const int scip_priority_;
76 
77  /** relative position of the display column */
78  const int scip_position_;
79 
80  /** should the column be separated with a line from its right neighbour? */
82 
83  /** default constructor */
85  SCIP* scip, /**< SCIP data structure */
86  const char* name, /**< name of display column */
87  const char* desc, /**< description of display column */
88  const char* header, /**< head line of display column */
89  int width, /**< width of display column (no. of chars used) */
90  int priority, /**< priority of display column */
91  int position, /**< relative position of display column */
92  SCIP_Bool stripline /**< should the column be separated with a line from its right neighbour? */
93  )
94  : scip_(scip),
95  scip_name_(0),
96  scip_desc_(0),
97  scip_header_(0),
98  scip_width_(width),
99  scip_priority_(priority),
100  scip_position_(position),
101  scip_stripline_(stripline)
102  {
103  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
104  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
105  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
106  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_header_, header, std::strlen(header)+1) );
107  }
108 
109  /** copy constructor */
110  ObjDisp(const ObjDisp& o)
111  : ObjDisp(o.scip_, o.scip_name_, o.scip_desc_, o.scip_header_, o.scip_width_, o.scip_priority_, o.scip_position_,
112  o.scip_stripline_)
113  {
114  }
115 
116  /** move constructor */
118  : scip_(o.scip_),
119  scip_name_(0),
120  scip_desc_(0),
121  scip_header_(0),
122  scip_width_(o.scip_width_),
123  scip_priority_(o.scip_priority_),
124  scip_position_(o.scip_position_),
125  scip_stripline_(o.scip_stripline_)
126  {
127  std::swap(scip_name_, o.scip_name_);
128  std::swap(scip_desc_, o.scip_desc_);
129  std::swap(scip_header_, o.scip_header_);
130  }
131 
132  /** destructor */
133  virtual ~ObjDisp()
134  {
135  /* the macro SCIPfreeMemoryArray does not need the first argument: */
136  /*lint --e{64}*/
137  SCIPfreeMemoryArray(scip_, &scip_name_);
138  SCIPfreeMemoryArray(scip_, &scip_desc_);
139  SCIPfreeMemoryArray(scip_, &scip_header_);
140  }
141 
142  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
143  ObjDisp& operator=(const ObjDisp& o) = delete;
144 
145  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
146  ObjDisp& operator=(ObjDisp&& o) = delete;
147 
148  /** destructor of display column to free user data (called when SCIP is exiting)
149  *
150  * @see SCIP_DECL_DISPFREE(x) in @ref type_disp.h
151  */
152  virtual SCIP_DECL_DISPFREE(scip_free)
153  { /*lint --e{715}*/
154  return SCIP_OKAY;
155  }
156 
157  /** initialization method of display column (called after problem was transformed)
158  *
159  * @see SCIP_DECL_DISPINIT(x) in @ref type_disp.h
160  */
161  virtual SCIP_DECL_DISPINIT(scip_init)
162  { /*lint --e{715}*/
163  return SCIP_OKAY;
164  }
165 
166  /** deinitialization method of display column (called before transformed problem is freed)
167  *
168  * @see SCIP_DECL_DISPEXIT(x) in @ref type_disp.h
169  */
170  virtual SCIP_DECL_DISPEXIT(scip_exit)
171  { /*lint --e{715}*/
172  return SCIP_OKAY;
173  }
174 
175  /** solving process initialization method of display column (called when branch and bound process is about to begin)
176  *
177  * @see SCIP_DECL_DISPINITSOL(x) in @ref type_disp.h
178  */
179  virtual SCIP_DECL_DISPINITSOL(scip_initsol)
180  { /*lint --e{715}*/
181  return SCIP_OKAY;
182  }
183 
184  /** solving process deinitialization method of display column (called before branch and bound process data is freed)
185  *
186  * @see SCIP_DECL_DISPEXITSOL(x) in @ref type_disp.h
187  */
188  virtual SCIP_DECL_DISPEXITSOL(scip_exitsol)
189  { /*lint --e{715}*/
190  return SCIP_OKAY;
191  }
192 
193  /** output method of display column to output file stream 'file'
194  *
195  * @see SCIP_DECL_DISPOUTPUT(x) in @ref type_disp.h
196  */
197  virtual SCIP_DECL_DISPOUTPUT(scip_output) = 0;
198 };
199 
200 } /* namespace scip */
201 
202 
203 
204 /** creates the display column for the given display column object and includes it in SCIP
205  *
206  * The method should be called in one of the following ways:
207  *
208  * 1. The user is resposible of deleting the object:
209  * SCIP_CALL( SCIPcreate(&scip) );
210  * ...
211  * MyDisp* mydisp = new MyDisp(...);
212  * SCIP_CALL( SCIPincludeObjDisp(scip, &mydisp, FALSE) );
213  * ...
214  * SCIP_CALL( SCIPfree(&scip) );
215  * delete mydisp; // delete disp AFTER SCIPfree() !
216  *
217  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
218  * SCIP_CALL( SCIPcreate(&scip) );
219  * ...
220  * SCIP_CALL( SCIPincludeObjDisp(scip, new MyDisp(...), TRUE) );
221  * ...
222  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyDisp is called here
223  */
224 SCIP_EXPORT
226  SCIP* scip, /**< SCIP data structure */
227  scip::ObjDisp* objdisp, /**< display column object */
228  SCIP_Bool deleteobject /**< should the display column object be deleted when display column is freed? */
229  );
230 
231 /** returns the display column object of the given name, or 0 if not existing */
232 SCIP_EXPORT
234  SCIP* scip, /**< SCIP data structure */
235  const char* name /**< name of display column */
236  );
237 
238 /** returns the display column object for the given display column */
239 SCIP_EXPORT
241  SCIP* scip, /**< SCIP data structure */
242  SCIP_DISP* disp /**< display column */
243  );
244 
245 #endif
const int scip_width_
Definition: objdisp.h:72
scip::ObjDisp * SCIPfindObjDisp(SCIP *scip, const char *name)
Definition: objdisp.cpp:232
C++ wrapper for display columns.
Definition: objdisp.h:54
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
ObjDisp & operator=(const ObjDisp &o)=delete
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
char * scip_header_
Definition: objdisp.h:69
ObjDisp(const ObjDisp &o)
Definition: objdisp.h:110
const SCIP_Bool scip_stripline_
Definition: objdisp.h:81
definition of base class for all clonable classes
virtual ~ObjDisp()
Definition: objdisp.h:133
char * scip_name_
Definition: objdisp.h:63
virtual SCIP_DECL_DISPEXITSOL(scip_exitsol)
Definition: objdisp.h:188
SCIP * scip_
Definition: objdisp.h:60
virtual SCIP_DECL_DISPINIT(scip_init)
Definition: objdisp.h:161
#define SCIP_Bool
Definition: def.h:93
scip::ObjDisp * SCIPgetObjDisp(SCIP *scip, SCIP_DISP *disp)
Definition: objdisp.cpp:251
virtual SCIP_DECL_DISPOUTPUT(scip_output)=0
const int scip_priority_
Definition: objdisp.h:75
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
char * scip_desc_
Definition: objdisp.h:66
virtual SCIP_DECL_DISPEXIT(scip_exit)
Definition: objdisp.h:170
const int scip_position_
Definition: objdisp.h:78
ObjDisp(SCIP *scip, const char *name, const char *desc, const char *header, int width, int priority, int position, SCIP_Bool stripline)
Definition: objdisp.h:84
virtual SCIP_DECL_DISPINITSOL(scip_initsol)
Definition: objdisp.h:179
SCIP_RETCODE SCIPincludeObjDisp(SCIP *scip, scip::ObjDisp *objdisp, SCIP_Bool deleteobject)
Definition: objdisp.cpp:204
#define SCIP_CALL_ABORT(x)
Definition: def.h:372
virtual SCIP_DECL_DISPFREE(scip_free)
Definition: objdisp.h:152
SCIP callable library.
ObjDisp(ObjDisp &&o)
Definition: objdisp.h:117