Scippy

SCIP

Solving Constraint Integer Programs

scip_dialog.c
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-2019 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 visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_dialog.c
17  * @brief public methods for dialog handler plugins
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "scip/debug.h"
36 #include "scip/dialog_default.h"
37 #include "scip/dialog.h"
38 #include "scip/pub_dialog.h"
39 #include "scip/pub_message.h"
40 #include "scip/scip_dialog.h"
41 #include "scip/set.h"
42 #include "scip/struct_scip.h"
43 
44 /** creates and includes dialog
45  *
46  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
47  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
48  */
50  SCIP* scip, /**< SCIP data structure */
51  SCIP_DIALOG** dialog, /**< pointer to store the dialog */
52  SCIP_DECL_DIALOGCOPY ((*dialogcopy)), /**< copy method of dialog or NULL if you don't want to copy your plugin into sub-SCIPs */
53  SCIP_DECL_DIALOGEXEC ((*dialogexec)), /**< execution method of dialog */
54  SCIP_DECL_DIALOGDESC ((*dialogdesc)), /**< description output method of dialog, or NULL */
55  SCIP_DECL_DIALOGFREE ((*dialogfree)), /**< destructor of dialog to free user data, or NULL */
56  const char* name, /**< name of dialog: command name appearing in parent's dialog menu */
57  const char* desc, /**< description of dialog used if description output method is NULL */
58  SCIP_Bool issubmenu, /**< is the dialog a submenu? */
59  SCIP_DIALOGDATA* dialogdata /**< user defined dialog data */
60  )
61 {
62  assert(scip != NULL);
63  assert(dialog != NULL);
64 
65  /* check whether display column is already present */
66  if( dialogcopy != NULL && SCIPexistsDialog(scip, *dialog) )
67  {
68  SCIPerrorMessage("dialog <%s> already included.\n", name);
69  return SCIP_INVALIDDATA;
70  }
71 
72  SCIP_CALL( SCIPdialogCreate(dialog, dialogcopy, dialogexec, dialogdesc, dialogfree, name, desc, issubmenu, dialogdata) );
73  SCIP_CALL( SCIPsetIncludeDialog(scip->set, *dialog) );
74 
75  return SCIP_OKAY;
76 }
77 
78 /** returns if the dialog already exists
79  *
80  * @return TRUE is returned if the dialog exits, otherwise FALSE.
81  */
83  SCIP* scip, /**< SCIP data structure */
84  SCIP_DIALOG* dialog /**< dialog */
85  )
86 {
87  assert(scip != NULL);
88 
89  return SCIPsetExistsDialog(scip->set, dialog);
90 }
91 
92 /** captures a dialog
93  *
94  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
95  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
96  */
98  SCIP* scip, /**< SCIP data structure */
99  SCIP_DIALOG* dialog /**< dialog */
100  )
101 {
102  assert(scip != NULL);
103 
104  SCIPdialogCapture(dialog);
105 
106  return SCIP_OKAY;
107 }
108 
109 /** releases a dialog
110  *
111  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
112  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
113  */
115  SCIP* scip, /**< SCIP data structure */
116  SCIP_DIALOG** dialog /**< pointer to the dialog */
117  )
118 {
119  assert(scip != NULL);
120 
121  SCIP_CALL( SCIPdialogRelease(scip, dialog) );
122 
123  return SCIP_OKAY;
124 }
125 
126 /** makes given dialog the root dialog of SCIP's interactive user shell; captures dialog and releases former root dialog
127  *
128  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
129  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
130  */
132  SCIP* scip, /**< SCIP data structure */
133  SCIP_DIALOG* dialog /**< dialog to be the root */
134  )
135 {
136  assert(scip != NULL);
137 
138  SCIP_CALL( SCIPdialoghdlrSetRoot(scip, scip->dialoghdlr, dialog) );
139 
140  return SCIP_OKAY;
141 }
142 
143 /** returns the root dialog of SCIP's interactive user shell
144  *
145  * @return the root dialog of SCIP's interactive user shell is returned.
146  */
148  SCIP* scip /**< SCIP data structure */
149  )
150 {
151  assert(scip != NULL);
152 
153  return SCIPdialoghdlrGetRoot(scip->dialoghdlr);
154 }
155 
156 /** adds a sub dialog to the given dialog as menu entry and captures it
157  *
158  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
159  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
160  */
162  SCIP* scip, /**< SCIP data structure */
163  SCIP_DIALOG* dialog, /**< dialog to extend, or NULL for root dialog */
164  SCIP_DIALOG* subdialog /**< subdialog to add as menu entry in dialog */
165  )
166 {
167  assert(scip != NULL);
168 
169  if( dialog == NULL )
170  dialog = SCIPdialoghdlrGetRoot(scip->dialoghdlr);
171 
172  SCIP_CALL( SCIPdialogAddEntry(dialog, scip->set, subdialog) );
173 
174  return SCIP_OKAY;
175 }
176 
177 /** adds a single line of input which is treated as if the user entered the command line
178  *
179  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
180  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
181  */
183  SCIP* scip, /**< SCIP data structure */
184  const char* inputline /**< input line to add */
185  )
186 {
187  assert(scip != NULL);
188 
189  SCIP_CALL( SCIPdialoghdlrAddInputLine(scip->dialoghdlr, inputline) );
190 
191  return SCIP_OKAY;
192 }
193 
194 /** adds a single line of input to the command history which can be accessed with the cursor keys
195  *
196  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
197  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
198  */
200  SCIP* scip, /**< SCIP data structure */
201  const char* inputline /**< input line to add */
202  )
203 {
204  assert(scip != NULL);
205 
206  SCIP_CALL( SCIPdialoghdlrAddHistory(scip->dialoghdlr, NULL, inputline, FALSE) );
207 
208  return SCIP_OKAY;
209 }
210 
211 /** starts interactive mode of SCIP by executing the root dialog
212  *
213  * @return \ref SCIP_OKAY is returned if everything worked. otherwise a suitable error code is passed. see \ref
214  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
215  *
216  * @pre This method can be called if @p scip is in one of the following stages:
217  * - \ref SCIP_STAGE_INIT
218  * - \ref SCIP_STAGE_FREE
219  *
220  * @post After calling this method \SCIP reaches one of the following stages depending on if and when the
221  * interactive shell was closed:
222  * - \ref SCIP_STAGE_PROBLEM if the interactive shell was closed after the problem was created
223  * - \ref SCIP_STAGE_TRANSFORMED if the interactive shell was closed after the problem was transformed
224  * - \ref SCIP_STAGE_PRESOLVING if the interactive shell was closed during presolving
225  * - \ref SCIP_STAGE_PRESOLVED if the interactive shell was closed after presolve
226  * - \ref SCIP_STAGE_SOLVING if the interactive shell was closed during the tree search
227  * - \ref SCIP_STAGE_SOLVED if the interactive shell was closed after the problem was solved
228  * - \ref SCIP_STAGE_FREE if the interactive shell was closed after the problem was freed
229  *
230  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
231  */
233  SCIP* scip /**< SCIP data structure */
234  )
235 {
236  SCIP_CALL( SCIPcheckStage(scip, "SCIPstartInteraction", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
237 
238  /* includes or updates the default dialog menus in SCIP */
240 
241  SCIP_CALL( SCIPdialoghdlrExec(scip->dialoghdlr, scip->set) );
242 
243  return SCIP_OKAY;
244 }
#define NULL
Definition: def.h:253
SCIP_RETCODE SCIPdialogRelease(SCIP *scip, SCIP_DIALOG **dialog)
Definition: dialog.c:909
#define SCIP_DECL_DIALOGCOPY(x)
Definition: type_dialog.h:53
SCIP_RETCODE SCIPdialoghdlrAddInputLine(SCIP_DIALOGHDLR *dialoghdlr, const char *inputline)
Definition: dialog.c:684
SCIP_RETCODE SCIPsetIncludeDialog(SCIP_SET *set, SCIP_DIALOG *dialog)
Definition: set.c:4869
#define FALSE
Definition: def.h:73
SCIP_DIALOG * SCIPgetRootDialog(SCIP *scip)
Definition: scip_dialog.c:147
SCIP_RETCODE SCIPaddDialogEntry(SCIP *scip, SCIP_DIALOG *dialog, SCIP_DIALOG *subdialog)
Definition: scip_dialog.c:161
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPaddDialogHistoryLine(SCIP *scip, const char *inputline)
Definition: scip_dialog.c:199
SCIP_RETCODE SCIPcaptureDialog(SCIP *scip, SCIP_DIALOG *dialog)
Definition: scip_dialog.c:97
struct SCIP_DialogData SCIP_DIALOGDATA
Definition: type_dialog.h:42
SCIP_DIALOG * SCIPdialoghdlrGetRoot(SCIP_DIALOGHDLR *dialoghdlr)
Definition: dialog.c:423
SCIP_DIALOGHDLR * dialoghdlr
Definition: struct_scip.h:64
void SCIPdialogCapture(SCIP_DIALOG *dialog)
Definition: dialog.c:899
#define SCIP_DECL_DIALOGDESC(x)
Definition: type_dialog.h:73
SCIP_RETCODE SCIPdialoghdlrAddHistory(SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog, const char *command, SCIP_Bool escapecommand)
Definition: dialog.c:713
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2010
SCIP_Bool SCIPsetExistsDialog(SCIP_SET *set, SCIP_DIALOG *dialog)
Definition: set.c:4891
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:365
SCIP main data structure.
SCIP_RETCODE SCIPdialogCreate(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: dialog.c:811
internal methods for user interface dialog
#define SCIP_Bool
Definition: def.h:70
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:49
methods for debugging
SCIP_RETCODE SCIPreleaseDialog(SCIP *scip, SCIP_DIALOG **dialog)
Definition: scip_dialog.c:114
SCIP_RETCODE SCIPdialoghdlrSetRoot(SCIP *scip, SCIP_DIALOGHDLR *dialoghdlr, SCIP_DIALOG *dialog)
Definition: dialog.c:400
#define SCIP_DECL_DIALOGFREE(x)
Definition: type_dialog.h:61
#define SCIP_DECL_DIALOGEXEC(x)
Definition: type_dialog.h:87
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
default user interface dialog
public methods for dialog handler plugins
SCIP_RETCODE SCIPdialogAddEntry(SCIP_DIALOG *dialog, SCIP_SET *set, SCIP_DIALOG *subdialog)
Definition: dialog.c:951
SCIP_RETCODE SCIPdialoghdlrExec(SCIP_DIALOGHDLR *dialoghdlr, SCIP_SET *set)
Definition: dialog.c:372
SCIP_RETCODE SCIPincludeDialogDefault(SCIP *scip)
public methods for user interface dialog
SCIP_RETCODE SCIPstartInteraction(SCIP *scip)
Definition: scip_dialog.c:232
SCIP_Bool SCIPexistsDialog(SCIP *scip, SCIP_DIALOG *dialog)
Definition: scip_dialog.c:82
SCIP_RETCODE SCIPaddDialogInputLine(SCIP *scip, const char *inputline)
Definition: scip_dialog.c:182
SCIP_RETCODE SCIPsetRootDialog(SCIP *scip, SCIP_DIALOG *dialog)
Definition: scip_dialog.c:131