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