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