GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
solver_cplex.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_cplex.c
30 * @brief cplex solver for pricing problems
31 * @author Gerald Gamrath
32 * @author Alexander Gross
33 * @author Hanna Franzen
34 * @author Christian Puchert
35 */
36
37/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
38/* #define DEBUG_PRICING_ALL_OUTPUT */
39
40#include <string.h>
41
42#include "scip/scip.h"
43#include "gcg/gcg.h"
44#include "gcg/solver_cplex.h"
45#include "gcg/pub_solver.h"
46#include "gcg/pub_gcgcol.h"
47
48#include "gcg/pricer_gcg.h"
49#include "gcg/scip_misc.h"
50
51#include "cplex.h"
52
53#define CHECK_ZERO(x) { int _restat_; \
54 if( (_restat_ = (x)) != 0 ) \
55 { \
56 SCIPerrorMessage("Error in pricing solver: CPLEX returned %d\n", _restat_); \
57 retval = SCIP_INVALIDRESULT; \
58 goto TERMINATE; \
59 } \
60 }
61
62#define CPX_LONG_MAX 9223372036800000000LL
63
64
65#define SOLVER_NAME "cplex"
66#define SOLVER_DESC "cplex solver for pricing problems"
67#define SOLVER_PRIORITY 20
68#define SOLVER_HEURENABLED FALSE /**< indicates whether the heuristic solving method of the solver should be enabled */
69#define SOLVER_EXACTENABLED FALSE /**< indicates whether the exact solving method of the solver should be enabled */
70
71#define DEFAULT_CHECKSOLS TRUE /**< should solutions of the pricing MIPs be checked for duplicity? */
72#define DEFAULT_THREADS 1 /**< number of threads the CPLEX pricing solver is allowed to use (0: automatic) */
73#define DEFAULT_STARTNODELIMIT 1000LL /**< start node limit for heuristic pricing */
74#define DEFAULT_STARTGAPLIMIT 0.2 /**< start gap limit for heuristic pricing */
75#define DEFAULT_STARTSOLLIMIT 10LL /**< start solution limit for heuristic pricing */
76#define DEFAULT_NODELIMITFAC 1.25 /**< factor by which to increase node limit for heuristic pricing (1.0: add start limit) */
77#define DEFAULT_STALLNODELIMITFAC 1.25 /**< factor by which to increase stalling node limit for heuristic pricing */
78#define DEFAULT_GAPLIMITFAC 0.8 /**< factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit) */
79#define DEFAULT_SOLLIMITFAC 1.5 /**< factor by which to increase solution limit for heuristic pricing (1.0: add start limit) */
80
81
82/** pricing solver data */
83struct GCG_SolverData
84{
85 GCG* gcg; /**< GCG instance */
86 SCIP** pricingprobs; /**< array storing the SCIP instances for all pricing problems */
87 int npricingprobs; /**< number of pricing problems */
88 CPXENVptr* cpxenv; /**< array of CPLEX environments for the pricing problems */
89 CPXLPptr* lp; /**< array of CPLEX problems for the pricing problems */
90 int* nupdates; /**< array storing the number of updates for all of the pricing problems */
91 SCIP_Longint* curnodelimit; /**< current node limit per pricing problem */
92 SCIP_Real* curgaplimit; /**< current gap limit per pricing problem */
93 SCIP_Longint* cursollimit; /**< current solution limit per pricing problem */
94 /**
95 * information about the basic pricing problem (without potential branching constraints)
96 */
97 SCIP_VAR*** pricingvars; /**< array storing the variables of the pricing problems */
98 SCIP_CONS*** pricingconss; /**< array storing the constraints of the pricing problems */
99 int* npricingvars; /**< array storing the number of variables of the pricing problems */
100 int* nbasicpricingconss; /**< array storing the basic number of constraints of the pricing problems */
101 /**
102 * parameters
103 */
104 SCIP_Bool checksols; /**< should solutions of the pricing MIPs be checked for duplicity? */
105 int threads; /**< number of threads the CPLEX pricing solver is allowed to use (0: automatic) */
106 SCIP_Longint startnodelimit; /**< start node limit for heuristic pricing */
107 SCIP_Real startgaplimit; /**< start gap limit for heuristic pricing */
108 SCIP_Longint startsollimit; /**< start solution limit for heuristic pricing */
109 SCIP_Real nodelimitfac; /**< factor by which to increase node limit for heuristic pricing (1.0: add start limit) */
110 SCIP_Real gaplimitfac; /**< factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit) */
111 SCIP_Real sollimitfac; /**< factor by which to increase solution limit for heuristic pricing (1.0: add start limit) */
112};
113
114/*
115 * local methods
116 */
117
118/** creates a CPLEX environment and builds the pricing problem */
119static
121 GCG* gcg, /**< GCG data structure */
122 GCG_SOLVERDATA* solverdata, /**< solver data structure */
123 SCIP* pricingprob, /**< pricing problem */
124 int probnr /**< problem number */
125 )
126{
127 SCIP* scip;
128 SCIP_CONS** conss;
129 SCIP_VAR** vars;
130 SCIP_VAR** consvars;
131 SCIP_Real* consvals;
132 SCIP_VAR* var;
133 double* varobj;
134 double* varlb;
135 double* varub;
136 char* vartype;
137 char** varnames = NULL;
138 char** consnames = NULL;
139 double* rhss;
140 double* ranges;
141 char* senses;
142 double* coefs = NULL;
143 int* rowidx;
144 int* colidx;
145 SCIP_Real lhs;
146 SCIP_Real rhs;
147 SCIP_VARTYPE type;
148 SCIP_RETCODE retval;
149 int nconss = 0;
150 int nvars = 0;
151 int status;
152 int varidx;
153 int nconsvars;
154 int nnonzeros;
155 int idx;
156 int c;
157 int i;
158 int v;
159
161
162 /* open CPLEX environment and create problem */
163 solverdata->cpxenv[probnr] = CPXopenCPLEX(&status);
164 solverdata->lp[probnr] = CPXcreateprob(solverdata->cpxenv[probnr], &status, SCIPgetProbName(pricingprob));
165 solverdata->pricingprobs[probnr] = pricingprob;
166
167 retval = SCIP_OKAY;
168
169 /* set parameters */
170 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPGAP, 0.0) );
171 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPAGAP, 0.0) );
172 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPRHS, SCIPfeastol(pricingprob)) );
173 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPINT, SCIPfeastol(pricingprob)) );
174 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_THREADS, solverdata->threads) );
175#ifdef DEBUG_PRICING_ALL_OUTPUT
176 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_SCRIND, CPX_ON) );
177#endif
178
179 /* set objective sense */
181#if (CPX_VERSION_VERSION == 12 && CPX_VERSION_RELEASE >= 5) || CPX_VERSION_VERSION > 12
182 CHECK_ZERO( CPXchgobjsen(solverdata->cpxenv[probnr], solverdata->lp[probnr], CPX_MIN) );
183#else
184 CPXchgobjsen(solverdata->cpxenv[probnr], solverdata->lp[probnr], CPX_MIN);
185#endif
186
187 conss = SCIPgetOrigConss(pricingprob);
188 nconss = SCIPgetNOrigConss(pricingprob);
189 vars = SCIPgetOrigVars(pricingprob);
190 nvars = SCIPgetNOrigVars(pricingprob);
191
192 /* arrays for storing the basic constraints and variables */
193 solverdata->npricingvars[probnr] = nvars;
194 solverdata->nbasicpricingconss[probnr] = nconss;
195
196 SCIP_CALL( SCIPallocMemoryArray(scip, &solverdata->pricingvars[probnr], nvars) ); /*lint !e866*/
197 SCIP_CALL( SCIPallocMemoryArray(scip, &solverdata->pricingconss[probnr], nconss) ); /*lint !e866*/
198
199 /* temporary memory for storing all data about the variables */
205
206 /* temporary memory for storing data about the constraints */
207 SCIP_CALL( SCIPallocBufferArray(scip, &rhss, nconss) );
208 SCIP_CALL( SCIPallocBufferArray(scip, &senses, nconss) );
209 SCIP_CALL( SCIPallocBufferArray(scip, &ranges, nconss) );
210 SCIP_CALL( SCIPallocBufferArray(scip, &consnames, nconss) );
211
212 BMSclearMemoryArray(consnames, nconss);
213 BMSclearMemoryArray(varnames, nvars);
214
215 /* collect information about variables: bounds, objective function, name, type */
216 for( i = 0; i < nvars; i++ )
217 {
218 var = vars[i];
219 varidx = SCIPvarGetIndex(var);
220 assert(0 <= varidx);
221 assert(varidx < nvars);
222 solverdata->pricingvars[probnr][varidx] = var;
223 SCIP_CALL( SCIPcaptureVar(pricingprob, var) );
224
225 varlb[varidx] = SCIPvarGetLbLocal(var);
226 varub[varidx] = SCIPvarGetUbLocal(var);
227 varobj[varidx] = SCIPvarGetObj(var);
229 (int)(strlen(SCIPvarGetName(var))+1)) ); /*lint !e866*/
230
231 type = SCIPvarGetType(var);
232
233 switch( type )
234 {
236 vartype[varidx] = 'B';
237 break;
239 vartype[varidx] = 'C';
240 break;
242 vartype[varidx] = 'I';
243 break;
244 default:
245 SCIPerrorMessage("invalid variable type\n");
246 return SCIP_INVALIDDATA;
247 }
248 }
249
250 /* collect right hand sides and ranges of the constraints, count total number of nonzeros */
251 nnonzeros = 0;
252 for( c = 0; c < nconss; ++c )
253 {
254 solverdata->pricingconss[probnr][c] = conss[c];
255 SCIP_CALL( SCIPcaptureCons(pricingprob, conss[c]) );
256
257 nnonzeros += GCGconsGetNVars(scip, conss[c]);
258 lhs = GCGconsGetLhs(pricingprob, conss[c]);
259 rhs = GCGconsGetRhs(pricingprob, conss[c]);
261 (int)(strlen(SCIPconsGetName(conss[c]))+1)) ); /*lint !e866*/
262
263 if( SCIPisInfinity(scip, -lhs) )
264 {
265 senses[c] = 'L';
266 rhss[c] = (double) rhs;
267 ranges[c] = 0.0;
268 }
269 else if( SCIPisInfinity(scip, rhs) )
270 {
271 senses[c] = 'G';
272 rhss[c] = (double) lhs;
273 ranges[c] = 0.0;
274 }
275 else if( SCIPisEQ(scip, lhs, rhs) )
276 {
277 senses[c] = 'E';
278 rhss[c] = (double) lhs;
279 ranges[c] = 0.0;
280 }
281 else
282 {
283 assert(SCIPisLT(scip, lhs, rhs));
284 senses[c] = 'R';
285 rhss[c] = (double) lhs;
286 ranges[c] = (double) (rhs - lhs);
287 }
288 }
289
290 /* temporary memory for storing data about coefficients in the constraints */
293
294 /* temporary memory for storing nonzeros */
295 SCIP_CALL( SCIPallocBufferArray(scip, &rowidx, nnonzeros) );
296 SCIP_CALL( SCIPallocBufferArray(scip, &colidx, nnonzeros) );
297 SCIP_CALL( SCIPallocBufferArray(scip, &coefs, nnonzeros) );
298
299 /* collect nonzeros */
300 for( c = 0, idx = 0; c < nconss; ++c )
301 {
302 nconsvars = GCGconsGetNVars(scip, conss[c]);
303 SCIP_CALL( GCGconsGetVals(pricingprob, conss[c], consvals, nvars) );
304 SCIP_CALL( GCGconsGetVars(pricingprob, conss[c], consvars, nvars) );
305
306 /* get coefficients */
307 for( v = 0; v < nconsvars; ++v )
308 {
309 rowidx[idx] = c;
310 colidx[idx] = SCIPvarGetIndex(consvars[v]);
311 coefs[idx] = (double)consvals[v];
312 idx++;
313 }
314 }
315 assert(idx == nnonzeros);
316
317 /* add variables to CPLEX problem */
318 CHECK_ZERO( CPXnewcols(solverdata->cpxenv[probnr], solverdata->lp[probnr], nvars, varobj, varlb, varub, vartype, varnames) );
319
320 /* add empty constraints to CPLEX problem */
321 CHECK_ZERO( CPXnewrows(solverdata->cpxenv[probnr], solverdata->lp[probnr], nconss, rhss, senses, ranges, consnames) );
322
323 /* add variables to constraints in CPLEX problem */
324 CHECK_ZERO( CPXchgcoeflist(solverdata->cpxenv[probnr], solverdata->lp[probnr], nnonzeros, rowidx, colidx, coefs) );
325
326#ifdef WRITEPROBLEMS
327 {
328 char filename[SCIP_MAXSTRLEN];
329 (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "cplex-%s.lp", SCIPgetProbName(pricingprob));
330 SCIPinfoMessage(pricingprob, NULL, "print pricing problem to %s\n", filename);
331 CHECK_ZERO( CPXwriteprob(solverdata->cpxenv[probnr], solverdata->lp[probnr], filename, "lp") );
332 }
333#endif
334
335 TERMINATE:
336 /* free temporary memory */
337 if( coefs != NULL )
338 {
339 SCIPfreeBufferArray(scip, &coefs);
340 SCIPfreeBufferArray(scip, &colidx);
341 SCIPfreeBufferArray(scip, &rowidx);
342
343 SCIPfreeBufferArray(scip, &consvals);
344 SCIPfreeBufferArray(scip, &consvars);
345
346 for( v = nvars - 1; v >= 0; --v )
347 {
348 assert(varnames != NULL);
349 SCIPfreeBufferArrayNull(scip, &varnames[v]);
350 }
351
352 for( c = nconss - 1; c >= 0; --c )
353 {
354 assert(consnames != NULL);
355 SCIPfreeBufferArrayNull(scip, &consnames[c]);
356 }
357
358 SCIPfreeBufferArray(scip, &consnames);
359 SCIPfreeBufferArray(scip, &ranges);
360 SCIPfreeBufferArray(scip, &senses);
362
363 SCIPfreeBufferArray(scip, &varnames);
364 SCIPfreeBufferArray(scip, &varub);
365 SCIPfreeBufferArray(scip, &varlb);
366 SCIPfreeBufferArray(scip, &vartype);
367 SCIPfreeBufferArray(scip, &varobj);
368 }
369
370 return retval;
371}
372
373
374/** updates bounds and objective coefficients of variables in the given pricing problem */
375static
377 SCIP* scip, /**< SCIP data structure */
378 GCG_SOLVERDATA* solverdata, /**< solver data structure */
379 SCIP* pricingprob, /**< pricing problem */
380 int probnr, /**< problem number */
381 SCIP_Bool varobjschanged, /**< have the objective coefficients changed? */
382 SCIP_Bool varbndschanged /**< have the lower and upper bounds changed? */
383 )
384{
385 SCIP_VAR** vars;
386 double* varobj;
387 double* bounds;
388 int* objidx;
389 int* updatevaridx;
390 char* boundtypes;
391 int nvars;
392 int npricingvars;
393
394 SCIP_RETCODE retval;
395 int i;
396
397 vars = SCIPgetOrigVars(pricingprob);
398 nvars = SCIPgetNOrigVars(pricingprob);
399 npricingvars = solverdata->npricingvars[probnr];
400
401 assert(npricingvars == nvars);
402 assert(npricingvars == CPXgetnumcols(solverdata->cpxenv[probnr], solverdata->lp[probnr]));
403
404 retval = SCIP_OKAY;
405
406 if( varobjschanged )
407 {
408 SCIP_CALL( SCIPallocBufferArray(scip, &objidx, npricingvars) );
409 SCIP_CALL( SCIPallocBufferArray(scip, &varobj, npricingvars) );
410 }
411
412 if( varbndschanged)
413 {
414 SCIP_CALL( SCIPallocBufferArray(scip, &updatevaridx, 2 * npricingvars) );
415 SCIP_CALL( SCIPallocBufferArray(scip, &boundtypes, 2 * npricingvars) );
416 SCIP_CALL( SCIPallocBufferArray(scip, &bounds, 2 * npricingvars) );
417 }
418
419 /* get new bounds and objective coefficients of variables */
420 for( i = 0; i < nvars; i++ )
421 {
422 SCIP_VAR* origvar;
423 SCIP_VAR* var;
424 int varidx;
425
426 origvar = vars[i];
427 varidx = SCIPvarGetIndex(origvar);
428 assert(0 <= varidx);
429 assert(varidx < npricingvars);
430
431 if( SCIPgetStage(pricingprob) >= SCIP_STAGE_TRANSFORMED )
432 var = SCIPvarGetTransVar(origvar);
433 else
434 var = origvar;
435
436 if( varbndschanged )
437 {
438 updatevaridx[2 * (size_t)varidx] = varidx;
439 updatevaridx[2 * (size_t)varidx + 1] = varidx;
440 boundtypes[2 * (size_t)varidx] = 'L';
441 boundtypes[2 * (size_t)varidx + 1] = 'U';
442 bounds[2 * (size_t)varidx] = (double) SCIPvarGetLbGlobal(var);
443 bounds[2 * (size_t)varidx + 1] = (double) SCIPvarGetUbGlobal(var);
444 }
445
446 if( varobjschanged )
447 {
448 objidx[varidx] = varidx;
449 varobj[varidx] = SCIPvarGetObj(origvar);
450 }
451 }
452
453 /* update bounds and objective coefficient of basic variables */
454 if( varbndschanged )
455 {
456 CHECK_ZERO( CPXchgbds(solverdata->cpxenv[probnr], solverdata->lp[probnr], 2 * nvars, updatevaridx, boundtypes, bounds) );
457 }
458 if( varobjschanged )
459 {
460 CHECK_ZERO( CPXchgobj(solverdata->cpxenv[probnr], solverdata->lp[probnr], nvars, objidx, varobj) );
461 }
462
463TERMINATE:
464 if( varbndschanged )
465 {
466 SCIPfreeBufferArray(scip, &bounds);
467 SCIPfreeBufferArray(scip, &boundtypes);
468 SCIPfreeBufferArray(scip, &updatevaridx);
469 }
470 if( varobjschanged)
471 {
472 SCIPfreeBufferArray(scip, &varobj);
473 SCIPfreeBufferArray(scip, &objidx);
474 }
475
476 return retval;
477}
478
479/** updates branching constraints in the given pricing problem */
480static
482 SCIP* scip, /**< SCIP data structure */
483 GCG_SOLVERDATA* solverdata, /**< solver data structure */
484 SCIP* pricingprob, /**< pricing problem */
485 int probnr /**< problem number */
486 )
487{
488 SCIP_CONS** conss;
489 SCIP_VAR** consvars;
490 SCIP_Real* consvals;
491 char** newconsnames = NULL;
492 char* newsenses;
493 double* newrhss;
494 double* newranges;
495 double* newcoefs;
496 int* newrowidx;
497 int* newcolidx;
498 int nconss;
499 int nbasicpricingconss;
500 int ncpxrows;
501 int nnewconss = 0;
502 int nnonzeros;
503 int nvars;
504
505 SCIP_RETCODE retval;
506 int idx;
507 int c;
508
509 conss = SCIPgetOrigConss(pricingprob);
510 nconss = SCIPgetNOrigConss(pricingprob);
511 nbasicpricingconss = solverdata->nbasicpricingconss[probnr];
512
513 nvars = SCIPgetNOrigVars(pricingprob);
514
515 retval = SCIP_OKAY;
516
517 ncpxrows = CPXgetnumrows(solverdata->cpxenv[probnr], solverdata->lp[probnr]);
518
519 if( nbasicpricingconss < ncpxrows )
520 {
521 CHECK_ZERO( CPXdelrows(solverdata->cpxenv[probnr], solverdata->lp[probnr], nbasicpricingconss, ncpxrows - 1) );
522 }
523
524 nnewconss = nconss - nbasicpricingconss;
525
526 if( nnewconss == 0 )
527 return retval;
528
529 /* temporary arrays for storing data about new constraints */
530 SCIP_CALL( SCIPallocBufferArray(scip, &newsenses, nnewconss) );
531 SCIP_CALL( SCIPallocBufferArray(scip, &newrhss, nnewconss) );
532 SCIP_CALL( SCIPallocBufferArray(scip, &newranges, nnewconss) );
533 SCIP_CALL( SCIPallocClearBufferArray(scip, &newconsnames, nnewconss) );
534
535 /* get information about new constraints */
536 nnonzeros = 0;
537
538 for( c = 0; c < nconss; ++c )
539 {
540 SCIP_Real lhs;
541 SCIP_Real rhs;
542 int nconsvars;
543 int considx;
544
545 /* we assume that nothing changed about the basic constraints */
546 if( c < nbasicpricingconss )
547 {
548 assert(conss[c] == solverdata->pricingconss[probnr][c]);
549 continue;
550 }
551
552 considx = c - nbasicpricingconss;
553 assert(considx >= 0);
554
555 nconsvars = GCGconsGetNVars(scip, conss[c]);
556 lhs = GCGconsGetLhs(pricingprob, conss[c]);
557 rhs = GCGconsGetRhs(pricingprob, conss[c]);
558 SCIP_CALL( SCIPduplicateBufferArray(scip, &newconsnames[considx], SCIPconsGetName(conss[c]),
559 (int)(strlen(SCIPconsGetName(conss[c]))+1)) ); /*lint !e866*/
560
561 if( SCIPisInfinity(scip, -lhs) )
562 {
563 newsenses[considx] = 'L';
564 newrhss[considx] = (double) rhs;
565 newranges[considx] = 0.0;
566 }
567 else if( SCIPisInfinity(scip, rhs) )
568 {
569 newsenses[considx] = 'G';
570 newrhss[considx] = (double) lhs;
571 newranges[considx] = 0.0;
572 }
573 else if( SCIPisEQ(scip, lhs, rhs) )
574 {
575 newsenses[considx] = 'E';
576 newrhss[considx] = (double) lhs;
577 newranges[considx] = 0.0;
578 }
579 else
580 {
581 assert(SCIPisLT(scip, lhs, rhs));
582 newsenses[considx] = 'R';
583 newrhss[considx] = (double) lhs;
584 newranges[considx] = (double) (rhs - lhs);
585 }
586
587 nnonzeros += nconsvars;
588 }
589
590 /* temporary arrays for getting variables and coefficients in new constraints */
593
594 /* temporary arrays for storing data about new constraints */
595 SCIP_CALL( SCIPallocBufferArray(scip, &newrowidx, nnonzeros) );
596 SCIP_CALL( SCIPallocBufferArray(scip, &newcolidx, nnonzeros) );
597 SCIP_CALL( SCIPallocBufferArray(scip, &newcoefs, nnonzeros) );
598
599 /* collect coefficients in new constriants */
600 for( c = 0, idx = 0; c < nconss; ++c )
601 {
602 int nconsvars;
603
604 int v;
605
606 /* we assume that nothing changed about the basic constraints */
607 if( c < nbasicpricingconss )
608 {
609 assert(conss[c] == solverdata->pricingconss[probnr][c]);
610 continue;
611 }
612
613 nconsvars = GCGconsGetNVars(scip, conss[c]);
614 SCIP_CALL( GCGconsGetVars(pricingprob, conss[c], consvars, nvars) );
615 SCIP_CALL( GCGconsGetVals(pricingprob, conss[c], consvals, nvars) );
616
617 /* get coefficients */
618 for( v = 0; v < nconsvars; ++v )
619 {
620 newrowidx[idx] = c;
621 newcolidx[idx] = SCIPvarGetIndex(consvars[v]);
622 newcoefs[idx] = (double)consvals[v];
623 idx++;
624 }
625 }
626 assert(idx == nnonzeros);
627
628 /* add new constraints */
629 CHECK_ZERO( CPXnewrows(solverdata->cpxenv[probnr], solverdata->lp[probnr], nnewconss, newrhss, newsenses, newranges, newconsnames) );
630 CHECK_ZERO( CPXchgcoeflist(solverdata->cpxenv[probnr], solverdata->lp[probnr], nnonzeros, newrowidx, newcolidx, newcoefs) );
631
632TERMINATE:
633 if( nnewconss > 0 )
634 {
635 SCIPfreeBufferArray(scip, &newcoefs);
636 SCIPfreeBufferArray(scip, &newcolidx);
637 SCIPfreeBufferArray(scip, &newrowidx);
638
639 SCIPfreeBufferArray(scip, &consvals);
640 SCIPfreeBufferArray(scip, &consvars);
641
642 for( c = nnewconss - 1; c >= 0; --c )
643 {
644 assert(newconsnames != NULL);
645 SCIPfreeBufferArrayNull(scip, &newconsnames[c]);
646 }
647
648 SCIPfreeBufferArray(scip, &newconsnames);
649 SCIPfreeBufferArray(scip, &newranges);
650 SCIPfreeBufferArray(scip, &newrhss);
651 SCIPfreeBufferArray(scip, &newsenses);
652 }
653
654 return retval;
655}
656
657
658/** solves the pricing problem with CPLEX */
659static
661 GCG* gcg, /**< GCG data structure (master problem) */
662 GCG_SOLVERDATA* solverdata, /**< solver data structure */
663 SCIP* pricingprob, /**< pricing problem */
664 int probnr, /**< problem number */
665 SCIP_Real dualsolconv, /**< dual solution value of the corresponding convexity constraint */
666 SCIP_Real* lowerbound, /**< pointer to store lower bound */
667 int* ncols, /**< pointer to store number of columns */
668 GCG_PRICINGSTATUS* status /**< pointer to store the pricing status */
669 )
670{ /*lint -e715*/
671 SCIP* scip;
672 GCG_COL* col;
673 SCIP_RETCODE retval;
674 SCIP_Bool predisabled = FALSE;
675 double* cplexsolvals;
676 double objective;
677 double upperbound;
678 double* primsol = NULL;
679 int curpreind = -1;
680 int curadvind = -1;
681 int nsolscplex;
682 int numcols;
683 int cpxstatus;
684 int s;
685
687 *ncols = 0;
689 upperbound = SCIPinfinity(pricingprob);
690
691 retval = SCIP_OKAY;
692
693 numcols = CPXgetnumcols(solverdata->cpxenv[probnr], solverdata->lp[probnr]);
694 assert(numcols == SCIPgetNOrigVars(pricingprob));
695
696 SCIP_CALL( SCIPallocBufferArray(scip, &cplexsolvals, numcols) );
697 SOLVEAGAIN:
698 /* the optimization call */
699 if( predisabled )
700 {
701 CHECK_ZERO( CPXprimopt(solverdata->cpxenv[probnr], solverdata->lp[probnr]) );
702 }
703 else
704 {
705 CHECK_ZERO( CPXmipopt(solverdata->cpxenv[probnr], solverdata->lp[probnr]) );
706 }
707
708 /* get number of solutions */
709 nsolscplex = CPXgetsolnpoolnumsolns(solverdata->cpxenv[probnr], solverdata->lp[probnr]);
710
711 /* get solution status */
712 cpxstatus = CPXgetstat(solverdata->cpxenv[probnr], solverdata->lp[probnr]);
713
714 /* handle CPLEX solution status */
715 switch( cpxstatus )
716 {
717 /* pricing problem was solved to optimality */
718 case CPXMIP_OPTIMAL: /* 101 */
719 assert(nsolscplex > 0);
721 CHECK_ZERO( CPXgetobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], &upperbound) );
722 break;
723
724 /* pricing problem was proven to be infeasible */
725 case CPXMIP_INFEASIBLE: /* 103 */
726 assert(nsolscplex == 0);
728 break;
729
730 /* pricing problem is possibly unbounded */
731 case CPXMIP_UNBOUNDED: /* 118 */
732 case CPXMIP_INForUNBD: /* 119 */
733 {
734 int cpxretval;
735 int dummy;
736
737 SCIP_CALL( SCIPallocBufferArray(scip, &primsol, numcols) );
738
739 CHECK_ZERO( CPXsolution(solverdata->cpxenv[probnr], solverdata->lp[probnr], &dummy, NULL, primsol, NULL, NULL, NULL) );
740
741 assert(dummy == cpxstatus);
742
743 cpxretval = CPXgetray(solverdata->cpxenv[probnr], solverdata->lp[probnr], cplexsolvals);
744
745 if( cpxretval == 1254 )
746 {
747 assert(!predisabled);
748
749 SCIPdebugMessage(" -> disable presolving in CPLEX to get primal ray\n");
750
751 CHECK_ZERO( CPXgetintparam(solverdata->cpxenv[probnr], CPX_PARAM_PREIND, &curpreind) );
752 CHECK_ZERO( CPXgetintparam(solverdata->cpxenv[probnr], CPX_PARAM_ADVIND, &curadvind) );
753
754 CHECK_ZERO( CPXchgprobtype(solverdata->cpxenv[probnr], solverdata->lp[probnr], CPXPROB_FIXEDMILP) );
755
756 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_ADVIND, 0) );
757 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_PREIND, 0) );
758
759 predisabled = TRUE;
760
761 goto SOLVEAGAIN;
762 }
763 else
764 {
765 CHECK_ZERO( cpxretval );
766 }
767
768 SCIP_CALL( GCGcreateGcgCol(gcg, pricingprob, &col, probnr, solverdata->pricingvars[probnr], cplexsolvals, numcols, TRUE, SCIPinfinity(pricingprob)) );
770 ++(*ncols);
771
773
774 SCIPfreeBufferArray(scip, &primsol);
775
776 goto TERMINATE;
777 }
778
779 /* a heuristic pricing limit was reached and may be increased in the next round */
780 /* @todo: CPXMIP_OPTIMAL_TOL = 102 seems to occur even if gaplimit is set to 0 */
781 case CPXMIP_OPTIMAL_TOL: /* 102 */
782 assert(nsolscplex > 0);
783 if( solverdata->gaplimitfac < 1.0 )
784 solverdata->curgaplimit[probnr] *= solverdata->gaplimitfac;
785 else
786 solverdata->curgaplimit[probnr] = MAX(solverdata->curgaplimit[probnr] - solverdata->startgaplimit, 0.0);
787 SCIPdebugMessage(" -> gap limit reached, decreasing to %g\n", solverdata->curgaplimit[probnr]);
789 CHECK_ZERO( CPXgetobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], &upperbound) );
790 break;
791
792 case CPXMIP_NODE_LIM_FEAS: /* 105 */
793 assert(nsolscplex > 0);
794 if( solverdata->nodelimitfac > 1.0 )
795 solverdata->curnodelimit[probnr] = (SCIP_Longint) (solverdata->curnodelimit[probnr] * solverdata->nodelimitfac);
796 else
797 solverdata->curnodelimit[probnr] += solverdata->startnodelimit;
798 SCIPdebugMessage(" -> node limit reached, increasing to %"SCIP_LONGINT_FORMAT"\n", solverdata->curnodelimit[probnr]);
800 CHECK_ZERO( CPXgetobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], &upperbound) );
801 break;
802
803 case CPXMIP_SOL_LIM: /* 104 */
804 assert(nsolscplex > 0);
805 if( solverdata->sollimitfac > 1.0 )
806 solverdata->cursollimit[probnr] = (SCIP_Longint) (solverdata->cursollimit[probnr] * solverdata->sollimitfac);
807 else
808 solverdata->cursollimit[probnr] += solverdata->startsollimit;
809 SCIPdebugMessage(" -> solution limit reached, increasing to %"SCIP_LONGINT_FORMAT"\n", solverdata->cursollimit[probnr]);
811 CHECK_ZERO( CPXgetobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], &upperbound) );
812 break;
813
814 /* no feasible solution was found, not clear whether one exists or the problem is infeasible */
815 case CPXMIP_NODE_LIM_INFEAS: /* 106 */
816 case CPXMIP_TIME_LIM_INFEAS: /* 108 */
817 case CPXMIP_MEM_LIM_INFEAS: /* 111 */
818 case CPXMIP_ABORT_INFEAS: /* 114 */
819 assert(nsolscplex == 0);
821 break;
822
823 /* a feasible solution exists */
824 case CPXMIP_TIME_LIM_FEAS: /* 107 */
825 case CPXMIP_MEM_LIM_FEAS: /* 112 */
826 case CPXMIP_ABORT_FEAS: /* 113 */
827 case CPXMIP_FEASIBLE: /* 127 */
828 assert(nsolscplex > 0);
829 CHECK_ZERO( CPXgetobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], &upperbound) );
831 break;
832
833 default:
835 goto TERMINATE;
836 }
837
838 CHECK_ZERO( CPXgetbestobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], lowerbound) );
839
840 /* In case of optimality, it might happen that the "lower bound" returned by CPLEX exceeds the optimal solution value;
841 * probably, this is not a bug but a feature
842 */
843 *lowerbound = MIN(*lowerbound, upperbound);
844
845 SCIPdebugMessage(" -> pricing problem %d solved: cpxstatus=%d, nsols=%d, lowerbound=%g, upperbound=%g\n", probnr, cpxstatus, nsolscplex, *lowerbound, upperbound);
846
847 assert(SCIPisFeasEQ(scip, *lowerbound, upperbound) || cpxstatus != CPXMIP_OPTIMAL);
848
849#ifndef NDEBUG
850 /* in debug mode, we check that the first solution in the solution pool is the incumbent */
851 if( nsolscplex > 0 )
852 {
853 double oldobjective;
854
855 CHECK_ZERO( CPXgetsolnpoolobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], 0, &oldobjective) );
856
857 for( s = 1; s < nsolscplex; ++s )
858 {
859 CHECK_ZERO( CPXgetsolnpoolobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], s, &objective) );
860 assert(SCIPisFeasGE(scip, objective, oldobjective));
861 }
862 }
863#endif
864
865 /* iterate over all CPLEX solutions and check for negative reduced costs; the first solution should always be the
866 * incumbent, all other solutions are unsorted
867 */
868 for( s = 0; s < nsolscplex; ++s )
869 {
870 SCIP_SOL* sol;
871 SCIP_Bool feasible;
872
873 CHECK_ZERO( CPXgetsolnpoolobjval(solverdata->cpxenv[probnr], solverdata->lp[probnr], s, &objective) );
874
875 CHECK_ZERO( CPXgetsolnpoolx(solverdata->cpxenv[probnr], solverdata->lp[probnr], s, cplexsolvals, 0, numcols - 1) );
876
877 SCIP_CALL( SCIPcreateOrigSol(pricingprob, &sol, NULL) );
878 SCIP_CALL( SCIPsetSolVals(pricingprob, sol, numcols, solverdata->pricingvars[probnr], cplexsolvals) );
879
880 feasible = FALSE;
881
882 /* check whether the solution is feasible */
883 if( !solverdata->checksols )
884 {
885 SCIP_CALL( SCIPcheckSolOrig(pricingprob, sol, &feasible, FALSE, FALSE) );
886
887 /* if the optimal solution is not feasible, we return GCG_PRICINGSTATUS_UNKNOWN as status */
888 if( !feasible && s == 0 )
889 {
891 }
892 }
893 else
894 {
895 feasible = TRUE;
896 }
897
898 if( feasible )
899 {
900 SCIP_CALL( GCGcreateGcgColFromSol(gcg, pricingprob, NULL, NULL, &col, probnr, sol, FALSE, SCIPinfinity(pricingprob)) );
902 ++(*ncols);
903 }
904
905 SCIP_CALL( SCIPfreeSol(pricingprob, &sol) );
906 }
907
908 assert(*status != GCG_PRICINGSTATUS_OPTIMAL || *ncols > 0);
909 TERMINATE:
910 if( predisabled )
911 {
912 assert(curpreind >= 0);
913 assert(curadvind >= 0);
914 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_PREIND, curpreind) );
915 CHECK_ZERO( CPXsetintparam(solverdata->cpxenv[probnr], CPX_PARAM_ADVIND, curadvind) );
916
917 CHECK_ZERO( CPXchgprobtype(solverdata->cpxenv[probnr], solverdata->lp[probnr], CPXPROB_MILP) );
918 }
919
920 if( primsol != NULL )
921 SCIPfreeBufferArray(scip, &primsol);
922
923 SCIPfreeBufferArray(scip, &cplexsolvals);
924
925 return retval;
926}
927
928
929/** destructor of pricing solver to free user data (called when SCIP is exiting) */
930static
931GCG_DECL_SOLVERFREE(solverFreeCplex)
932{
933 GCG_SOLVERDATA* solverdata;
934
935 assert(gcg != NULL);
936 assert(solver != NULL);
937
938 solverdata = GCGsolverGetData(solver);
939 assert(solverdata != NULL);
940
942 GCGsolverSetData(solver, NULL);
943
944 return SCIP_OKAY;
945}
946
947/** solving process initialization method of pricing solver (called when branch and bound process is about to begin) */
948static
949GCG_DECL_SOLVERINITSOL(solverInitsolCplex)
950{
951 GCG_SOLVERDATA* solverdata;
952 int npricingprobs;
953 SCIP* scip;
954
955 int i;
956
957 assert(gcg != NULL);
958 assert(solver != NULL);
959
961 solverdata = GCGsolverGetData(solver);
962 assert(solverdata != NULL);
963
965 npricingprobs = solverdata->npricingprobs;
966
967 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->cpxenv), npricingprobs) );
968 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->lp), npricingprobs) );
969 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->nupdates), npricingprobs) );
970 BMSclearMemoryArray(solverdata->nupdates, npricingprobs);
971
972 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->pricingprobs), npricingprobs) );
973 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->pricingvars), npricingprobs) );
974 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->pricingconss), npricingprobs) );
975 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->npricingvars), npricingprobs) );
976 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(solverdata->nbasicpricingconss), npricingprobs) );
977 BMSclearMemoryArray(solverdata->npricingvars, npricingprobs);
978 BMSclearMemoryArray(solverdata->nbasicpricingconss, npricingprobs);
979
980 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &solverdata->curnodelimit, npricingprobs) );
981 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &solverdata->curgaplimit, npricingprobs) );
982 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &solverdata->cursollimit, npricingprobs) );
983
984 for( i = 0; i < npricingprobs; ++i )
985 {
987 {
988 SCIP_CALL( buildProblem(gcg, solverdata, GCGgetPricingprob(gcg, i), i) );
989 }
990
991 solverdata->curnodelimit[i] = solverdata->startnodelimit;
992 solverdata->curgaplimit[i] = solverdata->startgaplimit;
993 solverdata->cursollimit[i] = solverdata->startsollimit;
994 }
995
996 return SCIP_OKAY;
997}
998
999/** solving process deinitialization method of pricing solver (called before branch and bound process data is freed) */
1000static
1001GCG_DECL_SOLVEREXITSOL(solverExitsolCplex)
1002{
1003 SCIP* scip;
1004 GCG_SOLVERDATA* solverdata;
1005 SCIP_RETCODE retval;
1006 int npricingprobs;
1007 int i;
1008 int j;
1009
1010 assert(gcg != NULL);
1011 assert(solver != NULL);
1012
1014 solverdata = GCGsolverGetData(solver);
1015 assert(solverdata != NULL);
1016
1017 retval = SCIP_OKAY;
1018
1019 npricingprobs = GCGgetNPricingprobs(gcg);
1020
1021 /* free pricing problems */
1022 for( i = 0; i < npricingprobs; ++i )
1023 {
1025 {
1026 /* free LP */
1027 CHECK_ZERO( CPXfreeprob(solverdata->cpxenv[i], &solverdata->lp[i]) );
1028
1029 /* free environment */
1030 CHECK_ZERO( CPXcloseCPLEX(&solverdata->cpxenv[i]) );
1031
1032 if( solverdata->nbasicpricingconss[i] > 0 )
1033 {
1034 /* release stored constraints */
1035 for( j = 0; j < solverdata->nbasicpricingconss[i]; ++j )
1036 {
1037 SCIP_CALL( SCIPreleaseCons(solverdata->pricingprobs[i], &solverdata->pricingconss[i][j]) );
1038 }
1039 SCIPfreeMemoryArray(scip, &(solverdata->pricingconss[i]));
1040 }
1041
1042 if( solverdata->npricingvars[i] > 0 )
1043 {
1044 /* release stored constraints */
1045 for( j = 0; j < solverdata->npricingvars[i]; ++j )
1046 {
1047 SCIP_CALL( SCIPreleaseVar(solverdata->pricingprobs[i], &solverdata->pricingvars[i][j]) );
1048 }
1049 SCIPfreeMemoryArray(scip, &(solverdata->pricingvars[i]));
1050 }
1051 }
1052 }
1053
1054 TERMINATE:
1055 SCIPfreeBlockMemoryArray(scip, &solverdata->cursollimit, solverdata->npricingprobs);
1056 SCIPfreeBlockMemoryArray(scip, &solverdata->curgaplimit, solverdata->npricingprobs);
1057 SCIPfreeBlockMemoryArray(scip, &solverdata->curnodelimit, solverdata->npricingprobs);
1058
1059 SCIPfreeBlockMemoryArray(scip, &(solverdata->nbasicpricingconss), solverdata->npricingprobs);
1060 SCIPfreeBlockMemoryArray(scip, &(solverdata->npricingvars), solverdata->npricingprobs);
1061 SCIPfreeBlockMemoryArray(scip, &(solverdata->pricingconss), solverdata->npricingprobs);
1062 SCIPfreeBlockMemoryArray(scip, &(solverdata->pricingvars), solverdata->npricingprobs);
1063 SCIPfreeBlockMemoryArray(scip, &(solverdata->pricingprobs), solverdata->npricingprobs);
1064
1065 SCIPfreeBlockMemoryArray(scip, &(solverdata->nupdates), solverdata->npricingprobs);
1066 SCIPfreeBlockMemoryArray(scip, &(solverdata->lp), solverdata->npricingprobs);
1067 SCIPfreeBlockMemoryArray(scip, &(solverdata->cpxenv), solverdata->npricingprobs);
1068
1069 return retval;
1070}
1071
1072#define solverInitCplex NULL
1073#define solverExitCplex NULL
1074
1075/** update method for pricing solver, used to update solver specific pricing problem data */
1076static
1077GCG_DECL_SOLVERUPDATE(solverUpdateCplex)
1078{
1079 GCG_SOLVERDATA* solverdata;
1080
1081 solverdata = GCGsolverGetData(solver);
1082 assert(solverdata != NULL);
1083
1084 SCIPdebugMessage("CPLEX solver -- update data for problem %d: varobjschanged = %u, varbndschanged = %u, consschanged = %u\n",
1085 probnr, varobjschanged, varbndschanged, consschanged);
1086
1087 /* update pricing problem information */
1088 SCIP_CALL( updateVars(GCGgetMasterprob(gcg), solverdata, pricingprob, probnr, varobjschanged, varbndschanged) );
1089 if( consschanged )
1090 {
1091 SCIP_CALL( updateBranchingConss(GCGgetMasterprob(gcg), solverdata, pricingprob, probnr) );
1092 }
1093
1094 /* reset heuristic pricing limits */
1095 solverdata->curnodelimit[probnr] = solverdata->startnodelimit;
1096 solverdata->curgaplimit[probnr] = solverdata->startgaplimit;
1097 solverdata->cursollimit[probnr] = solverdata->startsollimit;
1098
1099#ifdef WRITEPROBLEMS
1100 /* Print the pricing problem after updating:
1101 * * after checking variable bounds, because they change in particular when a new generic branching subproblem is considered
1102 * * but not after adding new branching constraints, since objectives will be set afterwards before solving
1103 */
1104 if( varbndschanged && !consschanged )
1105 {
1106 char filename[SCIP_MAXSTRLEN];
1107
1108 ++(solverdata->nupdates[probnr]);
1109
1110 (void) SCIPsnprintf(filename, SCIP_MAXSTRLEN, "cplex-%s-%d-%d.lp", SCIPgetProbName(pricingprob), SCIPgetNNodes(GCGgetMasterprob(gcg)), solverdata->nupdates[probnr]);
1111 SCIPinfoMessage(pricingprob, NULL, "print pricing problem to %s\n", filename);
1112 CHECK_ZERO( CPXwriteprob(solverdata->cpxenv[probnr], solverdata->lp[probnr], filename, "lp") );
1113 }
1114#endif
1115
1116 return SCIP_OKAY;
1117}
1118
1119/** heuristic solving method of CPLEX solver */
1120static
1121GCG_DECL_SOLVERSOLVEHEUR(solverSolveHeurCplex)
1122{
1123 GCG_SOLVERDATA* solverdata;
1124 int ncols;
1125 SCIP_RETCODE retval;
1126
1127 solverdata = GCGsolverGetData(solver);
1128 assert(solverdata != NULL);
1129
1130 SCIPdebugMessage("calling heuristic pricing with CPLEX for pricing problem %d\n", probnr);
1131
1132 retval = SCIP_OKAY;
1133
1134 /* set heuristic limits */
1135 CHECK_ZERO( CPXsetlongparam(solverdata->cpxenv[probnr], CPX_PARAM_NODELIM, (long long) solverdata->curnodelimit[probnr]) );
1136 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPGAP, (double) solverdata->curgaplimit[probnr]) );
1137 CHECK_ZERO( CPXsetlongparam(solverdata->cpxenv[probnr], CPX_PARAM_INTSOLLIM, (long long) solverdata->cursollimit[probnr]) );
1138
1139 /* solve the pricing problem and evaluate solution */
1140 SCIP_CALL( solveCplex(gcg, solverdata, pricingprob, probnr, dualsolconv, lowerbound, &ncols, status) );
1141 assert(*status != GCG_PRICINGSTATUS_OPTIMAL || ncols > 0);
1142
1143 TERMINATE:
1144 return retval;
1145}
1146
1147/** solving method for pricing solver which solves the pricing problem to optimality */
1148static
1149GCG_DECL_SOLVERSOLVE(solverSolveCplex)
1150{
1151 GCG_SOLVERDATA* solverdata;
1152 int ncols;
1153 SCIP_RETCODE retval;
1154
1155 assert(solver != NULL);
1156
1157 solverdata = GCGsolverGetData(solver);
1158 assert(solverdata != NULL);
1159
1160 SCIPdebugMessage("calling exact pricing with CPLEX for pricing problem %d\n", probnr);
1161
1162 retval = SCIP_OKAY;
1163
1164 /* set limits to (infinite/zero) default values */
1165 CHECK_ZERO( CPXsetlongparam(solverdata->cpxenv[probnr], CPX_PARAM_NODELIM, CPX_LONG_MAX) );
1166 CHECK_ZERO( CPXsetdblparam(solverdata->cpxenv[probnr], CPX_PARAM_EPGAP, 0.0) );
1167 CHECK_ZERO( CPXsetlongparam(solverdata->cpxenv[probnr], CPX_PARAM_INTSOLLIM, CPX_LONG_MAX) );
1168
1169 /* solve the pricing problem and evaluate solution */
1170 SCIP_CALL( solveCplex(gcg, solverdata, pricingprob, probnr, dualsolconv, lowerbound, &ncols, status) );
1171 assert(*status != GCG_PRICINGSTATUS_OPTIMAL || ncols > 0);
1172
1173 TERMINATE:
1174 return retval;
1175}
1176
1177/** creates the CPLEX pricing solver and includes it in GCG */
1179 GCG* gcg /**< GCG data structure */
1180 )
1181{
1182 GCG_SOLVERDATA* solverdata;
1183 SCIP* origprob;
1184
1186 solverdata->gcg = gcg;
1187
1189
1192 solverUpdateCplex, solverSolveCplex, solverSolveHeurCplex, solverFreeCplex, solverInitCplex,
1193 solverExitCplex, solverInitsolCplex, solverExitsolCplex, solverdata));
1194
1195 SCIP_CALL( SCIPaddBoolParam(origprob, "pricingsolver/cplex/checksols",
1196 "should solutions of the pricing MIPs be checked for duplicity?",
1197 &solverdata->checksols, TRUE, DEFAULT_CHECKSOLS, NULL, NULL));
1198
1199 SCIP_CALL( SCIPaddIntParam(origprob, "pricingsolver/cplex/threads",
1200 "number of threads the CPLEX pricing solver is allowed to use (0: automatic)",
1201 &solverdata->threads, TRUE, DEFAULT_THREADS, 0, INT_MAX, NULL, NULL));
1202
1203 SCIP_CALL( SCIPaddLongintParam(origprob, "pricingsolver/cplex/startnodelimit",
1204 "start node limit for heuristic pricing",
1206
1207 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/cplex/startgaplimit",
1208 "start gap limit for heuristic pricing",
1209 &solverdata->startgaplimit, TRUE, DEFAULT_STARTGAPLIMIT, 0.0, 1.0, NULL, NULL) );
1210
1211 SCIP_CALL( SCIPaddLongintParam(origprob, "pricingsolver/cplex/startsollimit",
1212 "start solution limit for heuristic pricing",
1214
1215 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/cplex/nodelimitfac",
1216 "factor by which to increase node limit for heuristic pricing (1.0: add start limit)",
1218
1219 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/cplex/gaplimitfac",
1220 "factor by which to decrease gap limit for heuristic pricing (1.0: subtract start limit)",
1221 &solverdata->gaplimitfac, TRUE, DEFAULT_GAPLIMITFAC, 0.0, 1.0, NULL, NULL) );
1222
1223 SCIP_CALL( SCIPaddRealParam(origprob, "pricingsolver/cplex/sollimitfac",
1224 "factor by which to increase solution limit for heuristic pricing (1.0: add start limit)",
1226 return SCIP_OKAY;
1227}
#define DEFAULT_THREADS
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define MAX(x, y)
#define SCIP_LONGINT_FORMAT
#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
GCG_EXPORT SCIP * GCGgetPricingprob(GCG *gcg, int pricingprobnr)
Definition relax_gcg.c:4075
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
GCG_EXPORT SCIP_Bool GCGisPricingprobRelevant(GCG *gcg, int pricingprobnr)
Definition relax_gcg.c:4132
SCIP_STAGE SCIPgetStage(SCIP *scip)
const char * SCIPgetProbName(SCIP *scip)
int SCIPgetNOrigConss(SCIP *scip)
SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
int SCIPgetNOrigVars(SCIP *scip)
SCIP_CONS ** SCIPgetOrigConss(SCIP *scip)
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
SCIP_Real GCGconsGetRhs(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:109
SCIP_RETCODE GCGconsGetVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int nvars)
Definition scip_misc.c:487
SCIP_Real GCGconsGetLhs(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:207
SCIP_RETCODE GCGconsGetVals(SCIP *scip, SCIP_CONS *cons, SCIP_Real *vals, int nvals)
Definition scip_misc.c:618
int GCGconsGetNVars(SCIP *scip, SCIP_CONS *cons)
Definition scip_misc.c:433
void SCIPinfoMessage(SCIP *scip, FILE *file, 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 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 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)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_RETCODE SCIPcaptureCons(SCIP *scip, SCIP_CONS *cons)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocClearBufferArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBufferArrayNull(scip, ptr)
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeastol(SCIP *scip)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
int SCIPvarGetIndex(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetTransVar(SCIP_VAR *var)
SCIP_RETCODE SCIPcaptureVar(SCIP *scip, SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
SCIP_VAR * var
SCIP_VAR ** vars
int j
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
SCIP_SOL * sol
#define NULL
#define BMSclearMemoryArray(ptr, num)
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
various SCIP helper methods
#define SOLVER_HEURENABLED
#define SOLVER_EXACTENABLED
#define SOLVER_NAME
#define SOLVER_DESC
#define SOLVER_PRIORITY
#define DEFAULT_SOLLIMITFAC
#define DEFAULT_STARTSOLLIMIT
static SCIP_RETCODE buildProblem(GCG *gcg, GCG_SOLVERDATA *solverdata, SCIP *pricingprob, int probnr)
static SCIP_RETCODE updateVars(SCIP *scip, GCG_SOLVERDATA *solverdata, SCIP *pricingprob, int probnr, SCIP_Bool varobjschanged, SCIP_Bool varbndschanged)
#define CHECK_ZERO(x)
#define DEFAULT_CHECKSOLS
#define solverInitCplex
#define DEFAULT_STARTGAPLIMIT
static SCIP_RETCODE solveCplex(GCG *gcg, GCG_SOLVERDATA *solverdata, SCIP *pricingprob, int probnr, SCIP_Real dualsolconv, SCIP_Real *lowerbound, int *ncols, GCG_PRICINGSTATUS *status)
#define DEFAULT_STARTNODELIMIT
static SCIP_RETCODE updateBranchingConss(SCIP *scip, GCG_SOLVERDATA *solverdata, SCIP *pricingprob, int probnr)
#define CPX_LONG_MAX
#define DEFAULT_GAPLIMITFAC
#define DEFAULT_NODELIMITFAC
SCIP_RETCODE GCGincludeSolverCplex(GCG *gcg)
#define solverExitCplex
cplex solver for pricing problems
CPXLPptr * lp
SCIP_VAR *** pricingvars
SCIP_CONS *** pricingconss
CPXENVptr * cpxenv
SCIP_Longint startnodelimit
SCIP_Real * curgaplimit
SCIP_Real nodelimitfac
SCIP_Real startgaplimit
SCIP_Bool checksols
SCIP_Real gaplimitfac
SCIP_Longint * cursollimit
SCIP_Longint * curnodelimit
int * nbasicpricingconss
SCIP_Longint startsollimit
SCIP ** pricingprobs
SCIP_Real sollimitfac
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct GCG_Col GCG_COL
Definition type_gcgcol.h:44
enum GCG_PricingStatus GCG_PRICINGSTATUS
@ GCG_PRICINGSTATUS_OPTIMAL
@ GCG_PRICINGSTATUS_UNBOUNDED
@ GCG_PRICINGSTATUS_SOLVERLIMIT
@ GCG_PRICINGSTATUS_INFEASIBLE
@ GCG_PRICINGSTATUS_UNKNOWN
SCIP_OBJSENSE_MINIMIZE
SCIP_INVALIDDATA
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_TRANSFORMED
struct SCIP_Sol SCIP_SOL
#define GCG_DECL_SOLVERFREE(x)
Definition type_solver.h:60
#define GCG_DECL_SOLVERUPDATE(x)
#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
struct SCIP_Var SCIP_VAR
SCIP_VARTYPE_INTEGER
SCIP_VARTYPE_CONTINUOUS
SCIP_VARTYPE_BINARY
enum SCIP_Vartype SCIP_VARTYPE