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 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 */ 59 SCIP_RETCODE SCIPincludeDialog( 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 */ 92 SCIP_Bool SCIPexistsDialog( 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 */ 107 SCIP_RETCODE SCIPcaptureDialog( 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 */ 124 SCIP_RETCODE SCIPreleaseDialog( 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 */ 141 SCIP_RETCODE SCIPsetRootDialog( 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 */ 157 SCIP_DIALOG* SCIPgetRootDialog( 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 */ 171 SCIP_RETCODE SCIPaddDialogEntry( 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 */ 192 SCIP_RETCODE SCIPaddDialogInputLine( 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 */ 209 SCIP_RETCODE SCIPaddDialogHistoryLine( 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 */ 242 SCIP_RETCODE SCIPstartInteraction( 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 */ 249 SCIP_CALL( SCIPincludeDialogDefaultSet(scip) ); 250 SCIP_CALL( SCIPincludeDialogDefaultFix(scip) ); 251 252 SCIP_CALL( SCIPdialoghdlrExec(scip->dialoghdlr, scip->set) ); 253 254 return SCIP_OKAY; 255 } 256