Scippy

SCIP

Solving Constraint Integer Programs

lpi_grb.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2014 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file lpi_grb.c
17  * @ingroup LPIS
18  * @brief LP interface for Gurobi
19  * @author Marc Pfetsch
20  *
21  * This LPI is beta!
22  *
23  * Several things are missing in the Gurobi interface that make this LPI relatively useless:
24  *
25  * - Gurobi currently does not allow to access the basis inverse.
26  * - Strong branching is supported, but not documented.
27  * - The support of ranged rows is complicated for the user: one has to keep track of the additional
28  * variables, which are added to generate a ranged row. Hence, one would need to adapt the count
29  * of variables and retrieve the information of ranged rows to get the correct answers.
30  *
31  * While the first two issues only influence the performance, the third is critical for some
32  * problems, which contain ranged rows.
33  *
34  * @todo Check whether functions for basis inverses are correct. Which ones are the right ones?
35  *
36  * @todo Check whether solisbasic is correctly used.
37  *
38  * @todo Try quad-precision and concurrent runs.
39  */
40 
41 /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
42 
43 #include <assert.h>
44 #include <string.h>
45 
46 #include "gurobi_c.h"
47 #include "lpi/lpi.h"
48 #include "scip/pub_message.h"
49 
50 static unsigned char warnedbeta = 0;
51 
52 #define CHECK_ZERO(messagehdlr, x) { int _restat_; \
53  if( (_restat_ = (x)) != 0 ) \
54  { \
55  SCIPmessagePrintWarning((messagehdlr), "Gurobi error %d: %s\n", _restat_, GRBgeterrormsg(grbenv)); \
56  return SCIP_LPERROR; \
57  } \
58  }
59 
60 #if GRB_VERSION_MAJOR == 6 && GRB_VERSION_MINOR == 0
61 struct _GRBsvec
62 {
63  int len;
64  int *ind;
65  double *val;
66 };
67 #endif
68 
69 #ifndef SVECTOR
70 #define SVECTOR GRBsvec
71 #endif
72 
73 #if( GRB_VERSION_MAJOR < 4 )
74 #define GRB_METHOD_DUAL GRB_LPMETHOD_DUAL
75 #define GRB_METHOD_PRIMAL GRB_LPMETHOD_PRIMAL
76 #define GRB_INT_PAR_METHOD GRB_INT_PAR_LPMETHOD
77 #endif
78 
79 typedef unsigned int SCIP_SINGLEPACKET; /**< storing single bits in packed format */
80 #define SCIP_SINGLEPACKETSIZE (sizeof(SCIP_SINGLEPACKET)*8) /**< each entry needs one bit of information */
81 typedef unsigned int SCIP_DUALPACKET; /**< storing bit pairs in packed format */
82 #define SCIP_DUALPACKETSIZE (sizeof(SCIP_DUALPACKET)*4) /**< each entry needs two bits of information */
83 
84 typedef SCIP_DUALPACKET COLPACKET; /* each column needs two bits of information (basic/on_lower/on_upper) */
85 #define COLS_PER_PACKET SCIP_DUALPACKETSIZE
86 typedef SCIP_DUALPACKET ROWPACKET; /* each row needs two bit of information (basic/on_lower/on_upper) */
87 #define ROWS_PER_PACKET SCIP_DUALPACKETSIZE
88 
89 
90 /* At several places we need to guarantee to have a factorization of an optimal basis and call the simplex to produce
91  * it. In a numerical perfect world, this should need no iterations. However, due to numerical inaccuracies after
92  * refactorization, it might be necessary to do a few extra pivot steps. */
93 #define GRB_REFACTORMAXITERS 50 /* maximal number of iterations allowed for producing a refactorization of the basis */
94 
95 
96 /* Gurobi parameter lists which can be changed */
97 #define NUMINTPARAM 4
98 
99 static const char* intparam[NUMINTPARAM] =
100 {
101  GRB_INT_PAR_SCALEFLAG,
102  GRB_INT_PAR_PRESOLVE,
103  GRB_INT_PAR_SIMPLEXPRICING,
104  GRB_INT_PAR_OUTPUTFLAG
105 };
106 
107 #define NUMDBLPARAM 6
108 
109 static const char* dblparam[NUMDBLPARAM] =
110 {
111  GRB_DBL_PAR_FEASIBILITYTOL,
112  GRB_DBL_PAR_OPTIMALITYTOL,
113  GRB_DBL_PAR_CUTOFF,
114  GRB_DBL_PAR_TIMELIMIT,
115  GRB_DBL_PAR_ITERATIONLIMIT,
116  GRB_DBL_PAR_MARKOWITZTOL
117 };
118 
119 static const double dblparammin[NUMDBLPARAM] =
120 {
121  +1e-09, /* GRB_DBL_PAR_FEASIBILITYTOL */
122  +1e-09, /* GRB_DBL_PAR_OPTIMALITYTOL */
123  -GRB_INFINITY, /* GRB_DBL_PAR_CUTOFF */
124  0, /* GRB_DBL_PAR_TIMELIMIT */
125  0, /* GRB_DBL_PAR_ITERATIONLIMIT */
126  1e-04 /* GRB_DBL_PAR_MARKOWITZTOL */
127 };
128 
129 /** Gurobi parameter settings */
130 struct GRBParam
131 {
132  int intparval[NUMINTPARAM]; /**< integer parameter values */
133  double dblparval[NUMDBLPARAM]; /**< double parameter values */
134 };
135 typedef struct GRBParam GRBPARAM;
136 
137 
138 /** LP interface */
139 struct SCIP_LPi
140 {
141  GRBmodel* grbmodel; /**< Gurobi model pointer */
142  GRBenv* grbenv; /**< environment corresponding to model */
143  int solstat; /**< solution status of last optimization call */
144  GRBPARAM defparam; /**< default parameter values */
145  GRBPARAM curparam; /**< current parameter values stored in Gurobi LP */
146  GRBPARAM grbparam; /**< current parameter values for this LP */
147  char* senarray; /**< array for storing row senses */
148  SCIP_Real* rhsarray; /**< array for storing rhs values */
149  SCIP_Real* valarray; /**< array for storing coefficient values */
150  int* cstat; /**< array for storing column basis status */
151  int* rstat; /**< array for storing row basis status */
152  int* indarray; /**< array for storing coefficient indices */
153  int sidechgsize; /**< size of senarray */
154  int valsize; /**< size of valarray and indarray */
155  int cstatsize; /**< size of cstat array */
156  int rstatsize; /**< size of rstat array */
157  int iterations; /**< number of iterations used in the last solving call */
158  SCIP_Bool solisbasic; /**< is current LP solution a basic solution? */
159  SCIP_Bool fromscratch; /**< should each solve be performed without previous basis state? */
160  SCIP_PRICING pricing; /**< SCIP pricing setting */
161  SCIP_MESSAGEHDLR* messagehdlr; /**< messagehdlr handler to printing messages, or NULL */
162 };
163 
164 /** LPi state stores basis information */
165 struct SCIP_LPiState
166 {
167  int ncols; /**< number of LP columns */
168  int nrows; /**< number of LP rows */
169  COLPACKET* packcstat; /**< column basis status in compressed form */
170  ROWPACKET* packrstat; /**< row basis status in compressed form */
171 };
172 
173 
174 static GRBenv* grbenv = NULL; /**< Gurobi environment (only needed for initialization) */
175 static int numlp = 0; /**< number of open LP objects */
176 
177 
178 
179 /*
180  * dynamic memory arrays
181  */
182 
183 /** resizes senarray to have at least num entries */
184 static
185 SCIP_RETCODE ensureSidechgMem(
186  SCIP_LPI* lpi, /**< LP interface structure */
187  int num /**< minimal number of entries in array */
188  )
189 {
190  assert(lpi != NULL);
191 
192  if( num > lpi->sidechgsize )
193  {
194  int newsize;
195 
196  newsize = MAX(2*lpi->sidechgsize, num);
197  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->senarray, newsize) );
198  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->rhsarray, newsize) );
199  lpi->sidechgsize = newsize;
200  }
201  assert(num <= lpi->sidechgsize);
202 
203  return SCIP_OKAY;
204 }
205 
206 /** resizes valarray and indarray to have at least num entries */
207 static
208 SCIP_RETCODE ensureValMem(
209  SCIP_LPI* lpi, /**< LP interface structure */
210  int num /**< minimal number of entries in array */
211  )
212 {
213  assert(lpi != NULL);
214 
215  if( num > lpi->valsize )
216  {
217  int newsize;
218 
219  newsize = MAX(2*lpi->valsize, num);
220  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->valarray, newsize) );
221  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->indarray, newsize) );
222  lpi->valsize = newsize;
223  }
224  assert(num <= lpi->valsize);
225 
226  return SCIP_OKAY;
227 }
228 
229 /** resizes cstat array to have at least num entries */
230 static
231 SCIP_RETCODE ensureCstatMem(
232  SCIP_LPI* lpi, /**< LP interface structure */
233  int num /**< minimal number of entries in array */
234  )
235 {
236  assert(lpi != NULL);
237 
238  if( num > lpi->cstatsize )
239  {
240  int newsize;
241 
242  newsize = MAX(2*lpi->cstatsize, num);
243  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->cstat, newsize) );
244  lpi->cstatsize = newsize;
245  }
246  assert(num <= lpi->cstatsize);
247 
248  return SCIP_OKAY;
249 }
250 
251 /** resizes rstat array to have at least num entries */
252 static
253 SCIP_RETCODE ensureRstatMem(
254  SCIP_LPI* lpi, /**< LP interface structure */
255  int num /**< minimal number of entries in array */
256  )
257 {
258  assert(lpi != NULL);
259 
260  if( num > lpi->rstatsize )
261  {
262  int newsize;
263 
264  newsize = MAX(2*lpi->rstatsize, num);
265  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->rstat, newsize) );
266  lpi->rstatsize = newsize;
267  }
268  assert(num <= lpi->rstatsize);
269 
270  return SCIP_OKAY;
271 }
272 
273 /** stores current basis in internal arrays of LPI data structure */
274 static
275 SCIP_RETCODE getBase(
276  SCIP_LPI* lpi, /**< LP interface structure */
277  SCIP_Bool* success /**< whether basis information has successfully been obtained */
278  )
279 {
280  int ncols;
281  int nrows;
282  int res;
283 
284  assert( lpi != NULL );
285  assert( lpi->grbmodel != NULL );
286  assert( lpi->grbenv != NULL );
287 
288  SCIPdebugMessage("getBase()\n");
289  if ( success != NULL )
290  *success = TRUE;
291 
292  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
293  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
294 
295  /* allocate enough memory for storing uncompressed basis information */
296  SCIP_CALL( ensureCstatMem(lpi, ncols) );
297  SCIP_CALL( ensureRstatMem(lpi, nrows) );
298 
299  /* get unpacked basis information from Gurobi */
300  res = GRBgetintattrarray(lpi->grbmodel, GRB_INT_ATTR_VBASIS, 0, ncols, lpi->cstat);
301  if ( res == GRB_ERROR_DATA_NOT_AVAILABLE )
302  {
303  /* if the model is infeasible Gurobi does not currently return basis information */
304  if ( success != NULL )
305  *success = FALSE;
306  return SCIP_OKAY;
307  }
308  else if ( res != 0 )
309  {
310  SCIPerrorMessage("Gurobi error %d: %s\n", res, GRBgeterrormsg(lpi->grbenv));
311  return SCIP_LPERROR;
312  }
313 
314  res = GRBgetintattrarray(lpi->grbmodel, GRB_INT_ATTR_CBASIS, 0, nrows, lpi->rstat);
315  if ( res == GRB_ERROR_DATA_NOT_AVAILABLE )
316  {
317  /* if the model is infeasible Gurobi does not currently return basis information */
318  if ( success != NULL )
319  *success = FALSE;
320  return SCIP_OKAY;
321  }
322  else if ( res != 0 )
323  {
324  SCIPerrorMessage("Gurobi error %d: %s\n", res, GRBgeterrormsg(lpi->grbenv));
325  return SCIP_LPERROR;
326  }
327 
328  return SCIP_OKAY;
329 }
330 
331 /** loads basis stored in internal arrays of LPI data structure into Gurobi */
332 static
333 SCIP_RETCODE setBase(
334  SCIP_LPI* lpi /**< LP interface structure */
335  )
336 {
337  int ncols;
338  int nrows;
339 
340  assert( lpi != NULL );
341  assert( lpi->grbmodel != NULL );
342 
343  SCIPdebugMessage("setBase()\n");
344 
345  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
346  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
347 
348  /* load basis information into Gurobi */
349  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrarray(lpi->grbmodel, GRB_INT_ATTR_VBASIS, 0, ncols, lpi->cstat) );
350  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrarray(lpi->grbmodel, GRB_INT_ATTR_CBASIS, 0, nrows, lpi->rstat) );
351 
352  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
353 
354  return SCIP_OKAY;
355 }
356 
357 
358 
359 
360 /*
361  * LPi state methods
362  */
363 
364 /** returns the number of packets needed to store column packet information */
365 static
366 int colpacketNum(
367  int ncols /**< number of columns to store */
368  )
369 {
370  return (ncols+(int)COLS_PER_PACKET-1)/(int)COLS_PER_PACKET;
371 }
372 
373 /** returns the number of packets needed to store row packet information */
374 static
375 int rowpacketNum(
376  int nrows /**< number of rows to store */
377  )
378 {
379  return (nrows+(int)ROWS_PER_PACKET-1)/(int)ROWS_PER_PACKET;
380 }
381 
382 
383 /* The basis information for Gurobi is negative. So we cannot use the functions in bitencode.h/c. The functions below are a modified copy. */
384 
385 /** encode a negated dual bit vector into packed format */
386 static
387 void SCIPencodeDualBitNeg(
388  const int* inp, /**< unpacked input vector */
389  SCIP_DUALPACKET* out, /**< buffer to store the packed vector */
390  int count /**< number of elements */
391  )
392 {
393  static const SCIP_DUALPACKET mask[SCIP_DUALPACKETSIZE][4] = { /* if the packet size changes, the mask has to be updated */
394  {0x00000000, 0x00000001, 0x00000002, 0x00000003},
395  {0x00000000, 0x00000004, 0x00000008, 0x0000000C},
396  {0x00000000, 0x00000010, 0x00000020, 0x00000030},
397  {0x00000000, 0x00000040, 0x00000080, 0x000000C0},
398  {0x00000000, 0x00000100, 0x00000200, 0x00000300},
399  {0x00000000, 0x00000400, 0x00000800, 0x00000C00},
400  {0x00000000, 0x00001000, 0x00002000, 0x00003000},
401  {0x00000000, 0x00004000, 0x00008000, 0x0000C000},
402  {0x00000000, 0x00010000, 0x00020000, 0x00030000},
403  {0x00000000, 0x00040000, 0x00080000, 0x000C0000},
404  {0x00000000, 0x00100000, 0x00200000, 0x00300000},
405  {0x00000000, 0x00400000, 0x00800000, 0x00C00000},
406  {0x00000000, 0x01000000, 0x02000000, 0x03000000},
407  {0x00000000, 0x04000000, 0x08000000, 0x0C000000},
408  {0x00000000, 0x10000000, 0x20000000, 0x30000000},
409  {0x00000000, 0x40000000, 0x80000000, 0xC0000000}
410  };
411  int i;
412  int rest;
413  int nfull;
414 
415  assert(inp != NULL || count == 0);
416  assert(out != NULL || count == 0);
417  assert(count >= 0);
418  assert(SCIP_DUALPACKETSIZE == 16);
419 
420  rest = count % (int)SCIP_DUALPACKETSIZE;
421  nfull = count - rest;
422 
423  for( i = 0; i < nfull; i += (int)SCIP_DUALPACKETSIZE, inp += (int)SCIP_DUALPACKETSIZE )
424  {
425  assert(inp != NULL);
426  assert(out != NULL);
427 
428 #ifndef NDEBUG
429  {
430  unsigned int j;
431  for( j = 0; j < SCIP_DUALPACKETSIZE; ++j )
432  assert(0 <= -inp[j] && -inp[j] <= 3);
433  }
434 #endif
435  *out++ =
436  mask[0][-inp[0]] | mask[1][-inp[1]] | mask[2][-inp[2]] | mask[3][inp[3]]
437  | mask[4][-inp[4]] | mask[5][-inp[5]] | mask[6][-inp[6]]
438  | mask[7][-inp[7]] | mask[8][-inp[8]] | mask[9][-inp[9]]
439  | mask[10][-inp[10]] | mask[11][-inp[11]] | mask[12][-inp[12]]
440  | mask[13][-inp[13]] | mask[14][-inp[14]] | mask[15][-inp[15]];
441  }
442 
443  if( rest > 0 )
444  {
446 
447  assert(inp != NULL);
448  assert(out != NULL);
449 
450  for( i = 0; i < rest; i++ )
451  m |= mask[i][-inp[i]];
452  *out = m;
453  }
454 }
455 
456 /** decode a packed dual bit vector into negated unpacked format */
457 static
458 void SCIPdecodeDualBitNeg(
459  const SCIP_DUALPACKET* inp, /**< packed input vector */
460  int* out, /**< buffer to store unpacked vector */
461  int count /**< number of elements */
462  )
463 {
464  SCIP_DUALPACKET m;
465  int rest;
466  int nfull;
467  int i;
468 
469  assert(inp != NULL || count == 0);
470  assert(out != NULL || count == 0);
471  assert(count >= 0);
472  assert(SCIP_DUALPACKETSIZE == 16);
473 
474  rest = count % (int)SCIP_DUALPACKETSIZE;
475  nfull = count - rest;
476 
477  for( i = 0; i < nfull; i += (int)SCIP_DUALPACKETSIZE )
478  {
479  assert(inp != NULL);
480  assert(out != NULL);
481 
482  m = *inp++;
483 
484  *out++ = -(int)(m & 3);
485  m >>= 2;
486  *out++ = -(int)(m & 3);
487  m >>= 2;
488  *out++ = -(int)(m & 3);
489  m >>= 2;
490  *out++ = -(int)(m & 3);
491  m >>= 2;
492  *out++ = -(int)(m & 3);
493  m >>= 2;
494  *out++ = -(int)(m & 3);
495  m >>= 2;
496  *out++ = -(int)(m & 3);
497  m >>= 2;
498  *out++ = -(int)(m & 3);
499  m >>= 2;
500  *out++ = -(int)(m & 3);
501  m >>= 2;
502  *out++ = -(int)(m & 3);
503  m >>= 2;
504  *out++ = -(int)(m & 3);
505  m >>= 2;
506  *out++ = -(int)(m & 3);
507  m >>= 2;
508  *out++ = -(int)(m & 3);
509  m >>= 2;
510  *out++ = -(int)(m & 3);
511  m >>= 2;
512  *out++ = -(int)(m & 3);
513  m >>= 2;
514  *out++ = -(int)(m & 3);
515  assert(m >> 2 == 0);
516  }
517 
518  if( rest > 0 )
519  {
520  assert(inp != NULL);
521  assert(out != NULL);
522 
523  m = *inp;
524  for( i = 0; i < rest; i++ )
525  {
526  *out++ = -(int)(m & 3);
527  m >>= 2;
528  }
529  }
530 }
531 
532 /** store row and column basis status in a packed LPi state object */
533 static
534 void lpistatePack(
535  SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
536  const int* cstat, /**< basis status of columns in unpacked format */
537  const int* rstat /**< basis status of rows in unpacked format */
538  )
539 {
540  assert(lpistate != NULL);
541  assert(lpistate->packcstat != NULL);
542  assert(lpistate->packrstat != NULL);
543 
544  SCIPencodeDualBitNeg(cstat, lpistate->packcstat, lpistate->ncols);
545  SCIPencodeDualBitNeg(rstat, lpistate->packrstat, lpistate->nrows);
546 }
547 
548 /** unpacks row and column basis status from a packed LPi state object */
549 static
550 void lpistateUnpack(
551  const SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
552  int* cstat, /**< buffer for storing basis status of columns in unpacked format */
553  int* rstat /**< buffer for storing basis status of rows in unpacked format */
554  )
555 {
556  assert(lpistate != NULL);
557  assert(lpistate->packcstat != NULL);
558  assert(lpistate->packrstat != NULL);
559 
560  SCIPdecodeDualBitNeg(lpistate->packcstat, cstat, lpistate->ncols);
561  SCIPdecodeDualBitNeg(lpistate->packrstat, rstat, lpistate->nrows);
562 }
563 
564 /** creates LPi state information object */
565 static
566 SCIP_RETCODE lpistateCreate(
567  SCIP_LPISTATE** lpistate, /**< pointer to LPi state */
568  BMS_BLKMEM* blkmem, /**< block memory */
569  int ncols, /**< number of columns to store */
570  int nrows /**< number of rows to store */
571  )
572 {
573  assert(lpistate != NULL);
574  assert(blkmem != NULL);
575  assert(ncols >= 0);
576  assert(nrows >= 0);
577 
578  SCIP_ALLOC( BMSallocBlockMemory(blkmem, lpistate) );
579  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum(ncols)) );
580  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum(nrows)) );
581 
582  return SCIP_OKAY;
583 }
584 
585 /** frees LPi state information */
586 static
587 void lpistateFree(
588  SCIP_LPISTATE** lpistate, /**< pointer to LPi state information (like basis information) */
589  BMS_BLKMEM* blkmem /**< block memory */
590  )
591 {
592  assert(blkmem != NULL);
593  assert(lpistate != NULL);
594  assert(*lpistate != NULL);
595 
596  BMSfreeBlockMemoryArrayNull(blkmem, &(*lpistate)->packcstat, colpacketNum((*lpistate)->ncols));
597  BMSfreeBlockMemoryArrayNull(blkmem, &(*lpistate)->packrstat, rowpacketNum((*lpistate)->nrows));
598  BMSfreeBlockMemory(blkmem, lpistate);
599 }
600 
601 
602 
603 /*
604  * local methods
605  */
606 
607 /** gets all Gurobi parameters used in LPI */
608 static
609 SCIP_RETCODE getParameterValues(
610  SCIP_LPI* lpi, /**< LP interface structure */
611  GRBPARAM* grbparam /**< Gurobi parameters */
612  )
613 {
614  int i;
615 
616  assert( lpi != NULL );
617  assert( lpi->grbenv != NULL );
618  assert( grbparam != NULL );
619 
620  SCIPdebugMessage("getParameterValues()\n");
621 
622  for( i = 0; i < NUMINTPARAM; ++i )
623  {
624  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, intparam[i], &(grbparam->intparval[i])) );
625  }
626  for( i = 0; i < NUMDBLPARAM; ++i )
627  {
628  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, dblparam[i], &(grbparam->dblparval[i])) );
629  }
630 
631  return SCIP_OKAY;
632 }
633 
634 /** in debug mode, checks validity of Gurobi parameters */
635 static
636 SCIP_RETCODE checkParameterValues(
637  SCIP_LPI* lpi /**< LP interface structure */
638  )
639 {
640 #ifndef NDEBUG
641  GRBPARAM par;
642  int i;
643 
644  SCIP_CALL( getParameterValues(lpi, &par) );
645  for (i = 0; i < NUMINTPARAM; ++i)
646  assert( lpi->curparam.intparval[i] == par.intparval[i] );
647  for (i = 0; i < NUMDBLPARAM; ++i)
648  assert(MAX(lpi->curparam.dblparval[i], dblparammin[i]) == par.dblparval[i]); /*lint !e777*/
649 #endif
650 
651  return SCIP_OKAY;
652 }
653 
654 /** sets all Gurobi parameters used in LPI */
655 static
656 SCIP_RETCODE setParameterValues(
657  SCIP_LPI* lpi, /**< LP interface structure */
658  GRBPARAM* grbparam /**< Gurobi parameters */
659  )
660 {
661  int i;
662 
663  assert( lpi != NULL );
664  assert( lpi->grbenv != NULL );
665  assert( grbparam != NULL );
666 
667  SCIPdebugMessage("setParameterValues()\n");
668 
669  for( i = 0; i < NUMINTPARAM; ++i )
670  {
671  if( lpi->curparam.intparval[i] != grbparam->intparval[i] )
672  {
673  SCIPdebugMessage("setting Gurobi int parameter %s from %d to %d\n",
674  intparam[i], lpi->curparam.intparval[i], grbparam->intparval[i]);
675  lpi->curparam.intparval[i] = grbparam->intparval[i];
676  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, intparam[i], lpi->curparam.intparval[i]) );
677  }
678  }
679  for( i = 0; i < NUMDBLPARAM; ++i )
680  {
681  if( lpi->curparam.dblparval[i] != grbparam->dblparval[i] ) /*lint !e777*/
682  {
683  SCIPdebugMessage("setting Gurobi dbl parameter %s from %g to %g\n",
684  dblparam[i], lpi->curparam.dblparval[i], MAX(grbparam->dblparval[i], dblparammin[i]));
685  lpi->curparam.dblparval[i] = MAX(grbparam->dblparval[i], dblparammin[i]);
686  CHECK_ZERO( lpi->messagehdlr, GRBsetdblparam(lpi->grbenv, dblparam[i], lpi->curparam.dblparval[i]) );
687  }
688  }
689 
690  SCIP_CALL( checkParameterValues(lpi) );
691 
692  return SCIP_OKAY;
693 }
694 
695 /** copies Gurobi parameters from source to dest */
696 static
697 void copyParameterValues(
698  GRBPARAM* dest, /**< destination Gurobi parameters */
699  const GRBPARAM* source /**< original Gurobi parameters */
700  )
701 {
702  int i;
703 
704  for( i = 0; i < NUMINTPARAM; ++i )
705  dest->intparval[i] = source->intparval[i];
706  for( i = 0; i < NUMDBLPARAM; ++i )
707  dest->dblparval[i] = source->dblparval[i];
708 }
709 
710 /** gets a single integer parameter value */
711 static
712 SCIP_RETCODE getIntParam(
713  SCIP_LPI* lpi, /**< LP interface structure */
714  const char* param, /**< parameter name */
715  int* p /**< value of parameter */
716  )
717 {
718  int i;
719 
720  assert( lpi != NULL );
721 
722  for( i = 0; i < NUMINTPARAM; ++i )
723  {
724  if( strcmp(intparam[i], param) == 0 )
725  {
726  *p = lpi->grbparam.intparval[i];
727  return SCIP_OKAY;
728  }
729  }
730 
731  SCIPerrorMessage("unknown Gurobi integer parameter <%s>.\n", param);
732  return SCIP_LPERROR;
733 }
734 
735 /** sets a single integer parameter value */
736 static
737 SCIP_RETCODE setIntParam(
738  SCIP_LPI* lpi, /**< LP interface structure */
739  const char* param, /**< parameter name */
740  int parval /**< value of parameter */
741  )
742 {
743  int i;
744 
745  assert( lpi != NULL );
746 
747  for( i = 0; i < NUMINTPARAM; ++i )
748  {
749  if( strcmp(intparam[i], param) == 0 )
750  {
751  lpi->grbparam.intparval[i] = parval;
752  return SCIP_OKAY;
753  }
754  }
755 
756  SCIPerrorMessage("unknown Gurobi integer parameter <%s>.\n", param);
757  return SCIP_LPERROR;
758 }
759 
760 /** gets a single double parameter value */
761 static
762 SCIP_RETCODE getDblParam(SCIP_LPI* lpi, const char* param, double* p)
763 {
764  int i;
765 
766  assert(lpi != NULL);
767 
768  for( i = 0; i < NUMDBLPARAM; ++i )
769  {
770  if( strcmp(dblparam[i], param) == 0 )
771  {
772  *p = lpi->grbparam.dblparval[i];
773  return SCIP_OKAY;
774  }
775  }
776 
777  SCIPerrorMessage("unknown Gurobi double parameter <%s>.\n", param);
778  return SCIP_LPERROR;
779 }
780 
781 /** sets a single double parameter value */
782 static
783 SCIP_RETCODE setDblParam(
784  SCIP_LPI* lpi, /**< LP interface structure */
785  const char* param, /**< parameter name */
786  double parval /**< value of parameter */
787  )
788 {
789  int i;
790 
791  assert( lpi != NULL );
792 
793  for( i = 0; i < NUMDBLPARAM; ++i )
794  {
795  if( strcmp(dblparam[i], param) == 0 )
796  {
797  lpi->grbparam.dblparval[i] = parval;
798  return SCIP_OKAY;
799  }
800  }
801 
802  SCIPerrorMessage("unknown Gurobi double parameter <%s>.\n", param);
803  return SCIP_LPERROR;
804 }
805 
806 /** marks the current LP to be unsolved */
807 static
808 void invalidateSolution(
809  SCIP_LPI* lpi /**< LP interface structure */
810  )
811 {
812  assert(lpi != NULL);
813  lpi->solstat = -1;
814 }
815 
816 /** converts SCIP's lhs/rhs pairs into Gurobi's sen/rhs */
817 static
818 SCIP_RETCODE convertSides(
819  SCIP_LPI* lpi, /**< LP interface structure */
820  int nrows, /**< number of rows */
821  const SCIP_Real* lhs, /**< left hand side vector */
822  const SCIP_Real* rhs, /**< right hand side vector */
823  int* rngcount /**< number of ranged rows found */
824  )
825 {
826  int i;
827 
828  assert(lpi != NULL);
829  assert(nrows >= 0);
830  assert(lhs != NULL);
831  assert(rhs != NULL);
832 
833  /* convert lhs/rhs into sen/rhs */
834  *rngcount = 0;
835  for( i = 0; i < nrows; ++i )
836  {
837  assert(lhs[i] <= rhs[i]);
838 
839  if( lhs[i] == rhs[i] ) /*lint !e777*/
840  {
841  assert(-GRB_INFINITY < rhs[i] && rhs[i] < GRB_INFINITY);
842  lpi->senarray[i] = GRB_EQUAL;
843  lpi->rhsarray[i] = rhs[i];
844  }
845  else if( lhs[i] <= -GRB_INFINITY )
846  {
847  assert(-GRB_INFINITY < rhs[i] && rhs[i] < GRB_INFINITY);
848  lpi->senarray[i] = GRB_LESS_EQUAL;
849  lpi->rhsarray[i] = rhs[i];
850  }
851  else if( rhs[i] >= GRB_INFINITY )
852  {
853  assert(-GRB_INFINITY < lhs[i] && lhs[i] < GRB_INFINITY);
854  lpi->senarray[i] = GRB_GREATER_EQUAL;
855  lpi->rhsarray[i] = lhs[i];
856  }
857  else
858  {
859  /* Gurobi cannot handle ranged rows */
860  SCIPerrorMessage("Gurobi cannot handle ranged rows.\n");
861  SCIPABORT();
862  return SCIP_LPERROR;
863  /* (*rngcount)++; */
864  }
865  }
866  return SCIP_OKAY;
867 }
868 
869 /** converts Gurobi's sen/rhs pairs into SCIP's lhs/rhs pairs */
870 static
871 SCIP_RETCODE reconvertBothSides(
872  SCIP_LPI* lpi, /**< LP interface structure */
873  int nrows, /**< number of rows */
874  SCIP_Real* lhs, /**< buffer to store the left hand side vector */
875  SCIP_Real* rhs /**< buffer to store the right hand side vector */
876  )
877 {
878  int i;
879 
880  assert(lpi != NULL);
881  assert(nrows >= 0);
882  assert(lhs != NULL);
883  assert(rhs != NULL);
884 
885  for (i = 0; i < nrows; ++i)
886  {
887  switch( lpi->senarray[i] )
888  {
889  case GRB_EQUAL:
890  lhs[i] = lpi->rhsarray[i];
891  rhs[i] = lpi->rhsarray[i];
892  break;
893 
894  case GRB_LESS_EQUAL:
895  lhs[i] = -GRB_INFINITY;
896  rhs[i] = lpi->rhsarray[i];
897  break;
898 
899  case GRB_GREATER_EQUAL:
900  lhs[i] = lpi->rhsarray[i];
901  rhs[i] = GRB_INFINITY;
902  break;
903 
904  default:
905  SCIPerrorMessage("invalid row sense\n");
906  SCIPABORT();
907  return SCIP_LPERROR;
908  }
909  assert(lhs[i] <= rhs[i]);
910  }
911  return SCIP_OKAY;
912 }
913 
914 /** converts Gurobi's sen/rhs pairs into SCIP's lhs/rhs pairs, only storing the left hand side */
915 static
916 SCIP_RETCODE reconvertLhs(
917  SCIP_LPI* lpi, /**< LP interface structure */
918  int nrows, /**< number of rows */
919  SCIP_Real* lhs /**< buffer to store the left hand side vector */
920  )
921 {
922  int i;
923 
924  assert(lpi != NULL);
925  assert(nrows >= 0);
926  assert(lhs != NULL);
927 
928  for (i = 0; i < nrows; ++i)
929  {
930  switch( lpi->senarray[i] )
931  {
932  case GRB_EQUAL:
933  lhs[i] = lpi->rhsarray[i];
934  break;
935 
936  case GRB_LESS_EQUAL:
937  lhs[i] = -GRB_INFINITY;
938  break;
939 
940  case GRB_GREATER_EQUAL:
941  lhs[i] = lpi->rhsarray[i];
942  break;
943 
944  default:
945  SCIPerrorMessage("invalid row sense\n");
946  SCIPABORT();
947  return SCIP_LPERROR;
948  }
949  }
950  return SCIP_OKAY;
951 }
952 
953 /** converts Gurobi's sen/rhs pairs into SCIP's lhs/rhs pairs, only storing the right hand side */
954 static
955 SCIP_RETCODE reconvertRhs(
956  SCIP_LPI* lpi, /**< LP interface structure */
957  int nrows, /**< number of rows */
958  SCIP_Real* rhs /**< buffer to store the right hand side vector */
959  )
960 {
961  int i;
962 
963  assert(lpi != NULL);
964  assert(nrows >= 0);
965  assert(rhs != NULL);
966 
967  for (i = 0; i < nrows; ++i)
968  {
969  switch( lpi->senarray[i] )
970  {
971  case GRB_EQUAL:
972  rhs[i] = lpi->rhsarray[i];
973  break;
974 
975  case GRB_LESS_EQUAL:
976  rhs[i] = lpi->rhsarray[i];
977  break;
978 
979  case GRB_GREATER_EQUAL:
980  rhs[i] = GRB_INFINITY;
981  break;
982 
983  default:
984  SCIPerrorMessage("invalid row sense\n");
985  SCIPABORT();
986  return SCIP_LPERROR;
987  }
988  }
989  return SCIP_OKAY;
990 }
991 
992 /** converts Gurobi's sen/rhs pairs into SCIP's lhs/rhs pairs */
993 static
994 SCIP_RETCODE reconvertSides(
995  SCIP_LPI* lpi, /**< LP interface structure */
996  int nrows, /**< number of rows */
997  SCIP_Real* lhs, /**< buffer to store the left hand side vector, or NULL */
998  SCIP_Real* rhs /**< buffer to store the right hand side vector, or NULL */
999  )
1000 {
1001  if( lhs != NULL && rhs != NULL )
1002  {
1003  SCIP_CALL( reconvertBothSides(lpi, nrows, lhs, rhs) );
1004  }
1005  else if( lhs != NULL )
1006  {
1007  SCIP_CALL( reconvertLhs(lpi, nrows, lhs) );
1008  }
1009  else if( rhs != NULL )
1010  {
1011  SCIP_CALL( reconvertRhs(lpi, nrows, rhs) );
1012  }
1013  return SCIP_OKAY;
1014 }
1015 
1016 /** after restoring old LP data, need to resolve the LP to be able to retrieve correct information */
1017 static
1018 SCIP_RETCODE restoreLPData(
1019  SCIP_LPI* lpi /**< LP interface structure */
1020  )
1021 {
1022  assert( lpi != NULL );
1023 
1024  /* set dual simplex */
1025  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, GRB_METHOD_DUAL) );
1026  CHECK_ZERO( lpi->messagehdlr, GRBoptimize(lpi->grbmodel) );
1027 
1028 #ifndef NDEBUG
1029  {
1030  double cnt;
1031 
1032  /* modifying the LP, restoring the old LP, and loading the old basis is not enough for Gurobi to be able to return
1033  * the basis -> we have to resolve the LP;
1034  *
1035  * In a numerical perfect world, GRB_REFACTORMAXITERS below should be zero. However, due to numerical inaccuracies
1036  * after refactorization, it might be necessary to do a few extra pivot steps.
1037  */
1038  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
1039  if ( cnt > (double) GRB_REFACTORMAXITERS )
1040  SCIPmessagePrintWarning(lpi->messagehdlr, "Gurobi needed %d iterations to restore optimal basis.\n", (int) cnt);
1041  }
1042 #endif
1043 
1044  return SCIP_OKAY;
1045 }
1046 
1047 
1048 
1049 /*
1050  * LP Interface Methods
1051  */
1052 
1053 
1054 /*
1055  * Miscellaneous Methods
1056  */
1057 
1058 static char grbname[100];
1059 
1060 /**@name Miscellaneous Methods */
1061 /**@{ */
1062 
1063 /** gets name and version of LP solver */
1065  void
1066  )
1067 {
1068  int major;
1069  int minor;
1070  int technical;
1071 
1072  GRBversion(&major, &minor, &technical);
1073  sprintf(grbname, "Gurobi %d.%d.%d", major, minor, technical);
1074  return grbname;
1075 }
1076 
1077 /** gets description of LP solver (developer, webpage, ...) */
1079  void
1080  )
1081 {
1082  return "Linear Programming Solver developed by Gurobi Optimization (www.gurobi.com)";
1083 }
1084 
1085 /** gets pointer for LP solver - use only with great care
1086  *
1087  * Here we return the pointer to the model.
1088  */
1090  SCIP_LPI* lpi /**< pointer to an LP interface structure */
1091  )
1092 {
1093  return (void*) lpi->grbmodel;
1094 }
1095 /**@} */
1096 
1097 
1098 
1099 
1100 /*
1101  * LPI Creation and Destruction Methods
1102  */
1103 
1104 /**@name LPI Creation and Destruction Methods */
1105 /**@{ */
1106 
1107 /** creates an LP problem object */
1109  SCIP_LPI** lpi, /**< pointer to an LP interface structure */
1110  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler to use for printing messages, or NULL */
1111  const char* name, /**< problem name */
1112  SCIP_OBJSEN objsen /**< objective sense */
1113  )
1114 {
1115  assert(sizeof(SCIP_Real) == sizeof(double)); /* Gurobi only works with doubles as floating points */
1116  assert(sizeof(SCIP_Bool) == sizeof(int)); /* Gurobi only works with ints as bools */
1117  assert(lpi != NULL);
1118  assert(numlp >= 0);
1119 
1120  SCIPdebugMessage("SCIPlpiCreate()\n");
1121 
1122  /* create environment
1123  *
1124  * Each problem will get a copy of the original environment. Thus, grbenv is only needed once.
1125  */
1126  if ( grbenv == NULL )
1127  {
1128  /* initialize environment - no log file */
1129  CHECK_ZERO( messagehdlr, GRBloadenv(&grbenv, NULL) );
1130 
1131  /* turn off output for all models */
1132  CHECK_ZERO( messagehdlr, GRBsetintparam(grbenv, GRB_INT_PAR_OUTPUTFLAG, 0) );
1133 
1134  /* turn on that basis information for infeasible and unbounded models is available */
1135  CHECK_ZERO( messagehdlr, GRBsetintparam(grbenv, GRB_INT_PAR_INFUNBDINFO, 1) );
1136  }
1137  assert( grbenv != NULL );
1138 
1139  /* create empty LPI */
1140  SCIP_ALLOC( BMSallocMemory(lpi) );
1141  CHECK_ZERO( messagehdlr, GRBnewmodel(grbenv, &(*lpi)->grbmodel, name, 0, NULL, NULL, NULL, NULL, NULL) );
1142 
1143  /* get local copy of environment */
1144  (*lpi)->grbenv = GRBgetenv((*lpi)->grbmodel);
1145  (*lpi)->senarray = NULL;
1146  (*lpi)->rhsarray = NULL;
1147  (*lpi)->valarray = NULL;
1148  (*lpi)->cstat = NULL;
1149  (*lpi)->rstat = NULL;
1150  (*lpi)->indarray = NULL;
1151  (*lpi)->sidechgsize = 0;
1152  (*lpi)->valsize = 0;
1153  (*lpi)->cstatsize = 0;
1154  (*lpi)->rstatsize = 0;
1155  (*lpi)->iterations = 0;
1156  (*lpi)->solisbasic = FALSE;
1157  (*lpi)->fromscratch = FALSE;
1158  (*lpi)->pricing = SCIP_PRICING_LPIDEFAULT;
1159  (*lpi)->messagehdlr = messagehdlr;
1160  invalidateSolution(*lpi);
1161 
1162  /* get default parameter values */
1163  SCIP_CALL( getParameterValues((*lpi), &((*lpi)->defparam)) );
1164  copyParameterValues(&((*lpi)->curparam), &((*lpi)->defparam));
1165  copyParameterValues(&((*lpi)->grbparam), &((*lpi)->defparam));
1166  ++numlp;
1167 
1168  /* set objective sense */
1169  SCIP_CALL( SCIPlpiChgObjsen(*lpi, objsen) );
1170 
1171  /* set default pricing */
1172  SCIP_CALL( SCIPlpiSetIntpar(*lpi, SCIP_LPPAR_PRICING, (*lpi)->pricing) );
1173 
1174  if( !warnedbeta ) {
1175  warnedbeta = 1;
1176  SCIPmessagePrintWarning(messagehdlr, "The Gurobi LPI is a beta version only - use with care.\n");
1177  }
1178 
1179  return SCIP_OKAY;
1180 }
1181 
1182 /** deletes an LP problem object */
1184  SCIP_LPI** lpi /**< pointer to an LP interface structure */
1185  )
1186 {
1187  assert(grbenv != NULL);
1188  assert(lpi != NULL);
1189  assert(*lpi != NULL);
1190 
1191  SCIPdebugMessage("SCIPlpiFree()\n");
1192 
1193  /* free model */
1194  CHECK_ZERO( (*lpi)->messagehdlr, GRBfreemodel((*lpi)->grbmodel) );
1195 
1196  /* free memory */
1197  BMSfreeMemoryArrayNull(&(*lpi)->senarray);
1198  BMSfreeMemoryArrayNull(&(*lpi)->rhsarray);
1199  BMSfreeMemoryArrayNull(&(*lpi)->cstat);
1200  BMSfreeMemoryArrayNull(&(*lpi)->rstat);
1201  BMSfreeMemory(lpi);
1202 
1203  /* free environment */
1204  --numlp;
1205  if( numlp == 0 )
1206  {
1207  GRBfreeenv(grbenv);
1208  grbenv = NULL;
1209  }
1210 
1211  return SCIP_OKAY;
1212 }
1213 
1214 /**@} */
1215 
1216 
1217 
1218 
1219 /*
1220  * Modification Methods
1221  */
1222 
1223 /**@name Modification Methods */
1224 /**@{ */
1225 
1226 /** copies LP data with column matrix into LP solver */
1228  SCIP_LPI* lpi, /**< LP interface structure */
1229  SCIP_OBJSEN objsen, /**< objective sense */
1230  int ncols, /**< number of columns */
1231  const SCIP_Real* obj, /**< objective function values of columns */
1232  const SCIP_Real* lb, /**< lower bounds of columns */
1233  const SCIP_Real* ub, /**< upper bounds of columns */
1234  char** colnames, /**< column names, or NULL */
1235  int nrows, /**< number of rows */
1236  const SCIP_Real* lhs, /**< left hand sides of rows */
1237  const SCIP_Real* rhs, /**< right hand sides of rows */
1238  char** rownames, /**< row names, or NULL */
1239  int nnonz, /**< number of nonzero elements in the constraint matrix */
1240  const int* beg, /**< start index of each column in ind- and val-array */
1241  const int* ind, /**< row indices of constraint matrix entries */
1242  const SCIP_Real* val /**< values of constraint matrix entries */
1243  )
1244 {
1245  int* cnt;
1246  int rngcount;
1247  int c;
1248 
1249  assert(lpi != NULL);
1250  assert(lpi->grbmodel != NULL);
1251  assert(lpi->grbenv != NULL);
1252  assert(objsen == SCIP_OBJSEN_MAXIMIZE || objsen == SCIP_OBJSEN_MINIMIZE);
1253 
1254  SCIPdebugMessage("loading LP in column format into Gurobi: %d cols, %d rows\n", ncols, nrows);
1255 
1256  invalidateSolution(lpi);
1257 
1258  SCIP_CALL( ensureSidechgMem(lpi, nrows) );
1259 
1260  /* convert lhs/rhs into sen/rhs/range tuples */
1261  SCIP_CALL( convertSides(lpi, nrows, lhs, rhs, &rngcount) );
1262  assert( rngcount == 0 );
1263 
1264  /* calculate column lengths */
1265  SCIP_ALLOC( BMSallocMemoryArray(&cnt, ncols) );
1266  for( c = 0; c < ncols-1; ++c )
1267  {
1268  cnt[c] = beg[c+1] - beg[c];
1269  assert(cnt[c] >= 0);
1270  }
1271  cnt[ncols-1] = nnonz - beg[ncols-1];
1272  assert(cnt[ncols-1] >= 0);
1273 
1274  /* delete model */
1275  assert( lpi->grbmodel != NULL );
1276  CHECK_ZERO( lpi->messagehdlr, GRBfreemodel(lpi->grbmodel) );
1277 
1278  /* load model - all variables are continuous */
1279  CHECK_ZERO( lpi->messagehdlr, GRBloadmodel(lpi->grbenv, &(lpi->grbmodel), NULL, ncols, nrows, objsen, 0.0, (SCIP_Real*)obj,
1280  lpi->senarray, lpi->rhsarray, (int*)beg, cnt, (int*)ind, (SCIP_Real*)val, (SCIP_Real*)lb, (SCIP_Real*)ub, NULL, colnames, rownames) );
1281  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1282 
1283  /* free temporary memory */
1284  BMSfreeMemoryArray(&cnt);
1285 
1286 #ifndef NDEBUG
1287  {
1288  int temp;
1289 
1290  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &temp) );
1291  assert( temp == ncols);
1292 
1293  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &temp) );
1294  assert( temp == nrows);
1295 
1296  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMNZS, &temp) );
1297  assert( temp == nnonz);
1298  }
1299 #endif
1300 
1301  return SCIP_OKAY;
1302 }
1303 
1304 /** adds columns to the LP */
1306  SCIP_LPI* lpi, /**< LP interface structure */
1307  int ncols, /**< number of columns to be added */
1308  const SCIP_Real* obj, /**< objective function values of new columns */
1309  const SCIP_Real* lb, /**< lower bounds of new columns */
1310  const SCIP_Real* ub, /**< upper bounds of new columns */
1311  char** colnames, /**< column names, or NULL */
1312  int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
1313  const int* beg, /**< start index of each column in ind- and val-array, or NULL if nnonz == 0 */
1314  const int* ind, /**< row indices of constraint matrix entries, or NULL if nnonz == 0 */
1315  const SCIP_Real* val /**< values of constraint matrix entries, or NULL if nnonz == 0 */
1316  )
1317 {
1318  assert(lpi != NULL);
1319  assert(lpi->grbmodel != NULL);
1320 
1321  SCIPdebugMessage("adding %d columns with %d nonzeros to Gurobi\n", ncols, nnonz);
1322 
1323  invalidateSolution(lpi);
1324 
1325  /* add columns - all new variables are continuous */
1326  CHECK_ZERO( lpi->messagehdlr, GRBaddvars(lpi->grbmodel, ncols, nnonz, (int*)beg, (int*)ind, (SCIP_Real*)val, (SCIP_Real*)obj, (SCIP_Real*)lb, (SCIP_Real*)ub, NULL, colnames) )
1327  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1328 
1329  return SCIP_OKAY;
1330 }
1331 
1332 /** deletes all columns in the given range from LP */
1334  SCIP_LPI* lpi, /**< LP interface structure */
1335  int firstcol, /**< first column to be deleted */
1336  int lastcol /**< last column to be deleted */
1337  )
1338 {
1339  int j;
1340  int* which;
1341 
1342  assert(lpi != NULL);
1343  assert(lpi->grbmodel != NULL);
1344 #ifndef NDEBUG
1345  {
1346  int temp;
1347 
1348  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &temp) );
1349  assert(0 <= firstcol && firstcol <= lastcol && lastcol < temp);
1350  }
1351 #endif
1352 
1353  SCIPdebugMessage("deleting %d columns from Gurobi\n", lastcol - firstcol + 1);
1354 
1355  invalidateSolution(lpi);
1356 
1357  /* Gurobi can't delete a range of columns, we have to set up an index array */
1358  SCIP_ALLOC( BMSallocMemoryArray(&which, lastcol-firstcol+1) );;
1359  for( j = firstcol; j <= lastcol; ++j )
1360  which[j - firstcol] = j;
1361 
1362  CHECK_ZERO( lpi->messagehdlr, GRBdelvars(lpi->grbmodel, lastcol-firstcol+1, which) );
1363  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1364 
1365  BMSfreeMemoryArray( &which );
1366 
1367  return SCIP_OKAY;
1368 }
1369 
1370 /** deletes columns from SCIP_LP; the new position of a column must not be greater that its old position */
1372  SCIP_LPI* lpi, /**< LP interface structure */
1373  int* dstat /**< deletion status of columns
1374  * input: 1 if column should be deleted, 0 if not
1375  * output: new position of column, -1 if column was deleted */
1376  )
1377 {
1378  int j, nvars, num;
1379  int* which;
1380 
1381  assert(lpi != NULL);
1382  assert(lpi->grbmodel != NULL);
1383 
1384  SCIPdebugMessage("deleting a column set from Gurobi\n");
1385 
1386  invalidateSolution(lpi);
1387 
1388  /* Gurobi can't delete a range of columns, we have to set up an index array */
1389  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &nvars) );
1390 
1391  SCIP_ALLOC( BMSallocMemoryArray(&which, nvars) );;
1392  num = 0;
1393  for( j = 0; j < nvars; ++j )
1394  {
1395  if( dstat[j] )
1396  which[num++] = j;
1397  }
1398  CHECK_ZERO( lpi->messagehdlr, GRBdelvars(lpi->grbmodel, num, which) );
1399  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1400 
1401  BMSfreeMemoryArray( &which );
1402 
1403  return SCIP_OKAY;
1404 }
1405 
1406 /** adds rows to the LP */
1408  SCIP_LPI* lpi, /**< LP interface structure */
1409  int nrows, /**< number of rows to be added */
1410  const SCIP_Real* lhs, /**< left hand sides of new rows */
1411  const SCIP_Real* rhs, /**< right hand sides of new rows */
1412  char** rownames, /**< row names, or NULL */
1413  int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
1414  const int* beg, /**< start index of each row in ind- and val-array, or NULL if nnonz == 0 */
1415  const int* ind, /**< column indices of constraint matrix entries, or NULL if nnonz == 0 */
1416  const SCIP_Real* val /**< values of constraint matrix entries, or NULL if nnonz == 0 */
1417  )
1418 {
1419  int rngcount;
1420 
1421  assert(lpi != NULL);
1422  assert(lpi->grbmodel != NULL);
1423 
1424  SCIPdebugMessage("adding %d rows with %d nonzeros to Gurobi\n", nrows, nnonz);
1425 
1426  invalidateSolution(lpi);
1427 
1428  SCIP_CALL( ensureSidechgMem(lpi, nrows) );
1429 
1430  /* convert lhs/rhs into sen/rhs/range tuples */
1431  SCIP_CALL( convertSides(lpi, nrows, lhs, rhs, &rngcount) );
1432  assert( rngcount == 0 );
1433 
1434  /* add rows to LP */
1435  CHECK_ZERO( lpi->messagehdlr, GRBaddconstrs(lpi->grbmodel, nrows, nnonz, (int*)beg, (int*)ind, (SCIP_Real*)val, lpi->senarray, lpi->rhsarray, rownames) );
1436  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1437 
1438  return SCIP_OKAY;
1439 }
1440 
1441 /** deletes all rows in the given range from LP */
1443  SCIP_LPI* lpi, /**< LP interface structure */
1444  int firstrow, /**< first row to be deleted */
1445  int lastrow /**< last row to be deleted */
1446  )
1447 {
1448  int i;
1449  int* which;
1450 
1451  assert(lpi != NULL);
1452  assert(lpi->grbmodel != NULL);
1453 #ifndef NDEBUG
1454  {
1455  int nrows;
1456  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
1457  assert(0 <= firstrow && firstrow <= lastrow && lastrow < nrows);
1458  }
1459 #endif
1460 
1461  SCIPdebugMessage("deleting %d rows from Gurobi\n", lastrow - firstrow + 1);
1462 
1463  invalidateSolution(lpi);
1464 
1465  /* Gurobi can't delete a range of rows, we have to set up an index array */
1466  SCIP_ALLOC( BMSallocMemoryArray(&which, lastrow-firstrow+1) );;
1467  for( i = firstrow; i <= lastrow; ++i )
1468  which[i - firstrow] = i;
1469 
1470  CHECK_ZERO( lpi->messagehdlr, GRBdelconstrs(lpi->grbmodel, lastrow-firstrow+1, which) );
1471  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1472 
1473  BMSfreeMemoryArray( &which );
1474 
1475  return SCIP_OKAY;
1476 }
1477 
1478 /** deletes rows from SCIP_LP; the new position of a row must not be greater that its old position */
1480  SCIP_LPI* lpi, /**< LP interface structure */
1481  int* dstat /**< deletion status of rows
1482  * input: 1 if row should be deleted, 0 if not
1483  * output: new position of row, -1 if row was deleted */
1484  )
1485 {
1486  int i, num;
1487  int nrows;
1488  int* which;
1489 
1490  assert(lpi != NULL);
1491  assert(lpi->grbmodel != NULL);
1492 
1493  SCIPdebugMessage("deleting a row set from Gurobi\n");
1494 
1495  invalidateSolution(lpi);
1496 
1497  /* Gurobi can't delete a range of rows, we have to set up an index array */
1498  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
1499  SCIP_ALLOC( BMSallocMemoryArray(&which, nrows) );;
1500  num = 0;
1501  for( i = 0; i < nrows; ++i )
1502  {
1503  if( dstat[i] )
1504  which[num++] = i;
1505  }
1506  CHECK_ZERO( lpi->messagehdlr, GRBdelconstrs(lpi->grbmodel, num, which) );
1507  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1508 
1509  /* update dstat */
1510  num = 0;
1511  for( i = 0; i < nrows; ++i )
1512  {
1513  if( dstat[i] )
1514  {
1515  dstat[i] = -1;
1516  ++num;
1517  }
1518  else
1519  dstat[i] = i - num;
1520  }
1521 
1522  BMSfreeMemoryArray( &which );
1523 
1524  return SCIP_OKAY;
1525 }
1526 
1527 /** clears the whole LP */
1529  SCIP_LPI* lpi /**< LP interface structure */
1530  )
1531 {
1532  assert( lpi != NULL );
1533  assert( lpi->grbmodel != NULL );
1534  assert( lpi->grbenv != NULL );
1535 
1536  SCIPdebugMessage("clearing Gurobi LP\n");
1537 
1538  invalidateSolution(lpi);
1539 
1540  CHECK_ZERO( lpi->messagehdlr, GRBfreemodel(lpi->grbmodel) );
1541  CHECK_ZERO( lpi->messagehdlr, GRBnewmodel(lpi->grbenv, &(lpi->grbmodel), "", 0, NULL, NULL, NULL, NULL, NULL) );
1542  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1543 
1544  return SCIP_OKAY;
1545 }
1546 
1547 /** changes lower and upper bounds of columns */
1549  SCIP_LPI* lpi, /**< LP interface structure */
1550  int ncols, /**< number of columns to change bounds for */
1551  const int* ind, /**< column indices */
1552  const SCIP_Real* lb, /**< values for the new lower bounds */
1553  const SCIP_Real* ub /**< values for the new upper bounds */
1554  )
1555 {
1556  assert(lpi != NULL);
1557  assert(lpi->grbmodel != NULL);
1558 
1559  SCIPdebugMessage("changing %d bounds in Gurobi\n", ncols);
1560 #ifdef SCIP_DEBUG
1561  {
1562  int i;
1563  for( i = 0; i < ncols; ++i )
1564  SCIPdebugPrintf(" col %d: [%g,%g]\n", ind[i], lb[i], ub[i]);
1565  }
1566 #endif
1567 
1568  invalidateSolution(lpi);
1569 
1570  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrlist(lpi->grbmodel, GRB_DBL_ATTR_LB, ncols, (int*)ind, (SCIP_Real*)lb) );
1571  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrlist(lpi->grbmodel, GRB_DBL_ATTR_UB, ncols, (int*)ind, (SCIP_Real*)ub) );
1572 
1573  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1574 
1575  return SCIP_OKAY;
1576 }
1577 
1578 /** changes left and right hand sides of rows */
1580  SCIP_LPI* lpi, /**< LP interface structure */
1581  int nrows, /**< number of rows to change sides for */
1582  const int* ind, /**< row indices */
1583  const SCIP_Real* lhs, /**< new values for left hand sides */
1584  const SCIP_Real* rhs /**< new values for right hand sides */
1585  )
1586 {
1587  int rngcount;
1588 
1589  assert(lpi != NULL);
1590  assert(lpi->grbmodel != NULL);
1591 
1592  SCIPdebugMessage("changing %d sides in Gurobi\n", nrows);
1593 
1594  invalidateSolution(lpi);
1595 
1596  /* convert lhs/rhs into sen/rhs/range tuples */
1597  SCIP_CALL( ensureSidechgMem(lpi, nrows) );
1598  SCIP_CALL( convertSides(lpi, nrows, lhs, rhs, &rngcount) );
1599  assert( rngcount == 0 );
1600 
1601  /* change row sides */
1602  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrlist(lpi->grbmodel, GRB_DBL_ATTR_RHS, nrows, (int*)ind, lpi->rhsarray) );
1603  CHECK_ZERO( lpi->messagehdlr, GRBsetcharattrlist(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, nrows, (int*)ind, lpi->senarray) );
1604 
1605  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1606 
1607  return SCIP_OKAY;
1608 }
1609 
1610 /** changes a single coefficient */
1612  SCIP_LPI* lpi, /**< LP interface structure */
1613  int row, /**< row number of coefficient to change */
1614  int col, /**< column number of coefficient to change */
1615  SCIP_Real newval /**< new value of coefficient */
1616  )
1617 {
1618  assert(lpi != NULL);
1619  assert(lpi->grbmodel != NULL);
1620 
1621  SCIPdebugMessage("changing coefficient row %d, column %d in Gurobi to %g\n", row, col, newval);
1622 
1623  invalidateSolution(lpi);
1624 
1625  CHECK_ZERO( lpi->messagehdlr, GRBchgcoeffs(lpi->grbmodel, 1, &row, &col, &newval) );
1626  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1627 
1628  return SCIP_OKAY;
1629 }
1630 
1631 /** changes the objective sense */
1633  SCIP_LPI* lpi, /**< LP interface structure */
1634  SCIP_OBJSEN objsen /**< new objective sense */
1635  )
1636 {
1637  assert(lpi != NULL);
1638  assert(lpi->grbmodel != NULL);
1639  assert(objsen == SCIP_OBJSEN_MAXIMIZE || objsen == SCIP_OBJSEN_MINIMIZE);
1640 
1641  SCIPdebugMessage("changing objective sense in Gurobi to %d\n", objsen);
1642 
1643  invalidateSolution(lpi);
1644 
1645  /* The objective sense of Gurobi and SCIP are equal */
1646  CHECK_ZERO( lpi->messagehdlr, GRBsetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, objsen) );
1647 
1648  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1649 
1650  return SCIP_OKAY;
1651 }
1652 
1653 /** changes objective values of columns in the LP */
1655  SCIP_LPI* lpi, /**< LP interface structure */
1656  int ncols, /**< number of columns to change objective value for */
1657  int* ind, /**< column indices to change objective value for */
1658  SCIP_Real* obj /**< new objective values for columns */
1659  )
1660 {
1661  assert(lpi != NULL);
1662  assert(lpi->grbmodel != NULL);
1663 
1664  SCIPdebugMessage("changing %d objective values in Gurobi\n", ncols);
1665 
1666  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrlist(lpi->grbmodel, GRB_DBL_ATTR_OBJ, ncols, ind, obj) );
1667 
1668  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
1669 
1670  return SCIP_OKAY;
1671 }
1672 
1673 /** multiplies a row with a non-zero scalar; for negative scalars, the row's sense is switched accordingly */
1675  SCIP_LPI* lpi, /**< LP interface structure */
1676  int row, /**< row number to scale */
1677  SCIP_Real scaleval /**< scaling multiplier */
1678  )
1679 {
1680  SCIP_Real lhs;
1681  SCIP_Real rhs;
1682  int nnonz;
1683  int ncols;
1684  int beg;
1685  int i;
1686 
1687  assert(lpi != NULL);
1688  assert(lpi->grbmodel != NULL);
1689  assert(scaleval != 0.0);
1690 
1691  SCIPdebugMessage("scaling row %d with factor %g in Gurobi\n", row, scaleval);
1692 
1693  invalidateSolution(lpi);
1694 
1695  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
1696  SCIP_CALL( ensureValMem(lpi, ncols) );
1697 
1698  /* get the row */
1699  SCIP_CALL( SCIPlpiGetRows(lpi, row, row, &lhs, &rhs, &nnonz, &beg, lpi->indarray, lpi->valarray) );
1700 
1701  /* scale row coefficients */
1702  for( i = 0; i < nnonz; ++i )
1703  {
1704  SCIP_CALL( SCIPlpiChgCoef(lpi, row, lpi->indarray[i], lpi->valarray[i] * scaleval) );
1705  }
1706 
1707  /* scale row sides */
1708  if( lhs > -GRB_INFINITY )
1709  lhs *= scaleval;
1710  else if( scaleval < 0.0 )
1711  lhs = GRB_INFINITY;
1712  if( rhs < GRB_INFINITY )
1713  rhs *= scaleval;
1714  else if( scaleval < 0.0 )
1715  rhs = -GRB_INFINITY;
1716  if( scaleval > 0.0 )
1717  {
1718  SCIP_CALL( SCIPlpiChgSides(lpi, 1, &row, &lhs, &rhs) );
1719  }
1720  else
1721  {
1722  SCIP_CALL( SCIPlpiChgSides(lpi, 1, &row, &rhs, &lhs) );
1723  }
1724 
1725  return SCIP_OKAY;
1726 }
1727 
1728 /** multiplies a column with a non-zero scalar; the objective value is multiplied with the scalar, and the bounds
1729  * are divided by the scalar; for negative scalars, the column's bounds are switched
1730  */
1732  SCIP_LPI* lpi, /**< LP interface structure */
1733  int col, /**< column number to scale */
1734  SCIP_Real scaleval /**< scaling multiplier */
1735  )
1736 {
1737  SCIP_Real lb;
1738  SCIP_Real ub;
1739  SCIP_Real obj;
1740  int nnonz;
1741  int ncols;
1742  int beg;
1743  int i;
1744 
1745  assert(lpi != NULL);
1746  assert(lpi->grbmodel != NULL);
1747  assert(scaleval != 0.0);
1748 
1749  SCIPdebugMessage("scaling column %d with factor %g in Gurobi\n", col, scaleval);
1750 
1751  invalidateSolution(lpi);
1752 
1753  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
1754  SCIP_CALL( ensureValMem(lpi, ncols) );
1755 
1756  /* get the column */
1757  SCIP_CALL( SCIPlpiGetCols(lpi, col, col, &lb, &ub, &nnonz, &beg, lpi->indarray, lpi->valarray) );
1758 
1759  /* get objective coefficient */
1760  SCIP_CALL( SCIPlpiGetObj(lpi, col, col, &obj) );
1761 
1762  /* scale column coefficients */
1763  for( i = 0; i < nnonz; ++i )
1764  {
1765  SCIP_CALL( SCIPlpiChgCoef(lpi, lpi->indarray[i], col, lpi->valarray[i] * scaleval) );
1766  }
1767 
1768  /* scale objective value */
1769  obj *= scaleval;
1770  SCIP_CALL( SCIPlpiChgObj(lpi, 1, &col, &obj) );
1771 
1772  /* scale column bounds */
1773  if( lb > -GRB_INFINITY )
1774  lb /= scaleval;
1775  else if( scaleval < 0.0 )
1776  lb = GRB_INFINITY;
1777  if( ub < GRB_INFINITY )
1778  ub /= scaleval;
1779  else if( scaleval < 0.0 )
1780  ub = -GRB_INFINITY;
1781  if( scaleval > 0.0 )
1782  {
1783  SCIP_CALL( SCIPlpiChgBounds(lpi, 1, &col, &lb, &ub) );
1784  }
1785  else
1786  {
1787  SCIP_CALL( SCIPlpiChgBounds(lpi, 1, &col, &ub, &lb) );
1788  }
1789 
1790  return SCIP_OKAY;
1791 }
1792 
1793 /**@} */
1794 
1795 
1796 
1797 
1798 /*
1799  * Data Accessing Methods
1800  */
1801 
1802 /**@name Data Accessing Methods */
1803 /**@{ */
1804 
1805 /** gets the number of rows in the LP */
1807  SCIP_LPI* lpi, /**< LP interface structure */
1808  int* nrows /**< pointer to store the number of rows */
1809  )
1810 {
1811  assert(lpi != NULL);
1812  assert(nrows != NULL);
1813 
1814  SCIPdebugMessage("getting number of rows\n");
1815 
1816  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, nrows) );
1817 
1818  return SCIP_OKAY;
1819 }
1820 
1821 /** gets the number of columns in the LP */
1823  SCIP_LPI* lpi, /**< LP interface structure */
1824  int* ncols /**< pointer to store the number of cols */
1825  )
1826 {
1827  assert(lpi != NULL);
1828  assert(ncols != NULL);
1829 
1830  SCIPdebugMessage("getting number of columns\n");
1831 
1832  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, ncols) );
1833 
1834  return SCIP_OKAY;
1835 }
1836 
1837 /** gets the number of nonzero elements in the LP constraint matrix */
1839  SCIP_LPI* lpi, /**< LP interface structure */
1840  int* nnonz /**< pointer to store the number of nonzeros */
1841  )
1842 {
1843  assert(lpi != NULL);
1844  assert(nnonz != NULL);
1845 
1846  SCIPdebugMessage("getting number of non-zeros\n");
1847 
1848  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMNZS, nnonz) );
1849 
1850  return SCIP_OKAY;
1851 }
1852 
1853 /** gets columns from LP problem object; the arrays have to be large enough to store all values
1854  * Either both, lb and ub, have to be NULL, or both have to be non-NULL,
1855  * either nnonz, beg, ind, and val have to be NULL, or all of them have to be non-NULL.
1856  */
1858  SCIP_LPI* lpi, /**< LP interface structure */
1859  int firstcol, /**< first column to get from LP */
1860  int lastcol, /**< last column to get from LP */
1861  SCIP_Real* lb, /**< buffer to store the lower bound vector, or NULL */
1862  SCIP_Real* ub, /**< buffer to store the upper bound vector, or NULL */
1863  int* nnonz, /**< pointer to store the number of nonzero elements returned, or NULL */
1864  int* beg, /**< buffer to store start index of each column in ind- and val-array, or NULL */
1865  int* ind, /**< buffer to store column indices of constraint matrix entries, or NULL */
1866  SCIP_Real* val /**< buffer to store values of constraint matrix entries, or NULL */
1867  )
1868 {
1869  assert(lpi != NULL);
1870  assert(lpi->grbmodel != NULL);
1871 #ifndef NDEBUG
1872  {
1873  int ncols;
1874  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
1875  assert(0 <= firstcol && firstcol <= lastcol && lastcol < ncols);
1876  }
1877 #endif
1878 
1879  SCIPdebugMessage("getting columns %d to %d\n", firstcol, lastcol);
1880 
1881  if( lb != NULL )
1882  {
1883  assert(ub != NULL);
1884 
1885  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_LB, firstcol, lastcol-firstcol+1, lb) );
1886  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_UB, firstcol, lastcol-firstcol+1, ub) );
1887  }
1888  else
1889  assert(ub == NULL);
1890 
1891  if( nnonz != NULL )
1892  {
1893  assert(beg != NULL);
1894  assert(ind != NULL);
1895  assert(val != NULL);
1896 
1897  /* get matrix entries */
1898  CHECK_ZERO( lpi->messagehdlr, GRBgetvars(lpi->grbmodel, nnonz, beg, ind, val, firstcol, lastcol-firstcol+1) )
1899  }
1900  else
1901  {
1902  assert(beg == NULL);
1903  assert(ind == NULL);
1904  assert(val == NULL);
1905  }
1906 
1907  return SCIP_OKAY;
1908 }
1909 
1910 /** gets rows from LP problem object; the arrays have to be large enough to store all values.
1911  * Either both, lhs and rhs, have to be NULL, or both have to be non-NULL,
1912  * either nnonz, beg, ind, and val have to be NULL, or all of them have to be non-NULL.
1913  */
1915  SCIP_LPI* lpi, /**< LP interface structure */
1916  int firstrow, /**< first row to get from LP */
1917  int lastrow, /**< last row to get from LP */
1918  SCIP_Real* lhs, /**< buffer to store left hand side vector, or NULL */
1919  SCIP_Real* rhs, /**< buffer to store right hand side vector, or NULL */
1920  int* nnonz, /**< pointer to store the number of nonzero elements returned, or NULL */
1921  int* beg, /**< buffer to store start index of each row in ind- and val-array, or NULL */
1922  int* ind, /**< buffer to store row indices of constraint matrix entries, or NULL */
1923  SCIP_Real* val /**< buffer to store values of constraint matrix entries, or NULL */
1924  )
1925 {
1926  assert(lpi != NULL);
1927  assert(lpi->grbmodel != NULL);
1928 #ifndef NDEBUG
1929  {
1930  int nrows;
1931  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
1932  assert(0 <= firstrow && firstrow <= lastrow && lastrow < nrows);
1933  }
1934 #endif
1935 
1936  SCIPdebugMessage("getting rows %d to %d\n", firstrow, lastrow);
1937 
1938  if( lhs != NULL || rhs != NULL )
1939  {
1940  /* get row sense and rhs */
1941  SCIP_CALL( ensureSidechgMem(lpi, lastrow - firstrow + 1) );
1942  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_RHS, firstrow, lastrow-firstrow+1, lpi->rhsarray) );
1943  CHECK_ZERO( lpi->messagehdlr, GRBgetcharattrarray(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, firstrow, lastrow-firstrow+1, lpi->senarray) );
1944 
1945  /* convert sen and rhs into lhs/rhs tuples */
1946  SCIP_CALL( reconvertSides(lpi, lastrow - firstrow + 1, lhs, rhs) );
1947  }
1948 
1949  if( nnonz != NULL )
1950  {
1951  assert(beg != NULL);
1952  assert(ind != NULL);
1953  assert(val != NULL);
1954 
1955  /* get matrix entries */
1956  CHECK_ZERO( lpi->messagehdlr, GRBgetconstrs(lpi->grbmodel, nnonz, beg, ind, val, firstrow, lastrow-firstrow+1) );
1957  }
1958  else
1959  {
1960  assert(beg == NULL);
1961  assert(ind == NULL);
1962  assert(val == NULL);
1963  }
1964 
1965  return SCIP_OKAY;
1966 }
1967 
1968 /** gets column names */
1970  SCIP_LPI* lpi, /**< LP interface structure */
1971  int firstcol, /**< first column to get name from LP */
1972  int lastcol, /**< last column to get name from LP */
1973  char** colnames, /**< pointers to column names (of size at least lastcol-firstcol+1) */
1974  char* namestorage, /**< storage for col names */
1975  int namestoragesize, /**< size of namestorage (if 0, storageleft returns the storage needed) */
1976  int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) */
1977  )
1978 {
1979  SCIPerrorMessage("SCIPlpiGetColNames() has not been implemented yet.\n");
1980  return SCIP_LPERROR;
1981 }
1982 
1983 /** gets row names */
1985  SCIP_LPI* lpi, /**< LP interface structure */
1986  int firstrow, /**< first row to get name from LP */
1987  int lastrow, /**< last row to get name from LP */
1988  char** rownames, /**< pointers to row names (of size at least lastrow-firstrow+1) */
1989  char* namestorage, /**< storage for row names */
1990  int namestoragesize, /**< size of namestorage (if 0, -storageleft returns the storage needed) */
1991  int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) */
1992  )
1993 {
1994  SCIPerrorMessage("SCIPlpiGetRowNames() has not been implemented yet.\n");
1995  return SCIP_LPERROR;
1996 }
1997 
1998 /** gets the objective sense of the LP */
2000  SCIP_LPI* lpi, /**< LP interface structure */
2001  SCIP_OBJSEN* objsen /**< pointer to store objective sense */
2002  )
2003 {
2004  int grbobjsen;
2005 
2006  assert( lpi != NULL );
2007  assert( lpi->grbmodel != NULL );
2008  assert( objsen != NULL );
2009 
2010  SCIPdebugMessage("getting objective sense\n");
2011 
2012  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &grbobjsen) );
2013  assert(grbobjsen == GRB_MINIMIZE || grbobjsen == GRB_MAXIMIZE);
2014 
2015  *objsen = (grbobjsen == GRB_MINIMIZE) ? SCIP_OBJSEN_MINIMIZE : SCIP_OBJSEN_MAXIMIZE;
2016 
2017  return SCIP_OKAY;
2018 }
2019 
2020 /** gets objective coefficients from LP problem object */
2022  SCIP_LPI* lpi, /**< LP interface structure */
2023  int firstcol, /**< first column to get objective coefficient for */
2024  int lastcol, /**< last column to get objective coefficient for */
2025  SCIP_Real* vals /**< array to store objective coefficients */
2026  )
2027 {
2028  assert(lpi != NULL);
2029  assert(lpi->grbmodel != NULL);
2030  assert(firstcol <= lastcol);
2031  assert(vals != NULL);
2032 
2033  SCIPdebugMessage("getting objective values %d to %d\n", firstcol, lastcol);
2034 
2035  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_OBJ, firstcol, lastcol-firstcol+1, vals) );
2036 
2037  return SCIP_OKAY;
2038 }
2039 
2040 /** gets current bounds from LP problem object */
2042  SCIP_LPI* lpi, /**< LP interface structure */
2043  int firstcol, /**< first column to get bounds for */
2044  int lastcol, /**< last column to get bounds for */
2045  SCIP_Real* lbs, /**< array to store lower bound values, or NULL */
2046  SCIP_Real* ubs /**< array to store upper bound values, or NULL */
2047  )
2048 {
2049  assert(lpi != NULL);
2050  assert(lpi->grbmodel != NULL);
2051 #ifndef NDEBUG
2052  {
2053  int ncols;
2054  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
2055  assert(0 <= firstcol && firstcol <= lastcol && lastcol < ncols);
2056  }
2057 #endif
2058 
2059  SCIPdebugMessage("getting bounds %d to %d\n", firstcol, lastcol);
2060 
2061  if( lbs != NULL )
2062  {
2063  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_LB, firstcol, lastcol-firstcol+1, lbs) );
2064  }
2065 
2066  if( ubs != NULL )
2067  {
2068  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_UB, firstcol, lastcol-firstcol+1, ubs) );
2069  }
2070 
2071  return SCIP_OKAY;
2072 }
2073 
2074 /** gets current row sides from LP problem object */
2076  SCIP_LPI* lpi, /**< LP interface structure */
2077  int firstrow, /**< first row to get sides for */
2078  int lastrow, /**< last row to get sides for */
2079  SCIP_Real* lhss, /**< array to store left hand side values, or NULL */
2080  SCIP_Real* rhss /**< array to store right hand side values, or NULL */
2081  )
2082 {
2083  assert(lpi != NULL);
2084  assert(lpi->grbmodel != NULL);
2085  assert(firstrow <= lastrow);
2086 
2087  SCIPdebugMessage("getting row sides %d to %d\n", firstrow, lastrow);
2088 
2089  /* get row sense, rhs, and ranges */
2090  SCIP_CALL( ensureSidechgMem(lpi, lastrow - firstrow + 1) );
2091 
2092  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_RHS, firstrow, lastrow-firstrow+1, lpi->rhsarray) );
2093  CHECK_ZERO( lpi->messagehdlr, GRBgetcharattrarray(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, firstrow, lastrow-firstrow+1, lpi->senarray) );
2094 
2095  /* convert sen and rhs into lhs/rhs tuples */
2096  SCIP_CALL( reconvertSides(lpi, lastrow - firstrow + 1, lhss, rhss) );
2097 
2098  return SCIP_OKAY;
2099 }
2100 
2101 /** gets a single coefficient */
2103  SCIP_LPI* lpi, /**< LP interface structure */
2104  int row, /**< row number of coefficient */
2105  int col, /**< column number of coefficient */
2106  SCIP_Real* val /**< pointer to store the value of the coefficient */
2107  )
2108 {
2109  assert(lpi != NULL);
2110  assert(lpi->grbmodel != NULL);
2111 
2112  SCIPdebugMessage("getting coefficient of row %d col %d\n", row, col);
2113 
2114  CHECK_ZERO( lpi->messagehdlr, GRBgetcoeff(lpi->grbmodel, row, col, val) );
2115 
2116  return SCIP_OKAY;
2117 }
2118 
2119 /**@} */
2120 
2121 
2122 
2123 
2124 /*
2125  * Solving Methods
2126  */
2127 
2128 /**@name Solving Methods */
2129 /**@{ */
2130 
2131 /** calls primal simplex to solve the LP
2132  *
2133  * @todo Check concurrent (GRB_METHOD_CONCURRENT or GRB_METHOD_DETERMINISTIC_CONCURRENT)
2134  */
2136  SCIP_LPI* lpi /**< LP interface structure */
2137  )
2138 {
2139  double cnt;
2140  int retval;
2141  int primalfeasible;
2142  int dualfeasible;
2143 
2144  assert( lpi != NULL );
2145  assert( lpi->grbmodel != NULL );
2146  assert( lpi->grbenv != NULL );
2147 
2148 #ifdef SCIP_DEBUG
2149  {
2150  int ncols, nrows;
2151  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
2152  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
2153  SCIPdebugMessage("calling Gurobi primal simplex: %d cols, %d rows\n", ncols, nrows);
2154  }
2155 #endif
2156 
2157  invalidateSolution(lpi);
2158 
2159  if ( lpi->fromscratch )
2160  {
2161  CHECK_ZERO( lpi->messagehdlr, GRBresetmodel(lpi->grbmodel) );
2162  }
2163 
2164  SCIPdebugMessage("calling GRBoptimize() - primal\n");
2165 
2166  /* set primal simplex */
2167  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2168  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, GRB_METHOD_PRIMAL) );
2169 
2170  retval = GRBoptimize(lpi->grbmodel);
2171  switch( retval )
2172  {
2173  case 0:
2174  break;
2175  case GRB_ERROR_OUT_OF_MEMORY:
2176  return SCIP_NOMEMORY;
2177  default:
2178  return SCIP_LPERROR;
2179  }
2180 
2181  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2182  lpi->iterations = (int) cnt;
2183 
2184  lpi->solisbasic = TRUE;
2185  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2186 
2187  SCIPdebugMessage("Gurobi primal simplex needed %d iterations to gain LP status %d\n", (int) cnt, lpi->solstat);
2188 
2189  /*
2190  CHECK_ZERO( lpi->messagehdlr, CPXsolninfo(lpi->grbenv, lpi->grbmodel, NULL, NULL, &primalfeasible, &dualfeasible) );
2191  SCIPdebugMessage(" -> Gurobi returned solstat=%d, pfeas=%d, dfeas=%d (%d iterations)\n",
2192  lpi->solstat, primalfeasible, dualfeasible, lpi->iterations);
2193  */
2194  primalfeasible = FALSE;
2195  dualfeasible = FALSE;
2196 
2197  if( lpi->solstat == GRB_INF_OR_UNBD
2198  || (lpi->solstat == GRB_INFEASIBLE && !dualfeasible)
2199  || (lpi->solstat == GRB_UNBOUNDED && !primalfeasible) )
2200  {
2201  int presolve;
2202 
2203  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_PRESOLVE, &presolve) );
2204 
2205  if( presolve != GRB_PRESOLVE_OFF )
2206  {
2207  /* maybe the preprocessor solved the problem; but we need a solution, so solve again without preprocessing */
2208  SCIPdebugMessage("presolver may have solved the problem -> calling Gurobi primal simplex again without presolve\n");
2209 
2210  /* switch off preprocessing */
2211  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_OFF) );
2212 
2213  retval = GRBoptimize(lpi->grbmodel);
2214  switch( retval )
2215  {
2216  case 0:
2217  break;
2218  case GRB_ERROR_OUT_OF_MEMORY:
2219  return SCIP_NOMEMORY;
2220  default:
2221  return SCIP_LPERROR;
2222  }
2223 
2224  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2225  lpi->iterations += (int) cnt;
2226  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2227  SCIPdebugMessage(" -> Gurobi returned solstat=%d (%d iterations)\n", lpi->solstat, lpi->iterations);
2228 
2229  /* reset parameters */
2230  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_PRESOLVE, presolve) );
2231  }
2232 
2233  if( lpi->solstat == GRB_INF_OR_UNBD )
2234  {
2235  /* preprocessing was not the problem; issue a warning message and treat LP as infeasible */
2236  SCIPerrorMessage("Gurobi primal simplex returned GRB_INF_OR_UNBD after presolving was turned off\n");
2237  }
2238  }
2239 
2240  return SCIP_OKAY;
2241 }
2242 
2243 /** calls dual simplex to solve the LP
2244  *
2245  * @todo Check concurrent (GRB_METHOD_CONCURRENT or GRB_METHOD_DETERMINISTIC_CONCURRENT)
2246  */
2248  SCIP_LPI* lpi /**< LP interface structure */
2249  )
2250 {
2251  int retval;
2252  double cnt;
2253 
2254  assert( lpi != NULL );
2255  assert( lpi->grbmodel != NULL );
2256  assert( lpi->grbenv != NULL );
2257 
2258 #ifdef SCIP_DEBUG
2259  {
2260  int ncols, nrows;
2261  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
2262  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
2263  SCIPdebugMessage("calling Gurobi dual simplex: %d cols, %d rows\n", ncols, nrows);
2264  }
2265 #endif
2266 
2267  invalidateSolution(lpi);
2268 
2269  if ( lpi->fromscratch )
2270  {
2271  CHECK_ZERO( lpi->messagehdlr, GRBresetmodel(lpi->grbmodel) );
2272  }
2273 
2274  SCIPdebugMessage("calling GRBoptimize() - dual\n");
2275 
2276  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2277 
2278  /* set dual simplex */
2279  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, GRB_METHOD_DUAL) );
2280 
2281  retval = GRBoptimize(lpi->grbmodel);
2282  switch( retval )
2283  {
2284  case 0:
2285  break;
2286  case GRB_ERROR_OUT_OF_MEMORY:
2287  return SCIP_NOMEMORY;
2288  default:
2289  return SCIP_LPERROR;
2290  }
2291 
2292  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2293  lpi->iterations = (int) cnt;
2294 
2295  lpi->solisbasic = TRUE;
2296  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2297 
2298  SCIPdebugMessage("Gurobi dual simplex needed %d iterations to gain LP status %d\n", (int) cnt, lpi->solstat);
2299 
2300  /*
2301  SCIPdebugMessage(" -> Gurobi returned solstat=%d, pfeas=%d, dfeas=%d (%d iterations)\n",
2302  lpi->solstat, primalfeasible, dualfeasible, lpi->iterations);
2303  */
2304 
2305  if( lpi->solstat == GRB_INF_OR_UNBD )
2306  {
2307  int presolve;
2308  CHECK_ZERO( lpi->messagehdlr, getIntParam(lpi, GRB_INT_PAR_PRESOLVE, &presolve) );
2309 
2310  if( presolve != GRB_PRESOLVE_OFF )
2311  {
2312  /* maybe the preprocessor solved the problem; but we need a solution, so solve again without preprocessing */
2313  SCIPdebugMessage("presolver may have solved the problem -> calling Gurobi dual simplex again without presolve\n");
2314 
2315  /* switch off preprocessing */
2316  CHECK_ZERO( lpi->messagehdlr, setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_OFF) );
2317  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2318 
2319  retval = GRBoptimize(lpi->grbmodel);
2320  switch( retval )
2321  {
2322  case 0:
2323  break;
2324  case GRB_ERROR_OUT_OF_MEMORY:
2325  return SCIP_NOMEMORY;
2326  default:
2327  return SCIP_LPERROR;
2328  }
2329 
2330  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2331  lpi->iterations += (int) cnt;
2332  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2333  SCIPdebugMessage(" -> Gurobi returned solstat=%d (%d iterations)\n", lpi->solstat, lpi->iterations);
2334 
2335  /* switch on preprocessing again */
2336  CHECK_ZERO( lpi->messagehdlr, setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_AUTO) );
2337  }
2338 
2339  if( lpi->solstat == GRB_INF_OR_UNBD )
2340  {
2341  /* preprocessing was not the problem; issue a warning message and treat LP as infeasible */
2342  SCIPerrorMessage("Gurobi dual simplex returned GRB_INF_OR_UNBD after presolving was turned off\n");
2343  }
2344  }
2345 
2346  return SCIP_OKAY;
2347 }
2348 
2349 /** calls barrier or interior point algorithm to solve the LP with crossover to simplex basis */
2351  SCIP_LPI* lpi, /**< LP interface structure */
2352  SCIP_Bool crossover /**< perform crossover */
2353  )
2354 {
2355  int retval;
2356  double cnt;
2357 
2358  assert( lpi != NULL );
2359  assert( lpi->grbmodel != NULL );
2360  assert( lpi->grbenv != NULL );
2361 
2362 #ifdef SCIP_DEBUG
2363  {
2364  int ncols, nrows;
2365  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
2366  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
2367  SCIPdebugMessage("calling Gurobi barrier: %d cols, %d rows\n", ncols, nrows);
2368  }
2369 #endif
2370 
2371  invalidateSolution(lpi);
2372 
2373  if ( lpi->fromscratch )
2374  {
2375  CHECK_ZERO( lpi->messagehdlr, GRBresetmodel(lpi->grbmodel) );
2376  }
2377 
2378  SCIPdebugMessage("calling GRBoptimize() - barrier\n");
2379 
2380  /* set barrier */
2381  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2382 
2383  if( crossover )
2384  {
2385  /* turn on crossover to automatic setting (-1) */
2386  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_CROSSOVER, -1) );
2387  }
2388  else
2389  {
2390  /* turn off crossover */
2391  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_CROSSOVER, 0) );
2392  }
2393 
2394  CHECK_ZERO( lpi->messagehdlr, GRBsetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, GRB_METHOD_BARRIER) );
2395 
2396  retval = GRBoptimize(lpi->grbmodel);
2397  switch( retval )
2398  {
2399  case 0:
2400  break;
2401  case GRB_ERROR_OUT_OF_MEMORY:
2402  return SCIP_NOMEMORY;
2403  default:
2404  return SCIP_LPERROR;
2405  }
2406 
2407  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2408  lpi->iterations = (int) cnt;
2409 
2410  lpi->solisbasic = crossover;
2411  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2412 
2413  SCIPdebugMessage("Gurobi barrier needed %d iterations to gain LP status %d\n", (int) cnt, lpi->solstat);
2414 
2415  /*
2416  SCIPdebugMessage(" -> Gurobi returned solstat=%d, pfeas=%d, dfeas=%d (%d iterations)\n",
2417  lpi->solstat, primalfeasible, dualfeasible, lpi->iterations);
2418  */
2419 
2420  if( lpi->solstat == GRB_INF_OR_UNBD )
2421  {
2422  int presolve;
2423  CHECK_ZERO( lpi->messagehdlr, getIntParam(lpi, GRB_INT_PAR_PRESOLVE, &presolve) );
2424 
2425  if( presolve != GRB_PRESOLVE_OFF )
2426  {
2427  /* maybe the preprocessor solved the problem; but we need a solution, so solve again without preprocessing */
2428  SCIPdebugMessage("presolver may have solved the problem -> calling Gurobi barrier again without presolve\n");
2429 
2430  /* switch off preprocessing */
2431  CHECK_ZERO( lpi->messagehdlr, setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_OFF) );
2432  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2433 
2434  retval = GRBoptimize(lpi->grbmodel);
2435  switch( retval )
2436  {
2437  case 0:
2438  break;
2439  case GRB_ERROR_OUT_OF_MEMORY:
2440  return SCIP_NOMEMORY;
2441  default:
2442  return SCIP_LPERROR;
2443  }
2444 
2445  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_ITERCOUNT, &cnt) );
2446  lpi->iterations += (int) cnt;
2447  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &lpi->solstat) );
2448  SCIPdebugMessage(" -> Gurobi returned solstat=%d (%d iterations)\n", lpi->solstat, lpi->iterations);
2449 
2450  /* switch on preprocessing again */
2451  CHECK_ZERO( lpi->messagehdlr, setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_AUTO) );
2452  }
2453 
2454  if( lpi->solstat == GRB_INF_OR_UNBD )
2455  {
2456  /* preprocessing was not the problem; issue a warning message and treat LP as infeasible */
2457  SCIPerrorMessage("Gurobi dual simplex returned GRB_INF_OR_UNBD after presolving was turned off\n");
2458  }
2459  }
2460  return SCIP_OKAY;
2461 }
2462 
2463 /** start strong branching - call before any strong branching */
2465  SCIP_LPI* lpi /**< LP interface structure */
2466  )
2467 {
2468  /* currently do nothing */
2469  return SCIP_OKAY;
2470 }
2471 
2472 /** end strong branching - call after any strong branching */
2474  SCIP_LPI* lpi /**< LP interface structure */
2475  )
2476 {
2477  /* currently do nothing */
2478  return SCIP_OKAY;
2479 }
2480 
2481 /** performs strong branching iterations on one candidate */
2482 static
2483 SCIP_RETCODE lpiStrongbranch(
2484  SCIP_LPI* lpi, /**< LP interface structure */
2485  int col, /**< column to apply strong branching on */
2486  SCIP_Real psol, /**< current primal solution value of column */
2487  int itlim, /**< iteration limit for strong branchings */
2488  SCIP_Real* down, /**< stores dual bound after branching column down */
2489  SCIP_Real* up, /**< stores dual bound after branching column up */
2490  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
2491  * otherwise, it can only be used as an estimate value */
2492  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
2493  * otherwise, it can only be used as an estimate value */
2494  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2495  )
2496 {
2497  SCIP_Real oldlb;
2498  SCIP_Real oldub;
2499  SCIP_Real newlb;
2500  SCIP_Real newub;
2501  SCIP_Real olditlim;
2502  SCIP_Bool error;
2503  SCIP_Bool success;
2504  int objsen;
2505  int it;
2506 
2507  assert( lpi != NULL );
2508  assert( lpi->grbmodel != NULL );
2509  assert( lpi->grbenv != NULL );
2510  assert( down != NULL );
2511  assert( up != NULL );
2512  assert( downvalid != NULL );
2513  assert( upvalid != NULL );
2514 
2515  SCIPdebugMessage("performing strong branching on variable %d (%d iterations)\n", col, itlim);
2516 
2517  SCIP_CALL( setParameterValues(lpi, &(lpi->grbparam)) );
2518 
2519  error = FALSE;
2520  *downvalid = FALSE;
2521  *upvalid = FALSE;
2522  if( iter != NULL )
2523  *iter = 0;
2524 
2525  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &objsen) );
2526 
2527  /* save current LP basis and bounds*/
2528  SCIP_CALL( getBase(lpi, &success) );
2529  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_LB, col, &oldlb) );
2530  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_UB, col, &oldub) );
2531 
2532  if ( lpi->fromscratch )
2533  {
2534  CHECK_ZERO( lpi->messagehdlr, GRBresetmodel(lpi->grbmodel) );
2535  }
2536 
2537  /* save old iteration limit and set iteration limit to strong branching limit */
2538  if( itlim > INT_MAX )
2539  itlim = INT_MAX;
2540 
2541  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_ITERATIONLIMIT, &olditlim) );
2542  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_ITERATIONLIMIT, (double) itlim) );
2543 
2544  /* down branch */
2545  newub = EPSCEIL(psol-1.0, 1e-06);
2546  if( newub >= oldlb - 0.5 )
2547  {
2548  SCIPdebugMessage("strong branching down (%g) on x%d (%g) with %d iterations\n", newub, col, psol, itlim);
2549 
2550  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_UB, col, newub) );
2551 
2552  SCIP_CALL( SCIPlpiSolveDual(lpi) );
2553  /* when iteration limit was reached the objective value is not computed */
2554  if( SCIPlpiIsOptimal(lpi) ) /*|| SCIPlpiIsIterlimExc(lpi) ) */
2555  {
2556  SCIP_CALL( SCIPlpiGetObjval(lpi, down) );
2557  *downvalid = TRUE;
2558  }
2559  else if( SCIPlpiIsPrimalInfeasible(lpi) || SCIPlpiIsObjlimExc(lpi) )
2560  {
2561  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_CUTOFF, down) );
2562  }
2563  else if( !SCIPlpiIsIterlimExc(lpi) )
2564  error = TRUE;
2565 
2566  if( iter != NULL )
2567  {
2568  SCIP_CALL( SCIPlpiGetIterations(lpi, &it) );
2569  *iter += it;
2570  }
2571  SCIPdebugMessage(" -> down (x%d <= %g): %g\n", col, newub, *down);
2572 
2573  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_UB, col, oldub) );
2574  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
2575 #ifdef SCIP_DEBUG
2576  {
2577  double b;
2578  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_UB, col, &b) );
2579  assert( b == oldub );
2580  }
2581 #endif
2582 
2583  if ( success )
2584  {
2585  SCIP_CALL( setBase(lpi) );
2586  }
2587  }
2588  else
2589  {
2590  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_CUTOFF, down) );
2591  *downvalid = TRUE;
2592  }
2593 
2594  /* up branch */
2595  if( !error )
2596  {
2597  newlb = EPSFLOOR(psol+1.0, 1e-06);
2598  if( newlb <= oldub + 0.5 )
2599  {
2600  SCIPdebugMessage("strong branching up (%g) on x%d (%g) with %d iterations\n", newlb, col, psol, itlim);
2601 
2602  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_LB, col, newlb) );
2603 
2604  SCIP_CALL( SCIPlpiSolveDual(lpi) );
2605  /* when iteration limit was reached the objective value is not computed */
2606  if( SCIPlpiIsOptimal(lpi) ) /*|| SCIPlpiIsIterlimExc(lpi) ) */
2607  {
2608  SCIP_CALL( SCIPlpiGetObjval(lpi, up) );
2609  *upvalid = TRUE;
2610  }
2611  else if( SCIPlpiIsPrimalInfeasible(lpi) || SCIPlpiIsObjlimExc(lpi) )
2612  {
2613  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_CUTOFF, up) );
2614  }
2615  else if( !SCIPlpiIsIterlimExc(lpi) )
2616  error = TRUE;
2617 
2618  if( iter != NULL )
2619  {
2620  SCIP_CALL( SCIPlpiGetIterations(lpi, &it) );
2621  *iter += it;
2622  }
2623  SCIPdebugMessage(" -> up (x%d >= %g): %g\n", col, newlb, *up);
2624 
2625  CHECK_ZERO( lpi->messagehdlr, GRBsetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_LB, col, oldlb) );
2626  CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) );
2627 #ifdef SCIP_DEBUG
2628  {
2629  double b;
2630  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrelement(lpi->grbmodel, GRB_DBL_ATTR_LB, col, &b) );
2631  assert( b == oldlb );
2632  }
2633 #endif
2634 
2635  if ( success )
2636  {
2637  SCIP_CALL( setBase(lpi) );
2638  }
2639  }
2640  else
2641  {
2642  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_CUTOFF, up) );
2643  *upvalid = TRUE;
2644  }
2645  }
2646 
2647  /* reset iteration limit */
2648  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_ITERATIONLIMIT, olditlim) );
2649  /* CHECK_ZERO( lpi->messagehdlr, GRBupdatemodel(lpi->grbmodel) ); */
2650 
2651  if( error )
2652  {
2653  SCIPerrorMessage("LP error in strong branching.\n");
2654  return SCIP_LPERROR;
2655  }
2656 
2657  return SCIP_OKAY;
2658 }
2659 
2660 /** performs strong branching iterations on one @b fractional candidate */
2662  SCIP_LPI* lpi, /**< LP interface structure */
2663  int col, /**< column to apply strong branching on */
2664  SCIP_Real psol, /**< fractional current primal solution value of column */
2665  int itlim, /**< iteration limit for strong branchings */
2666  SCIP_Real* down, /**< stores dual bound after branching column down */
2667  SCIP_Real* up, /**< stores dual bound after branching column up */
2668  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
2669  * otherwise, it can only be used as an estimate value */
2670  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
2671  * otherwise, it can only be used as an estimate value */
2672  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2673  )
2674 {
2675  /* pass call on to lpiStrongbranch() */
2676  SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2677 
2678  return SCIP_OKAY;
2679 }
2680 
2681 /** performs strong branching iterations on given @b fractional candidates */
2683  SCIP_LPI* lpi, /**< LP interface structure */
2684  int* cols, /**< columns to apply strong branching on */
2685  int ncols, /**< number of columns */
2686  SCIP_Real* psols, /**< fractional current primal solution values of columns */
2687  int itlim, /**< iteration limit for strong branchings */
2688  SCIP_Real* down, /**< stores dual bounds after branching columns down */
2689  SCIP_Real* up, /**< stores dual bounds after branching columns up */
2690  SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
2691  * otherwise, they can only be used as an estimate values */
2692  SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
2693  * otherwise, they can only be used as an estimate values */
2694  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2695  )
2696 {
2697  int j;
2698 
2699  assert( iter != NULL );
2700  assert( cols != NULL );
2701  assert( psols != NULL );
2702  assert( down != NULL );
2703  assert( up != NULL );
2704  assert( downvalid != NULL );
2705  assert( upvalid != NULL );
2706  assert( down != NULL );
2707 
2708  if( iter != NULL )
2709  *iter = 0;
2710 
2711  for( j = 0; j < ncols; ++j )
2712  {
2713  /* pass call on to lpiStrongbranch() */
2714  SCIP_CALL( lpiStrongbranch(lpi, cols[j], psols[j], itlim, &(down[j]), &(up[j]), &(downvalid[j]), &(upvalid[j]), iter) );
2715  }
2716  return SCIP_OKAY;
2717 }
2718 
2719 /** performs strong branching iterations on one candidate with @b integral value */
2721  SCIP_LPI* lpi, /**< LP interface structure */
2722  int col, /**< column to apply strong branching on */
2723  SCIP_Real psol, /**< current integral primal solution value of column */
2724  int itlim, /**< iteration limit for strong branchings */
2725  SCIP_Real* down, /**< stores dual bound after branching column down */
2726  SCIP_Real* up, /**< stores dual bound after branching column up */
2727  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
2728  * otherwise, it can only be used as an estimate value */
2729  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
2730  * otherwise, it can only be used as an estimate value */
2731  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2732  )
2733 {
2734  /* pass call on to lpiStrongbranch() */
2735  SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2736 
2737  return SCIP_OKAY;
2738 }
2739 
2740 /** performs strong branching iterations on given candidates with @b integral values */
2742  SCIP_LPI* lpi, /**< LP interface structure */
2743  int* cols, /**< columns to apply strong branching on */
2744  int ncols, /**< number of columns */
2745  SCIP_Real* psols, /**< current integral primal solution values of columns */
2746  int itlim, /**< iteration limit for strong branchings */
2747  SCIP_Real* down, /**< stores dual bounds after branching columns down */
2748  SCIP_Real* up, /**< stores dual bounds after branching columns up */
2749  SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
2750  * otherwise, they can only be used as an estimate values */
2751  SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
2752  * otherwise, they can only be used as an estimate values */
2753  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2754  )
2755 {
2756  int j;
2757 
2758  assert( iter != NULL );
2759  assert( cols != NULL );
2760  assert( psols != NULL );
2761  assert( down != NULL );
2762  assert( up != NULL );
2763  assert( downvalid != NULL );
2764  assert( upvalid != NULL );
2765  assert( down != NULL );
2766 
2767  if( iter != NULL )
2768  *iter = 0;
2769 
2770  for( j = 0; j < ncols; ++j )
2771  {
2772  /* pass call on to lpiStrongbranch() */
2773  SCIP_CALL( lpiStrongbranch(lpi, cols[j], psols[j], itlim, &(down[j]), &(up[j]), &(downvalid[j]), &(upvalid[j]), iter) );
2774  }
2775  return SCIP_OKAY;
2776 }
2777 /**@} */
2778 
2779 
2780 
2781 
2782 /*
2783  * Solution Information Methods
2784  */
2785 
2786 /**@name Solution Information Methods */
2787 /**@{ */
2788 
2789 /** returns whether a solve method was called after the last modification of the LP */
2791  SCIP_LPI* lpi /**< LP interface structure */
2792  )
2793 {
2794  assert(lpi != NULL);
2795 
2796  return (lpi->solstat != -1);
2797 }
2798 
2799 /** gets information about primal and dual feasibility of the current LP solution */
2801  SCIP_LPI* lpi, /**< LP interface structure */
2802  SCIP_Bool* primalfeasible, /**< stores primal feasibility status */
2803  SCIP_Bool* dualfeasible /**< stores dual feasibility status */
2804  )
2805 {
2806  int algo;
2807 
2808  assert( lpi != NULL );
2809  assert( lpi->grbmodel != NULL );
2810  assert( lpi->grbenv != NULL );
2811  assert( lpi->solstat >= 1 );
2812 
2813  SCIPdebugMessage("getting solution feasibility\n");
2814 
2815  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, &algo) );
2816 
2817  if( primalfeasible != NULL )
2818  {
2819  *primalfeasible = (lpi->solstat == GRB_OPTIMAL || (lpi->solstat == GRB_UNBOUNDED && algo == GRB_METHOD_PRIMAL));
2820  }
2821 
2822  if( dualfeasible != NULL )
2823  {
2824  *dualfeasible = (lpi->solstat == GRB_OPTIMAL || (lpi->solstat == GRB_INFEASIBLE && algo == GRB_METHOD_DUAL));
2825  }
2826 
2827 
2828 #ifdef SCIP_DISABLED_CODE
2829  /* @todo: check whether this code is needed anymore (this was the first version) */
2830  SCIP_Real viol;
2831  SCIP_Real tol;
2832 
2833  assert( lpi != NULL );
2834  assert( lpi->grbmodel != NULL );
2835  assert( lpi->solstat >= 1 );
2836 
2837  SCIPdebugMessage("getting solution feasibility\n");
2838 
2839  if( primalfeasible != NULL )
2840  {
2841  if(lpi->solstat != GRB_INF_OR_UNBD && lpi->solstat != GRB_INFEASIBLE)
2842  {
2843  /* check whether maximum scaled violation is smaller than feasibility tolerance */
2844  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_CONSTR_SRESIDUAL, &viol) );
2845  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_FEASIBILITYTOL, &tol) );
2846  *primalfeasible = (viol <= tol) ? TRUE : FALSE;
2847  SCIPdebugMessage("primal violation: %g (tol: %g)\n", viol, tol);
2848  }
2849  else
2850  *primalfeasible = FALSE;
2851  }
2852 
2853  if( dualfeasible != NULL )
2854  {
2855  if(lpi->solstat != GRB_UNBOUNDED && lpi->solstat != GRB_INFEASIBLE)
2856  {
2857  /* check whether maximum scaled dual violation is smaller than optimality tolerance */
2858  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_DUAL_SRESIDUAL, &viol) );
2859  CHECK_ZERO( lpi->messagehdlr, GRBgetdblparam(lpi->grbenv, GRB_DBL_PAR_OPTIMALITYTOL, &tol) );
2860  *dualfeasible = (viol <= tol) ? TRUE : FALSE;
2861  SCIPdebugMessage("dual violation: %g (tol: %g)\n", viol, tol);
2862  }
2863  else
2864  *dualfeasible = FALSE;
2865  }
2866 #endif
2867 
2868  return SCIP_OKAY;
2869 }
2870 
2871 /** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point);
2872  * this does not necessarily mean, that the solver knows and can return the primal ray
2873  */
2875  SCIP_LPI* lpi /**< LP interface structure */
2876  )
2877 {
2878  assert(lpi != NULL);
2879  assert(lpi->grbmodel != NULL);
2880  assert(lpi->solstat >= 0);
2881 
2882  return (lpi->solstat == GRB_UNBOUNDED);
2883 }
2884 
2885 /** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point),
2886  * and the solver knows and can return the primal ray
2887  */
2889  SCIP_LPI* lpi /**< LP interface structure */
2890  )
2891 {
2892  assert(lpi != NULL);
2893  assert(lpi->grbmodel != NULL);
2894  assert(lpi->solstat >= 0);
2895 
2896  return (lpi->solstat == GRB_UNBOUNDED);
2897 }
2898 
2899 /** returns TRUE iff LP is proven to be primal unbounded */
2901  SCIP_LPI* lpi /**< LP interface structure */
2902  )
2903 {
2904  SCIP_Bool primalfeasible;
2905  SCIP_RETCODE retcode;
2906 
2907  assert(lpi != NULL);
2908  assert(lpi->grbmodel != NULL);
2909  assert(lpi->solstat >= 0);
2910 
2911  SCIPdebugMessage("checking for primal unboundedness\n");
2912 
2913  primalfeasible = FALSE; /* to fix compiler warning */
2914  retcode = SCIPlpiGetSolFeasibility(lpi, &primalfeasible, NULL);
2915  if ( retcode != SCIP_OKAY )
2916  return FALSE;
2917 
2918  /* Probably GRB_UNBOUNDED means that the problem has an unbounded ray, but not necessarily that a feasible primal solution exists. */
2919  return (primalfeasible && (lpi->solstat == GRB_UNBOUNDED || lpi->solstat == GRB_INF_OR_UNBD));
2920 }
2921 
2922 /** returns TRUE iff LP is proven to be primal infeasible */
2924  SCIP_LPI* lpi /**< LP interface structure */
2925  )
2926 {
2927  assert(lpi != NULL);
2928  assert(lpi->grbmodel != NULL);
2929  assert(lpi->solstat >= 0);
2930 
2931  SCIPdebugMessage("checking for primal infeasibility\n");
2932 
2933  assert( lpi->solstat != GRB_INF_OR_UNBD );
2934  return (lpi->solstat == GRB_INFEASIBLE);
2935 }
2936 
2937 /** returns TRUE iff LP is proven to be primal feasible */
2939  SCIP_LPI* lpi /**< LP interface structure */
2940  )
2941 {
2942  int algo;
2943 
2944  assert( lpi != NULL );
2945  assert( lpi->grbmodel != NULL );
2946  assert( lpi->grbenv != NULL );
2947  assert( lpi->solstat >= 0 );
2948 
2949  SCIPdebugMessage("checking for primal feasibility\n");
2950 
2951  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, &algo) );
2952 
2953  return (lpi->solstat == GRB_OPTIMAL || (lpi->solstat == GRB_UNBOUNDED && algo == GRB_METHOD_PRIMAL));
2954 }
2955 
2956 /** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point);
2957  * this does not necessarily mean, that the solver knows and can return the dual ray
2958  */
2960  SCIP_LPI* lpi /**< LP interface structure */
2961  )
2962 {
2963  assert(lpi != NULL);
2964  assert(lpi->grbmodel != NULL);
2965  assert(lpi->solstat >= 0);
2966 
2967  return (lpi->solstat == GRB_INFEASIBLE); /* ????????? */
2968 }
2969 
2970 /** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point),
2971  * and the solver knows and can return the dual ray
2972  */
2974  SCIP_LPI* lpi /**< LP interface structure */
2975  )
2976 {
2977  int algo;
2978 
2979  assert( lpi != NULL );
2980  assert( lpi->grbmodel != NULL );
2981  assert( lpi->grbenv != NULL );
2982  assert( lpi->solstat >= 0 );
2983 
2984  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, &algo) );
2985 
2986  return (lpi->solstat == GRB_INFEASIBLE && algo == GRB_METHOD_DUAL);
2987 }
2988 
2989 /** returns TRUE iff LP is proven to be dual unbounded */
2991  SCIP_LPI* lpi /**< LP interface structure */
2992  )
2993 {
2994  int algo;
2995 
2996  assert( lpi != NULL );
2997  assert( lpi->grbmodel != NULL );
2998  assert( lpi->grbenv != NULL );
2999  assert( lpi->solstat >= 0 );
3000 
3001  SCIPdebugMessage("checking for dual unboundedness\n");
3002 
3003  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, &algo) );
3004 
3005  return (lpi->solstat == GRB_INFEASIBLE && algo == GRB_METHOD_DUAL);
3006 }
3007 
3008 /** returns TRUE iff LP is proven to be dual infeasible */
3010  SCIP_LPI* lpi /**< LP interface structure */
3011  )
3012 {
3013  assert( lpi != NULL );
3014  assert( lpi->grbmodel != NULL );
3015  assert( lpi->solstat >= 0 );
3016 
3017  SCIPdebugMessage("checking for dual infeasibility\n");
3018 
3019  return (lpi->solstat == GRB_UNBOUNDED);
3020 }
3021 
3022 /** returns TRUE iff LP is proven to be dual feasible */
3024  SCIP_LPI* lpi /**< LP interface structure */
3025  )
3026 {
3027  int algo;
3028 
3029  assert( lpi != NULL );
3030  assert( lpi->grbmodel != NULL );
3031  assert( lpi->grbenv != NULL );
3032  assert( lpi->solstat >= 0 );
3033 
3034  SCIPdebugMessage("checking for dual feasibility\n");
3035 
3036  CHECK_ZERO( lpi->messagehdlr, GRBgetintparam(lpi->grbenv, GRB_INT_PAR_METHOD, &algo) );
3037 
3038  return (lpi->solstat == GRB_OPTIMAL || (lpi->solstat == GRB_INFEASIBLE && algo == GRB_METHOD_DUAL));
3039 }
3040 
3041 /** returns TRUE iff LP was solved to optimality */
3043  SCIP_LPI* lpi /**< LP interface structure */
3044  )
3045 {
3046  assert(lpi != NULL);
3047  assert(lpi->grbmodel != NULL);
3048  assert(lpi->solstat >= 0);
3049 
3050  return (lpi->solstat == GRB_OPTIMAL);
3051 }
3052 
3053 /** returns TRUE iff current LP basis is stable */
3055  SCIP_LPI* lpi /**< LP interface structure */
3056  )
3057 {
3058  assert(lpi != NULL);
3059  assert(lpi->grbmodel != NULL);
3060  assert(lpi->solstat >= 0);
3061 
3062  SCIPdebugMessage("checking for stability: Gurobi solstat = %d\n", lpi->solstat);
3063 
3064  return (lpi->solstat != GRB_NUMERIC);
3065 }
3066 
3067 /** returns TRUE iff the objective limit was reached */
3069  SCIP_LPI* lpi /**< LP interface structure */
3070  )
3071 {
3072  assert(lpi != NULL);
3073  assert(lpi->grbmodel != NULL);
3074  assert(lpi->solstat >= 0);
3075 
3076  return (lpi->solstat == GRB_CUTOFF);
3077 }
3078 
3079 /** returns TRUE iff the iteration limit was reached */
3081  SCIP_LPI* lpi /**< LP interface structure */
3082  )
3083 {
3084  assert(lpi != NULL);
3085  assert(lpi->grbmodel != NULL);
3086  assert(lpi->solstat >= 0);
3087 
3088  return (lpi->solstat == GRB_ITERATION_LIMIT);
3089 }
3090 
3091 /** returns TRUE iff the time limit was reached */
3093  SCIP_LPI* lpi /**< LP interface structure */
3094  )
3095 {
3096  assert(lpi != NULL);
3097  assert(lpi->grbmodel != NULL);
3098  assert(lpi->solstat >= 0);
3099 
3100  return (lpi->solstat == GRB_TIME_LIMIT);
3101 }
3102 
3103 /** returns the internal solution status of the solver */
3105  SCIP_LPI* lpi /**< LP interface structure */
3106  )
3107 {
3108  assert(lpi != NULL);
3109  assert(lpi->grbmodel != NULL);
3110 
3111  return lpi->solstat;
3112 }
3113 
3114 /** tries to reset the internal status of the LP solver in order to ignore an instability of the last solving call */
3116  SCIP_LPI* lpi, /**< LP interface structure */
3117  SCIP_Bool* success /**< pointer to store, whether the instability could be ignored */
3118  )
3119 {
3120  assert(lpi != NULL);
3121  assert(lpi->grbmodel != NULL);
3122  assert(success != NULL);
3123 
3124  *success = FALSE;
3125 
3126  return SCIP_OKAY;
3127 }
3128 
3129 /** gets objective value of solution
3130  *
3131  * @note if the solution status is iteration limit reached (GRB_ITERATION_LIMIT), the objective value was not computed
3132  */
3134  SCIP_LPI* lpi, /**< LP interface structure */
3135  SCIP_Real* objval /**< stores the objective value */
3136  )
3137 {
3138  assert(lpi != NULL);
3139  assert(lpi->grbmodel != NULL);
3140 
3141  SCIPdebugMessage("getting solution's objective value\n");
3142 
3143  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_OBJVAL, objval) );
3144 
3145  return SCIP_OKAY;
3146 }
3147 
3148 /** gets primal and dual solution vectors */
3150  SCIP_LPI* lpi, /**< LP interface structure */
3151  SCIP_Real* objval, /**< stores the objective value, may be NULL if not needed */
3152  SCIP_Real* primsol, /**< primal solution vector, may be NULL if not needed */
3153  SCIP_Real* dualsol, /**< dual solution vector, may be NULL if not needed */
3154  SCIP_Real* activity, /**< row activity vector, may be NULL if not needed */
3155  SCIP_Real* redcost /**< reduced cost vector, may be NULL if not needed */
3156  )
3157 {
3158  int ncols;
3159  int nrows;
3160 
3161  assert(lpi != NULL);
3162  assert(lpi->grbmodel != NULL);
3163  assert(lpi->solstat >= 0);
3164 
3165  SCIPdebugMessage("getting solution\n");
3166 
3167  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3168  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3169  assert( ncols >= 0 && nrows >= 0 );
3170 
3171  if( objval != NULL )
3172  {
3173  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_OBJVAL, objval) );
3174  }
3175 
3176  if( primsol != NULL )
3177  {
3178  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_X, 0, ncols, primsol) );
3179  }
3180 
3181  if( dualsol != NULL )
3182  {
3183  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_PI, 0, nrows, dualsol) );
3184  }
3185 
3186  if( activity != NULL )
3187  {
3188  int i;
3189 
3190  /* first get the values of the slack variables */
3191  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_SLACK, 0, nrows, activity) );
3192 
3193  SCIP_CALL( ensureSidechgMem(lpi, nrows) );
3194 
3195  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_RHS, 0, nrows, lpi->rhsarray) );
3196  CHECK_ZERO( lpi->messagehdlr, GRBgetcharattrarray(lpi->grbmodel, GRB_CHAR_ATTR_SENSE, 0, nrows, lpi->senarray) );
3197 
3198  for( i = 0; i < nrows; ++i )
3199  {
3200  switch(lpi->senarray[i])
3201  {
3202  case GRB_LESS_EQUAL:
3203  case GRB_EQUAL:
3204  activity[i] = lpi->rhsarray[i] - activity[i];
3205  break;
3206  case GRB_GREATER_EQUAL:
3207  activity[i] = lpi->rhsarray[i] - activity[i];
3208  break;
3209  default:
3210  SCIPerrorMessage("Unkown sense %c.\n", lpi->senarray[i]);
3211  SCIPABORT();
3212  return SCIP_INVALIDDATA; /*lint !e527*/
3213  }
3214  }
3215  }
3216 
3217  if( redcost != NULL )
3218  {
3219  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_RC, 0, ncols, redcost) );
3220  }
3221 
3222  return SCIP_OKAY;
3223 }
3224 
3225 /** gets primal ray for unbounded LPs */
3227  SCIP_LPI* lpi, /**< LP interface structure */
3228  SCIP_Real* ray /**< primal ray */
3229  )
3230 {
3231  int ncols;
3232 
3233  assert(lpi != NULL);
3234  assert(lpi->grbmodel != NULL);
3235  assert(lpi->solstat >= 0);
3236 
3237  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3238  assert( ncols >= 0 );
3239 
3240  SCIPdebugMessage("calling Gurobi get primal ray: %d cols\n", ncols);
3241 
3242  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_UNBDRAY, 0, ncols, ray) );
3243 
3244  return SCIP_OKAY;
3245 }
3246 
3247 /** gets dual Farkas proof for infeasibility */
3249  SCIP_LPI* lpi, /**< LP interface structure */
3250  SCIP_Real* dualfarkas /**< dual Farkas row multipliers */
3251  )
3252 {
3253  int nrows;
3254 
3255  assert(lpi != NULL);
3256  assert(lpi->grbmodel != NULL);
3257  assert(lpi->solstat >= 0);
3258  assert(dualfarkas != NULL);
3259 
3260  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3261  assert( nrows >= 0 );
3262 
3263  SCIPdebugMessage("calling Gurobi dual Farkas: %d rows\n", nrows);
3264 
3265  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_FARKASDUAL, 0, nrows, dualfarkas) );
3266 
3267  return SCIP_LPERROR;
3268 }
3269 
3270 /** gets the number of LP iterations of the last solve call */
3272  SCIP_LPI* lpi, /**< LP interface structure */
3273  int* iterations /**< pointer to store the number of iterations of the last solve call */
3274  )
3275 {
3276  assert(lpi != NULL);
3277  assert(lpi->grbmodel != NULL);
3278  assert(iterations != NULL);
3279 
3280  *iterations = lpi->iterations;
3281 
3282  return SCIP_OKAY;
3283 }
3284 
3285 /** gets information about the quality of an LP solution
3286  *
3287  * Such information is usually only available, if also a (maybe not optimal) solution is available.
3288  * The LPI should return SCIP_INVALID for @p quality, if the requested quantity is not available.
3289  */
3291  SCIP_LPI* lpi, /**< LP interface structure */
3292  SCIP_LPSOLQUALITY qualityindicator, /**< indicates which quality should be returned */
3293  SCIP_Real* quality /**< pointer to store quality number */
3294  )
3295 {
3296  assert(lpi != NULL);
3297  assert(quality != NULL);
3298 
3299  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattr(lpi->grbmodel, GRB_DBL_ATTR_KAPPA, quality) );
3300 
3301  return SCIP_OKAY;
3302 }
3303 
3304 /**@} */
3305 
3306 
3307 
3308 
3309 /*
3310  * LP Basis Methods
3311  */
3312 
3313 /**@name LP Basis Methods */
3314 /**@{ */
3315 
3316 /** gets current basis status for columns and rows; arrays must be large enough to store the basis status */
3318  SCIP_LPI* lpi, /**< LP interface structure */
3319  int* cstat, /**< array to store column basis status, or NULL */
3320  int* rstat /**< array to store row basis status, or NULL */
3321  )
3322 {
3323  assert(lpi != NULL);
3324  assert(lpi->grbmodel != NULL);
3325 
3326  SCIPdebugMessage("saving Gurobi basis into %p/%p\n", (void*) cstat, (void*) rstat);
3327 
3328  if( rstat != 0 )
3329  {
3330  int i;
3331  int nrows;
3332 
3333  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3334 
3335  for( i = 0; i < nrows; ++i )
3336  {
3337  int stat;
3338  CHECK_ZERO( lpi->messagehdlr, GRBgetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, &stat) );
3339 
3340  switch( stat )
3341  {
3342  case GRB_BASIC:
3343  rstat[i] = SCIP_BASESTAT_BASIC;
3344  break;
3345 
3346  case GRB_NONBASIC_LOWER:
3347  rstat[i] = SCIP_BASESTAT_LOWER;
3348  break;
3349 
3350  case GRB_NONBASIC_UPPER:
3351  rstat[i] = SCIP_BASESTAT_UPPER;
3352  break;
3353 
3354  case GRB_SUPERBASIC:
3355  rstat[i] = SCIP_BASESTAT_ZERO;
3356  break;
3357 
3358  default:
3359  SCIPerrorMessage("invalid basis status %d\n", stat);
3360  SCIPABORT();
3361  return SCIP_INVALIDDATA; /*lint !e527*/
3362  }
3363  }
3364  }
3365 
3366  if( cstat != 0 )
3367  {
3368  int j;
3369  int ncols;
3370 
3371  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3372 
3373  for( j = 0; j < ncols; ++j )
3374  {
3375  int stat;
3376  CHECK_ZERO( lpi->messagehdlr, GRBgetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, &stat) );
3377 
3378  switch( stat )
3379  {
3380  case GRB_BASIC:
3381  cstat[j] = SCIP_BASESTAT_BASIC;
3382  break;
3383 
3384  case GRB_NONBASIC_LOWER:
3385  cstat[j] = SCIP_BASESTAT_LOWER;
3386  break;
3387 
3388  case GRB_NONBASIC_UPPER:
3389  cstat[j] = SCIP_BASESTAT_UPPER;
3390  break;
3391  case GRB_SUPERBASIC:
3392  cstat[j] = SCIP_BASESTAT_ZERO;
3393  break;
3394 
3395  default:
3396  SCIPerrorMessage("invalid basis status %d\n", stat);
3397  SCIPABORT();
3398  return SCIP_INVALIDDATA; /*lint !e527*/
3399  }
3400  }
3401  }
3402 
3403  return SCIP_OKAY;
3404 }
3405 
3406 /** sets current basis status for columns and rows */
3408  SCIP_LPI* lpi, /**< LP interface structure */
3409  int* cstat, /**< array with column basis status */
3410  int* rstat /**< array with row basis status */
3411  )
3412 {
3413  int i, j;
3414  int nrows, ncols;
3415 
3416  assert(lpi != NULL);
3417  assert(lpi->grbmodel != NULL);
3418  assert(cstat != NULL);
3419  assert(rstat != NULL);
3420 
3421  SCIPdebugMessage("loading basis %p/%p into Gurobi\n", (void*) cstat, (void*) rstat);
3422 
3423  invalidateSolution(lpi);
3424 
3425  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3426  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3427 
3428  for( i = 0; i < nrows; ++i )
3429  {
3430  switch( rstat[i] )
3431  {
3432  case SCIP_BASESTAT_BASIC:
3433  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, GRB_BASIC) );
3434  break;
3435 
3436  case SCIP_BASESTAT_LOWER:
3437  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, GRB_NONBASIC_LOWER) );
3438  break;
3439 
3440  case SCIP_BASESTAT_UPPER:
3441  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, GRB_NONBASIC_UPPER) );
3442  break;
3443 
3444  case SCIP_BASESTAT_ZERO:
3445  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, GRB_SUPERBASIC) );
3446  break;
3447 
3448  default:
3449  SCIPerrorMessage("invalid basis status %d\n", rstat[i]);
3450  SCIPABORT();
3451  return SCIP_INVALIDDATA; /*lint !e527*/
3452  }
3453  }
3454 
3455  for( j = 0; j < ncols; ++j )
3456  {
3457  switch( cstat[j] )
3458  {
3459  case SCIP_BASESTAT_BASIC:
3460  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, GRB_BASIC) );
3461  break;
3462 
3463  case SCIP_BASESTAT_LOWER:
3464  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, GRB_NONBASIC_LOWER) );
3465  break;
3466 
3467  case SCIP_BASESTAT_UPPER:
3468  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, GRB_NONBASIC_UPPER) );
3469 
3470  case SCIP_BASESTAT_ZERO:
3471  CHECK_ZERO( lpi->messagehdlr, GRBsetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, GRB_SUPERBASIC) );
3472  break;
3473 
3474  default:
3475  SCIPerrorMessage("invalid basis status %d\n", cstat[j]);
3476  SCIPABORT();
3477  return SCIP_INVALIDDATA; /*lint !e527*/
3478  }
3479  }
3480 
3481  return SCIP_OKAY;
3482 }
3483 
3484 /** returns the indices of the basic columns and rows; basic column n gives value n, basic row m gives value -1-m */
3485 extern
3487  SCIP_LPI* lpi, /**< LP interface structure */
3488  int* bind /**< pointer to store basis indices ready to keep number of rows entries */
3489  )
3490 {
3491  int i;
3492  int nrows;
3493  int ncols;
3494  int* bhead;
3495  int status;
3496 
3497  assert(lpi != NULL);
3498  assert(lpi->grbmodel != NULL);
3499 
3500  SCIPdebugMessage("getting basis information\n");
3501 
3502  /* check whether we have to reoptimize */
3503  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &status) );
3504  if ( status == GRB_LOADED || status == GRB_INTERRUPTED || status == GRB_INPROGRESS )
3505  {
3506  SCIP_CALL_QUIET( restoreLPData(lpi) );
3507  }
3508 
3509  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3510  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3511 
3512 
3513  /* get space for bhead */
3514  SCIP_ALLOC( BMSallocMemoryArray(&bhead, nrows+ncols) );
3515 
3516  /* bet basis indices */
3517  CHECK_ZERO( lpi->messagehdlr, GRBgetBasisHead(lpi->grbmodel, bhead) );
3518 
3519  for (i = 0; i < nrows; ++i)
3520  {
3521  /* entries >= ncols refer to slack variables */
3522  if ( bhead[i] < ncols )
3523  bind[i] = bhead[i];
3524  else
3525  bind[i] = -1 - (bhead[i] - ncols);
3526  }
3527  BMSfreeMemoryArray(&bhead);
3528 
3529 #ifdef SCIP_DISABLED_CODE
3530  /* old implementation */
3531  cnt = 0;
3532  for( i = 0; i < nrows; ++i )
3533  {
3534  int stat;
3535  CHECK_ZERO( lpi->messagehdlr, GRBgetintattrelement(lpi->grbmodel, GRB_INT_ATTR_CBASIS, i, &stat) );
3536 
3537  if( stat == GRB_BASIC )
3538  bind[cnt++] = -1 - i;
3539  }
3540 
3541  for( j = 0; j < ncols; ++j )
3542  {
3543  int stat;
3544  CHECK_ZERO( lpi->messagehdlr, GRBgetintattrelement(lpi->grbmodel, GRB_INT_ATTR_VBASIS, j, &stat) );
3545 
3546  if( stat == GRB_BASIC )
3547  bind[cnt++] = j;
3548  }
3549  assert( cnt == nrows );
3550 #endif
3551 
3552  return SCIP_OKAY;
3553 }
3554 
3555 /** get dense row of inverse basis matrix B^-1
3556  *
3557  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3558  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3559  * see also the explanation in lpi.h.
3560  *
3561  * @todo check that the result is in terms of the LP interface definition
3562  */
3564  SCIP_LPI* lpi, /**< LP interface structure */
3565  int r, /**< row number */
3566  SCIP_Real* coef /**< pointer to store the coefficients of the row */
3567  )
3568 {
3569  SVECTOR x;
3570  SVECTOR b;
3571  int nrows;
3572  double val;
3573  int ind;
3574  int k;
3575  int i;
3576  int status;
3577 
3578  assert(lpi != NULL);
3579  assert(lpi->grbmodel != NULL);
3580 
3581  SCIPdebugMessage("getting binv-row %d\n", r);
3582 
3583  /* check whether we have to reoptimize */
3584  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &status) );
3585  if ( status == GRB_LOADED || status == GRB_INTERRUPTED || status == GRB_INPROGRESS )
3586  {
3587  SCIP_CALL_QUIET( restoreLPData(lpi) );
3588  }
3589 
3590  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3591 
3592  /* set up solution vector */
3593  x.len = 0;
3594  SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), nrows) );
3595  SCIP_ALLOC( BMSallocMemoryArray(&(x.val), nrows) );
3596 
3597  /* set up rhs */
3598  b.len = 1;
3599  ind = r;
3600  val = 1.0;
3601  b.ind = &ind;
3602  b.val = &val;
3603 
3604  /* solve B^T x = e_r, which results in the r-th row of the basis inverse */
3605  CHECK_ZERO( lpi->messagehdlr, GRBBSolve(lpi->grbmodel, &b, &x) );
3606 
3607  /* size should be at most the number of rows */
3608  assert( x.len <= nrows );
3609 
3610  /* copy solution to dense vector */
3611  k = 0;
3612  for (i = 0; i < nrows; ++i)
3613  {
3614  assert( k <= x.len );
3615  if ( k < x.len && (x.ind)[k] == i )
3616  coef[i] = (x.val)[k++];
3617  else
3618  coef[i] = 0.0;
3619  }
3620 
3621  /* free solution space */
3622  BMSfreeMemoryArray(&(x.val));
3623  BMSfreeMemoryArray(&(x.ind));
3624 
3625  return SCIP_OKAY;
3626 }
3627 
3628 /** get dense column of inverse basis matrix B^-1
3629  *
3630  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3631  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3632  * see also the explanation in lpi.h.
3633  *
3634  * @todo check that the result is in terms of the LP interface definition
3635  */
3637  SCIP_LPI* lpi, /**< LP interface structure */
3638  int c, /**< column number of B^-1; this is NOT the number of the column in the LP;
3639  * you have to call SCIPlpiGetBasisInd() to get the array which links the
3640  * B^-1 column numbers to the row and column numbers of the LP!
3641  * c must be between 0 and nrows-1, since the basis has the size
3642  * nrows * nrows */
3643  SCIP_Real* coef /**< pointer to store the coefficients of the column */
3644  )
3645 {
3646  SVECTOR x;
3647  SVECTOR b;
3648  int nrows;
3649  double val;
3650  int ind;
3651  int k;
3652  int i;
3653  int status;
3654 
3655  assert(lpi != NULL);
3656  assert(lpi->grbmodel != NULL);
3657 
3658  SCIPdebugMessage("getting binv-col %d\n", c);
3659 
3660  /* check whether we have to reoptimize */
3661  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &status) );
3662  if ( status == GRB_LOADED || status == GRB_INTERRUPTED || status == GRB_INPROGRESS )
3663  {
3664  SCIP_CALL_QUIET( restoreLPData(lpi) );
3665  }
3666 
3667  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3668 
3669  /* set up solution vector */
3670  x.len = 0;
3671  SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), nrows) );
3672  SCIP_ALLOC( BMSallocMemoryArray(&(x.val), nrows) );
3673 
3674  /* set up rhs */
3675  b.len = 1;
3676  ind = c;
3677  val = 1.0;
3678  b.ind = &ind;
3679  b.val = &val;
3680 
3681  /* solve B x = e_c, which results in the c-th columns of the basis inverse */
3682  CHECK_ZERO( lpi->messagehdlr, GRBFSolve(lpi->grbmodel, &b, &x) );
3683 
3684  /* size should be at most the number of rows */
3685  assert( x.len <= nrows );
3686 
3687  /* copy solution to dense vector */
3688  k = 0;
3689  for (i = 0; i < nrows; ++i)
3690  {
3691  assert( k <= x.len );
3692  if ( k < x.len && (x.ind)[k] == i )
3693  coef[i] = (x.val)[k++];
3694  else
3695  coef[i] = 0.0;
3696  }
3697 
3698  /* free solution space */
3699  BMSfreeMemoryArray(&(x.val));
3700  BMSfreeMemoryArray(&(x.ind));
3701 
3702  return SCIP_OKAY;
3703 }
3704 
3705 /** get dense row of inverse basis matrix times constraint matrix B^-1 * A
3706  *
3707  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3708  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3709  * see also the explanation in lpi.h.
3710  *
3711  * @todo check that the result is in terms of the LP interface definition
3712  */
3714  SCIP_LPI* lpi, /**< LP interface structure */
3715  int r, /**< row number */
3716  const SCIP_Real* binvrow, /**< row in (A_B)^-1 from prior call to SCIPlpiGetBInvRow(), or NULL */
3717  SCIP_Real* coef /**< vector to return coefficients */
3718  )
3719 { /*lint --e{715}*/
3720  SVECTOR x;
3721  int ncols;
3722  int nrows;
3723  int k;
3724  int j;
3725  int status;
3726 
3727  assert(lpi != NULL);
3728  assert(lpi->grbmodel != NULL);
3729 
3730  SCIPdebugMessage("getting binv-row %d\n", r);
3731 
3732  /* check whether we have to reoptimize */
3733  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &status) );
3734  if ( status == GRB_LOADED || status == GRB_INTERRUPTED || status == GRB_INPROGRESS )
3735  {
3736  SCIP_CALL_QUIET( restoreLPData(lpi) );
3737  }
3738 
3739  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3740  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3741 
3742  x.len = 0;
3743  SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), ncols + nrows) );
3744  SCIP_ALLOC( BMSallocMemoryArray(&(x.val), ncols + nrows) );
3745 
3746  CHECK_ZERO( lpi->messagehdlr, GRBBinvRowi(lpi->grbmodel, r, &x) );
3747 
3748  /* size should be at most the number of columns plus rows for slack variables */
3749  assert( x.len <= ncols + nrows );
3750 
3751  k = 0;
3752  for (j = 0; j < ncols; ++j)
3753  {
3754  assert( k <= x.len );
3755  if ( k < x.len && (x.ind)[k] == j )
3756  coef[j] = (x.val)[k++];
3757  else
3758  coef[j] = 0.0;
3759  }
3760 
3761  /* free solution space */
3762  BMSfreeMemoryArray(&(x.val));
3763  BMSfreeMemoryArray(&(x.ind));
3764 
3765  return SCIP_OKAY;
3766 }
3767 
3768 /** get dense column of inverse basis matrix times constraint matrix B^-1 * A
3769  *
3770  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3771  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3772  * see also the explanation in lpi.h.
3773  *
3774  * @todo check that the result is in terms of the LP interface definition
3775  */
3777  SCIP_LPI* lpi, /**< LP interface structure */
3778  int c, /**< column number */
3779  SCIP_Real* coef /**< vector to return coefficients */
3780  )
3781 { /*lint --e{715}*/
3782  SVECTOR x;
3783  int nrows;
3784  int k;
3785  int j;
3786  int status;
3787 
3788  assert(lpi != NULL);
3789  assert(lpi->grbmodel != NULL);
3790 
3791  SCIPdebugMessage("getting binv-col %d\n", c);
3792 
3793  /* check whether we have to reoptimize */
3794  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_STATUS, &status) );
3795  if ( status == GRB_LOADED || status == GRB_INTERRUPTED || status == GRB_INPROGRESS )
3796  {
3797  SCIP_CALL_QUIET( restoreLPData(lpi) );
3798  }
3799 
3800  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3801 
3802  x.len = 0;
3803  SCIP_ALLOC( BMSallocMemoryArray(&(x.ind), nrows) );
3804  SCIP_ALLOC( BMSallocMemoryArray(&(x.val), nrows) );
3805 
3806  CHECK_ZERO( lpi->messagehdlr, GRBBinvColj(lpi->grbmodel, c, &x) );
3807 
3808  /* size should be at most the number of rows */
3809  assert( x.len <= nrows );
3810 
3811  k = 0;
3812  for (j = 0; j < nrows; ++j)
3813  {
3814  assert( k <= x.len );
3815  if ( k < x.len && (x.ind)[k] == j )
3816  coef[j] = (x.val)[k++];
3817  else
3818  coef[j] = 0.0;
3819  }
3820 
3821  /* free solution space */
3822  BMSfreeMemoryArray(&(x.val));
3823  BMSfreeMemoryArray(&(x.ind));
3824 
3825  return SCIP_OKAY;
3826 }
3827 
3828 /**@} */
3829 
3830 
3831 
3832 
3833 /*
3834  * LP State Methods
3835  */
3836 
3837 /**@name LP State Methods */
3838 /**@{ */
3839 
3840 /** stores LPi state (like basis information) into lpistate object */
3842  SCIP_LPI* lpi, /**< LP interface structure */
3843  BMS_BLKMEM* blkmem, /**< block memory */
3844  SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
3845  )
3846 {
3847  SCIP_Bool success;
3848  int ncols;
3849  int nrows;
3850 
3851  assert(blkmem != NULL);
3852  assert(lpi != NULL);
3853  assert(lpi->grbmodel != NULL);
3854  assert(lpistate != NULL);
3855 
3856  /* if there is no basis information available, no state can be saved */
3857  if( !lpi->solisbasic )
3858  {
3859  *lpistate = NULL;
3860  return SCIP_OKAY;
3861  }
3862 
3863  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3864  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3865  assert(ncols >= 0);
3866  assert(nrows >= 0);
3867 
3868  /* get unpacked basis information from Gurobi */
3869  SCIP_CALL( getBase(lpi, &success) );
3870 
3871  if ( success )
3872  {
3873  /* allocate lpistate data */
3874  SCIP_CALL( lpistateCreate(lpistate, blkmem, ncols, nrows) );
3875  (*lpistate)->ncols = ncols;
3876  (*lpistate)->nrows = nrows;
3877 
3878  SCIPdebugMessage("stored Gurobi LPI state in %p (%d cols, %d rows)\n", (void*) *lpistate, ncols, nrows);
3879 
3880  /* pack LPi state data */
3881  lpistatePack(*lpistate, lpi->cstat, lpi->rstat);
3882  }
3883  else
3884  {
3885  /* In this case no basis information is available. Since SCIP expects the information to work
3886  in any case, we allocate the lpistate, but do not use the packed information. This might
3887  happen if the model is infeasible, since Gurobi currently does not return basis information
3888  in this case. */
3889  SCIP_ALLOC( BMSallocBlockMemory(blkmem, lpistate) );
3890  (*lpistate)->ncols = ncols;
3891  (*lpistate)->nrows = nrows;
3892  (*lpistate)->packrstat = NULL;
3893  (*lpistate)->packcstat = NULL;
3894  }
3895 
3896  return SCIP_OKAY;
3897 }
3898 
3899 /** loads LPi state (like basis information) into solver; note that the LP might have been extended with additional
3900  * columns and rows since the state was stored with SCIPlpiGetState()
3901  */
3903  SCIP_LPI* lpi, /**< LP interface structure */
3904  BMS_BLKMEM* blkmem, /**< block memory */
3905  SCIP_LPISTATE* lpistate /**< LPi state information (like basis information) */
3906  )
3907 {
3908  int ncols;
3909  int nrows;
3910  int i;
3911 
3912  assert(blkmem != NULL);
3913  assert(lpi != NULL);
3914  assert(lpi->grbmodel != NULL);
3915 
3916  /* if there was no basis information available, the LPI state was not stored */
3917  if( lpistate == NULL || lpistate->packrstat == NULL || lpistate->packcstat )
3918  return SCIP_OKAY;
3919 
3920  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMCONSTRS, &nrows) );
3921  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_NUMVARS, &ncols) );
3922  assert(lpistate->ncols <= ncols);
3923  assert(lpistate->nrows <= nrows);
3924 
3925  SCIPdebugMessage("loading LPI state %p (%d cols, %d rows) into Gurobi LP with %d cols and %d rows\n",
3926  (void*) lpistate, lpistate->ncols, lpistate->nrows, ncols, nrows);
3927 
3928  if( lpistate->ncols == 0 || lpistate->nrows == 0 )
3929  return SCIP_OKAY;
3930 
3931  /* allocate enough memory for storing uncompressed basis information */
3932  SCIP_CALL( ensureCstatMem(lpi, ncols) );
3933  SCIP_CALL( ensureRstatMem(lpi, nrows) );
3934 
3935  /* unpack LPi state data */
3936  lpistateUnpack(lpistate, lpi->cstat, lpi->rstat);
3937 
3938  /* extend the basis to the current LP beyond the previously existing columns */
3939  for( i = lpistate->ncols; i < ncols; ++i )
3940  {
3941  SCIP_Real bnd;
3942  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_LB, i, i, &bnd) );
3943  if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
3944  {
3945  /* if lower bound is +/- infinity -> try upper bound */
3946  CHECK_ZERO( lpi->messagehdlr, GRBgetdblattrarray(lpi->grbmodel, GRB_DBL_ATTR_UB, i, i, &bnd) );
3947  if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
3948  lpi->cstat[i] = SCIP_BASESTAT_ZERO; /* variable is free */
3949  else
3950  lpi->cstat[i] = SCIP_BASESTAT_UPPER; /* use finite upper bound */
3951  }
3952  else
3953  lpi->cstat[i] = SCIP_BASESTAT_LOWER; /* use finite lower bound */
3954  }
3955  for( i = lpistate->nrows; i < nrows; ++i )
3956  lpi->rstat[i] = SCIP_BASESTAT_BASIC;
3957 
3958  /* load basis information into Gurobi */
3959  SCIP_CALL( setBase(lpi) );
3960 
3961  return SCIP_OKAY;
3962 }
3963 
3964 /** clears current LPi state (like basis information) of the solver */
3966  SCIP_LPI* lpi /**< LP interface structure */
3967  )
3968 {
3969  assert(lpi != NULL);
3970 
3971  CHECK_ZERO( lpi->messagehdlr, GRBresetmodel(lpi->grbmodel) );
3972 
3973  return SCIP_OKAY;
3974 }
3975 
3976 /** frees LPi state information */
3978  SCIP_LPI* lpi, /**< LP interface structure */
3979  BMS_BLKMEM* blkmem, /**< block memory */
3980  SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
3981  )
3982 {
3983  assert(lpi != NULL);
3984  assert(lpistate != NULL);
3985 
3986  if( *lpistate != NULL )
3987  lpistateFree(lpistate, blkmem);
3988 
3989  return SCIP_OKAY;
3990 }
3991 
3992 /** checks, whether the given LP state contains simplex basis information */
3994  SCIP_LPI* lpi, /**< LP interface structure */
3995  SCIP_LPISTATE* lpistate /**< LP state information (like basis information) */
3996  )
3997 { /*lint --e{715}*/
3998  return (lpistate != NULL);
3999 }
4000 
4001 /** reads LP state (like basis information from a file */
4003  SCIP_LPI* lpi, /**< LP interface structure */
4004  const char* fname /**< file name */
4005  )
4006 {
4007  size_t l;
4008  assert(lpi != NULL);
4009  assert(lpi->grbmodel != NULL);
4010 
4011  SCIPdebugMessage("reading LP state from file <%s>\n", fname);
4012 
4013  /* gurobi reads a basis if the extension is ".bas" */
4014  l = strlen(fname);
4015  if ( l > 4 && fname[l-4] == '.' && fname[l-3] == 'b' && fname[l-2] == 'a' && fname[l-1] == 's' )
4016  {
4017  CHECK_ZERO( lpi->messagehdlr, GRBread(lpi->grbmodel, fname) );
4018  }
4019  else
4020  {
4021  SCIPerrorMessage("To read a basis with gurobi, the extension has to be '.bas'.\n");
4022  return SCIP_LPERROR;
4023  }
4024 
4025  return SCIP_OKAY;
4026 }
4027 
4028 /** writes LP state (like basis information) to a file */
4030  SCIP_LPI* lpi, /**< LP interface structure */
4031  const char* fname /**< file name */
4032  )
4033 {
4034  size_t l;
4035  assert(lpi != NULL);
4036  assert(lpi->grbmodel != NULL);
4037 
4038  SCIPdebugMessage("writing basis state to file <%s>\n", fname);
4039 
4040  /* gurobi writes the basis if the extension is ".bas" */
4041  l = strlen(fname);
4042  if ( l > 4 && fname[l-4] == '.' && fname[l-3] == 'b' && fname[l-2] == 'a' && fname[l-1] == 's' )
4043  {
4044  CHECK_ZERO( lpi->messagehdlr, GRBwrite(lpi->grbmodel, fname) );
4045  }
4046  else
4047  {
4048  char name[SCIP_MAXSTRLEN];
4049 
4050  /* force extension to be ".bas" */
4051  assert(strlen(fname) < SCIP_MAXSTRLEN-4);
4052  sprintf(name, "%s.bas", fname);
4053  CHECK_ZERO( lpi->messagehdlr, GRBwrite(lpi->grbmodel, fname) );
4054  }
4055 
4056  return SCIP_OKAY;
4057 }
4058 
4059 /**@} */
4060 
4061 
4062 
4063 
4064 /*
4065  * LP Pricing Norms Methods
4066  */
4067 
4068 /**@name LP Pricing Norms Methods */
4069 /**@{ */
4070 
4071 /** stores LPi pricing norms information
4072  * @todo should we store norm information?
4073  */
4075  SCIP_LPI* lpi, /**< LP interface structure */
4076  BMS_BLKMEM* blkmem, /**< block memory */
4077  SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information */
4078  )
4079 {
4080  assert(lpinorms != NULL);
4081 
4082  (*lpinorms) = NULL;
4083 
4084  return SCIP_OKAY;
4085 }
4086 
4087 /** loads LPi pricing norms into solver; note that the LP might have been extended with additional
4088  * columns and rows since the state was stored with SCIPlpiGetNorms()
4089  */
4091  SCIP_LPI* lpi, /**< LP interface structure */
4092  BMS_BLKMEM* blkmem, /**< block memory */
4093  SCIP_LPINORMS* lpinorms /**< LPi pricing norms information */
4094  )
4095 {
4096  assert(lpinorms == NULL);
4097 
4098  /* no work necessary */
4099  return SCIP_OKAY;
4100 }
4101 
4102 /** frees pricing norms information */
4104  SCIP_LPI* lpi, /**< LP interface structure */
4105  BMS_BLKMEM* blkmem, /**< block memory */
4106  SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information */
4107  )
4108 {
4109  assert(lpinorms == NULL);
4110 
4111  /* no work necessary */
4112  return SCIP_OKAY;
4113 }
4114 
4115 /**@} */
4116 
4117 
4118 
4119 
4120 /*
4121  * Parameter Methods
4122  */
4123 
4124 /**@name Parameter Methods */
4125 /**@{ */
4126 
4127 /** gets integer parameter of LP */
4129  SCIP_LPI* lpi, /**< LP interface structure */
4130  SCIP_LPPARAM type, /**< parameter number */
4131  int* ival /**< buffer to store the parameter value */
4132  )
4133 {
4134  int temp;
4135  SCIP_Real dtemp;
4136 
4137  assert(lpi != NULL);
4138  assert(lpi->grbmodel != NULL);
4139  assert(ival != NULL);
4140 
4141  SCIPdebugMessage("getting int parameter %d\n", type);
4142 
4143  switch( type )
4144  {
4146  *ival = (int) lpi->fromscratch;
4147  break;
4148  case SCIP_LPPAR_FASTMIP:
4149  /* maybe set perturbation */
4150  return SCIP_PARAMETERUNKNOWN;
4151  case SCIP_LPPAR_SCALING:
4152  SCIP_CALL( getIntParam(lpi, GRB_INT_PAR_SCALEFLAG, &temp) );
4153  assert( temp == 0 || temp == 1 );
4154  *ival = (temp == 1) ? TRUE : FALSE;
4155  break;
4156  case SCIP_LPPAR_PRESOLVING:
4157  SCIP_CALL( getIntParam(lpi, GRB_INT_PAR_PRESOLVE, &temp) );
4158  assert( temp == GRB_PRESOLVE_AUTO || temp == GRB_PRESOLVE_OFF || temp == GRB_PRESOLVE_CONSERVATIVE || temp == GRB_PRESOLVE_AGGRESSIVE );
4159  *ival = (temp == GRB_PRESOLVE_OFF) ? FALSE : TRUE;
4160  break;
4161  case SCIP_LPPAR_PRICING:
4162  *ival = (int) lpi->pricing;
4163  break;
4164  case SCIP_LPPAR_LPINFO:
4165  SCIP_CALL( getIntParam(lpi, GRB_INT_PAR_OUTPUTFLAG, &temp) );
4166  assert( temp == 0 || temp == 1 );
4167  *ival = (temp == 1) ? TRUE : FALSE;
4168  break;
4169  case SCIP_LPPAR_LPITLIM:
4170  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_ITERATIONLIMIT, &dtemp) );
4171  assert( dtemp >= 0.0 );
4172  if( dtemp >= GRB_INFINITY )
4173  *ival = INT_MAX;
4174  else
4175  *ival = (int) dtemp;
4176  break;
4177  default:
4178  return SCIP_PARAMETERUNKNOWN;
4179  } /*lint !e788*/
4180 
4181  return SCIP_OKAY;
4182 }
4183 
4184 /** sets integer parameter of LP */
4186  SCIP_LPI* lpi, /**< LP interface structure */
4187  SCIP_LPPARAM type, /**< parameter number */
4188  int ival /**< parameter value */
4189  )
4190 {
4191  assert(lpi != NULL);
4192  assert(lpi->grbmodel != NULL);
4193 
4194  SCIPdebugMessage("setting int parameter %d to %d\n", type, ival);
4195 
4196  switch( type )
4197  {
4199  assert(ival == TRUE || ival == FALSE);
4200  lpi->fromscratch = (SCIP_Bool) ival;
4201  break;
4202  case SCIP_LPPAR_FASTMIP:
4203  assert(ival == TRUE || ival == FALSE);
4204  return SCIP_PARAMETERUNKNOWN;
4205  break;
4206  case SCIP_LPPAR_SCALING:
4207  assert(ival == TRUE || ival == FALSE);
4208  if( ival )
4209  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SCALEFLAG, 1) );
4210  else
4211  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SCALEFLAG, 0) );
4212  break;
4213  case SCIP_LPPAR_PRESOLVING:
4214  assert(ival == TRUE || ival == FALSE);
4215  if( ival )
4216  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_AUTO) );
4217  else
4218  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_PRESOLVE, GRB_PRESOLVE_OFF) );
4219  break;
4220  case SCIP_LPPAR_PRICING:
4221  lpi->pricing = (SCIP_PRICING)ival;
4222  switch( (SCIP_PRICING)ival )
4223  {
4225  case SCIP_PRICING_AUTO:
4226  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_AUTO) );
4227  break;
4228  case SCIP_PRICING_FULL:
4229  /* full does not seem to exist -> use auto */
4230  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_AUTO) );
4231  break;
4232  case SCIP_PRICING_PARTIAL:
4233  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_PARTIAL) );
4234  break;
4235  case SCIP_PRICING_STEEP:
4236  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_STEEPEST_EDGE) );
4237  break;
4239  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_STEEPEST_QUICK) );
4240  break;
4241  case SCIP_PRICING_DEVEX:
4242  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_SIMPLEXPRICING, GRB_SIMPLEXPRICING_DEVEX) );
4243  break;
4244  default:
4245  return SCIP_LPERROR;
4246  }
4247  break;
4248  case SCIP_LPPAR_LPINFO:
4249  assert(ival == TRUE || ival == FALSE);
4250  if( ival )
4251  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_OUTPUTFLAG, 1) );
4252  else
4253  SCIP_CALL( setIntParam(lpi, GRB_INT_PAR_OUTPUTFLAG, 0) );
4254  break;
4255  case SCIP_LPPAR_LPITLIM:
4256  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_ITERATIONLIMIT, (double) ival) );
4257  break;
4258  default:
4259  return SCIP_PARAMETERUNKNOWN;
4260  } /*lint !e788*/
4261 
4262  return SCIP_OKAY;
4263 }
4264 
4265 /** gets floating point parameter of LP */
4267  SCIP_LPI* lpi, /**< LP interface structure */
4268  SCIP_LPPARAM type, /**< parameter number */
4269  SCIP_Real* dval /**< buffer to store the parameter value */
4270  )
4271 {
4272  int objsen;
4273 
4274  assert(lpi != NULL);
4275  assert(lpi->grbmodel != NULL);
4276  assert(dval != NULL);
4277 
4278  SCIPdebugMessage("getting real parameter %d\n", type);
4279 
4280  switch( type )
4281  {
4282  case SCIP_LPPAR_FEASTOL:
4283  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_FEASIBILITYTOL, dval) );
4284  break;
4286  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_OPTIMALITYTOL, dval) );
4287  break;
4289  return SCIP_PARAMETERUNKNOWN;
4290  break;
4291  case SCIP_LPPAR_LOBJLIM:
4292  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &objsen) );
4293  if( objsen == 1 )
4294  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_CUTOFF, dval) );
4295  else
4296  return SCIP_PARAMETERUNKNOWN;
4297  break;
4298  case SCIP_LPPAR_UOBJLIM:
4299  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &objsen) );
4300  if( objsen == 0 )
4301  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_CUTOFF, dval) );
4302  else
4303  return SCIP_PARAMETERUNKNOWN;
4304  break;
4305  case SCIP_LPPAR_LPTILIM:
4306  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_TIMELIMIT, dval) );
4307  break;
4308  case SCIP_LPPAR_MARKOWITZ:
4309  SCIP_CALL( getDblParam(lpi, GRB_DBL_PAR_MARKOWITZTOL, dval) );
4310  break;
4311  default:
4312  return SCIP_PARAMETERUNKNOWN;
4313  } /*lint !e788*/
4314 
4315  return SCIP_OKAY;
4316 }
4317 
4318 /** sets floating point parameter of LP */
4320  SCIP_LPI* lpi, /**< LP interface structure */
4321  SCIP_LPPARAM type, /**< parameter number */
4322  SCIP_Real dval /**< parameter value */
4323  )
4324 {
4325  int objsen;
4326 
4327  assert(lpi != NULL);
4328  assert(lpi->grbmodel != NULL);
4329 
4330  SCIPdebugMessage("setting real parameter %d to %g\n", type, dval);
4331 
4332  switch( type )
4333  {
4334  case SCIP_LPPAR_FEASTOL:
4335  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_FEASIBILITYTOL, dval) );
4336  break;
4338  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_OPTIMALITYTOL, dval) );
4339  break;
4341  return SCIP_PARAMETERUNKNOWN;
4342  break;
4343  case SCIP_LPPAR_LOBJLIM:
4344  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &objsen) );
4345  if( objsen == 1 )
4346  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_CUTOFF, dval) );
4347  break;
4348  case SCIP_LPPAR_UOBJLIM:
4349  CHECK_ZERO( lpi->messagehdlr, GRBgetintattr(lpi->grbmodel, GRB_INT_ATTR_MODELSENSE, &objsen) );
4350  if( objsen == 0 )
4351  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_CUTOFF, dval) );
4352  break;
4353  case SCIP_LPPAR_LPTILIM:
4354  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_TIMELIMIT, dval) );
4355  break;
4356  case SCIP_LPPAR_MARKOWITZ:
4357  SCIP_CALL( setDblParam(lpi, GRB_DBL_PAR_MARKOWITZTOL, dval) );
4358  break;
4359  default:
4360  return SCIP_PARAMETERUNKNOWN;
4361  } /*lint !e788*/
4362 
4363  return SCIP_OKAY;
4364 }
4365 
4366 /**@} */
4367 
4368 
4369 
4370 
4371 /*
4372  * Numerical Methods
4373  */
4374 
4375 /**@name Numerical Methods */
4376 /**@{ */
4377 
4378 /** returns value treated as infinity in the LP solver */
4380  SCIP_LPI* lpi /**< LP interface structure */
4381  )
4382 { /*lint --e{715}*/
4383  return GRB_INFINITY;
4384 }
4385 
4386 /** checks if given value is treated as infinity in the LP solver */
4388  SCIP_LPI* lpi, /**< LP interface structure */
4389  SCIP_Real val /**< value to be checked for infinity */
4390  )
4391 { /*lint --e{715}*/
4392  return (val >= GRB_INFINITY);
4393 }
4394 
4395 /**@} */
4396 
4397 
4398 
4399 
4400 /*
4401  * File Interface Methods
4402  */
4403 
4404 /**@name File Interface Methods */
4405 /**@{ */
4406 
4407 /** reads LP from a file */
4409  SCIP_LPI* lpi, /**< LP interface structure */
4410  const char* fname /**< file name */
4411  )
4412 {
4413  assert(lpi != NULL);
4414  assert(lpi->grbmodel != NULL);
4415 
4416  SCIPdebugMessage("reading LP from file <%s>\n", fname);
4417 
4418  CHECK_ZERO( lpi->messagehdlr, GRBread(lpi->grbmodel, fname) );
4419 
4420  return SCIP_OKAY;
4421 }
4422 
4423 /** writes LP to a file */
4425  SCIP_LPI* lpi, /**< LP interface structure */
4426  const char* fname /**< file name */
4427  )
4428 {
4429  assert(lpi != NULL);
4430  assert(lpi->grbmodel != NULL);
4431 
4432  SCIPdebugMessage("writing LP to file <%s>\n", fname);
4433 
4434  CHECK_ZERO( lpi->messagehdlr, GRBwrite(lpi->grbmodel, fname) );
4435 
4436  return SCIP_OKAY;
4437 }
4438 
4439 /**@} */
SCIP_RETCODE SCIPlpiStrongbranchesInt(SCIP_LPI *lpi, int *cols, int ncols, SCIP_Real *psols, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
Definition: lpi_grb.c:2741
SCIP_RETCODE SCIPlpiGetBInvACol(SCIP_LPI *lpi, int c, SCIP_Real *coef)
Definition: lpi_grb.c:3776
enum SCIP_LPSolQuality SCIP_LPSOLQUALITY
Definition: type_lpi.h:92
#define NUMINTPARAM
Definition: lpi_grb.c:97
SCIP_RETCODE SCIPlpiGetRealSolQuality(SCIP_LPI *lpi, SCIP_LPSOLQUALITY qualityindicator, SCIP_Real *quality)
Definition: lpi_grb.c:3290
SCIP_RETCODE SCIPlpiSetState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE *lpistate)
Definition: lpi_grb.c:3902
SCIP_DUALPACKET COLPACKET
Definition: lpi_grb.c:84
SCIP_RETCODE SCIPlpiGetObjsen(SCIP_LPI *lpi, SCIP_OBJSEN *objsen)
Definition: lpi_grb.c:1999
SCIP_RETCODE SCIPlpiStartStrongbranch(SCIP_LPI *lpi)
Definition: lpi_grb.c:2464
SCIP_RETCODE SCIPlpiGetNNonz(SCIP_LPI *lpi, int *nnonz)
Definition: lpi_grb.c:1838
SCIP_RETCODE SCIPlpiGetCols(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *lb, SCIP_Real *ub, int *nnonz, int *beg, int *ind, SCIP_Real *val)
Definition: lpi_grb.c:1857
unsigned int SCIP_DUALPACKET
Definition: lpi_grb.c:81
struct GRBParam GRBPARAM
Definition: lpi_grb.c:135
SCIP_RETCODE SCIPlpiScaleCol(SCIP_LPI *lpi, int col, SCIP_Real scaleval)
Definition: lpi_grb.c:1731
SCIP_RETCODE SCIPlpiChgBounds(SCIP_LPI *lpi, int ncols, const int *ind, const SCIP_Real *lb, const SCIP_Real *ub)
Definition: lpi_grb.c:1548
#define SCIP_MAXSTRLEN
Definition: def.h:196
SCIP_RETCODE SCIPlpiAddCols(SCIP_LPI *lpi, int ncols, const SCIP_Real *obj, const SCIP_Real *lb, const SCIP_Real *ub, char **colnames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
Definition: lpi_grb.c:1305
enum SCIP_ObjSen SCIP_OBJSEN
Definition: type_lpi.h:36
SCIP_Bool SCIPlpiIsObjlimExc(SCIP_LPI *lpi)
Definition: lpi_grb.c:3068
#define NULL
Definition: lpi_spx.cpp:129
SCIP_RETCODE SCIPlpiChgCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real newval)
Definition: lpi_grb.c:1611
SCIP_RETCODE SCIPlpiFreeNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
Definition: lpi_grb.c:4103
interface methods for specific LP solvers
SCIP_RETCODE SCIPlpiGetBInvRow(SCIP_LPI *lpi, int r, SCIP_Real *coef)
Definition: lpi_grb.c:3563
SCIP_Bool SCIPlpiIsIterlimExc(SCIP_LPI *lpi)
Definition: lpi_grb.c:3080
struct SCIP_Messagehdlr SCIP_MESSAGEHDLR
Definition: type_message.h:50
SCIP_RETCODE SCIPlpiGetDualfarkas(SCIP_LPI *lpi, SCIP_Real *dualfarkas)
Definition: lpi_grb.c:3248
SCIP_RETCODE SCIPlpiSolveDual(SCIP_LPI *lpi)
Definition: lpi_grb.c:2247
SCIP_RETCODE SCIPlpiDelRowset(SCIP_LPI *lpi, int *dstat)
Definition: lpi_grb.c:1479
#define FALSE
Definition: def.h:52
SCIP_RETCODE SCIPlpiStrongbranchInt(SCIP_LPI *lpi, int col, SCIP_Real psol, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
Definition: lpi_grb.c:2720
#define TRUE
Definition: def.h:51
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPlpiGetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
Definition: lpi_grb.c:4074
SCIP_RETCODE SCIPlpiGetRowNames(SCIP_LPI *lpi, int firstrow, int lastrow, char **rownames, char *namestorage, int namestoragesize, int *storageleft)
Definition: lpi_grb.c:1984
enum SCIP_LPParam SCIP_LPPARAM
Definition: type_lpi.h:61
SCIP_RETCODE SCIPlpiGetBInvARow(SCIP_LPI *lpi, int r, const SCIP_Real *binvrow, SCIP_Real *coef)
Definition: lpi_grb.c:3713
SCIP_RETCODE SCIPlpiGetSol(SCIP_LPI *lpi, SCIP_Real *objval, SCIP_Real *primsol, SCIP_Real *dualsol, SCIP_Real *activity, SCIP_Real *redcost)
Definition: lpi_grb.c:3149
SCIP_Bool SCIPlpiIsTimelimExc(SCIP_LPI *lpi)
Definition: lpi_grb.c:3092
SCIP_RETCODE SCIPlpiGetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int *ival)
Definition: lpi_grb.c:4128
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_RETCODE SCIPlpiGetCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real *val)
Definition: lpi_grb.c:2102
SCIP_RETCODE SCIPlpiGetObj(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *vals)
Definition: lpi_grb.c:2021
SCIP_RETCODE SCIPlpiSetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int ival)
Definition: lpi_grb.c:4185
enum SCIP_Pricing SCIP_PRICING
Definition: type_lpi.h:74
SCIP_Bool SCIPlpiIsDualInfeasible(SCIP_LPI *lpi)
Definition: lpi_grb.c:3009
#define GRB_REFACTORMAXITERS
Definition: lpi_grb.c:93
SCIP_Bool SCIPlpiIsInfinity(SCIP_LPI *lpi, SCIP_Real val)
Definition: lpi_grb.c:4387
#define GRB_METHOD_PRIMAL
Definition: lpi_grb.c:75
#define GRB_INT_PAR_METHOD
Definition: lpi_grb.c:76
void SCIPmessagePrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
SCIP_RETCODE SCIPlpiGetBasisInd(SCIP_LPI *lpi, int *bind)
Definition: lpi_grb.c:3486
SCIP_DUALPACKET COLPACKET
Definition: lpi_clp.cpp:115
SCIP_RETCODE SCIPlpiChgObjsen(SCIP_LPI *lpi, SCIP_OBJSEN objsen)
Definition: lpi_grb.c:1632
#define SVECTOR
Definition: lpi_grb.c:70
#define SCIP_DUALPACKETSIZE
Definition: lpi_grb.c:82
SCIP_RETCODE SCIPlpiFreeState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
Definition: lpi_grb.c:3977
SCIP_Bool SCIPlpiIsOptimal(SCIP_LPI *lpi)
Definition: lpi_grb.c:3042
SCIP_RETCODE SCIPlpiReadLP(SCIP_LPI *lpi, const char *fname)
Definition: lpi_grb.c:4408
SCIP_RETCODE SCIPlpiGetNCols(SCIP_LPI *lpi, int *ncols)
Definition: lpi_grb.c:1822
SCIP_RETCODE SCIPlpiGetBInvCol(SCIP_LPI *lpi, int c, SCIP_Real *coef)
Definition: lpi_grb.c:3636
void * SCIPlpiGetSolverPointer(SCIP_LPI *lpi)
Definition: lpi_grb.c:1089
SCIP_RETCODE SCIPlpiGetNRows(SCIP_LPI *lpi, int *nrows)
Definition: lpi_grb.c:1806
#define SCIPerrorMessage
Definition: pub_message.h:45
#define SCIPdebugPrintf
Definition: pub_message.h:80
SCIP_RETCODE SCIPlpiGetState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
Definition: lpi_grb.c:3841
SCIP_RETCODE SCIPlpiGetSolFeasibility(SCIP_LPI *lpi, SCIP_Bool *primalfeasible, SCIP_Bool *dualfeasible)
Definition: lpi_grb.c:2800
SCIP_RETCODE SCIPlpiCreate(SCIP_LPI **lpi, SCIP_MESSAGEHDLR *messagehdlr, const char *name, SCIP_OBJSEN objsen)
Definition: lpi_grb.c:1108
SCIP_DUALPACKET ROWPACKET
Definition: lpi_clp.cpp:117
#define GRB_METHOD_DUAL
Definition: lpi_grb.c:74
SCIP_Bool SCIPlpiIsDualFeasible(SCIP_LPI *lpi)
Definition: lpi_grb.c:3023
struct SCIP_LPiState SCIP_LPISTATE
Definition: type_lpi.h:95
#define REALABS(x)
Definition: def.h:146
SCIP_RETCODE SCIPlpiIgnoreInstability(SCIP_LPI *lpi, SCIP_Bool *success)
Definition: lpi_grb.c:3115
SCIP_RETCODE SCIPlpiChgObj(SCIP_LPI *lpi, int ncols, int *ind, SCIP_Real *obj)
Definition: lpi_grb.c:1654
SCIP_Bool SCIPlpiExistsPrimalRay(SCIP_LPI *lpi)
Definition: lpi_grb.c:2874
#define SCIP_CALL(x)
Definition: def.h:258
#define COLS_PER_PACKET
Definition: lpi_grb.c:85
#define EPSCEIL(x, eps)
Definition: def.h:156
int SCIPlpiGetInternalStatus(SCIP_LPI *lpi)
Definition: lpi_grb.c:3104
SCIP_RETCODE SCIPlpiSolveBarrier(SCIP_LPI *lpi, SCIP_Bool crossover)
Definition: lpi_grb.c:2350
SCIP_RETCODE SCIPlpiGetIterations(SCIP_LPI *lpi, int *iterations)
Definition: lpi_grb.c:3271
SCIP_RETCODE SCIPlpiGetColNames(SCIP_LPI *lpi, int firstcol, int lastcol, char **colnames, char *namestorage, int namestoragesize, int *storageleft)
Definition: lpi_grb.c:1969
SCIP_RETCODE SCIPlpiGetBounds(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *lbs, SCIP_Real *ubs)
Definition: lpi_grb.c:2041
SCIP_RETCODE SCIPlpiGetObjval(SCIP_LPI *lpi, SCIP_Real *objval)
Definition: lpi_grb.c:3133
SCIP_RETCODE SCIPlpiGetSides(SCIP_LPI *lpi, int firstrow, int lastrow, SCIP_Real *lhss, SCIP_Real *rhss)
Definition: lpi_grb.c:2075
#define SCIP_Bool
Definition: def.h:49
SCIP_RETCODE SCIPlpiGetBase(SCIP_LPI *lpi, int *cstat, int *rstat)
Definition: lpi_grb.c:3317
SCIP_RETCODE SCIPlpiSetBase(SCIP_LPI *lpi, int *cstat, int *rstat)
Definition: lpi_grb.c:3407
SCIP_Bool SCIPlpiIsDualUnbounded(SCIP_LPI *lpi)
Definition: lpi_grb.c:2990
const char * SCIPlpiGetSolverDesc(void)
Definition: lpi_grb.c:1078
SCIP_RETCODE SCIPlpiClearState(SCIP_LPI *lpi)
Definition: lpi_grb.c:3965
SCIP_Bool SCIPlpiIsPrimalInfeasible(SCIP_LPI *lpi)
Definition: lpi_grb.c:2923
SCIP_RETCODE SCIPlpiSetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS *lpinorms)
Definition: lpi_grb.c:4090
SCIP_Bool SCIPlpiIsStable(SCIP_LPI *lpi)
Definition: lpi_grb.c:3054
#define MAX(x, y)
Definition: tclique_def.h:75
SCIP_Bool SCIPlpiHasPrimalRay(SCIP_LPI *lpi)
Definition: lpi_grb.c:2888
SCIP_RETCODE SCIPlpiSolvePrimal(SCIP_LPI *lpi)
Definition: lpi_grb.c:2135
SCIP_RETCODE SCIPlpiClear(SCIP_LPI *lpi)
Definition: lpi_grb.c:1528
SCIP_Bool SCIPlpiIsPrimalUnbounded(SCIP_LPI *lpi)
Definition: lpi_grb.c:2900
unsigned int SCIP_SINGLEPACKET
Definition: lpi_grb.c:79
#define NUMDBLPARAM
Definition: lpi_grb.c:107
SCIP_RETCODE SCIPlpiWriteLP(SCIP_LPI *lpi, const char *fname)
Definition: lpi_grb.c:4424
SCIP_RETCODE SCIPlpiReadState(SCIP_LPI *lpi, const char *fname)
Definition: lpi_grb.c:4002
SCIP_Real SCIPlpiInfinity(SCIP_LPI *lpi)
Definition: lpi_grb.c:4379
SCIP_RETCODE SCIPlpiStrongbranchesFrac(SCIP_LPI *lpi, int *cols, int ncols, SCIP_Real *psols, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
Definition: lpi_grb.c:2682
#define SCIP_CALL_QUIET(x)
Definition: def.h:233
SCIP_RETCODE SCIPlpiFree(SCIP_LPI **lpi)
Definition: lpi_grb.c:1183
SCIP_DUALPACKET ROWPACKET
Definition: lpi_grb.c:86
SCIP_Bool SCIPlpiHasStateBasis(SCIP_LPI *lpi, SCIP_LPISTATE *lpistate)
Definition: lpi_grb.c:3993
SCIP_RETCODE SCIPlpiLoadColLP(SCIP_LPI *lpi, SCIP_OBJSEN objsen, int ncols, const SCIP_Real *obj, const SCIP_Real *lb, const SCIP_Real *ub, char **colnames, int nrows, const SCIP_Real *lhs, const SCIP_Real *rhs, char **rownames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
Definition: lpi_grb.c:1227
const char * SCIPlpiGetSolverName(void)
Definition: lpi_grb.c:1064
SCIP_RETCODE SCIPlpiDelRows(SCIP_LPI *lpi, int firstrow, int lastrow)
Definition: lpi_grb.c:1442
SCIP_RETCODE SCIPlpiWriteState(SCIP_LPI *lpi, const char *fname)
Definition: lpi_grb.c:4029
public methods for message output
struct SCIP_LPi SCIP_LPI
Definition: type_lpi.h:94
SCIP_RETCODE SCIPlpiSetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real dval)
Definition: lpi_grb.c:4319
#define SCIP_Real
Definition: def.h:123
SCIP_RETCODE SCIPlpiGetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real *dval)
Definition: lpi_grb.c:4266
SCIP_Bool SCIPlpiIsPrimalFeasible(SCIP_LPI *lpi)
Definition: lpi_grb.c:2938
SCIP_RETCODE SCIPlpiDelCols(SCIP_LPI *lpi, int firstcol, int lastcol)
Definition: lpi_grb.c:1333
SCIP_RETCODE SCIPlpiEndStrongbranch(SCIP_LPI *lpi)
Definition: lpi_grb.c:2473
SCIP_Bool SCIPlpiHasDualRay(SCIP_LPI *lpi)
Definition: lpi_grb.c:2973
SCIP_Bool SCIPlpiExistsDualRay(SCIP_LPI *lpi)
Definition: lpi_grb.c:2959
SCIP_RETCODE SCIPlpiAddRows(SCIP_LPI *lpi, int nrows, const SCIP_Real *lhs, const SCIP_Real *rhs, char **rownames, int nnonz, const int *beg, const int *ind, const SCIP_Real *val)
Definition: lpi_grb.c:1407
SCIP_RETCODE SCIPlpiChgSides(SCIP_LPI *lpi, int nrows, const int *ind, const SCIP_Real *lhs, const SCIP_Real *rhs)
Definition: lpi_grb.c:1579
#define EPSFLOOR(x, eps)
Definition: def.h:155
#define ROWS_PER_PACKET
Definition: lpi_grb.c:87
SCIP_Bool SCIPlpiWasSolved(SCIP_LPI *lpi)
Definition: lpi_grb.c:2790
#define CHECK_ZERO(messagehdlr, x)
Definition: lpi_grb.c:52
SCIP_RETCODE SCIPlpiGetPrimalRay(SCIP_LPI *lpi, SCIP_Real *ray)
Definition: lpi_grb.c:3226
SCIP_RETCODE SCIPlpiScaleRow(SCIP_LPI *lpi, int row, SCIP_Real scaleval)
Definition: lpi_grb.c:1674
SCIP_RETCODE SCIPlpiStrongbranchFrac(SCIP_LPI *lpi, int col, SCIP_Real psol, int itlim, SCIP_Real *down, SCIP_Real *up, SCIP_Bool *downvalid, SCIP_Bool *upvalid, int *iter)
Definition: lpi_grb.c:2661
#define SCIP_ALLOC(x)
Definition: def.h:269
#define SCIPABORT()
Definition: def.h:230
SCIP_RETCODE SCIPlpiGetRows(SCIP_LPI *lpi, int firstrow, int lastrow, SCIP_Real *lhs, SCIP_Real *rhs, int *nnonz, int *beg, int *ind, SCIP_Real *val)
Definition: lpi_grb.c:1914
SCIP_RETCODE SCIPlpiDelColset(SCIP_LPI *lpi, int *dstat)
Definition: lpi_grb.c:1371