GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
solver_mip.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 solver_mip.c
30 * @brief pricing solver solving the pricing problem as a sub-MIP, using SCIP
31 * @author Gerald Gamrath
32 * @author Martin Bergner
33 * @author Christian Puchert
34 *
35 */
36
37/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
38/* #define DEBUG_PRICING_ALL_OUTPUT */
39
40#include <assert.h>
41#include <string.h>
42
43#include "gcg/solver_mip.h"
44#include "scip/cons_linear.h"
45#include "scip/cons_knapsack.h"
46#include "gcg/gcg.h"
47#include "gcg/pricer_gcg.h"
48#include "gcg/pub_solver.h"
49#include "scip/scipdefplugins.h"
50#include "gcg/pub_gcgcol.h"
51
52#define SOLVER_NAME "mip"
53#define SOLVER_DESC "pricing solver solving the pricing problem as a sub-MIP, using SCIP"
54#define SOLVER_PRIORITY 0
55#define SOLVER_HEURENABLED TRUE /**< indicates whether the heuristic solving method of the solver should be enabled */
56#define SOLVER_EXACTENABLED TRUE /**< indicates whether the exact solving method of the solver should be enabled */
57
58#define DEFAULT_CHECKSOLS TRUE /**< should solutions be checked extensively */
59#define DEFAULT_STARTNODELIMIT 1000LL /**< start node limit for heuristic pricing */
60#define DEFAULT_STARTSTALLNODELIMIT 100LL /**< start stalling node limit for heuristic pricing */
61#define DEFAULT_STARTGAPLIMIT 0.2 /**< start gap limit for heuristic pricing */
62#define DEFAULT_STARTSOLLIMIT 10 /**< start solution limit for heuristic pricing */
63#define DEFAULT_NODELIMITFAC 1.0 /**< factor by which to increase node limit for heuristic pricing (1.0: add start limit) */
64#define DEFAULT_STALLNODELIMITFAC 1.0 /**< factor by which to increase stalling node limit for heuristic pricing (1.0: add start limit) */
65#define DEFAULT_GAPLIMITFAC 0.8 /**< factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit) */
66#define DEFAULT_SOLLIMITFAC 1.0 /**< factor by which to increase solution limit for heuristic pricing (1.0: add start limit) */
67#define DEFAULT_SETTINGSFILE "-" /**< settings file to be applied in pricing problems */
68#define DEFAULT_ENABLE_WARNINGS FALSE /**< should warnings (of pricing problems) be enabled by default */
69
70
71
72/** pricing solver data */
73struct GCG_SolverData
74{
75 /* parameters */
76 SCIP_Bool checksols; /**< should solutions be checked extensively */
77 SCIP_Longint startnodelimit; /**< start node limit for heuristic pricing */
78 SCIP_Longint startstallnodelimit; /**< start stalling node limit for heuristic pricing */
79 SCIP_Real startgaplimit; /**< start gap limit for heuristic pricing */
80 int startsollimit; /**< start solution limit for heuristic pricing */
81 SCIP_Real nodelimitfac; /**< factor by which to increase node limit for heuristic pricing (1.0: add start limit) */
82 SCIP_Real stallnodelimitfac; /**< factor by which to increase stalling node limit for heuristic pricing (1.0: add start limit) */
83 SCIP_Real gaplimitfac; /**< factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit) */
84 SCIP_Real sollimitfac; /**< factor by which to increase solution limit for heuristic pricing (1.0: add start limit) */
85 char* settingsfile; /**< settings file to be applied in pricing problems */
86 SCIP_Bool enablewarnings; /**< enable warnings of pricing problems */
87
88 /* solver data */
89 SCIP_Longint* curnodelimit; /**< current node limit per pricing problem */
90 SCIP_Longint* curstallnodelimit; /**< current stalling node limit per pricing problem */
91 SCIP_Real* curgaplimit; /**< current gap limit per pricing problem */
92 int* cursollimit; /**< current solution limit per pricing problem */
93};
94
95
96/*
97 * Local methods
98 */
99
100/** solves the pricing problem again without presolving */
101static
103 SCIP* pricingprob /**< pricing problem to solve again */
104 )
105{
106 assert(pricingprob != NULL);
107 SCIP_CALL( SCIPfreeTransform(pricingprob) );
108
109 SCIP_CALL( SCIPsetIntParam(pricingprob, "presolving/maxrounds", 0) );
110 SCIP_CALL( SCIPtransformProb(pricingprob) );
111 SCIP_CALL( SCIPsolve(pricingprob) );
112 SCIP_CALL( SCIPsetIntParam(pricingprob, "presolving/maxrounds", -1) );
113
114 return SCIP_OKAY;
115}
116
117/** checks whether the given solution is equal to one of the former solutions in the sols array */
118static
120 SCIP* pricingprob, /**< pricing problem SCIP data structure */
121 SCIP_SOL** sols, /**< array of solutions */
122 int idx, /**< index of the solution */
123 SCIP_Bool* isnew /**< pointer to store whether the solution is new */
124 )
125{
126 SCIP_VAR** probvars;
127 int nprobvars;
128 SCIP_Real* newvals;
129
130 int s;
131 int i;
132
133 assert(pricingprob != NULL);
134 assert(sols != NULL);
135 assert(sols[idx] != NULL);
136 assert(isnew != NULL);
137
138 probvars = SCIPgetVars(pricingprob);
139 nprobvars = SCIPgetNVars(pricingprob);
140
141 *isnew = TRUE;
142
143 SCIP_CALL( SCIPallocBufferArray(pricingprob, &newvals, nprobvars) );
144
145 SCIP_CALL( SCIPgetSolVals(pricingprob, sols[idx], nprobvars, probvars, newvals) );
146
147 for( s = 0; s < idx && *isnew == TRUE; s++ )
148 {
149 assert(sols[s] != NULL);
150 /** @todo ensure that the solutions are sorted */
151 if( (!SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[s])) && !SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[idx])) )
152 && !SCIPisEQ(pricingprob, SCIPgetSolOrigObj(pricingprob, sols[s]), SCIPgetSolOrigObj(pricingprob, sols[idx])) )
153 continue;
154
155 if( (SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[s])) && !SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[idx])) )
156 ||(!SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[s])) && SCIPisInfinity(pricingprob, -SCIPgetSolOrigObj(pricingprob, sols[idx]))) )
157 continue;
158
159
161 continue;
162
163 for( i = 0; i < nprobvars; i++ )
164 if( !SCIPisEQ(pricingprob, SCIPgetSolVal(pricingprob, sols[s], probvars[i]), newvals[i]) )
165 break;
166
167 if( i == nprobvars )
168 *isnew = FALSE;
169 }
170
171 SCIPfreeBufferArray(pricingprob, &newvals);
172
173 return SCIP_OKAY;
174}
175
176/** check whether a column contains an infinite solution value */
177static
179 SCIP* pricingprob, /**< pricing problem SCIP data structure */
180 SCIP_SOL* sol /**< solution to be checked */
181 )
182{
183 SCIP_VAR** vars;
184 int nvars;
185
186 int i;
187
188 vars = SCIPgetOrigVars(pricingprob);
189 nvars = SCIPgetNOrigVars(pricingprob);
190
191 for( i = 0; i < nvars; ++i )
192 if( SCIPisInfinity(pricingprob, SCIPgetSolVal(pricingprob, sol, vars[i])) )
193 return TRUE;
194
195 return FALSE;
196}
197
198/** solves the given pricing problem as a sub-SCIP */
199static
201 GCG* gcg, /**< GCG data structure */
202 SCIP* pricingprob, /**< pricing problem SCIP data structure */
203 int probnr, /**< problem number */
204 GCG_SOLVERDATA* solverdata, /**< solver data structure */
205 SCIP_Real* lowerbound, /**< pointer to store lower bound */
206 GCG_PRICINGSTATUS* status /**< pointer to store pricing problem status */
207 )
208{
209 GCG_COL* col;
211#ifdef SCIP_STATISTIC
212 SCIP_Longint oldnnodes;
213#endif
214
215 assert(gcg != NULL);
216 assert(pricingprob != NULL);
217 assert(probnr >= 0);
218 assert(solverdata != NULL);
219 assert(lowerbound != NULL);
220 assert(status != NULL);
221
222#ifndef DEBUG_PRICING_ALL_OUTPUT
223 if( !solverdata->enablewarnings && !SCIPmessagehdlrIsQuiet(SCIPgetMessagehdlr(pricingprob)) )
224 {
225 SCIPsetMessagehdlrQuiet(pricingprob, TRUE);
226 }
227#endif
228
229#ifdef SCIP_STATISTIC
230 oldnnodes = SCIPgetNNodes(pricingprob);
231#endif
232
233 if( SCIPgetStage(pricingprob) == SCIP_STAGE_PROBLEM )
234 {
235 retcode = SCIPpresolve(pricingprob);
236 if( SCIPgetNContVars(pricingprob) > 0 )
237 {
238 /* disable presolving restarts because of numerical instability caused by these (workaround) */
239 SCIP_CALL( SCIPsetIntParam(pricingprob, "presolving/maxrestarts", 0) );
240 }
241 }
242
243 if( retcode == SCIP_OKAY )
244 {
245 /* solve the pricing SCIP */
246 retcode = SCIPsolve(pricingprob);
247 }
248
249 if( retcode != SCIP_OKAY )
250 {
251 SCIPwarningMessage(pricingprob, "Pricing problem %d terminated with retcode = %d, ignoring\n", probnr, retcode);
252 return SCIP_OKAY;
253 }
254
255 SCIPdebugMessage(" -> status = %d\n", SCIPgetStatus(pricingprob));
256 SCIPdebugMessage(" -> nsols = %d\n", SCIPgetNSols(pricingprob));
257
258#ifdef SCIP_STATISTIC
259 SCIPstatisticMessage("P p %d: %"SCIP_LONGINT_FORMAT" no\n", probnr, SCIPgetNNodes(pricingprob) - oldnnodes);
260#endif
261
262 *status = getPricingstatus(pricingprob);
263
265
266 switch( *status )
267 {
269 SCIPdebugMessage(" -> infeasible.\n");
270 break;
271
272 /* The pricing problem was declared to be unbounded and we should have a primal ray at hand,
273 * so copy the primal ray into the solution structure and mark it to be a primal ray
274 */
276 if( !SCIPhasPrimalRay(pricingprob) )
277 {
279 }
280
281 SCIPdebugMessage(" -> unbounded, creating column from ray\n");
282 SCIP_CALL( createColumnFromRay(gcg, pricingprob, NULL, NULL, probnr, &col) );
284
285 break;
286
287 /* If the pricing problem is neither infeasible nor unbounded, try to extract feasible columns */
291 assert(SCIPgetNSols(pricingprob) > 0
292 || (SCIPgetStatus(pricingprob) != SCIP_STATUS_OPTIMAL
293 && SCIPgetStatus(pricingprob) != SCIP_STATUS_GAPLIMIT
294 && SCIPgetStatus(pricingprob) != SCIP_STATUS_SOLLIMIT));
295
296 /* Transform at most maxcols many solutions from the pricing problem into columns */
297 SCIP_CALL( getColumnsFromPricingprob(gcg, pricingprob, NULL, NULL, probnr, solverdata->checksols) );
298
299 *lowerbound = SCIPgetDualbound(pricingprob);
300
301 SCIPdebugMessage(" -> lowerbound = %.4g\n", *lowerbound);
302 break;
303
304 default:
305 SCIPerrorMessage("Pricing problem %d has invalid status: %d\n", probnr, SCIPgetStatus(pricingprob));
306 break; /*lint !e788 */
307 }
308
309 return SCIP_OKAY;
310}
311
312
313/*
314 * Callback methods for pricing problem solver
315 */
316
317/** destructor of pricing solver to free user data (called when SCIP is exiting) */
318static
320{
321 GCG_SOLVERDATA* solverdata;
322 SCIP* scip;
323
324 assert(gcg != NULL);
325 assert(solver != NULL);
326
328 solverdata = GCGsolverGetData(solver);
329 assert(solverdata != NULL);
330
331 SCIPfreeBlockMemory(scip, &solverdata);
332
333 GCGsolverSetData(solver, NULL);
334
335 return SCIP_OKAY;
336}
337
338/** initialization method of pricing solver (called after problem was transformed and solver is active) */
339#define solverInitMip NULL
340
341/** deinitialization method of pricing solver (called before transformed problem is freed and solver is active) */
342#define solverExitMip NULL
343
344/** solving process initialization method of pricing solver (called when branch and bound process is about to begin) */
345static
346GCG_DECL_SOLVERINITSOL(solverInitsolMip)
347{
348 GCG_SOLVERDATA* solverdata;
349 int npricingprobs;
350 int i;
352
353 assert(gcg != NULL);
354 assert(solver != NULL);
355
357
358 solverdata = GCGsolverGetData(solver);
359 assert(solverdata != NULL);
360
361 npricingprobs = GCGgetNPricingprobs(gcg);
362
363 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &solverdata->curnodelimit, npricingprobs) );
364 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &solverdata->curstallnodelimit, npricingprobs) );
365 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &solverdata->curgaplimit, npricingprobs) );
366 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &solverdata->cursollimit, npricingprobs) );
367
368 for( i = 0; i < npricingprobs; ++i )
369 {
370 solverdata->curnodelimit[i] = solverdata->startnodelimit;
371 solverdata->curstallnodelimit[i] = solverdata->startstallnodelimit;
372 solverdata->curgaplimit[i] = solverdata->startgaplimit;
373 solverdata->cursollimit[i] = solverdata->startsollimit;
374 }
375
376 return SCIP_OKAY;
377}
378
379/** solving process deinitialization method of pricing solver (called before branch and bound process data is freed) */
380static
381GCG_DECL_SOLVEREXITSOL(solverExitsolMip)
382{
383 GCG_SOLVERDATA* solverdata;
384 int npricingprobs;
386
387 assert(gcg != NULL);
388 assert(solver != NULL);
389
391
392 solverdata = GCGsolverGetData(solver);
393 assert(solverdata != NULL);
394
395 npricingprobs = GCGgetNPricingprobs(gcg);
396
397 SCIPfreeBlockMemoryArray(masterprob, &solverdata->cursollimit, npricingprobs);
398 SCIPfreeBlockMemoryArray(masterprob, &solverdata->curgaplimit, npricingprobs);
399 SCIPfreeBlockMemoryArray(masterprob, &solverdata->curstallnodelimit, npricingprobs);
400 SCIPfreeBlockMemoryArray(masterprob, &solverdata->curnodelimit, npricingprobs);
401
402 return SCIP_OKAY;
403}
404
405#define solverUpdateMip NULL
406
407/** solving method for pricing solver which solves the pricing problem to optimality */
408static
409GCG_DECL_SOLVERSOLVE(solverSolveMip)
410{ /*lint --e{715}*/
411 GCG_SOLVERDATA* solverdata;
412
413 solverdata = GCGsolverGetData(solver);
414 assert(solverdata != NULL);
415
416 if( strcmp(solverdata->settingsfile, "-") != 0 )
417 {
418 SCIP_CALL( SCIPreadParams(pricingprob, solverdata->settingsfile) );
419 }
420
421 SCIP_CALL( SCIPsetLongintParam(pricingprob, "limits/stallnodes", -1LL) );
422 SCIP_CALL( SCIPsetLongintParam(pricingprob, "limits/nodes", -1LL) );
423 SCIP_CALL( SCIPsetRealParam(pricingprob, "limits/gap", 0.0) );
424 SCIP_CALL( SCIPsetIntParam(pricingprob, "limits/solutions", -1) );
425
426#ifdef DEBUG_PRICING_ALL_OUTPUT
427 SCIP_CALL( SCIPsetIntParam(pricingprob, "display/verblevel", SCIP_VERBLEVEL_HIGH) );
428 SCIP_CALL( SCIPwriteParams(pricingprob, "pricing.set", TRUE, TRUE) );
429#endif
430
431 *lowerbound = -SCIPinfinity(pricingprob);
432
433 SCIPdebugMessage("Solving pricing %d (pointer: %p)\n", probnr, (void*)pricingprob);
434 SCIP_CALL( solveProblem(gcg, pricingprob, probnr, solverdata, lowerbound, status) );
435
436#ifdef DEBUG_PRICING_ALL_OUTPUT
437 SCIP_CALL( SCIPsetIntParam(pricingprob, "display/verblevel", SCIP_VERBLEVEL_NONE) );
438 SCIP_CALL( SCIPprintStatistics(pricingprob, NULL) );
439#endif
440
441 return SCIP_OKAY;
442}
443
444/** heuristic solving method of mip solver */
445static
446GCG_DECL_SOLVERSOLVEHEUR(solverSolveHeurMip)
447{ /*lint --e{715}*/
448 GCG_SOLVERDATA* solverdata;
449
450#ifdef DEBUG_PRICING_ALL_OUTPUT
451 SCIP_CALL( SCIPsetIntParam(pricingprob, "display/verblevel", SCIP_VERBLEVEL_HIGH) );
452#endif
453
454 solverdata = GCGsolverGetData(solver);
455 assert(solverdata != NULL);
456
457 *lowerbound = -SCIPinfinity(pricingprob);
458
459 /* setup heuristic solver parameters */
460 if( SCIPgetStage(pricingprob) == SCIP_STAGE_PROBLEM )
461 {
462 solverdata->curnodelimit[probnr] = solverdata->startnodelimit;
463 solverdata->curstallnodelimit[probnr] = solverdata->startstallnodelimit;
464 solverdata->curgaplimit[probnr] = solverdata->startgaplimit;
465 solverdata->cursollimit[probnr] = solverdata->startsollimit;
466 }
467 else
468 {
469 if( SCIPgetStatus(pricingprob) == SCIP_STATUS_NODELIMIT )
470 {
471 if( solverdata->nodelimitfac > 1.0 )
472 solverdata->curnodelimit[probnr] = (SCIP_Longint) (solverdata->curnodelimit[probnr] * solverdata->nodelimitfac);
473 else
474 solverdata->curnodelimit[probnr] += solverdata->startnodelimit;
475 }
476 else if( SCIPgetStatus(pricingprob) == SCIP_STATUS_STALLNODELIMIT )
477 {
478 if( solverdata->stallnodelimitfac > 1.0 )
479 solverdata->curstallnodelimit[probnr] = (SCIP_Longint) (solverdata->curstallnodelimit[probnr] * solverdata->stallnodelimitfac);
480 else
481 solverdata->curstallnodelimit[probnr] += solverdata->startstallnodelimit;
482 }
483 else if( SCIPgetStatus(pricingprob) == SCIP_STATUS_GAPLIMIT )
484 {
485 if( solverdata->gaplimitfac < 1.0 )
486 solverdata->curgaplimit[probnr] *= solverdata->gaplimitfac;
487 else
488 solverdata->curgaplimit[probnr] = MAX(solverdata->curgaplimit[probnr] - solverdata->startgaplimit, 0.0);
489 }
490 else if( SCIPgetStatus(pricingprob) == SCIP_STATUS_SOLLIMIT )
491 {
492 if( solverdata->sollimitfac > 1.0 )
493 solverdata->cursollimit[probnr] = (int) (solverdata->cursollimit[probnr] * solverdata->sollimitfac);
494 else
495 solverdata->cursollimit[probnr] += solverdata->startsollimit;
496 }
497 else
498 {
500 return SCIP_OKAY;
501 }
502 }
503 SCIP_CALL( SCIPsetLongintParam(pricingprob, "limits/nodes", solverdata->curnodelimit[probnr]) );
504 SCIP_CALL( SCIPsetLongintParam(pricingprob, "limits/stallnodes", solverdata->curstallnodelimit[probnr]) );
505 SCIP_CALL( SCIPsetRealParam(pricingprob, "limits/gap", solverdata->curgaplimit[probnr]) );
506 SCIP_CALL( SCIPsetIntParam(pricingprob, "limits/solutions", solverdata->cursollimit[probnr]) );
507
508 /* solve the pricing problem */
509 SCIPdebugMessage("Solving pricing %d heuristically (pointer: %p)\n", probnr, (void*)pricingprob);
510 SCIP_CALL( solveProblem(gcg, pricingprob, probnr, solverdata, lowerbound, status) );
511
512#ifdef DEBUG_PRICING_ALL_OUTPUT
513 SCIP_CALL( SCIPsetIntParam(pricingprob, "display/verblevel", SCIP_VERBLEVEL_NONE) );
514 SCIP_CALL( SCIPprintStatistics(pricingprob, NULL) );
515#endif
516
517 return SCIP_OKAY;
518}
519
520/** extracts ray from a subproblem used to solve a pricing problem pricing problem (or directly from the pricing problem if no subproblem is specified) */
522 GCG* gcg, /**< GCG data structure */
523 SCIP* pricingprob, /**< pricing problem SCIP data structure */
524 SCIP* subproblem, /**< SCIP data structure that contains the actual solution (if NULL pricingprob will be used) */
525 SCIP_HASHMAP* varmap, /**< mapping of pricingprob vars to subproblem vars (can be NULL if subproblem is NULL) */
526 int probnr, /**< problem number */
527 GCG_COL** newcol /**< column pointer to store new column */
528)
529{
530 SCIP_VAR** probvars;
531 SCIP_VAR** solvars;
532 SCIP_Real* solvals;
533 int nprobvars;
534 int nsolvars;
535 int i;
536 SCIP* solprob;
537
538 if (subproblem == NULL)
539 solprob = pricingprob;
540 else
541 solprob = subproblem;
542
543 assert(pricingprob != NULL);
544 assert(newcol != NULL);
545 assert(SCIPhasPrimalRay(solprob));
546
547 probvars = SCIPgetOrigVars(pricingprob);
548 nprobvars = SCIPgetNOrigVars(pricingprob);
549 nsolvars = 0;
550 SCIP_CALL( SCIPallocBufferArray(pricingprob, &solvars, nprobvars) );
551 SCIP_CALL( SCIPallocBufferArray(pricingprob, &solvals, nprobvars) );
552
553 /* store the primal ray values */
554 for ( i = 0; i < nprobvars; i++ )
555 {
556 double solval;
557
558 if (varmap == NULL)
559 solval = SCIPgetPrimalRayVal(pricingprob, probvars[i]);
560 else
561 solval = SCIPgetPrimalRayVal(subproblem, SCIPhashmapGetImage(varmap, probvars[i]));
562
563 if ( SCIPisZero(solprob, solval) )
564 continue;
565
566 assert(!SCIPisInfinity(solprob, solval));
567 assert(!SCIPisInfinity(solprob, -solval));
568
569 solvars[nsolvars] = probvars[i];
570 solvals[nsolvars] = solval;
571 assert(!SCIPisInfinity(solprob, solvals[nsolvars]));
572 /* todo: check if/ensure that this value is integral! */
573 nsolvars++;
574
575 SCIPdebugMessage("%s: %g (obj = %g)\n", SCIPvarGetName(probvars[i]), solval, SCIPvarGetObj(probvars[i]));
576 }
577
578 SCIP_CALL( SCIPfreeSolve(solprob, TRUE) );
579 SCIP_CALL( SCIPtransformProb(solprob) );
580
581 /* todo: is it okay to write pricingprob into column structure? */
582 SCIP_CALL( GCGcreateGcgCol(gcg, pricingprob, newcol, probnr, solvars, solvals, nsolvars, TRUE, SCIPinfinity(pricingprob)) );
583
584 SCIPfreeBufferArray(pricingprob, &solvals);
585 SCIPfreeBufferArray(pricingprob, &solvars);
586
587 SCIPdebugMessage("pricingproblem has an unbounded ray!\n");
588
589 return SCIP_OKAY;
590}
591
593 SCIP* pricingprob /**< pricing problem SCIP data structure */
594 )
595{
596 /* all SCIP statuses handled so far; these are currently:
597 * SCIP_STATUS_USERINTERRUPT
598 * SCIP_STATUS_NODELIMIT
599 * SCIP_STATUS_TOTALNODELIMIT
600 * SCIP_STATUS_STALLNODELIMIT
601 * SCIP_STATUS_TIMELIMIT
602 * SCIP_STATUS_MEMLIMIT
603 * SCIP_STATUS_GAPLIMIT
604 * SCIP_STATUS_SOLLIMIT
605 * SCIP_STATUS_BESTSOLLIMIT
606 * SCIP_STATUS_OPTIMAL
607 * SCIP_STATUS_INFEASIBLE
608 * SCIP_STATUS_UNBOUNDED
609 * SCIP_STATUS_INFORUNBD
610 */
611 /* @todo: can SCIP_STATUS_UNKNOWN happen, too? */
613 || SCIPgetStatus(pricingprob) == SCIP_STATUS_OPTIMAL
614 || SCIPgetStatus(pricingprob) == SCIP_STATUS_INFEASIBLE
615 || SCIPgetStatus(pricingprob) == SCIP_STATUS_UNBOUNDED
616 || SCIPgetStatus(pricingprob) == SCIP_STATUS_INFORUNBD);
617
618 /* translate SCIP solution status to GCG pricing status */
619 switch( SCIPgetStatus(pricingprob) )
620 {
622 SCIPdebugMessage(" -> interrupted, %d solutions found\n", SCIPgetNSols(pricingprob)); /*lint -fallthrough*/
629
635
638
641
645
646 default:
647 SCIPerrorMessage("invalid SCIP status of pricing problem: %d\n", SCIPgetStatus(pricingprob));
649 }
650}
651
653 GCG* gcg, /**< GCG data structure */
654 SCIP* pricingprob, /**< pricing problem SCIP data structure */
655 SCIP* subproblem, /**< SCIP data structure that contains the actual solution (if NULL pricingprob will be used) */
656 SCIP_HASHMAP* varmap, /**< mapping of pricingprob vars to subproblem vars (can be NULL if subproblem is NULL) */
657 int probnr, /**< problem number */
658 SCIP_Bool checksols /**< should solutions be checked extensively */
659)
660{
661 SCIP_SOL** probsols;
662 int nprobsols;
663 SCIP* solprob;
664
665 int s;
666
667 if (subproblem == NULL)
668 solprob = pricingprob;
669 else
670 solprob = subproblem;
671
672 probsols = SCIPgetSols(solprob);
673 nprobsols = SCIPgetNSols(solprob);
674
675 for( s = 0; s < nprobsols; s++ )
676 {
677 GCG_COL* col;
678 SCIP_Bool feasible;
679 assert(probsols[s] != NULL);
680 SCIP_CALL( SCIPcheckSolOrig(solprob, probsols[s], &feasible, FALSE, FALSE) );
681
682 if( !feasible )
683 {
684 SCIPwarningMessage(solprob, "solution %d of pricing problem %d (%s) not feasible:\n", s, probnr, SCIPgetProbName(solprob));
685 SCIP_CALL( SCIPcheckSolOrig(solprob, probsols[s], &feasible, TRUE, TRUE) );
686 continue;
687 }
688
689 /* check whether the solution is equal to one of the previous solutions */
690 if( checksols )
691 {
692 SCIP_Bool isnew;
693
694 SCIP_CALL( checkSolNew(solprob, probsols, s, &isnew) );
695
696 if( !isnew )
697 continue;
698 }
699
700 /* Check whether the pricing problem solution has infinite values; if not, transform it to a column */
701 if( !solutionHasInfiniteValue(solprob, probsols[s]) )
702 {
703 SCIP_CALL( GCGcreateGcgColFromSol(gcg, pricingprob, subproblem, varmap, &col, probnr, probsols[s], FALSE, SCIPinfinity(solprob)) );
705 }
706 /* If the best solution has infinite values, try to repair it */
707 else if( s == 0 )
708 {
709 SCIP_SOL* newsol;
711
712 newsol = NULL;
713 success = FALSE;
714
715 SCIPdebugMessage("solution has infinite values, create a copy with finite values\n");
716
717 SCIP_CALL( SCIPcreateFiniteSolCopy(solprob, &newsol, probsols[0], &success) );
719 assert(newsol != NULL);
720
721 SCIP_CALL( GCGcreateGcgColFromSol(gcg, pricingprob, subproblem, varmap, &col, probnr, newsol, FALSE, SCIPinfinity(solprob)) );
723 }
724 }
725
726 return SCIP_OKAY;
727}
728
729/** creates the mip solver for pricing problems and includes it in GCG */
731 GCG* gcg /**< GCG data structure */
732 )
733{
734 SCIP* origprob;
736 GCG_SOLVERDATA* solverdata;
737
740
742 solverdata->settingsfile = NULL;
743
746 solverUpdateMip, solverSolveMip, solverSolveHeurMip, solverFreeMip, solverInitMip, solverExitMip,
747 solverInitsolMip, solverExitsolMip, solverdata) );
748
749 SCIP_CALL( SCIPaddBoolParam(origprob, "pricingsolver/mip/checksols",
750 "should solutions of the pricing MIPs be checked for duplicity?",
751 &solverdata->checksols, TRUE, DEFAULT_CHECKSOLS, NULL, NULL) );
752
753 SCIP_CALL( SCIPaddLongintParam(origprob, "pricingsolver/mip/startnodelimit",
754 "start node limit for heuristic pricing",
756
757 SCIP_CALL( SCIPaddLongintParam(origprob, "pricingsolver/mip/startstallnodelimit",
758 "start stalling node limit for heuristic pricing",
760
761 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/mip/startgaplimit",
762 "start gap limit for heuristic pricing",
764
765 SCIP_CALL( SCIPaddIntParam(origprob, "pricingsolver/mip/startsollimit",
766 "start solution limit for heuristic pricing",
767 &solverdata->startsollimit, TRUE, DEFAULT_STARTSOLLIMIT, -1, INT_MAX, NULL, NULL) );
768
769 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/mip/nodelimitfac",
770 "factor by which to increase node limit for heuristic pricing (1.0: add start limit)",
772
773 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/mip/stallnodelimitfac",
774 "factor by which to increase stalling node limit for heuristic pricing (1.0: add start limit)",
776
777 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/mip/gaplimitfac",
778 "factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit)",
779 &solverdata->gaplimitfac, TRUE, DEFAULT_GAPLIMITFAC, 0.0, 1.0, NULL, NULL) );
780
781 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/mip/sollimitfac",
782 "factor by which to increase solution limit for heuristic pricing (1.0: add start limit)",
784
785 SCIP_CALL( SCIPaddStringParam(origprob, "pricingsolver/mip/settingsfile",
786 "settings file for pricing problems",
787 &solverdata->settingsfile, TRUE, DEFAULT_SETTINGSFILE, NULL, NULL) );
788
789 SCIP_CALL( SCIPaddBoolParam(origprob, "pricingsolver/mip/enablewarnings",
790 "should warnings of pricing problems be printed",
792
793
794 return SCIP_OKAY;
795}
#define SCIP_Longint
#define SCIP_REAL_MAX
#define SCIP_Bool
#define SCIP_Real
#define MAX(x, y)
#define SCIP_LONGINT_FORMAT
#define SCIP_LONGINT_MAX
#define TRUE
#define FALSE
GCG interface methods.
SCIP_RETCODE GCGpricerAddCol(GCG *gcg, GCG_COL *col)
SCIP_RETCODE GCGcreateGcgColFromSol(GCG *gcg, SCIP *pricingprob, SCIP *subproblem, SCIP_HASHMAP *varmap, GCG_COL **gcgcol, int prob, SCIP_SOL *sol, SCIP_Bool isray, SCIP_Real redcost)
Definition gcgcol.c:267
SCIP_RETCODE GCGcreateGcgCol(GCG *gcg, SCIP *pricingprob, GCG_COL **gcgcol, int probnr, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Bool isray, SCIP_Real redcost)
Definition gcgcol.c:53
SCIP * GCGgetDwMasterprob(GCG *gcg)
Definition gcg.cpp:123
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
GCG_EXPORT int GCGgetNPricingprobs(GCG *gcg)
Definition relax_gcg.c:4113
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_STATUS SCIPgetStatus(SCIP *scip)
SCIP_STAGE SCIPgetStage(SCIP *scip)
const char * SCIPgetProbName(SCIP *scip)
int SCIPgetNContVars(SCIP *scip)
SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
int SCIPgetNOrigVars(SCIP *scip)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
GCG_EXPORT GCG_SOLVERDATA * GCGsolverGetData(GCG_SOLVER *solver)
Definition solver.c:400
GCG_EXPORT void GCGsolverSetData(GCG_SOLVER *solver, GCG_SOLVERDATA *solverdata)
Definition solver.c:410
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPreadParams(SCIP *scip, const char *filename)
SCIP_RETCODE SCIPwriteParams(SCIP *scip, const char *filename, SCIP_Bool comments, SCIP_Bool onlychanged)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
SCIP_SOLORIGIN SCIPsolGetOrigin(SCIP_SOL *sol)
int SCIPgetNSols(SCIP *scip)
SCIP_RETCODE SCIPcreateFiniteSolCopy(SCIP *scip, SCIP_SOL **sol, SCIP_SOL *sourcesol, SCIP_Bool *success)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_Real SCIPgetPrimalRayVal(SCIP *scip, SCIP_VAR *var)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
SCIP_Bool SCIPhasPrimalRay(SCIP *scip)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
SCIP_RETCODE SCIPpresolve(SCIP *scip)
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
SCIP_RETCODE SCIPfreeSolve(SCIP *scip, SCIP_Bool restart)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Real SCIPgetDualbound(SCIP *scip)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
SCIP_VAR ** vars
SCIP_Bool success
SCIP_Real solval
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
SCIP_RETCODE retcode
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
SCIP_SOL * sol
#define NULL
SCIP_Bool SCIPmessagehdlrIsQuiet(SCIP_MESSAGEHDLR *messagehdlr)
SCIP_RETCODE GCGpricerIncludeSolver(GCG *gcg, const char *name, const char *desc, int priority, SCIP_Bool heurenabled, SCIP_Bool exactenabled, GCG_DECL_SOLVERUPDATE((*solverupdate)), GCG_DECL_SOLVERSOLVE((*solversolve)), GCG_DECL_SOLVERSOLVEHEUR((*solversolveheur)), GCG_DECL_SOLVERFREE((*solverfree)), GCG_DECL_SOLVERINIT((*solverinit)), GCG_DECL_SOLVEREXIT((*solverexit)), GCG_DECL_SOLVERINITSOL((*solverinitsol)), GCG_DECL_SOLVEREXITSOL((*solverexitsol)), GCG_SOLVERDATA *solverdata)
GCG variable pricer.
public methods for working with gcg columns
#define SCIPerrorMessage
#define SCIPstatisticMessage
#define SOLVER_HEURENABLED
#define SOLVER_EXACTENABLED
#define SOLVER_NAME
#define SOLVER_DESC
#define SOLVER_PRIORITY
#define DEFAULT_SOLLIMITFAC
#define DEFAULT_STARTSOLLIMIT
#define DEFAULT_CHECKSOLS
#define DEFAULT_STARTGAPLIMIT
#define DEFAULT_STALLNODELIMITFAC
#define DEFAULT_STARTNODELIMIT
#define DEFAULT_GAPLIMITFAC
#define DEFAULT_NODELIMITFAC
#define DEFAULT_SETTINGSFILE
#define DEFAULT_ENABLE_WARNINGS
#define DEFAULT_STARTSTALLNODELIMIT
GCG_PRICINGSTATUS getPricingstatus(SCIP *pricingprob)
Definition solver_mip.c:592
SCIP_RETCODE GCGincludeSolverMip(GCG *gcg)
Definition solver_mip.c:730
#define solverExitMip
Definition solver_mip.c:342
#define solverInitMip
Definition solver_mip.c:339
static SCIP_RETCODE checkSolNew(SCIP *pricingprob, SCIP_SOL **sols, int idx, SCIP_Bool *isnew)
Definition solver_mip.c:119
static SCIP_Bool solutionHasInfiniteValue(SCIP *pricingprob, SCIP_SOL *sol)
Definition solver_mip.c:178
static SCIP_RETCODE solveProblem(GCG *gcg, SCIP *pricingprob, int probnr, GCG_SOLVERDATA *solverdata, SCIP_Real *lowerbound, GCG_PRICINGSTATUS *status)
Definition solver_mip.c:200
SCIP_RETCODE createColumnFromRay(GCG *gcg, SCIP *pricingprob, SCIP *subproblem, SCIP_HASHMAP *varmap, int probnr, GCG_COL **newcol)
Definition solver_mip.c:521
SCIP_RETCODE getColumnsFromPricingprob(GCG *gcg, SCIP *pricingprob, SCIP *subproblem, SCIP_HASHMAP *varmap, int probnr, SCIP_Bool checksols)
Definition solver_mip.c:652
#define solverUpdateMip
Definition solver_mip.c:405
static SCIP_RETCODE resolvePricingWithoutPresolving(SCIP *pricingprob)
Definition solver_mip.c:102
mip solver for pricing problems
SCIP_Longint startnodelimit
SCIP_Real * curgaplimit
SCIP_Real nodelimitfac
SCIP_Longint * curstallnodelimit
SCIP_Real startgaplimit
SCIP_Bool enablewarnings
SCIP_Bool checksols
SCIP_Real gaplimitfac
SCIP_Longint * cursollimit
SCIP_Longint * curnodelimit
SCIP_Longint startstallnodelimit
SCIP_Longint startsollimit
SCIP_Real stallnodelimitfac
SCIP_Real sollimitfac
struct Gcg GCG
Definition type_gcg.h:44
struct GCG_Col GCG_COL
Definition type_gcgcol.h:44
SCIP_VERBLEVEL_NONE
SCIP_VERBLEVEL_HIGH
struct SCIP_HashMap SCIP_HASHMAP
enum GCG_PricingStatus GCG_PRICINGSTATUS
@ GCG_PRICINGSTATUS_OPTIMAL
@ GCG_PRICINGSTATUS_UNBOUNDED
@ GCG_PRICINGSTATUS_SOLVERLIMIT
@ GCG_PRICINGSTATUS_NOTAPPLICABLE
@ GCG_PRICINGSTATUS_INFEASIBLE
@ GCG_PRICINGSTATUS_UNKNOWN
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_PROBLEM
struct SCIP_Sol SCIP_SOL
SCIP_SOLORIGIN_ORIGINAL
#define GCG_DECL_SOLVERFREE(x)
Definition type_solver.h:60
#define GCG_DECL_SOLVEREXITSOL(x)
Definition type_solver.h:98
#define GCG_DECL_SOLVERINITSOL(x)
Definition type_solver.h:87
#define GCG_DECL_SOLVERSOLVE(x)
#define GCG_DECL_SOLVERSOLVEHEUR(x)
struct GCG_SolverData GCG_SOLVERDATA
Definition type_solver.h:50
SCIP_STATUS_OPTIMAL
SCIP_STATUS_TOTALNODELIMIT
SCIP_STATUS_BESTSOLLIMIT
SCIP_STATUS_SOLLIMIT
SCIP_STATUS_UNBOUNDED
SCIP_STATUS_UNKNOWN
SCIP_STATUS_GAPLIMIT
SCIP_STATUS_USERINTERRUPT
SCIP_STATUS_INFORUNBD
SCIP_STATUS_STALLNODELIMIT
SCIP_STATUS_TIMELIMIT
SCIP_STATUS_INFEASIBLE
SCIP_STATUS_NODELIMIT
SCIP_STATUS_MEMLIMIT
struct SCIP_Var SCIP_VAR