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-2016 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License. */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objdialog.cpp
17  * @brief C++ wrapper for dialogs
18  * @author Kati Wolter
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objdialog.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** dialog data */
35 struct SCIP_DialogData
36 {
37  scip::ObjDialog* objdialog; /**< dialog object */
38  SCIP_Bool deleteobject; /**< should the dialog object be deleted when dialog is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of dialog
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for dialog plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_DIALOGCOPY(dialogCopyObj)
54 { /*lint --e{715}*/
55  SCIP_DIALOGDATA* dialogdata;
56 
57  assert(scip != 0);
58 
59  dialogdata = SCIPdialogGetData(dialog);
60  assert(dialogdata != 0);
61  assert(dialogdata->objdialog != 0);
62  assert(dialogdata->objdialog->scip_ != scip);
63 
64  if( dialogdata->objdialog->iscloneable() )
65  {
66  scip::ObjDialog* newobjdialog;
67  newobjdialog = dynamic_cast<scip::ObjDialog*> (dialogdata->objdialog->clone(scip));
68 
69  /* call include method of dialog object */
70  SCIP_CALL( SCIPincludeObjDialog(scip, newobjdialog, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of dialog to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_DIALOGFREE(dialogFreeObj)
79 { /*lint --e{715}*/
80  SCIP_DIALOGDATA* dialogdata;
81 
82  dialogdata = SCIPdialogGetData(dialog);
83  assert(dialogdata != 0);
84  assert(dialogdata->objdialog != 0);
85  assert(dialogdata->objdialog->scip_ == scip);
86 
87  /* call virtual method of dialog object */
88  SCIP_CALL( dialogdata->objdialog->scip_free(scip, dialog) );
89 
90  /* free dialog object */
91  if( dialogdata->deleteobject )
92  delete dialogdata->objdialog;
93 
94  /* free dialog data */
95  delete dialogdata;
96  SCIPdialogSetData(dialog, 0); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** description output method of dialog */
103 static
104 SCIP_DECL_DIALOGDESC(dialogDescObj)
105 { /*lint --e{715}*/
106  SCIP_DIALOGDATA* dialogdata;
107 
108  dialogdata = SCIPdialogGetData(dialog);
109  assert(dialogdata != 0);
110  assert(dialogdata->objdialog != 0);
111  assert(dialogdata->objdialog->scip_ == scip);
112 
113  /* call virtual method of dialog object */
114  SCIP_CALL( dialogdata->objdialog->scip_desc(scip, dialog) );
115 
116  return SCIP_OKAY;
117 }
118 
119 /** execution method of dialog */
120 static
121 SCIP_DECL_DIALOGEXEC(dialogExecObj)
122 { /*lint --e{715}*/
123  SCIP_DIALOGDATA* dialogdata;
124 
125  dialogdata = SCIPdialogGetData(dialog);
126  assert(dialogdata != 0);
127  assert(dialogdata->objdialog != 0);
128 
129  /* call virtual method of dialog object */
130  SCIP_CALL( dialogdata->objdialog->scip_exec(scip, dialog, dialoghdlr, nextdialog) );
131 
132  return SCIP_OKAY;
133 }
134 }
135 
136 
137 
138 /*
139  * dialog specific interface methods
140  */
141 
142 /** creates the dialog for the given dialog object and includes it in SCIP */
144  SCIP* scip, /**< SCIP data structure */
145  scip::ObjDialog* objdialog, /**< dialog object */
146  SCIP_Bool deleteobject /**< should the dialog object be deleted when dialog is freed? */
147  )
148 {/*lint --e{429} */
149  SCIP_DIALOG* parentdialog;
150 
151  assert(scip != 0);
152  assert(objdialog != 0);
153 
154  /* get parent dialog */
155  parentdialog = SCIPgetRootDialog(scip);
156  assert(parentdialog != 0);
157  /* TODO: (optional) change parent dialog from root dialog to another existing dialog (needs to be a menu) */
158 
159  /* create, include, and release dialog */
160  if( !SCIPdialogHasEntry(parentdialog, objdialog->scip_name_) )
161  {
162  SCIP_DIALOGDATA* dialogdata; /*lint !e593*/
163  SCIP_DIALOG* dialog;
164  SCIP_RETCODE retcode;
165 
166  dialog = 0;
167 
168  /* create dialog data */
169  dialogdata = new SCIP_DIALOGDATA;
170  dialogdata->objdialog = objdialog;
171  dialogdata->deleteobject = deleteobject;
172 
173  retcode = SCIPincludeDialog(scip, &dialog, dialogCopyObj, dialogExecObj, dialogDescObj, dialogFreeObj,
174  objdialog->scip_name_, objdialog->scip_desc_, objdialog->scip_issubmenu_, dialogdata);
175  if( retcode != SCIP_OKAY )
176  {
177  delete dialogdata;
178  SCIP_CALL( retcode );
179  }
180  SCIP_CALL( SCIPaddDialogEntry(scip, parentdialog, dialog) ); /*lint !e593*/
181  SCIP_CALL( SCIPreleaseDialog(scip, &dialog) ); /*lint !e593*/
182  } /*lint !e593*/
183 
184  return SCIP_OKAY; /*lint !e593*/
185 }
C++ wrapper for dialogs.
Definition: objdialog.h:44
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
struct SCIP_DialogData SCIP_DIALOGDATA
Definition: type_dialog.h:42
C++ wrapper for dialogs.
const SCIP_Bool scip_issubmenu_
Definition: objdialog.h:59
SCIP_DIALOG * SCIPgetRootDialog(SCIP *scip)
Definition: scip.c:8896
SCIP_DIALOGDATA * SCIPdialogGetData(SCIP_DIALOG *dialog)
Definition: dialog.c:1230
SCIP_RETCODE SCIPaddDialogEntry(SCIP *scip, SCIP_DIALOG *dialog, SCIP_DIALOG *subdialog)
Definition: scip.c:8910
char * scip_name_
Definition: objdialog.h:53
static SCIP_DECL_DIALOGFREE(dialogFreeObj)
Definition: objdialog.cpp:78
static SCIP_DECL_DIALOGEXEC(dialogExecObj)
Definition: objdialog.cpp:121
char * scip_desc_
Definition: objdialog.h:56
SCIP_RETCODE SCIPincludeObjDialog(SCIP *scip, scip::ObjDialog *objdialog, SCIP_Bool deleteobject)
Definition: objdialog.cpp:143
#define SCIP_Bool
Definition: def.h:53
static SCIP_DECL_DIALOGDESC(dialogDescObj)
Definition: objdialog.cpp:104
SCIP_Bool SCIPdialogHasEntry(SCIP_DIALOG *dialog, const char *entryname)
Definition: dialog.c:970
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.c:8798
static SCIP_DECL_DIALOGCOPY(dialogCopyObj)
Definition: objdialog.cpp:53
void SCIPdialogSetData(SCIP_DIALOG *dialog, SCIP_DIALOGDATA *dialogdata)
Definition: dialog.c:1240
SCIP_RETCODE SCIPreleaseDialog(SCIP *scip, SCIP_DIALOG **dialog)
Definition: scip.c:8863