Scippy

SCIP

Solving Constraint Integer Programs

objdialog.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-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 objdialog.cpp
26  * @brief C++ wrapper for dialogs
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 "objdialog.h"
35 
36 
37 
38 
39 /*
40  * Data structures
41  */
42 
43 /** dialog data */
44 struct SCIP_DialogData
45 {
46  scip::ObjDialog* objdialog; /**< dialog object */
47  SCIP_Bool deleteobject; /**< should the dialog object be deleted when dialog is freed? */
48 };
49 
50 
51 
52 
53 /*
54  * Callback methods of dialog
55  */
56 
57 extern "C"
58 {
59 
60 /** copy method for dialog plugins (called when SCIP copies plugins) */
61 static
62 SCIP_DECL_DIALOGCOPY(dialogCopyObj)
63 { /*lint --e{715}*/
64  SCIP_DIALOGDATA* dialogdata;
65 
66  assert(scip != 0);
67 
68  dialogdata = SCIPdialogGetData(dialog);
69  assert(dialogdata != 0);
70  assert(dialogdata->objdialog != 0);
71  assert(dialogdata->objdialog->scip_ != scip);
72 
73  if( dialogdata->objdialog->iscloneable() )
74  {
75  scip::ObjDialog* newobjdialog;
76  newobjdialog = dynamic_cast<scip::ObjDialog*> (dialogdata->objdialog->clone(scip));
77 
78  /* call include method of dialog object */
79  SCIP_CALL( SCIPincludeObjDialog(scip, newobjdialog, TRUE) );
80  }
81 
82  return SCIP_OKAY;
83 }
84 
85 /** destructor of dialog to free user data (called when SCIP is exiting) */
86 static
87 SCIP_DECL_DIALOGFREE(dialogFreeObj)
88 { /*lint --e{715}*/
89  SCIP_DIALOGDATA* dialogdata;
90 
91  dialogdata = SCIPdialogGetData(dialog);
92  assert(dialogdata != 0);
93  assert(dialogdata->objdialog != 0);
94  assert(dialogdata->objdialog->scip_ == scip);
95 
96  /* call virtual method of dialog object */
97  SCIP_CALL( dialogdata->objdialog->scip_free(scip, dialog) );
98 
99  /* free dialog object */
100  if( dialogdata->deleteobject )
101  delete dialogdata->objdialog;
102 
103  /* free dialog data */
104  delete dialogdata;
105  SCIPdialogSetData(dialog, 0); /*lint !e64*/
106 
107  return SCIP_OKAY;
108 }
109 
110 
111 /** description output method of dialog */
112 static
113 SCIP_DECL_DIALOGDESC(dialogDescObj)
114 { /*lint --e{715}*/
115  SCIP_DIALOGDATA* dialogdata;
116 
117  dialogdata = SCIPdialogGetData(dialog);
118  assert(dialogdata != 0);
119  assert(dialogdata->objdialog != 0);
120  assert(dialogdata->objdialog->scip_ == scip);
121 
122  /* call virtual method of dialog object */
123  SCIP_CALL( dialogdata->objdialog->scip_desc(scip, dialog) );
124 
125  return SCIP_OKAY;
126 }
127 
128 /** execution method of dialog */
129 static
130 SCIP_DECL_DIALOGEXEC(dialogExecObj)
131 { /*lint --e{715}*/
132  SCIP_DIALOGDATA* dialogdata;
133 
134  dialogdata = SCIPdialogGetData(dialog);
135  assert(dialogdata != 0);
136  assert(dialogdata->objdialog != 0);
137 
138  /* call virtual method of dialog object */
139  SCIP_CALL( dialogdata->objdialog->scip_exec(scip, dialog, dialoghdlr, nextdialog) );
140 
141  return SCIP_OKAY;
142 }
143 }
144 
145 
146 
147 /*
148  * dialog specific interface methods
149  */
150 
151 /** creates the dialog for the given dialog object and includes it in SCIP */
153  SCIP* scip, /**< SCIP data structure */
154  scip::ObjDialog* objdialog, /**< dialog object */
155  SCIP_Bool deleteobject /**< should the dialog object be deleted when dialog is freed? */
156  )
157 {/*lint --e{429} */
158  SCIP_DIALOG* parentdialog;
159 
160  assert(scip != 0);
161  assert(objdialog != 0);
162 
163  /* get parent dialog */
164  parentdialog = SCIPgetRootDialog(scip);
165  assert(parentdialog != 0);
166  /* TODO: (optional) change parent dialog from root dialog to another existing dialog (needs to be a menu) */
167 
168  /* create, include, and release dialog */
169  if( !SCIPdialogHasEntry(parentdialog, objdialog->scip_name_) )
170  {
171  SCIP_DIALOGDATA* dialogdata; /*lint !e593*/
172  SCIP_DIALOG* dialog;
173  SCIP_RETCODE retcode;
174 
175  dialog = 0;
176 
177  /* create dialog data */
178  dialogdata = new SCIP_DIALOGDATA;
179  dialogdata->objdialog = objdialog;
180  dialogdata->deleteobject = deleteobject;
181 
182  retcode = SCIPincludeDialog(scip, &dialog, dialogCopyObj, dialogExecObj, dialogDescObj, dialogFreeObj,
183  objdialog->scip_name_, objdialog->scip_desc_, objdialog->scip_issubmenu_, dialogdata);
184  if( retcode != SCIP_OKAY )
185  {
186  delete dialogdata;
187  SCIP_CALL( retcode );
188  }
189  SCIP_CALL( SCIPaddDialogEntry(scip, parentdialog, dialog) ); /*lint !e593*/
190  SCIP_CALL( SCIPreleaseDialog(scip, &dialog) ); /*lint !e593*/
191  } /*lint !e593*/
192 
193  return SCIP_OKAY; /*lint !e593*/
194 }
SCIP_RETCODE SCIPaddDialogEntry(SCIP *scip, SCIP_DIALOG *dialog, SCIP_DIALOG *subdialog)
Definition: scip_dialog.c:171
C++ wrapper for dialogs.
Definition: objdialog.h:53
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
struct SCIP_DialogData SCIP_DIALOGDATA
Definition: type_dialog.h:51
C++ wrapper for dialogs.
const SCIP_Bool scip_issubmenu_
Definition: objdialog.h:68
void SCIPdialogSetData(SCIP_DIALOG *dialog, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:1263
SCIP_DIALOG * SCIPgetRootDialog(SCIP *scip)
Definition: scip_dialog.c:157
SCIP_RETCODE SCIPincludeDialog(SCIP *scip, SCIP_DIALOG **dialog, SCIP_DECL_DIALOGCOPY((*dialogcopy)), SCIP_DECL_DIALOGEXEC((*dialogexec)), SCIP_DECL_DIALOGDESC((*dialogdesc)), SCIP_DECL_DIALOGFREE((*dialogfree)), const char *name, const char *desc, SCIP_Bool issubmenu, SCIP_DIALOGDATA *dialogdata)
Definition: scip_dialog.c:59
char * scip_name_
Definition: objdialog.h:62
static SCIP_DECL_DIALOGFREE(dialogFreeObj)
Definition: objdialog.cpp:87
static SCIP_DECL_DIALOGEXEC(dialogExecObj)
Definition: objdialog.cpp:130
#define SCIP_CALL(x)
Definition: def.h:394
char * scip_desc_
Definition: objdialog.h:65
SCIP_RETCODE SCIPincludeObjDialog(SCIP *scip, scip::ObjDialog *objdialog, SCIP_Bool deleteobject)
Definition: objdialog.cpp:152
#define SCIP_Bool
Definition: def.h:93
SCIP_Bool SCIPdialogHasEntry(SCIP_DIALOG *dialog, const char *entryname)
Definition: dialog.c:995
static SCIP_DECL_DIALOGDESC(dialogDescObj)
Definition: objdialog.cpp:113
static SCIP_DECL_DIALOGCOPY(dialogCopyObj)
Definition: objdialog.cpp:62
SCIP_RETCODE SCIPreleaseDialog(SCIP *scip, SCIP_DIALOG **dialog)
Definition: scip_dialog.c:124
SCIP_DIALOGDATA * SCIPdialogGetData(SCIP_DIALOG *dialog)
Definition: dialog.c:1253