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