GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
nodesel_master.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file nodesel_master.c
30 *
31 * @brief node selector for coordination of master and original formulation
32 * @author Gerald Gamrath
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39
40#include "gcg/nodesel_master.h"
41#include "gcg/cons_origbranch.h"
43#include "gcg/pricer_gcg.h"
44
45#define NODESEL_NAME "master"
46#define NODESEL_DESC "orig master coordination"
47#define NODESEL_STDPRIORITY 0
48#define NODESEL_MEMSAVEPRIORITY 100000
49#define EVENTHDLR_NAME "masterfocusnode"
50#define EVENTHDLR_DESC "event handler to transfer dual bounds from orig to master"
51
52
53/** node selector data */
55{
56 GCG* gcg; /**< GCG data structure */
58};
59
61{
62 GCG* gcg; /**< GCG data structure */
63};
64
65/*
66 * Callback methods
67 */
68
69#define nodeselCopyMaster NULL
70
71/** destructor of node selector to free user data (called when SCIP is exiting) */
72static
73SCIP_DECL_NODESELFREE(nodeselFreeMaster)
74{
75 SCIP_NODESELDATA* nodeseldata;
76
77 assert(nodesel != NULL);
78
79 nodeseldata = SCIPnodeselGetData(nodesel);
80 assert(nodeseldata != NULL);
81
82 SCIPfreeMemory(scip, &nodeseldata);
83
84 return SCIP_OKAY;
85}
86
87
88/** initialization method of node selector (called after problem was transformed) */
89#define nodeselInitMaster NULL
90
91
92/** deinitialization method of node selector (called before transformed problem is freed) */
93#define nodeselExitMaster NULL
94
95
96/** solving process initialization method of node selector (called when branch and bound process is about to begin) */
97static
98SCIP_DECL_NODESELINITSOL(nodeselInitsolMaster)
99{
100 SCIP_NODESELDATA* nodeseldata;
101 assert(nodesel != NULL);
102 assert(strcmp(SCIPnodeselGetName(nodesel), NODESEL_NAME) == 0);
103 assert(scip != NULL);
104
105 nodeseldata = SCIPnodeselGetData(nodesel);
106 assert(nodeseldata != NULL);
107
108 nodeseldata->lastorignodenumber = -1LL;
109
110 return SCIP_OKAY;
111}
112
113
114/** solving process deinitialization method of node selector (called before branch and bound process data is freed) */
115#define nodeselExitsolMaster NULL
116
117
118/** node selection method of node selector */
119static
120SCIP_DECL_NODESELSELECT(nodeselSelectMaster)
121{
122 SCIP_NODESELDATA* nodeseldata;
123 SCIP_NODE** nodes;
124 SCIP* origscip;
125 int nnodes;
126 SCIP_NODE* orignode;
127 SCIP_Longint orignodenumber;
128
129 assert(nodesel != NULL);
130 assert(strcmp(SCIPnodeselGetName(nodesel), NODESEL_NAME) == 0);
131 assert(scip != NULL);
132 assert(selnode != NULL);
133
134 nodeseldata = SCIPnodeselGetData(nodesel);
135 assert(nodeseldata != NULL);
136
137 origscip = GCGgetOrigprob(nodeseldata->gcg);
138
139 *selnode = NULL;
140
141 orignode = SCIPgetCurrentNode(origscip);
142 orignodenumber = SCIPnodeGetNumber(orignode);
143
144 if( orignodenumber != nodeseldata->lastorignodenumber )
145 {
146 SCIP_CONS* origcons = GCGconsOrigbranchGetActiveCons(nodeseldata->gcg);
147 SCIP_CONS* parentorigcons = GCGconsOrigbranchGetParentcons(origcons);
148
149 nodeseldata->lastorignodenumber = orignodenumber;
150
151 /* check whether the current node is the root node and has no parent */
152 if( parentorigcons == NULL )
153 {
154 if( SCIPgetRootNode(origscip) == orignode )
155 {
156 assert((GCGconsOrigbranchGetNode(origcons) == SCIPgetRootNode(origscip)) || (GCGconsOrigbranchGetNode(origcons) == NULL) );
159
160 *selnode = SCIPgetRootNode(scip);
161 SCIPdebugMessage("selected root node in the master program\n");
162 SCIP_CALL( GCGrestoreLimitSettings(nodeseldata->gcg) );
163 }
164 else
165 {
166 /* solving was interrupted and SCIP created a dummy node in the original problem */
168 if( SCIPgetNChildren(scip) == 0 )
169 {
170 /* create and select dummy node */
171 SCIP_NODE* child;
173 *selnode = child;
174 SCIPdebugMessage("created and selected dummy node in the master program\n");
175 }
176 else
177 {
178 /* select dummy node */
179 SCIP_NODE** children;
180 int nchildren;
181 SCIPgetChildren(scip, &children, &nchildren);
182 assert(nchildren > 0);
183 *selnode = children[0];
184 SCIPdebugMessage("selected dummy node in the master program\n");
185 }
186 }
187 }
188 else
189 {
190 assert(GCGconsOrigbranchGetMastercons(parentorigcons) != NULL);
192
194 assert( *selnode != NULL );
195 }
196
197 if( *selnode == NULL )
198 {
199 SCIPerrorMessage("nodesel_master could not find a node corresponding to the current original node!\n");
200 }
201 assert(*selnode != NULL);
202 }
203 else
204 {
205 SCIPdebugMessage("select random node\n");
206
207 if( SCIPgetNChildren(scip) > 0 )
208 {
209 SCIP_CALL( SCIPgetChildren(scip, &nodes, &nnodes) );
210 *selnode = nodes[0];
211 }
212 else if( SCIPgetNSiblings(scip) > 0 )
213 {
214 SCIP_CALL( SCIPgetSiblings(scip, &nodes, &nnodes) );
215 *selnode = nodes[0];
216 }
217 else if( SCIPgetNLeaves(scip) > 0 )
218 {
219 SCIP_CALL( SCIPgetLeaves(scip, &nodes, &nnodes) );
220 *selnode = nodes[0];
221 }
222 }
223
224#ifndef NDEBUG
227#endif
228
229 return SCIP_OKAY;
230}
231
232
233/** node comparison method of node selector */
234static
235SCIP_DECL_NODESELCOMP(nodeselCompMaster)
236{
237 assert(nodesel != NULL);
238 assert(strcmp(SCIPnodeselGetName(nodesel), NODESEL_NAME) == 0);
239 assert(scip != NULL);
240
241 if( SCIPnodeGetNumber(node1) < SCIPnodeGetNumber(node2) )
242 return 1;
243 else
244 return -1;
245}
246
247
248/** initialization method of event handler (called after problem was transformed) */
249static
250SCIP_DECL_EVENTINIT(eventInitFocusnode)
251{ /*lint --e{715}*/
252 assert(scip != NULL);
253 assert(eventhdlr != NULL);
254
255 /* catch SCIP_EVENTTYPE_NODEFOCUSED events */
257
258 return SCIP_OKAY;
259}
260
261
262/** deinitialization method of event handler (called before transformed problem is freed) */
263static
264SCIP_DECL_EVENTEXIT(eventExitFocusnode)
265{ /*lint --e{715}*/
266 assert(scip != NULL);
267 assert(eventhdlr != NULL);
268
269 /* stop event handling */
271
272 return SCIP_OKAY;
273}
274
275/** destructor of event handler */
276static
277SCIP_DECL_EVENTFREE(eventFreeFocusnode)
278{ /*lint --e{715}*/
279 SCIP_EVENTHDLRDATA* eventhdlrdata;
280
281 assert(scip != NULL);
282 assert(eventhdlr != NULL);
283 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
284
285 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
286 assert(eventhdlrdata != NULL);
287
288 SCIPfreeMemory(scip, &eventhdlrdata);
289
290 return SCIP_OKAY;
291}
292
293
294/** execution method of event handler */
295static
296SCIP_DECL_EVENTEXEC(eventExecFocusnode)
297{ /*lint --e{715}*/
298 SCIP* origscip;
299 SCIP_NODE* focusnode;
300 SCIP_EVENTHDLRDATA* eventhdlrdata;
301
302 assert(scip != NULL);
303 assert(eventhdlr != NULL);
304 assert(strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
305
306 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
307 assert(eventhdlrdata != NULL);
308
309 origscip = GCGgetOrigprob(eventhdlrdata->gcg);
310 assert(origscip != NULL);
311 focusnode = SCIPeventGetNode(event);
312 assert(focusnode != NULL);
313
314 /* set the dual bound to the lower bound of the corresponding original node */
316 assert(
318 && SCIPnodeGetDepth(SCIPgetCurrentNode(origscip)) == SCIPnodeGetDepth(focusnode))
320
321 return SCIP_OKAY;
322}
323
324
325/*
326 * master specific interface methods
327 */
328
329/** creates the node selector for depth first search and includes it in SCIP */
331 GCG* gcg /**< SCIP data structure */
332 )
333{
334 SCIP_NODESELDATA* nodeseldata;
335 SCIP_EVENTHDLR* eventhdlr;
336 SCIP_EVENTHDLRDATA* eventhdlrdata;
338
339 /* create master node selector data */
340 SCIP_CALL( SCIPallocMemory(scip, &nodeseldata) );
341 nodeseldata->gcg = gcg;
342 nodeseldata->lastorignodenumber = -1LL;
343
344 /* include node selector */
347 nodeselInitsolMaster, nodeselExitsolMaster, nodeselSelectMaster, nodeselCompMaster,
348 nodeseldata) );
349
350 /* include event handler into SCIP */
351 SCIP_CALL( SCIPallocMemory(scip, &eventhdlrdata) );
352 eventhdlrdata->gcg = gcg;
353 SCIP_CALL( SCIPincludeEventhdlrBasic(scip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecFocusnode, eventhdlrdata) );
354 assert(eventhdlr != NULL);
355
356 /* set non fundamental callbacks via setter functions */
357 SCIP_CALL( SCIPsetEventhdlrInit(scip, eventhdlr, eventInitFocusnode) );
358 SCIP_CALL( SCIPsetEventhdlrExit(scip, eventhdlr, eventExitFocusnode) );
359 SCIP_CALL( SCIPsetEventhdlrFree(scip, eventhdlr, eventFreeFocusnode) );
360
361 return SCIP_OKAY;
362}
SCIP_DECL_EVENTEXEC(EventhdlrNewSol::scip_exec)
SCIP_DECL_EVENTINIT(EventhdlrNewSol::scip_init)
SCIP_DECL_EVENTEXIT(EventhdlrNewSol::scip_exit)
SCIP_DECL_EVENTFREE(EventhdlrNewSol::scip_free)
#define EVENTHDLR_DESC
#define EVENTHDLR_NAME
void GCGconsMasterbranchCheckConsistency(GCG *gcg)
SCIP_NODE * GCGconsMasterbranchGetNode(SCIP_CONS *cons)
constraint handler for storing the branching decisions at each node of the tree
SCIP_CONS * GCGconsOrigbranchGetParentcons(SCIP_CONS *cons)
SCIP_CONS * GCGconsOrigbranchGetMastercons(SCIP_CONS *cons)
SCIP_NODE * GCGconsOrigbranchGetNode(SCIP_CONS *cons)
void GCGconsOrigbranchCheckConsistency(GCG *gcg)
SCIP_CONS * GCGconsOrigbranchGetActiveCons(GCG *gcg)
constraint handler for storing the branching decisions at each node of the tree
#define SCIP_Longint
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_RETCODE SCIPupdateNodeDualbound(SCIP *scip, SCIP_NODE *node, SCIP_Real newbound)
SCIP_Real SCIPgetNodeLowerbound(SCIP *scip, SCIP_NODE *node)
SCIP_Real SCIPgetLocalTransEstimate(SCIP *scip)
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIP_NODE * SCIPeventGetNode(SCIP_EVENT *event)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
#define SCIPallocMemory(scip, ptr)
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
int SCIPnodeGetDepth(SCIP_NODE *node)
SCIP_NODESELDATA * SCIPnodeselGetData(SCIP_NODESEL *nodesel)
const char * SCIPnodeselGetName(SCIP_NODESEL *nodesel)
SCIP_RETCODE SCIPincludeNodesel(SCIP *scip, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
int SCIPgetNSiblings(SCIP *scip)
int SCIPgetNChildren(SCIP *scip)
SCIP_RETCODE SCIPgetChildren(SCIP *scip, SCIP_NODE ***children, int *nchildren)
SCIP_RETCODE SCIPgetLeaves(SCIP *scip, SCIP_NODE ***leaves, int *nleaves)
int SCIPgetNLeaves(SCIP *scip)
SCIP_RETCODE SCIPgetSiblings(SCIP *scip, SCIP_NODE ***siblings, int *nsiblings)
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIP_NODE * SCIPgetRootNode(SCIP *scip)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
SCIP_Longint nnodes
#define NULL
#define nodeselExitMaster
SCIP_RETCODE GCGincludeNodeselMaster(GCG *gcg)
static SCIP_DECL_NODESELINITSOL(nodeselInitsolMaster)
#define NODESEL_NAME
static SCIP_DECL_NODESELFREE(nodeselFreeMaster)
static SCIP_DECL_NODESELCOMP(nodeselCompMaster)
#define NODESEL_MEMSAVEPRIORITY
#define nodeselCopyMaster
#define NODESEL_STDPRIORITY
#define NODESEL_DESC
#define nodeselExitsolMaster
#define nodeselInitMaster
static SCIP_DECL_NODESELSELECT(nodeselSelectMaster)
Node selector for coordination of master and original formulation.
GCG variable pricer.
#define SCIPerrorMessage
SCIP_RETCODE GCGrestoreLimitSettings(GCG *gcg)
Definition relax_gcg.c:5738
SCIP_Longint lastorignodenumber
struct SCIP_Cons SCIP_CONS
struct SCIP_Eventhdlr SCIP_EVENTHDLR
#define SCIP_EVENTTYPE_NODEFOCUSED
struct SCIP_EventhdlrData SCIP_EVENTHDLRDATA
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_NodeselData SCIP_NODESELDATA
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Node SCIP_NODE