Scippy

UG

Ubiquity Generator framework

scipParaObjCommPointHdlr.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2024 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file scipParaObjCommPointHdlr.h
27 * @brief Event handlr for communication point.
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#ifndef __SCIP_PARA_COMM_POINT_HDLR_H__
37#define __SCIP_PARA_COMM_POINT_HDLR_H__
38
39#include <cstring>
40#include "scipParaComm.h"
41#include "scipParaInstance.h"
42#include "scipParaSolver.h"
44#include "scipParaParamSet.h"
45#include "objscip/objeventhdlr.h"
46#include "scip/scipdefplugins.h"
47
48namespace ParaSCIP
49{
50
51class ScipParaSolver;
52
53/** C++ wrapper object for event handlers */
54class ScipParaObjCommPointHdlr : public scip::ObjEventhdlr
55{
63 // int originalPriority;
65 SCIP_Longint previousLpIter;
66 const char *changeNodeSelName;
67 // double previousCommTime;
68 bool cloned; // indicate that this hander is cloned or not
69 bool interrupting; // indicate that this handler called interrupt or not
70 bool startedCollectingNodesForInitialRampUp; // initial ramp-up collecting has been started
71 // int nThghtendLbs;
72 // int nTightendUbs;
73 void processNewSolution(SCIP *scip, SCIP_EVENT* event);
74 // void checkRootNodeSolvabilityAndSendParaNode(SCIP *scip);
76 void sendNode( SCIP *scip, SCIP_NODE* node, int depth, int nBranchVars, SCIP_VAR **branchVars, SCIP_Real *branchBounds, SCIP_BOUNDTYPE *boundTypes );
77 void changeSearchStrategy(SCIP *scip);
78 bool ifFeasibleInOriginalProblem(SCIP *scip, int nNewBranchVars, SCIP_VAR **newBranchVars, SCIP_Real *newBranchBounds);
79public:
82 ScipParaSolver *solver,
84 )
85 : scip::ObjEventhdlr::ObjEventhdlr(solver->getScip(), "ScipParaObjCommPointHdlr", "Event handler to communicate with LC"),
89 // nThghtendLbs(0), nTightendUbs(0)
90 {
93 {
94 /* initialize SCIP to check root solvability */
95 SCIP_CALL_ABORT( SCIPcreate(&scipToCheckRootSolvability) );
96 /* include default SCIP plugins */
97 SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(scipToCheckRootSolvability) );
98 ScipParaInstance* scipParaInstance = dynamic_cast< ScipParaInstance* >(scipParaSolver->getParaInstance());
103 NULL,
104 NULL,
105 NULL,
106 NULL
107 ); // LC presolving setting file should not be set, when it does this check!
108 }
111 {
113 }
114 }
115
118 ScipParaSolver *solver,
119 SCIP *subScip,
120 SCIP *inOriginalScip,
121 bool inCloned
122 ) : scip::ObjEventhdlr::ObjEventhdlr(subScip, "ScipParaObjCommPointHdlr", "Event handler to communicate with LC"),
126 // nThghtendLbs(0), nTightendUbs(0)
127 {
130 {
132 }
133 }
134
135 /** destructor */
137 )
138 {
140 {
141 SCIP_CALL_ABORT( SCIPfree(&scipToCheckRootSolvability) );
142 }
143 }
144
146 {
149 needToSendNode = false;
150 interrupting = false;
151 }
152
153 /** clone method, used to copy plugins which are not constraint handlers or variable pricer plugins */
154 ObjCloneable* clone(
155 SCIP* scip /**< SCIP data structure */
156 ) const
157 {
159 }
160 /** returns whether the objective plugin is copyable */
161 SCIP_Bool iscloneable(
162 void
163 ) const
164 {
165 return true;
166 }
167
168 // SCIP *getParentScip(){ return parentScip; }
169 bool isColne(){return cloned;}
170
172 {
175 }
176
177 /** destructor of event handler to free user data (called when SCIP is exiting) */
178 virtual SCIP_RETCODE scip_free(
179 SCIP* scip, /**< SCIP data structure */
180 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
181 )
182 { /*lint --e{715}*/
183 return SCIP_OKAY;
184 }
185
186 /** initialization method of event handler (called after problem was transformed) */
187 virtual SCIP_RETCODE scip_init(
188 SCIP* scip, /**< SCIP data structure */
189 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
190 )
191 { /*lint --e{715}*/
192#ifdef SCIP_EVENTTYPE_COMM
193 SCIP_CALL( SCIPcatchEvent( scip,
194 ( SCIP_EVENTTYPE_GBDCHANGED |
195 SCIP_EVENTTYPE_BOUNDTIGHTENED |
196 SCIP_EVENTTYPE_LPEVENT |
197 SCIP_EVENTTYPE_ROWEVENT |
198 // SCIP_EVENTTYPE_NODEFOCUSED |
199 SCIP_EVENTTYPE_NODEEVENT |
200 SCIP_EVENTTYPE_BESTSOLFOUND |
201 SCIP_EVENTTYPE_COMM
202 )
203 , eventhdlr, NULL, NULL) );
204#else
205 SCIP_CALL( SCIPcatchEvent( scip,
206 ( SCIP_EVENTTYPE_GBDCHANGED |
207 SCIP_EVENTTYPE_BOUNDTIGHTENED |
208 SCIP_EVENTTYPE_LPEVENT |
209 SCIP_EVENTTYPE_ROWEVENT |
210 // SCIP_EVENTTYPE_NODEFOCUSED |
211 SCIP_EVENTTYPE_NODEEVENT |
212 SCIP_EVENTTYPE_BESTSOLFOUND
213 )
214 , eventhdlr, NULL, NULL) );
215#endif
216
217 if( !cloned )
218 {
219 int i;
220 int nvars;
221 SCIP_VAR** vars;
222 // std::cout << "catching events in commpoint eventhdlr" << std::endl;
223 nvars = SCIPgetNVars(scip);
224 vars = SCIPgetVars(scip);
225 // SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_VARADDED, eventhdlr, NULL, NULL) );
226 for( i = 0; i < nvars ; ++i )
227 {
228 SCIP_CALL( SCIPcatchVarEvent(scip, vars[i], SCIP_EVENTTYPE_GBDCHANGED, eventhdlr, NULL, NULL) );
229 }
230 }
231
232 interrupting = false;
233 return SCIP_OKAY;
234 }
235
237 {
238 interrupting = true;
239 }
240
242 {
243 return interrupting;
244 }
245
246 /** deinitialization method of event handler (called before transformed problem is freed) */
247 virtual SCIP_RETCODE scip_exit(
248 SCIP* scip, /**< SCIP data structure */
249 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
250 )
251 { /*lint --e{715}*/
252 /* notify SCIP that your event handler wants to drop the event type best solution found */
253 return SCIP_OKAY;
254 }
255
256 /** solving process initialization method of event handler (called when branch and bound process is about to begin)
257 *
258 * This method is called when the presolving was finished and the branch and bound process is about to begin.
259 * The event handler may use this call to initialize its branch and bound specific data.
260 *
261 */
262 virtual SCIP_RETCODE scip_initsol(
263 SCIP* scip, /**< SCIP data structure */
264 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
265 )
266 { /*lint --e{715}*/
267 return SCIP_OKAY;
268 }
269
270 /** solving process deinitialization method of event handler (called before branch and bound process data is freed)
271 *
272 * This method is called before the branch and bound process is freed.
273 * The event handler should use this call to clean up its branch and bound data.
274 */
275 virtual SCIP_RETCODE scip_exitsol(
276 SCIP* scip, /**< SCIP data structure */
277 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
278 )
279 { /*lint --e{715}*/
280 return SCIP_OKAY;
281 }
282
283 /** frees specific constraint data */
284 virtual SCIP_RETCODE scip_delete(
285 SCIP* scip, /**< SCIP data structure */
286 SCIP_EVENTHDLR* eventhdlr, /**< the event handler itself */
287 SCIP_EVENTDATA** eventdata /**< pointer to the event data to free */
288 )
289 { /*lint --e{715}*/
290 return SCIP_OKAY;
291 }
292
293 /** execution method of event handler
294 *
295 * Processes the event. The method is called every time an event occurs, for which the event handler
296 * is responsible. Event handlers may declare themselves resposible for events by calling the
297 * corresponding SCIPcatch...() method. This method creates an event filter object to point to the
298 * given event handler and event data.
299 */
300 virtual SCIP_RETCODE scip_exec(
301 SCIP* scip, /**< SCIP data structure */
302 SCIP_EVENTHDLR* eventhdlr, /**< the event handler itself */
303 SCIP_EVENT* event, /**< event to process */
304 SCIP_EVENTDATA* eventdata /**< user data for the event */
305 );
306};
307
308} /* namespace ParaSCIP */
309
310#endif // __SCIP_PARA_COMM_POINT_HDLR_H__
void createProblem(SCIP *scip, int method, bool noPreprocessingInLC, bool usetRootNodeCuts, ScipDiffParamSet *scipDiffParamSetRoot, ScipDiffParamSet *scipDiffParamSet, char *settingsNameLC, char *isolname)
ObjCloneable * clone(SCIP *scip) const
ScipParaObjLimitUpdator * scipParaObjLimitUpdator
virtual SCIP_RETCODE scip_free(SCIP *scip, SCIP_EVENTHDLR *eventhdlr)
ScipParaObjCommPointHdlr(UG::ParaComm *comm, ScipParaSolver *solver, SCIP *subScip, SCIP *inOriginalScip, bool inCloned)
virtual SCIP_RETCODE scip_initsol(SCIP *scip, SCIP_EVENTHDLR *eventhdlr)
void processNewSolution(SCIP *scip, SCIP_EVENT *event)
ScipParaObjCommPointHdlr(UG::ParaComm *comm, ScipParaSolver *solver, ScipParaObjLimitUpdator *updator)
virtual SCIP_RETCODE scip_delete(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA **eventdata)
virtual SCIP_RETCODE scip_exitsol(SCIP *scip, SCIP_EVENTHDLR *eventhdlr)
virtual SCIP_RETCODE scip_exit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr)
void sendNode(SCIP *scip, SCIP_NODE *node, int depth, int nBranchVars, SCIP_VAR **branchVars, SCIP_Real *branchBounds, SCIP_BOUNDTYPE *boundTypes)
bool ifFeasibleInOriginalProblem(SCIP *scip, int nNewBranchVars, SCIP_VAR **newBranchVars, SCIP_Real *newBranchBounds)
virtual SCIP_RETCODE scip_exec(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENT *event, SCIP_EVENTDATA *eventdata)
virtual SCIP_RETCODE scip_init(SCIP *scip, SCIP_EVENTHDLR *eventhdlr)
const char * getChangeNodeSelName()
ParaParamSet * getParaParamSet()
get ParaParamSet object
ParaInstance * getParaInstance()
get ParaInstance object
Definition: bbParaSolver.h:991
Base class of communicator object.
Definition: paraComm.h:102
bool getBoolParamValue(int param)
get bool parameter value
int getIntParamValue(int param)
get int parameter value
static ScipParaCommTh * comm
Definition: fscip.cpp:73
static const int RootNodeSolvabilityCheck
static const int UseRootNodeCuts
static const int InstanceTransferMethod
static const int CollectOnce
static const int NoPreprocessingInLC
static const int RampUpPhaseProcess
ParaComm extension for SCIP solver.
ParaInstance extenstion for SCIP solver.
heuristic to update objlimit
ParaSolver extension for SCIP: Parallelized solver implementation for SCIP.