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-2025 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 SCIP_EVENTTYPE eventtype = SCIP_EVENTTYPE_LPEVENT |
193 SCIP_EVENTTYPE_ROWADDEDSEPA | SCIP_EVENTTYPE_ROWDELETEDSEPA | SCIP_EVENTTYPE_ROWADDEDLP | SCIP_EVENTTYPE_ROWDELETEDLP |
194 // SCIP_EVENTTYPE_NODEFOCUSED |
195 SCIP_EVENTTYPE_NODEEVENT |
196 SCIP_EVENTTYPE_BESTSOLFOUND;
197#ifdef SCIP_EVENTTYPE_COMM
198 eventtype |= SCIP_EVENTTYPE_COMM;
199#endif
200 SCIP_CALL( SCIPcatchEvent( scip, eventtype, eventhdlr, NULL, NULL) );
201
202 if( !cloned )
203 {
204 int i;
205 int nvars;
206 SCIP_VAR** vars;
207 // std::cout << "catching events in commpoint eventhdlr" << std::endl;
208 nvars = SCIPgetNVars(scip);
209 vars = SCIPgetVars(scip);
210 // SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_VARADDED, eventhdlr, NULL, NULL) );
211 for( i = 0; i < nvars ; ++i )
212 {
213 SCIP_CALL( SCIPcatchVarEvent(scip, vars[i], SCIP_EVENTTYPE_GBDCHANGED, eventhdlr, NULL, NULL) );
214 }
215 }
216
217 interrupting = false;
218 return SCIP_OKAY;
219 }
220
222 {
223 interrupting = true;
224 }
225
227 {
228 return interrupting;
229 }
230
231 /** deinitialization method of event handler (called before transformed problem is freed) */
232 virtual SCIP_RETCODE scip_exit(
233 SCIP* scip, /**< SCIP data structure */
234 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
235 )
236 { /*lint --e{715}*/
237 /* notify SCIP that your event handler wants to drop the event type best solution found */
238 return SCIP_OKAY;
239 }
240
241 /** solving process initialization method of event handler (called when branch and bound process is about to begin)
242 *
243 * This method is called when the presolving was finished and the branch and bound process is about to begin.
244 * The event handler may use this call to initialize its branch and bound specific data.
245 *
246 */
247 virtual SCIP_RETCODE scip_initsol(
248 SCIP* scip, /**< SCIP data structure */
249 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
250 )
251 { /*lint --e{715}*/
252 return SCIP_OKAY;
253 }
254
255 /** solving process deinitialization method of event handler (called before branch and bound process data is freed)
256 *
257 * This method is called before the branch and bound process is freed.
258 * The event handler should use this call to clean up its branch and bound data.
259 */
260 virtual SCIP_RETCODE scip_exitsol(
261 SCIP* scip, /**< SCIP data structure */
262 SCIP_EVENTHDLR* eventhdlr /**< the event handler itself */
263 )
264 { /*lint --e{715}*/
265 return SCIP_OKAY;
266 }
267
268 /** frees specific constraint data */
269 virtual SCIP_RETCODE scip_delete(
270 SCIP* scip, /**< SCIP data structure */
271 SCIP_EVENTHDLR* eventhdlr, /**< the event handler itself */
272 SCIP_EVENTDATA** eventdata /**< pointer to the event data to free */
273 )
274 { /*lint --e{715}*/
275 return SCIP_OKAY;
276 }
277
278 /** execution method of event handler
279 *
280 * Processes the event. The method is called every time an event occurs, for which the event handler
281 * is responsible. Event handlers may declare themselves resposible for events by calling the
282 * corresponding SCIPcatch...() method. This method creates an event filter object to point to the
283 * given event handler and event data.
284 */
285 virtual SCIP_RETCODE scip_exec(
286 SCIP* scip, /**< SCIP data structure */
287 SCIP_EVENTHDLR* eventhdlr, /**< the event handler itself */
288 SCIP_EVENT* event, /**< event to process */
289 SCIP_EVENTDATA* eventdata /**< user data for the event */
290 );
291};
292
293} /* namespace ParaSCIP */
294
295#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.