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