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