Scippy

GCG

Branch-and-Price & Column Generation for Everyone

objdialog.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
4 /* GCG --- Generic Column Generation */
5 /* a Dantzig-Wolfe decomposition based extension */
6 /* of the branch-cut-and-price framework */
7 /* SCIP --- Solving Constraint Integer Programs */
8 /* */
9 /* Copyright (C) 2010-2021 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
28 /**@file objdialog.h
29  * @brief C++ wrapper for dialogs
30  * @author Kati Wolter
31  * @author Martin Bergner
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #ifndef GCG_OBJDIALOG_H__
37 #define GCG_OBJDIALOG_H__
38 
39 #include <cstring>
40 
41 #include "scip/scip.h"
42 #include "objscip/objcloneable.h"
43 
44 namespace gcg
45 {
46 
47 /**
48  * @brief C++ wrapper for dialogs
49  *
50  * This class defines the interface for dialogs implemented in C++. Note that there is a pure virtual function (this
51  * function has to be implemented). This function is: scip_exec().
52  */
53 class ObjDialog : public scip::ObjCloneable
54 {
55 public:
56  /*lint --e{1540}*/
57 
58  /** SCIP data structure */
59  SCIP* scip_;
60 
61  /** name of the dialog */
62  char* scip_name_;
63 
64  /** description of the dialog */
65  char* scip_desc_;
66 
67  /** default for whether the dialog is a menu */
68  const SCIP_Bool scip_issubmenu_;
69 
70  /** default constructor */
72  SCIP* scip, /**< SCIP data structure */
73  const char* name, /**< name of the dialog */
74  const char* desc, /**< description of the dialog */
75  SCIP_Bool issubmenu /**< default for whether the dialog is a menu */
76  )
77  : scip_(scip),
78  scip_name_(0),
79  scip_desc_(0),
80  scip_issubmenu_(issubmenu)
81  {
82  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
83  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
84  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
85  }
86 
87  /** destructor */
88  virtual ~ObjDialog()
89  {
90  /* the macro SCIPfreeMemoryArray does not need the first argument: */
91  /*lint --e{64}*/
92  SCIPfreeMemoryArray(scip_, &scip_name_);
93  SCIPfreeMemoryArray(scip_, &scip_desc_);
94  scip_ = NULL;
95  }
96 
97  /** destructor of dialog to free user data (called when SCIP is exiting)
98  *
99  * @see SCIP_DECL_DIALOGFREE(x) in type_dialog.h
100  */
101  virtual SCIP_DECL_DIALOGFREE(scip_free)
102  { /*lint --e{715}*/
103  return SCIP_OKAY;
104  }
105 
106  /** description output method of dialog
107  *
108  * @see SCIP_DECL_DIALOGDESC(x) in type_dialog.h
109  */
110  virtual SCIP_DECL_DIALOGDESC(scip_desc)
111  { /*lint --e{715}*/
112  SCIPdialogMessage(scip, 0, "%s", scip_desc_);
113  return SCIP_OKAY;
114  }
115 
116  /** execution method of dialog
117  *
118  * @see SCIP_DECL_DIALOGEXEC(x) in type_dialog.h
119  */
120  virtual SCIP_DECL_DIALOGEXEC(scip_exec) = 0;
121 };
122 
123 } /* namespace scip */
124 
125 
126 
127 /** creates the dialog for the given dialog object and includes it in SCIP
128  *
129  * The method should be called in one of the following ways:
130  *
131  * 1. The user is resposible of deleting the object:
132  * SCIP_CALL( SCIPcreate(&scip) );
133  * ...
134  * MyDialog* mydialog = new MyDialog(...);
135  * SCIP_CALL( SCIPincludeObjDialog(scip, &mydialog, FALSE) );
136  * ...
137  * SCIP_CALL( SCIPfree(&scip) );
138  * delete mydialog; // delete dialog AFTER SCIPfree() !
139  *
140  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
141  * SCIP_CALL( SCIPcreate(&scip) );
142  * ...
143  * SCIP_CALL( SCIPincludeObjDialog(scip, new MyDialog(...), TRUE) );
144  * ...
145  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyDialog is called here
146  */
147 extern
148 SCIP_RETCODE SCIPincludeObjDialog(
149  SCIP* scip, /**< SCIP data structure */
150  SCIP_DIALOG* parentdialog, /**< parent dialog */
151  gcg::ObjDialog* objdialog, /**< dialog object */
152  SCIP_Bool deleteobject /**< should the dialog object be deleted when dialog is freed? */
153  );
154 
155 #endif
C++ wrapper for dialogs.
Definition: objdialog.h:53
SCIP * scip_
Definition: objdialog.h:59
const SCIP_Bool scip_issubmenu_
Definition: objdialog.h:68
virtual SCIP_DECL_DIALOGEXEC(scip_exec)=0
virtual ~ObjDialog()
Definition: objdialog.h:88
virtual SCIP_DECL_DIALOGDESC(scip_desc)
Definition: objdialog.h:110
ObjDialog(SCIP *scip, const char *name, const char *desc, SCIP_Bool issubmenu)
Definition: objdialog.h:71
char * scip_desc_
Definition: objdialog.h:65
SCIP_RETCODE SCIPincludeObjDialog(SCIP *scip, SCIP_DIALOG *parentdialog, gcg::ObjDialog *objdialog, SCIP_Bool deleteobject)
Definition: objdialog.cpp:127
virtual SCIP_DECL_DIALOGFREE(scip_free)
Definition: objdialog.h:101
char * scip_name_
Definition: objdialog.h:62