Scippy

SCIP

Solving Constraint Integer Programs

lpi_clp.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2014 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file lpi_clp.cpp
17  * @ingroup LPIS
18  * @brief LP interface for Clp
19  * @author Stefan Heinz
20  * @author Marc Pfetsch
21  * @author John Forrest
22  *
23  *
24  * Notes on this interface:
25  *
26  * - Currently, Clp (Version 1.10) supports two ways of adding rows/columns from arrays: One uses a
27  * length array that for each row/column specifies the number of nonzeros to be added. The second
28  * uses the @p beg array that gives the starting index for each row/column. We use the latter
29  * variant. Since for LPI there should be no gaps in the corresponding arrays, i.e., every entry in
30  * @p val and @a ind gives a nonzero entry, one can switch between the two formats. With the current
31  * Clp implementation both formats involve an overhead:
32  *
33  * - For the @p beg variant, Clp gets the end of the array from the last position in @p beg
34  * (i.e., the entry one after the last row/column) and we have to copy and extend @p beg for this
35  * purpose. In the matrix implementation a length information is then again computed.
36  *
37  * - For the @p length variant, Clp computes the number of elements from this length variant and
38  * there exists no matrix implementation that uses the length information, i.e., it is recomputed
39  * again.
40  *
41  * Concluding: the implementation of Clp/CoinPackeMatrix could be improved. The functions
42  * affected by this are SCIPlpiLoadColLP(), SCIPlpiAddCols(), SCIPlpiAddRows()
43  *
44  * - In former versions Clp used an "auxiliary model" that allows to save time when the model is
45  * scaled. This is discarded from version higher than 1.8.2.
46  *
47  * - Clp allows the setting of several special flags. These are now set when the FASTMIP option in
48  * SCIP is true. We tried to use the best settings, while still working correctly, see
49  * setFastmipClpParameters(). These settings probably have to be adapted to future Clp
50  * versions. Maybe more possibilities will appear.
51  *
52  * - At several places this interface corrects the return value of some Clp functions, e.g.,
53  * isProvenPrimalInfeasible(). Currently (version 1.10) no change in the Clp functions will be made,
54  * but this might change in the future.
55  */
56 /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
57 
58 
59 #include <ClpSimplex.hpp>
60 #include <ClpPrimalColumnSteepest.hpp>
61 #include <ClpDualRowSteepest.hpp>
62 #include <CoinIndexedVector.hpp>
63 #include <ClpConfig.h>
64 #ifndef CLP_VERSION
65 #include <config_clp.h>
66 #define CLP_VERSION VERSION
67 #endif
68 
69 #include <cassert>
70 #include <cstdlib>
71 #include <iostream>
72 #include <vector>
73 #include <string>
74 
75 #include "lpi/lpi.h"
76 #include "scip/bitencode.h"
77 #include "scip/pub_message.h"
78 
79 /* do defines for windows directly her to make the lpi more independent*/
80 #if defined(_WIN32) || defined(_WIN64)
81 #define snprintf _snprintf
82 #endif
83 
84 /* for debugging: alternatingly write files "debug_[p|d]_[0|1].mps" after each run - use with care! */
85 #ifdef LPI_CLP_DEBUG_WRITE_FILES
86 static int fileNr = 0;
87 #endif
88 
89 /* bound for accepting primal or dual sum of infeasibilities */
90 #define SUMINFEASBOUND 1.0e-3
91 
92 /** LP interface for Clp */
93 struct SCIP_LPi
94 {
95  ClpSimplex* clp; /**< Clp simiplex solver class */
96  int* cstat; /**< array for storing column basis status */
97  int* rstat; /**< array for storing row basis status */
98  int cstatsize; /**< size of cstat array */
99  int rstatsize; /**< size of rstat array */
100  bool startscratch; /**< start from scratch? */
101  bool presolving; /**< preform preprocessing? */
102  SCIP_PRICING pricing; /**< SCIP pricing setting */
103  bool validFactorization; /**< whether we have a valid factorization in clp */
104  SCIP_Bool solved; /**< was the current LP solved? */
105  bool setFactorizationFrequency; /**< store whether the factorization frequency is set */
106  SCIP_Bool fastmip; /**< are fast mip settings turned on */
107 };
108 
109 
110 
111 
112 
113 
114 /** Definitions for storing basis status (copied from lpi_spx.cpp) */
115 typedef SCIP_DUALPACKET COLPACKET; /* each column needs two bits of information (basic/on_lower/on_upper) */
116 #define COLS_PER_PACKET SCIP_DUALPACKETSIZE
117 typedef SCIP_DUALPACKET ROWPACKET; /* each row needs two bit of information (basic/on_lower/on_upper) */
118 #define ROWS_PER_PACKET SCIP_DUALPACKETSIZE
119 
120 /** LPi state stores basis information */
121 struct SCIP_LPiState
122 {
123  int ncols; /**< number of LP columns */
124  int nrows; /**< number of LP rows */
125  COLPACKET* packcstat; /**< column basis status in compressed form */
126  ROWPACKET* packrstat; /**< row basis status in compressed form */
127 };
128 
129 
130 
131 
132 /*
133  * dynamic memory arrays
134  */
135 
136 /** resizes cstat array to have at least num entries */
137 static
138 SCIP_RETCODE ensureCstatMem(
139  SCIP_LPI* lpi, /**< LP interface structure */
140  int num /**< minimal number of entries in array */
141  )
142 {
143  assert(lpi != 0);
144 
145  if( num > lpi->cstatsize )
146  {
147  int newsize;
148 
149  newsize = MAX(2*lpi->cstatsize, num);
150  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->cstat, newsize) );
151  lpi->cstatsize = newsize;
152  }
153  assert(num <= lpi->cstatsize);
154 
155  return SCIP_OKAY;
156 }
157 
158 /** resizes rstat array to have at least num entries */
159 static
160 SCIP_RETCODE ensureRstatMem(
161  SCIP_LPI* lpi, /**< LP interface structure */
162  int num /**< minimal number of entries in array */
163  )
164 {
165  assert(lpi != 0);
166 
167  if( num > lpi->rstatsize )
168  {
169  int newsize;
170 
171  newsize = MAX(2*lpi->rstatsize, num);
172  SCIP_ALLOC( BMSreallocMemoryArray(&lpi->rstat, newsize) );
173  lpi->rstatsize = newsize;
174  }
175  assert(num <= lpi->rstatsize);
176 
177  return SCIP_OKAY;
178 }
179 
180 
181 
182 
183 /*
184  * LPi state methods
185  */
186 
187 /** returns the number of packets needed to store column packet information */
188 static
189 int colpacketNum(
190  int ncols /**< number of columns to store */
191  )
192 {
193  return (ncols+(int)COLS_PER_PACKET-1)/(int)COLS_PER_PACKET;
194 }
195 
196 /** returns the number of packets needed to store row packet information */
197 static
198 int rowpacketNum(
199  int nrows /**< number of rows to store */
200  )
201 {
202  return (nrows+(int)ROWS_PER_PACKET-1)/(int)ROWS_PER_PACKET;
203 }
204 
205 /** store row and column basis status in a packed LPi state object */
206 static
207 void lpistatePack(
208  SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
209  const int* cstat, /**< basis status of columns in unpacked format */
210  const int* rstat /**< basis status of rows in unpacked format */
211  )
212 {
213  assert(lpistate != 0);
214  assert(lpistate->packcstat != 0);
215  assert(lpistate->packrstat != 0);
216 
217  SCIPencodeDualBit(cstat, lpistate->packcstat, lpistate->ncols);
218  SCIPencodeDualBit(rstat, lpistate->packrstat, lpistate->nrows);
219 }
220 
221 /** unpacks row and column basis status from a packed LPi state object */
222 static
223 void lpistateUnpack(
224  const SCIP_LPISTATE* lpistate, /**< pointer to LPi state data */
225  int* cstat, /**< buffer for storing basis status of columns in unpacked format */
226  int* rstat /**< buffer for storing basis status of rows in unpacked format */
227  )
228 {
229  assert(lpistate != 0);
230  assert(lpistate->packcstat != 0);
231  assert(lpistate->packrstat != 0);
232 
233  SCIPdecodeDualBit(lpistate->packcstat, cstat, lpistate->ncols);
234  SCIPdecodeDualBit(lpistate->packrstat, rstat, lpistate->nrows);
235 }
236 
237 /** creates LPi state information object */
238 static
239 SCIP_RETCODE lpistateCreate(
240  SCIP_LPISTATE** lpistate, /**< pointer to LPi state */
241  BMS_BLKMEM* blkmem, /**< block memory */
242  int ncols, /**< number of columns to store */
243  int nrows /**< number of rows to store */
244  )
245 {
246  assert(lpistate != 0);
247  assert(blkmem != 0);
248  assert(ncols >= 0);
249  assert(nrows >= 0);
250 
251  SCIP_ALLOC( BMSallocBlockMemory(blkmem, lpistate) );
252  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum(ncols)) );
253  SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum(nrows)) );
254 
255  return SCIP_OKAY;
256 }
257 
258 /** frees LPi state information */
259 static
260 void lpistateFree(
261  SCIP_LPISTATE** lpistate, /**< pointer to LPi state information (like basis information) */
262  BMS_BLKMEM* blkmem /**< block memory */
263  )
264 {
265  assert(blkmem != 0);
266  assert(lpistate != 0);
267  assert(*lpistate != 0);
268 
269  BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum((*lpistate)->ncols));
270  BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum((*lpistate)->nrows));
271  BMSfreeBlockMemory(blkmem, lpistate);
272 }
273 
274 
275 
276 
277 
278 /*
279  * local methods
280  */
281 
282 /** marks the current LP to be unsolved */
283 static
284 void invalidateSolution(
285  SCIP_LPI* lpi /**< LP interface structure */
286  )
287 {
288  assert(lpi != NULL);
289  lpi->solved = FALSE;
290 }
291 
292 /** set factorization frequency */
293 static
294 void setFactorizationFrequency(
295  SCIP_LPI* lpi /**< LP interface structure */
296  )
297 {
298  /* set the factorization frequency only once */
299  if ( lpi->setFactorizationFrequency )
300  return;
301 
302  lpi->clp->defaultFactorizationFrequency();
303  lpi->setFactorizationFrequency = true;
304 }
305 
306 /** this methods sets parameters of Clp */
307 static
308 void setFastmipClpParameters(
309  SCIP_LPI* lpi /**< LP interface structure */
310  )
311 {
312  lpi->fastmip = TRUE;
313 
314  /** Perturbation:
315  * 50 - switch on perturbation
316  * 100 - auto perturb if takes too long (1.0e-6 largest nonzero)
317  * 101 - we are perturbed
318  * 102 - don't try perturbing again
319  * - default is 100
320  * - others are for playing
321  *
322  * for Clp 1.8 stable: 50 seems to be 10% faster than 100
323  */
324  lpi->clp->setPerturbation(50);
325 
326  /** Special options description from ClpModell.hpp:
327  * 1 - Don't keep changing infeasibility weight
328  * 2 - Keep nonLinearCost round solves
329  * 4 - Force outgoing variables to exact bound (primal)
330  * 8 - Safe to use dense initial factorization
331  * 16 - Just use basic variables for operation if column generation
332  * 32 - Create ray even in BAB
333  * 64 - Treat problem as feasible until last minute (i.e. minimize infeasibilities)
334  * 128 - Switch off all matrix sanity checks
335  * 256 - No row copy
336  * 512 - If not in values pass, solution guaranteed, skip as much as possible
337  * 1024 - In branch and bound
338  * 2048 - Don't bother to re-factorize if < 20 iterations
339  * 4096 - Skip some optimality checks
340  * 8192 - Do Primal when cleaning up primal
341  * 16384 - In fast dual (so we can switch off things)
342  * 32768 - called from Osi
343  * 65536 - keep arrays around as much as possible (also use maximumR/C)
344  * 131072 - transposeTimes is -1.0 and can skip basic and fixed
345  * 262144 - extra copy of scaled matrix
346  * 524288 - Clp fast dual
347  * 1048576 - don't need to finish dual (can return 3)
348  * NOTE - many applications can call Clp but there may be some short cuts
349  * which are taken which are not guaranteed safe from all applications.
350  * Vetted applications will have a bit set and the code may test this
351  * At present I expect a few such applications - if too many I will
352  * have to re-think. It is up to application owner to change the code
353  * if she/he needs these short cuts. I will not debug unless in Coin
354  * repository. See COIN_CLP_VETTED comments.
355  * 0x01000000 is Cbc (and in branch and bound)
356  * 0x02000000 is in a different branch and bound
357  *
358  * Comments:
359  * 2 - nonlinear costs are used in primal for infeasibility weight
360  * 4 - in anti-degeneracy operations can move variables just off a bound
361  * 8 - means dense nucleus in factorization - normally not safe in first factorization as
362  * singularity handling is not useful. Is switched on if going from dual to primal or vv.
363  * 16 - Used for "real" column generation
364  * 64 - Good idea, since in B&B most problems are feasible.
365  * 128 - Assumes user will not create tiny or duplicate elements.
366  * 256 - Normally Clp keeps a scaled row copy for speed. For very large problems you might want to turn it off.
367  * 512 - Means nonbasic variables should be at bounds and basis will be reasonable.
368  * 4096 - Skip some optimality checks
369  * 8192 - If the primal has a perturbed problem and needs to clean up, it normally uses dual - but in some cases can be better to use primal.
370  * 32768 - Just switches off some messages e.g. empty problem.
371  * 131072 - used internally
372  * 262144 - Normally Clp has unscaled column copy of matrix - this makes an extra scaled copy.
373  * 524288 - used internally
374  * 1048576 - only set by fastDual
375  * 0x02000000 - main point: does allow use of disaster handler
376  *
377  * Cbc seems to use the following special options:
378  * lpi->clp->setSpecialOptions(64|128|1024|2048|4096|32768|262144|0x01000000);
379  * Sometimes 512+8192 and 8192 or 8 are used as well.
380  */
381 
382  // 2048 does not seem to work
383  // 65536 does not seem to work
384  // 262144 does not seem to work
385 
386 #ifndef NDEBUG
387  // in debug mode: leave checks on
388  lpi->clp->setSpecialOptions(32|64|512|1024|32768);
389 #else
390  lpi->clp->setSpecialOptions(32|64|128|512|1024|4096|32768);
391 #endif
392 
393  // 8192 bit - don't even think of using primal if user asks for dual (and vv)
394  lpi->clp->setMoreSpecialOptions(8192 | lpi->clp->moreSpecialOptions());
395 
396  // let memory grow only (do not shrink) - [needs specialOptions & 65536 != 0]
397  // does not seem to work
398  //lpi->clp->setPersistenceFlag(1);
399 }
400 
401 /** this methods sets parameters of Clp */
402 static
403 void unsetFastmipClpParameters(
404  SCIP_LPI* lpi /**< LP interface structure */
405  )
406 {
407  lpi->fastmip = FALSE;
408 
409  // reset to default value:
410  lpi->clp->setPerturbation(100);
411 
412  // turn off special options:
413  lpi->clp->setSpecialOptions(0);
414 
415  // turn off memory enlargement
416  lpi->clp->setPersistenceFlag(0);
417 }
418 
419 
420 /*
421  * LP Interface Methods
422  */
423 
424 
425 /*
426  * Miscellaneous Methods
427  */
428 
429 /**@name Miscellaneous Methods */
430 /**@{ */
431 
432 /** gets name and version of LP solver */
434  void
435  )
436 {
437  // Currently Clp has no function to get version, so we hard code it ...
438  return "Clp " CLP_VERSION;
439 }
440 
441 /** gets description of LP solver (developer, webpage, ...) */
443  void
444  )
445 {
446  return "COIN-OR Linear Programming Solver developed by J. Forrest et.al. (projects.coin-or.org/Clp)";
447 }
448 
449 /** gets pointer for LP solver - use only with great care */
451  SCIP_LPI* lpi /**< pointer to an LP interface structure */
452  )
453 {
454  return (void*) lpi->clp;
455 }
456 /**@} */
457 
458 
459 
460 
461 /*
462  * LPI Creation and Destruction Methods
463  */
464 
465 /**@name LPI Creation and Destruction Methods */
466 /**@{ */
467 
468 /** creates an LP problem object */
470  SCIP_LPI** lpi, /**< pointer to an LP interface structure */
471  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler to use for printing messages, or NULL */
472  const char* name, /**< problem name */
473  SCIP_OBJSEN objsen /**< objective sense */
474  )
475 {
476  assert(lpi != 0);
477 
478  SCIPdebugMessage("calling SCIPlpiCreate()\n");
479 
480  // create lpi object
481  SCIP_ALLOC( BMSallocMemory(lpi) );
482  (*lpi)->clp = new ClpSimplex();
483  (*lpi)->cstat = 0;
484  (*lpi)->rstat = 0;
485  (*lpi)->cstatsize = 0;
486  (*lpi)->rstatsize = 0;
487  (*lpi)->startscratch = true;
488  (*lpi)->pricing = SCIP_PRICING_LPIDEFAULT;
489  (*lpi)->validFactorization = false;
490  (*lpi)->setFactorizationFrequency = false;
491  (*lpi)->fastmip = FALSE;
492  invalidateSolution(*lpi);
493 
494  // if you want to use saveModel()
495  // (*lpi)->clp->setLengthNames(255);
496 
497  // set pricing routines
498 
499  // for primal:
500  // 0 is exact devex,
501  // 1 full steepest,
502  // 2 is partial exact devex
503  // 3 switches between 0 and 2 depending on factorization
504  // 4 starts as partial dantzig/devex but then may switch between 0 and 2.
505  // - currently (Clp 1.8stable) default is 3
506  ClpPrimalColumnSteepest primalSteepest;
507  (*lpi)->clp->setPrimalColumnPivotAlgorithm(primalSteepest);
508 
509  // for dual:
510  // 0 is uninitialized,
511  // 1 full,
512  // 2 is partial uninitialized,
513  // 3 starts as 2 but may switch to 1.
514  // - currently (Clp 1.8stable) default is 3
515  ClpDualRowSteepest dualSteepest;
516  (*lpi)->clp->setDualRowPivotAlgorithm(dualSteepest);
517 
518  // set problem name
519  (*lpi)->clp->setStrParam(ClpProbName, std::string(name) );
520 
521  // set objective sense: SCIP values are the same as the ones for Clp
522  (*lpi)->clp->setOptimizationDirection(objsen);
523 
524  // turn off output by default
525  (*lpi)->clp->setLogLevel(0);
526 
527  // turn off scaling by default
528  (*lpi)->clp->scaling(0);
529 
530  /* set default pricing */
531  SCIP_CALL( SCIPlpiSetIntpar(*lpi, SCIP_LPPAR_PRICING, (int)(*lpi)->pricing) );
532 
533  return SCIP_OKAY;
534 }
535 
536 
537 /** deletes an LP problem object */
539  SCIP_LPI** lpi /**< pointer to an LP interface structure */
540  )
541 {
542  assert(lpi != 0);
543  assert(*lpi != 0);
544  assert((*lpi)->clp != 0);
545 
546  SCIPdebugMessage("calling SCIPlpiFree()\n");
547 
548  /* free LP */
549  delete (*lpi)->clp;
550 
551  /* free memory */
552  BMSfreeMemoryArrayNull(&(*lpi)->cstat);
553  BMSfreeMemoryArrayNull(&(*lpi)->rstat);
554  BMSfreeMemory(lpi);
555 
556  return SCIP_OKAY;
557 }
558 
559 /**@} */
560 
561 
562 
563 
564 /*
565  * Modification Methods
566  */
567 
568 /**@name Modification Methods */
569 /**@{ */
570 
571 /** copies LP data with column matrix into LP solver */
573  SCIP_LPI* lpi, /**< LP interface structure */
574  SCIP_OBJSEN objsen, /**< objective sense */
575  int ncols, /**< number of columns */
576  const SCIP_Real* obj, /**< objective function values of columns */
577  const SCIP_Real* lb, /**< lower bounds of columns */
578  const SCIP_Real* ub, /**< upper bounds of columns */
579  char** colnames, /**< column names, or 0 */
580  int nrows, /**< number of rows */
581  const SCIP_Real* lhs, /**< left hand sides of rows */
582  const SCIP_Real* rhs, /**< right hand sides of rows */
583  char** rownames, /**< row names, or 0 */
584  int nnonz, /**< number of nonzero elements in the constraint matrix */
585  const int* beg, /**< start index of each column in ind- and val-array */
586  const int* ind, /**< row indices of constraint matrix entries */
587  const SCIP_Real* val /**< values of constraint matrix entries */
588  )
589 {
590  SCIPdebugMessage("calling SCIPlpiLoadColLP()\n");
591 
592  assert(lpi != 0);
593  assert(lpi->clp != 0);
594  assert(lhs != 0);
595  assert(rhs != 0);
596  assert( nnonz > beg[ncols-1] );
597 
598  invalidateSolution(lpi);
599 
600  ClpSimplex* clp = lpi->clp;
601 
602  // copy beg-array
603  int* mybeg = NULL;
604  SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
605  BMScopyMemoryArray(mybeg, beg, ncols);
606  mybeg[ncols] = nnonz; // add additional entry at end
607 
608  // load problem
609  clp->loadProblem(ncols, nrows, mybeg, ind, val, lb, ub, obj, lhs, rhs);
610  BMSfreeMemoryArray( &mybeg );
611 
612  // set objective sense
613  clp->setOptimizationDirection(objsen);
614 
615  // copy column and rownames if necessary
616  if ( colnames || rownames )
617  {
618  std::vector<std::string> columnNames(ncols);
619  std::vector<std::string> rowNames(nrows);
620  if (colnames)
621  {
622  for (int j = 0; j < ncols; ++j)
623  columnNames[j].assign(colnames[j]);
624  }
625  if (rownames)
626  {
627  for (int i = 0; i < ncols; ++i)
628  rowNames[i].assign(rownames[i]);
629  }
630  clp->copyNames(rowNames, columnNames);
631  }
632 
633  return SCIP_OKAY;
634 }
635 
636 
637 /** adds columns to the LP */
639  SCIP_LPI* lpi, /**< LP interface structure */
640  int ncols, /**< number of columns to be added */
641  const SCIP_Real* obj, /**< objective function values of new columns */
642  const SCIP_Real* lb, /**< lower bounds of new columns */
643  const SCIP_Real* ub, /**< upper bounds of new columns */
644  char** colnames, /**< column names, or 0 */
645  int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
646  const int* beg, /**< start index of each column in ind- and val-array, or 0 if nnonz == 0 */
647  const int* ind, /**< row indices of constraint matrix entries, or 0 if nnonz == 0 */
648  const SCIP_Real* val /**< values of constraint matrix entries, or 0 if nnonz == 0 */
649  )
650 {
651  SCIPdebugMessage("calling SCIPlpiAddCols()\n");
652 
653  assert(lpi != 0);
654  assert(lpi->clp != 0);
655  assert(obj != 0);
656  assert(lb != 0);
657  assert(ub != 0);
658  assert(nnonz == 0 || beg != 0);
659  assert(nnonz == 0 || ind != 0);
660  assert(nnonz == 0 || val != 0);
661  assert(nnonz >= 0);
662  assert(ncols >= 0);
663 
664  invalidateSolution(lpi);
665 
666  // store number of columns for later
667  int numCols = lpi->clp->getNumCols();
668 
669  // copy beg-array (if not 0)
670  int* mybeg = NULL;
671  SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
672 
673  // if columns are not empty
674  if ( nnonz != 0 )
675  {
676  BMScopyMemoryArray(mybeg, beg, ncols);
677  mybeg[ncols] = nnonz; // add additional entry at end
678 
679  // add columns
680  lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, ind, val);
681  }
682  else
683  {
684  for (int j = 0; j <= ncols; ++j)
685  mybeg[j] = 0;
686  // add empty columns
687  lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, 0, 0);
688  }
689  BMSfreeMemoryArray(&mybeg);
690 
691  // copy columnnames if necessary
692  if ( colnames )
693  {
694  std::vector<std::string> columnNames(ncols);
695  for (int j = 0; j < ncols; ++j)
696  columnNames[j].assign(colnames[j]);
697  lpi->clp->copyColumnNames(columnNames, numCols, numCols + ncols);
698  }
699 
700  return SCIP_OKAY;
701 }
702 
703 
704 /** deletes all columns in the given range from LP */
706  SCIP_LPI* lpi, /**< LP interface structure */
707  int firstcol, /**< first column to be deleted */
708  int lastcol /**< last column to be deleted */
709  )
710 {
711  SCIPdebugMessage("calling SCIPlpiDelCols()\n");
712 
713  assert(lpi != 0);
714  assert(lpi->clp != 0);
715  assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
716 
717  invalidateSolution(lpi);
718 
719  // Current Clp version (1.8) can't delete a range of columns; we have to use deleteColumns (see SCIPlpiDelColset)
720  int num = lastcol-firstcol+1;
721  int* which = NULL;
722  SCIP_ALLOC( BMSallocMemoryArray( &which, num) );;
723 
724  // fill array with interval
725  for (int j = firstcol; j <= lastcol; ++j)
726  which[j - firstcol] = j;
727 
728  lpi->clp->deleteColumns(num, which);
729  BMSfreeMemoryArray( &which );
730 
731  return SCIP_OKAY;
732 }
733 
734 
735 /** deletes columns from SCIP_LPI; the new position of a column must not be greater that its old position */
737  SCIP_LPI* lpi, /**< LP interface structure */
738  int* dstat /**< deletion status of columns
739  * input: 1 if column should be deleted, 0 if not
740  * output: new position of column, -1 if column was deleted */
741  )
742 {
743  SCIPdebugMessage("calling SCIPlpiDelColset()\n");
744 
745  assert(lpi != 0);
746  assert(lpi->clp != 0);
747  assert(dstat != 0);
748 
749  invalidateSolution(lpi);
750 
751  // transform dstat information
752  int ncols = lpi->clp->getNumCols();
753  int* which = NULL;
754  SCIP_ALLOC( BMSallocMemoryArray( &which, ncols) );
755  int cnt = 0;
756  for (int j = 0; j < ncols; ++j)
757  {
758  if ( dstat[j] == 1 )
759  which[cnt++] = j;
760  }
761  lpi->clp->deleteColumns(cnt, which);
762  BMSfreeMemoryArray(&which);
763 
764  // update dstat
765  cnt = 0;
766  for (int j = 0; j < ncols; ++j)
767  {
768  if ( dstat[j] == 1 )
769  {
770  dstat[j] = -1;
771  ++cnt;
772  }
773  else
774  dstat[j] = j - cnt;
775  }
776 
777  return SCIP_OKAY;
778 }
779 
780 
781 /** adds rows to the LP */
783  SCIP_LPI* lpi, /**< LP interface structure */
784  int nrows, /**< number of rows to be added */
785  const SCIP_Real* lhs, /**< left hand sides of new rows */
786  const SCIP_Real* rhs, /**< right hand sides of new rows */
787  char** rownames, /**< row names, or 0 */
788  int nnonz, /**< number of nonzero elements to be added to the constraint matrix */
789  const int* beg, /**< start index of each row in ind- and val-array, or 0 if nnonz == 0 */
790  const int* ind, /**< column indices of constraint matrix entries, or 0 if nnonz == 0 */
791  const SCIP_Real* val /**< values of constraint matrix entries, or 0 if nnonz == 0 */
792  )
793 {
794  SCIPdebugMessage("calling SCIPlpiAddRows()\n");
795 
796  assert(lpi != 0);
797  assert(lpi->clp != 0);
798  assert(lhs != 0);
799  assert(rhs != 0);
800  assert(nnonz == 0 || beg != 0);
801  assert(nnonz == 0 || ind != 0);
802  assert(nnonz == 0 || val != 0);
803 
804  invalidateSolution(lpi);
805 
806  // store number of rows for later use
807  int numRows = lpi->clp->getNumRows();
808 
809  int* mybeg = NULL;
810  SCIP_ALLOC( BMSallocMemoryArray( &mybeg, nrows + 1) );
811 
812  if ( nnonz != 0 )
813  {
814  // copy beg-array
815  BMScopyMemoryArray( mybeg, beg, nrows);
816  mybeg[nrows] = nnonz; // add additional entry at end
817 
818  // add rows
819  lpi->clp->addRows(nrows, lhs, rhs, mybeg, ind, val);
820  }
821  else
822  {
823  // add empty rows
824  for (int i = 0; i <= nrows; ++i)
825  mybeg[i] = 0;
826  lpi->clp->addRows(nrows, lhs, rhs, mybeg, 0, 0);
827  }
828  BMSfreeMemoryArray( &mybeg );
829 
830  // copy rownames if necessary
831  if ( rownames )
832  {
833  std::vector<std::string> rowNames(nrows);
834  for (int j = 0; j < nrows; ++j)
835  rowNames[j].assign(rownames[j]);
836  lpi->clp->copyRowNames(rowNames, numRows, numRows + nrows);
837  }
838 
839  return SCIP_OKAY;
840 }
841 
842 
843 /** deletes all rows in the given range from LP */
845  SCIP_LPI* lpi, /**< LP interface structure */
846  int firstrow, /**< first row to be deleted */
847  int lastrow /**< last row to be deleted */
848  )
849 {
850  SCIPdebugMessage("calling SCIPlpiDelRows() (number: %d)\n", lastrow-firstrow+1);
851 
852  assert(lpi != 0);
853  assert(lpi->clp != 0);
854  assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
855 
856  invalidateSolution(lpi);
857 
858  // Current Clp version (1.8) can't delete a range of rows; we have to use deleteRows (see SCIPlpiDelRowset)
859  int num = lastrow-firstrow+1;
860  int* which = NULL;
861  SCIP_ALLOC( BMSallocMemoryArray( &which, num) );
862 
863  // fill array with interval
864  for (int i = firstrow; i <= lastrow; ++i)
865  which[i - firstrow] = i;
866 
867  lpi->clp->deleteRows(num, which);
868 
869  BMSfreeMemoryArray( &which );
870 
871  return SCIP_OKAY;
872 }
873 
874 
875 /** deletes rows from SCIP_LP; the new position of a row must not be greater that its old position */
877  SCIP_LPI* lpi, /**< LP interface structure */
878  int* dstat /**< deletion status of rows
879  * input: 1 if row should be deleted, 0 if not
880  * output: new position of row, -1 if row was deleted */
881  )
882 {
883  SCIPdebugMessage("calling SCIPlpiDelRowset()\n");
884 
885  assert(lpi != 0);
886  assert(lpi->clp != 0);
887  assert(dstat != 0);
888 
889  invalidateSolution(lpi);
890 
891  // transform dstat information
892  int nrows = lpi->clp->getNumRows();
893  int* which = NULL;
894  SCIP_ALLOC( BMSallocMemoryArray( &which, nrows) );
895  int cnt = 0;
896  for (int i = 0; i < nrows; ++i)
897  {
898  if ( dstat[i] == 1 )
899  which[cnt++] = i;
900  }
901  lpi->clp->deleteRows(cnt, which);
902  BMSfreeMemoryArray( &which );
903 
904  // update dstat
905  cnt = 0;
906  for (int i = 0; i < nrows; ++i)
907  {
908  if ( dstat[i] == 1 )
909  {
910  dstat[i] = -1;
911  ++cnt;
912  }
913  else
914  dstat[i] = i - cnt;
915  }
916 
917  return SCIP_OKAY;
918 }
919 
920 
921 /** clears the whole LP */
923  SCIP_LPI* lpi /**< LP interface structure */
924  )
925 {
926  SCIPdebugMessage("calling SCIPlpiClear()\n");
927 
928  assert(lpi != 0);
929  assert(lpi->clp != 0);
930 
931  invalidateSolution(lpi);
932 
933  // We use the resize(0,0) to get rid of the model but keep all other settings
934  lpi->clp->resize(0,0);
935 
936  return SCIP_OKAY;
937 }
938 
939 
940 /** changes lower and upper bounds of columns */
942  SCIP_LPI* lpi, /**< LP interface structure */
943  int ncols, /**< number of columns to change bounds for */
944  const int* ind, /**< column indices */
945  const SCIP_Real* lb, /**< values for the new lower bounds */
946  const SCIP_Real* ub /**< values for the new upper bounds */
947  )
948 {
949  SCIPdebugMessage("calling SCIPlpiChgBounds()\n");
950 
951  assert(lpi != 0);
952  assert(lpi->clp != 0);
953  assert(ind != 0);
954  assert(lb != 0);
955  assert(ub != 0);
956 
957  invalidateSolution(lpi);
958 
959  ClpSimplex* clp = lpi->clp;
960 
961  /* We currently employ the following bug fix: the solution vector is modified to be set to the
962  * corresponding bounds. This avoids one error in Clp - maybe fixed in later versions. */
963  double* sol = lpi->clp->primalColumnSolution();
964  const double* colLower = lpi->clp->getColLower();
965  const double* colUpper = lpi->clp->getColUpper();
966 
967  for (int j = 0; j < ncols; ++j)
968  {
969  clp->setColumnBounds(ind[j], lb[j], ub[j]);
970  if ( sol != 0 )
971  {
972  if( clp->statusExists() )
973  {
974  assert( colLower != 0 );
975  assert( colUpper != 0 );
976  int k = ind[j];
977  switch ( clp->getColumnStatus(k) )
978  {
979  case ClpSimplex::isFree:
980  case ClpSimplex::superBasic:
981  sol[j] = 0.0;
982  break;
983  case ClpSimplex::atUpperBound:
984  sol[k] = colUpper[k];
985  assert( colUpper[k] == ub[j] );
986  break;
987  case ClpSimplex::isFixed:
988  case ClpSimplex::atLowerBound:
989  sol[k] = colLower[k];
990  assert( colLower[k] == lb[j] );
991  break;
992  default:;
993  }
994  }
995  else
996  { /* workaround: if there is no status, we assume something */
997  sol[j] = 0.0;
998  }
999  }
1000  }
1001 
1002  return SCIP_OKAY;
1003 }
1004 
1005 
1006 /** changes left and right hand sides of rows */
1008  SCIP_LPI* lpi, /**< LP interface structure */
1009  int nrows, /**< number of rows to change sides for */
1010  const int* ind, /**< row indices */
1011  const SCIP_Real* lhs, /**< new values for left hand sides */
1012  const SCIP_Real* rhs /**< new values for right hand sides */
1013  )
1014 {
1015  SCIPdebugMessage("calling SCIPlpiChgSides()\n");
1016 
1017  assert(lpi != 0);
1018  assert(lpi->clp != 0);
1019  assert(ind != 0);
1020  assert(lhs != 0);
1021  assert(rhs != 0);
1022 
1023  invalidateSolution(lpi);
1024 
1025  ClpSimplex* clp = lpi->clp;
1026 
1027  for (int i = 0; i < nrows; ++i)
1028  clp->setRowBounds(ind[i], lhs[i], rhs[i]);
1029 
1030  return SCIP_OKAY;
1031 }
1032 
1033 
1034 /** changes a single coefficient */
1036  SCIP_LPI* lpi, /**< LP interface structure */
1037  int row, /**< row number of coefficient to change */
1038  int col, /**< column number of coefficient to change */
1039  SCIP_Real newval /**< new value of coefficient */
1040  )
1041 {
1042  SCIPdebugMessage("calling SCIPlpiChgCoef()\n");
1043 
1044  assert(lpi != 0);
1045  assert(lpi->clp != 0);
1046  assert(0 <= row && row < lpi->clp->numberRows());
1047  assert(0 <= col && col < lpi->clp->numberColumns());
1048 
1049  invalidateSolution(lpi);
1050 
1051  lpi->clp->matrix()->modifyCoefficient(row, col, newval);
1052 
1053  return SCIP_OKAY;
1054 }
1055 
1056 
1057 /** changes the objective sense */
1059  SCIP_LPI* lpi, /**< LP interface structure */
1060  SCIP_OBJSEN objsen /**< new objective sense */
1061  )
1062 {
1063  SCIPdebugMessage("calling SCIPlpiChgObjsen()\n");
1064 
1065  assert(lpi != 0);
1066  assert(lpi->clp != 0);
1067 
1068  invalidateSolution(lpi);
1069 
1070  // set objective sense: SCIP values are the same as the ones for Clp
1071  lpi->clp->setOptimizationDirection(objsen);
1072 
1073  return SCIP_OKAY;
1074 }
1075 
1076 
1077 /** changes objective values of columns in the LP */
1079  SCIP_LPI* lpi, /**< LP interface structure */
1080  int ncols, /**< number of columns to change objective value for */
1081  int* ind, /**< column indices to change objective value for */
1082  SCIP_Real* obj /**< new objective values for columns */
1083  )
1084 {
1085  SCIPdebugMessage("calling SCIPlpiChgObj()\n");
1086 
1087  assert(lpi != 0);
1088  assert(lpi->clp != 0);
1089  assert(ind != 0);
1090  assert(obj != 0);
1091 
1092  invalidateSolution(lpi);
1093 
1094  ClpSimplex* clp = lpi->clp;
1095 
1096  // updates whatsChanged in Clp (bound checking in Clp)
1097  for( int j = 0; j < ncols; ++j )
1098  clp->setObjCoeff(ind[j], obj[j]); // inlined version of clp->setObjectiveCoefficient(ind[j], obj[j]);
1099 
1100  return SCIP_OKAY;
1101 }
1102 
1103 
1104 /** multiplies a row with a non-zero scalar; for negative scalars, the row's sense is switched accordingly */
1106  SCIP_LPI* lpi, /**< LP interface structure */
1107  int row, /**< row number to scale */
1108  SCIP_Real scaleval /**< scaling multiplier */
1109  )
1110 {
1111  SCIPdebugMessage("calling SCIPlpiScaleRow()\n");
1112 
1113  assert(lpi != 0);
1114  assert(lpi->clp != 0);
1115  assert(scaleval != 0.0);
1116  assert(0 <= row && row <= lpi->clp->numberRows() );
1117 
1118  invalidateSolution(lpi);
1119 
1120  // Note: if the scaling should be performed because of numerical stability,
1121  // there are other more effective methods in Clp to adjust the scaling values
1122  // for each row.
1123 
1124  ClpSimplex* clp = lpi->clp;
1125 
1126  // adjust the sides
1127  double* lhs = clp->rowLower();
1128  double* rhs = clp->rowUpper();
1129 
1130  double lhsval = lhs[row];
1131  if( lhsval > -COIN_DBL_MAX )
1132  lhsval *= scaleval;
1133  else if( scaleval < 0.0 )
1134  lhsval = COIN_DBL_MAX;
1135  double rhsval = rhs[row];
1136  if( rhsval < COIN_DBL_MAX)
1137  rhsval *= scaleval;
1138  else if( scaleval < 0.0 )
1139  rhsval = -COIN_DBL_MAX;
1140  if( scaleval < 0.0 )
1141  {
1142  SCIP_Real oldlhs = lhsval;
1143  lhsval = rhsval;
1144  rhsval = oldlhs;
1145  }
1146  lhs[row] = lhsval; // change values directly into Clp data!
1147  rhs[row] = rhsval;
1148 
1149  // apply scaling ...
1150 
1151  // WARNING: the following is quite expensive:
1152  // We have to loop over the matrix to find the row entries.
1153  // For columns we can do better, see @c SCIPlpiScaleCol.
1154  CoinPackedMatrix* M = clp->matrix();
1155  assert( M->getNumCols() == clp->numberColumns() );
1156 
1157  const CoinBigIndex* beg = M->getVectorStarts();
1158  const int* length = M->getVectorLengths();
1159  const int* ind = M->getIndices();
1160  double* val = M->getMutableElements();
1161 
1162  for (int j = 0; j < M->getNumCols(); ++j)
1163  {
1164  for (CoinBigIndex k = beg[j]; k < beg[j] + length[j]; ++k)
1165  {
1166  if (ind[k] == row)
1167  val[k] *= scaleval;
1168  }
1169  }
1170 
1171  return SCIP_OKAY;
1172 }
1173 
1174 
1175 /** multiplies a column with a non-zero scalar; the objective value is multiplied with the scalar, and the bounds
1176  * are divided by the scalar; for negative scalars, the column's bounds are switched
1177  */
1179  SCIP_LPI* lpi, /**< LP interface structure */
1180  int col, /**< column number to scale */
1181  SCIP_Real scaleval /**< scaling multiplier */
1182  )
1183 {
1184  SCIPdebugMessage("calling SCIPlpiScaleCol()\n");
1185 
1186  assert(lpi != 0);
1187  assert(lpi->clp != 0);
1188  assert(scaleval != 0.0);
1189  assert(0 <= col && col <= lpi->clp->numberColumns() );
1190 
1191  invalidateSolution(lpi);
1192 
1193  // Note: if the scaling should be performed because of numerical stability,
1194  // there are other more effective methods in Clp to adjust the scaling values
1195  // for each column.
1196 
1197  ClpSimplex* clp = lpi->clp;
1198 
1199  // adjust the objective coefficients
1200  double* objvec = clp->objective(); // we have direct access to the data of Clp!
1201  objvec[col] *= scaleval; // adjust the objective function value
1202 
1203  // adjust the bounds
1204  double* lb = clp->columnLower();
1205  double* ub = clp->columnUpper();
1206  double lbval = lb[col];
1207  double ubval = ub[col];
1208 
1209  if( lbval > -COIN_DBL_MAX )
1210  lbval /= scaleval;
1211  else if( scaleval < 0.0 )
1212  lbval = COIN_DBL_MAX;
1213  if( ubval < COIN_DBL_MAX )
1214  ubval /= scaleval;
1215  else if( scaleval < 0.0 )
1216  ubval = -COIN_DBL_MAX;
1217  if( scaleval < 0.0 )
1218  {
1219  SCIP_Real oldlb = lbval;
1220  lbval = ubval;
1221  ubval = oldlb;
1222  }
1223  lb[col] = lbval; // directly adjust values into Clp data
1224  ub[col] = ubval;
1225 
1226  // apply scaling directly to matrix (adapted from ClpPackedMatrix::reallyScale)
1227  // See also ClpModel::gutsOfScaling ...
1228  CoinPackedMatrix* M = clp->matrix();
1229  assert( M->getNumCols() == clp->numberColumns() );
1230 
1231  const CoinBigIndex* beg = M->getVectorStarts();
1232  const int* length = M->getVectorLengths();
1233  double* val = M->getMutableElements();
1234  for (CoinBigIndex k = beg[col]; k < beg[col] + length[col]; ++k)
1235  val[k] *= scaleval;
1236 
1237  return SCIP_OKAY;
1238 }
1239 
1240 
1241 
1242 /**@} */
1243 
1244 
1245 
1246 
1247 /*
1248  * Data Accessing Methods
1249  */
1250 
1251 /**@name Data Accessing Methods */
1252 /**@{ */
1253 
1254 /** gets the number of rows in the LP */
1256  SCIP_LPI* lpi, /**< LP interface structure */
1257  int* nrows /**< pointer to store the number of rows */
1258  )
1259 {
1260  SCIPdebugMessage("calling SCIPlpiGetNRows()\n");
1261 
1262  assert(lpi != 0);
1263  assert(lpi->clp != 0);
1264  assert(nrows != 0);
1265 
1266  *nrows = lpi->clp->numberRows();
1267 
1268  return SCIP_OKAY;
1269 }
1270 
1271 
1272 /** gets the number of columns in the LP */
1274  SCIP_LPI* lpi, /**< LP interface structure */
1275  int* ncols /**< pointer to store the number of cols */
1276  )
1277 {
1278  SCIPdebugMessage("calling SCIPlpiGetNCols()\n");
1279 
1280  assert(lpi != 0);
1281  assert(lpi->clp != 0);
1282  assert(ncols != 0);
1283 
1284  *ncols = lpi->clp->numberColumns();
1285 
1286  return SCIP_OKAY;
1287 }
1288 
1289 
1290 /** gets the number of nonzero elements in the LP constraint matrix */
1292  SCIP_LPI* lpi, /**< LP interface structure */
1293  int* nnonz /**< pointer to store the number of nonzeros */
1294  )
1295 {
1296  SCIPdebugMessage("calling SCIPlpiGetNNonz()\n");
1297 
1298  assert(lpi != 0);
1299  assert(lpi->clp != 0);
1300  assert(nnonz != 0);
1301 
1302  *nnonz = lpi->clp->getNumElements();
1303 
1304  return SCIP_OKAY;
1305 }
1306 
1307 
1308 /** gets columns from LP problem object; the arrays have to be large enough to store all values
1309  * Either both, lb and ub, have to be 0, or both have to be non-0,
1310  * either nnonz, beg, ind, and val have to be 0, or all of them have to be non-0.
1311  */
1313  SCIP_LPI* lpi, /**< LP interface structure */
1314  int firstcol, /**< first column to get from LP */
1315  int lastcol, /**< last column to get from LP */
1316  SCIP_Real* lb, /**< buffer to store the lower bound vector, or 0 */
1317  SCIP_Real* ub, /**< buffer to store the upper bound vector, or 0 */
1318  int* nnonz, /**< pointer to store the number of nonzero elements returned, or 0 */
1319  int* beg, /**< buffer to store start index of each column in ind- and val-array, or 0 */
1320  int* ind, /**< buffer to store column indices of constraint matrix entries, or 0 */
1321  SCIP_Real* val /**< buffer to store values of constraint matrix entries, or 0 */
1322  )
1323 {
1324  SCIPdebugMessage("calling SCIPlpiGetCols()\n");
1325 
1326  assert(lpi != 0);
1327  assert(lpi->clp != 0);
1328  assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1329 
1330  ClpSimplex* clp = lpi->clp;
1331 
1332  // get lower and upper bounds for the variables
1333  assert( (lb != 0 && ub != 0) || (lb == 0 && ub == 0) );
1334  if ( lb != 0 )
1335  {
1336  const double* colLower = clp->getColLower(); // Here we can use the const versions (see SCIPchgBounds)
1337  const double* colUpper = clp->getColUpper();
1338 
1339  BMScopyMemoryArray( lb, colLower + firstcol, (lastcol - firstcol + 1));
1340  BMScopyMemoryArray( ub, colUpper + firstcol, (lastcol - firstcol + 1));
1341  }
1342 
1343  assert( nnonz != 0 || beg == 0);
1344  assert( nnonz != 0 || ind == 0);
1345  assert( nnonz != 0 || val == 0);
1346 
1347  if ( nnonz != 0 )
1348  {
1349  CoinPackedMatrix* M = clp->matrix();
1350  assert( M != 0 );
1351  assert( M->getNumCols() == clp->numberColumns() );
1352 
1353  const CoinBigIndex* Mbeg = M->getVectorStarts(); // can use const versions
1354  const int* Mlength = M->getVectorLengths();
1355  const int* Mind = M->getIndices();
1356  const double* Mval = M->getElements();
1357 
1358  *nnonz = 0;
1359  // can we use memcpy for the whole set (requires that columns are stored sequentially)
1360  for (int j = firstcol; j <= lastcol; ++j)
1361  {
1362  beg[j-firstcol] = *nnonz;
1363 
1364  BMScopyMemoryArray( (ind + (*nnonz)), Mind + Mbeg[j], Mlength[j]);
1365  BMScopyMemoryArray( (val + (*nnonz)), Mval + Mbeg[j], Mlength[j]);
1366 
1367  (*nnonz) += Mlength[j];
1368  }
1369  }
1370 
1371  return SCIP_OKAY;
1372 }
1373 
1374 
1375 /** gets rows from LP problem object; the arrays have to be large enough to store all values.
1376  * Either both, lhs and rhs, have to be 0, or both have to be non-0,
1377  * either nnonz, beg, ind, and val have to be 0, or all of them have to be non-0.
1378  */
1380  SCIP_LPI* lpi, /**< LP interface structure */
1381  int firstrow, /**< first row to get from LP */
1382  int lastrow, /**< last row to get from LP */
1383  SCIP_Real* lhs, /**< buffer to store left hand side vector, or 0 */
1384  SCIP_Real* rhs, /**< buffer to store right hand side vector, or 0 */
1385  int* nnonz, /**< pointer to store the number of nonzero elements returned, or 0 */
1386  int* beg, /**< buffer to store start index of each row in ind- and val-array, or 0 */
1387  int* ind, /**< buffer to store row indices of constraint matrix entries, or 0 */
1388  SCIP_Real* val /**< buffer to store values of constraint matrix entries, or 0 */
1389  )
1390 {
1391  SCIPdebugMessage("calling SCIPlpiGetRows()\n");
1392 
1393  assert(lpi != 0);
1394  assert(lpi->clp != 0);
1395  assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
1396 
1397  ClpSimplex* clp = lpi->clp;
1398  assert( (lhs != 0 && rhs != 0) || (lhs == 0 && rhs == 0) );
1399  if ( lhs != 0 )
1400  {
1401  const double* rowLower = clp->getRowLower(); // Here we can use the const versions (see SCIPchgSides)
1402  const double* rowUpper = clp->getRowUpper();
1403 
1404  BMScopyMemoryArray( lhs, rowLower + firstrow, (lastrow - firstrow + 1) );
1405  BMScopyMemoryArray( rhs, rowUpper + firstrow, (lastrow - firstrow + 1) );
1406  }
1407 
1408  assert( nnonz != 0 || beg == 0);
1409  assert( nnonz != 0 || ind == 0);
1410  assert( nnonz != 0 || val == 0);
1411 
1412  if ( nnonz != 0 )
1413  {
1414  ClpMatrixBase* M = clp->rowCopy(); // get row view on matrix
1415  if ( M == 0 ) // can happen e.g. if no LP was solved yet ...
1416  M = clp->clpMatrix()->reverseOrderedCopy();
1417  assert( M != 0 );
1418  assert( M->getNumRows() == clp->numberRows() );
1419 
1420  const CoinBigIndex* Mbeg = M->getVectorStarts();
1421  const int* Mlength = M->getVectorLengths();
1422  const int* Mind = M->getIndices();
1423  const double* Mval = M->getElements();
1424 
1425  *nnonz = 0;
1426  for( int i = firstrow; i <= lastrow; ++i )
1427  {
1428  beg[i-firstrow] = *nnonz;
1429  for( CoinBigIndex k = Mbeg[i]; k < Mbeg[i] + Mlength[i]; ++k )
1430  {
1431  ind[*nnonz] = Mind[k];
1432  val[*nnonz] = Mval[k];
1433  (*nnonz)++;
1434  }
1435  }
1436  }
1437 
1438  return SCIP_OKAY;
1439 }
1440 
1441 
1442 /** gets column names */
1444  SCIP_LPI* lpi, /**< LP interface structure */
1445  int firstcol, /**< first column to get name from LP */
1446  int lastcol, /**< last column to get name from LP */
1447  char** colnames, /**< pointers to column names (of size at least lastcol-firstcol+1) */
1448  char* namestorage, /**< storage for col names */
1449  int namestoragesize, /**< size of namestorage (if 0, storageleft returns the storage needed) */
1450  int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) */
1451  )
1452 {
1453  SCIPerrorMessage("SCIPlpiGetColNames() has not been implemented yet.\n");
1454  return SCIP_LPERROR;
1455 }
1456 
1457 
1458 /** gets row names */
1460  SCIP_LPI* lpi, /**< LP interface structure */
1461  int firstrow, /**< first row to get name from LP */
1462  int lastrow, /**< last row to get name from LP */
1463  char** rownames, /**< pointers to row names (of size at least lastrow-firstrow+1) */
1464  char* namestorage, /**< storage for row names */
1465  int namestoragesize, /**< size of namestorage (if 0, -storageleft returns the storage needed) */
1466  int* storageleft /**< amount of storage left (if < 0 the namestorage was not big enough) */
1467  )
1468 {
1469  SCIPerrorMessage("SCIPlpiGetRowNames() has not been implemented yet.\n");
1470  return SCIP_LPERROR;
1471 }
1472 
1473 
1474 /** tries to reset the internal status of the LP solver in order to ignore an instability of the last solving call */
1476  SCIP_LPI* lpi, /**< LP interface structure */
1477  SCIP_Bool* success /**< pointer to store, whether the instability could be ignored */
1478  )
1479 {
1480  SCIPdebugMessage("calling SCIPlpiIgnoreInstability()\n");
1481 
1482  assert(lpi != NULL);
1483  assert(lpi->clp != NULL);
1484 
1485  /* unstable situations cannot be ignored */
1486  *success = FALSE;
1487 
1488  return SCIP_OKAY;
1489 }
1490 
1491 
1492 /** gets the objective sense of the LP */
1494  SCIP_LPI* lpi, /**< LP interface structure */
1495  SCIP_OBJSEN* objsen /**< pointer to store objective sense */
1496  )
1497 {
1498  assert( lpi != NULL );
1499  assert( lpi->clp != NULL );
1500  assert( objsen != NULL );
1501 
1502  // Clp direction of optimization (1 - minimize, -1 - maximize, 0 - ignore)
1503  if ( lpi->clp->getObjSense() < 0 )
1504  *objsen = SCIP_OBJSEN_MAXIMIZE;
1505  else
1506  *objsen = SCIP_OBJSEN_MINIMIZE;
1507 
1508  return SCIP_OKAY;
1509 }
1510 
1511 
1512 /** gets objective coefficients from LP problem object */
1514  SCIP_LPI* lpi, /**< LP interface structure */
1515  int firstcol, /**< first column to get objective coefficient for */
1516  int lastcol, /**< last column to get objective coefficient for */
1517  SCIP_Real* vals /**< array to store objective coefficients */
1518  )
1519 {
1520  SCIPdebugMessage("calling SCIPlpiGetObj()\n");
1521 
1522  assert(lpi != 0);
1523  assert(lpi->clp != 0);
1524  assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1525  assert(vals != 0);
1526 
1527  const double* obj = lpi->clp->getObjCoefficients(); // Here we can use the const versions (see SCIPchgObj)
1528 
1529  BMScopyMemoryArray( vals, obj + firstcol, (lastcol - firstcol + 1) );
1530 
1531  return SCIP_OKAY;
1532 }
1533 
1534 
1535 /** gets current bounds from LP problem object */
1537  SCIP_LPI* lpi, /**< LP interface structure */
1538  int firstcol, /**< first column to get objective value for */
1539  int lastcol, /**< last column to get objective value for */
1540  SCIP_Real* lbs, /**< array to store lower bound values, or 0 */
1541  SCIP_Real* ubs /**< array to store upper bound values, or 0 */
1542  )
1543 {
1544  SCIPdebugMessage("calling SCIPlpiGetBounds()\n");
1545 
1546  assert(lpi != 0);
1547  assert(lpi->clp != 0);
1548  assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1549 
1550  if ( lbs != 0 )
1551  {
1552  const double* colLower = lpi->clp->getColLower(); // Here we can use the const versions (see SCIPchgBounds)
1553  BMScopyMemoryArray( lbs, colLower + firstcol, (lastcol - firstcol + 1) );
1554  }
1555 
1556  if ( ubs != 0 )
1557  {
1558  const double* colUpper = lpi->clp->getColUpper();
1559  BMScopyMemoryArray( ubs, colUpper + firstcol, (lastcol - firstcol + 1) );
1560  }
1561 
1562  return SCIP_OKAY;
1563 }
1564 
1565 
1566 /** gets current row sides from LP problem object */
1568  SCIP_LPI* lpi, /**< LP interface structure */
1569  int firstrow, /**< first row to get sides for */
1570  int lastrow, /**< last row to get sides for */
1571  SCIP_Real* lhss, /**< array to store left hand side values, or 0 */
1572  SCIP_Real* rhss /**< array to store right hand side values, or 0 */
1573  )
1574 {
1575  SCIPdebugMessage("calling SCIPlpiGetSides()\n");
1576 
1577  assert(lpi != 0);
1578  assert(lpi->clp != 0);
1579  assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
1580 
1581  if ( lhss != 0 )
1582  {
1583  const double* rowLower = lpi->clp->getRowLower(); // Here we can use the const versions (see SCIPchgSides)
1584  BMScopyMemoryArray( lhss, rowLower + firstrow, (lastrow - firstrow + 1) );
1585  }
1586 
1587  if ( rhss != 0 )
1588  {
1589  const double* rowUpper = lpi->clp->getRowUpper();
1590  BMScopyMemoryArray( rhss, rowUpper + firstrow, (lastrow - firstrow + 1) );
1591  }
1592 
1593  return SCIP_OKAY;
1594 }
1595 
1596 
1597 /** gets a single coefficient */
1599  SCIP_LPI* lpi, /**< LP interface structure */
1600  int row, /**< row number of coefficient */
1601  int col, /**< column number of coefficient */
1602  SCIP_Real* val /**< pointer to store the value of the coefficient */
1603  )
1604 {
1605  SCIPdebugMessage("calling SCIPlpiGetCoef()\n");
1606 
1607  assert(lpi != 0);
1608  assert(lpi->clp != 0);
1609  assert(0 <= col && col < lpi->clp->numberColumns());
1610  assert(0 <= row && row < lpi->clp->numberRows());
1611  assert(val != 0);
1612 
1613  *val = lpi->clp->matrix()->getCoefficient(row, col);
1614 
1615  return SCIP_OKAY;
1616 }
1617 
1618 /**@} */
1619 
1620 
1621 
1622 
1623 /*
1624  * Solving Methods
1625  */
1626 
1627 /**@name Solving Methods */
1628 /**@{ */
1629 
1630 
1631 /** calls primal simplex to solve the LP */
1633  SCIP_LPI* lpi /**< LP interface structure */
1634  )
1635 {
1636  assert(lpi != 0);
1637  assert(lpi->clp != 0);
1638 
1639  SCIPdebugMessage("calling Clp primal(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1640 
1641 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1642  char filename[255];
1643  snprintf(filename, 255, "debug_p_%d.mps", fileNr);
1644  fileNr = fileNr % 2;
1645  SCIPlpiWriteLP(lpi, filename);
1646  SCIPdebugMessage("Wrote file <%s>\n", filename);
1647 #endif
1648 
1649  invalidateSolution(lpi);
1650 
1651  // intialize factorization freq. depending on model size - applied only once
1652  setFactorizationFrequency(lpi);
1653 
1654  // if we want to construct a new basis
1655  if ( lpi->startscratch )
1656  {
1657  lpi->clp->allSlackBasis(true); // reset basis
1658  lpi->validFactorization = false;
1659  }
1660 
1661  /** startFinishOptions - bits
1662  * 1 - do not delete work areas and factorization at end
1663  * 2 - use old factorization if same number of rows
1664  * 4 - skip as much initialization of work areas as possible (work in progress)
1665  *
1666  * 4 does not seem to work.
1667  */
1668  int startFinishOptions = 1;
1669  if ( lpi->validFactorization )
1670  startFinishOptions = startFinishOptions | 2;
1671 
1672  /** Primal algorithm */
1673  int status = lpi->clp->primal(0, startFinishOptions);
1674 
1675 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1676  char basisname[255];
1677  snprintf(basisname, 255, "debug_p_%d.bas", fileNr);
1678  SCIP_CALL( SCIPlpiWriteState(lpi, basisname) );
1679  SCIPdebugMessage("Wrote basis file <%s>\n", basisname);
1680  ++fileNr; /* not increased above! */
1681  fileNr = fileNr % 2;
1682 #endif
1683 
1684  lpi->validFactorization = true;
1685  lpi->solved = TRUE;
1686 
1687  // Unfortunately the status of Clp is hard coded ...
1688  // -1 - did not run
1689  // 0 - optimal
1690  // 1 - primal infeasible
1691  // 2 - dual infeasible
1692  // 3 - stopped on iterations or time
1693  // 4 - stopped due to errors
1694  // 5 - stopped by event handler
1695  assert( status != -1 ); // did not run should not occur
1696  assert( status != 5 ); // begin stopped by event handler should not occur
1697  if ( status == 4 || status == 5 || status == -1 )
1698  return SCIP_LPERROR;
1699 
1700  return SCIP_OKAY;
1701 }
1702 
1703 
1704 /** calls dual simplex to solve the LP */
1706  SCIP_LPI* lpi /**< LP interface structure */
1707  )
1708 {
1709  assert(lpi != 0);
1710  assert(lpi->clp != 0);
1711 
1712  SCIPdebugMessage("calling Clp dual(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1713 
1714 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1715  char filename[255];
1716  snprintf(filename, 255, "debug_d_%d.mps", fileNr);
1717  SCIPlpiWriteLP(lpi, filename);
1718  SCIPdebugMessage("Wrote file <%s>\n", filename);
1719  snprintf(filename, 255, "debug_d_%d.sav", fileNr);
1720  // lpi->clp->saveModel(filename);
1721  SCIPdebugMessage("Wrote file <%s>\n", filename);
1722 #endif
1723 
1724  invalidateSolution(lpi);
1725 
1726  // intialize factorization freq. depending on model size - applied only once
1727  setFactorizationFrequency(lpi);
1728 
1729  // if we want to construct a new basis
1730  if( lpi->startscratch )
1731  {
1732  lpi->clp->allSlackBasis(true); // reset basis
1733  lpi->validFactorization = false;
1734  }
1735 
1736  /** startFinishOptions - bits
1737  * 1 - do not delete work areas and factorization at end
1738  * 2 - use old factorization if same number of rows
1739  * 4 - skip as much initialization of work areas as possible (work in progress)
1740  *
1741  * 4 does not seem to work.
1742  */
1743  int startFinishOptions = 1;
1744  if ( lpi->validFactorization )
1745  startFinishOptions = startFinishOptions | 2;
1746 
1747  /** Dual algorithm */
1748  int status = lpi->clp->dual(0, startFinishOptions);
1749 
1750 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1751  char basisname[255];
1752  snprintf(basisname, 255, "debug_d_%d.bas", fileNr);
1753  SCIP_CALL( SCIPlpiWriteState(lpi, basisname) );
1754  SCIPdebugMessage("Wrote basis file <%s>\n", basisname);
1755  ++fileNr; /* not increased above! */
1756  fileNr = fileNr % 2;
1757 #endif
1758 
1759  lpi->validFactorization = true;
1760  lpi->solved = TRUE;
1761 
1762  // Unfortunately the status of Clp is hard coded ...
1763  // -1 - did not run
1764  // 0 - optimal
1765  // 1 - primal infeasible
1766  // 2 - dual infeasible
1767  // 3 - stopped on iterations or time
1768  // 4 - stopped due to errors
1769  // 5 - stopped by event handler
1770  assert( status != -1 ); // did not run should not occur
1771  assert( status != 5 ); // begin stopped by event handler should not occur
1772  if ( status == 4 || status == 5 || status == -1 )
1773  return SCIP_LPERROR;
1774 
1775  return SCIP_OKAY;
1776 }
1777 
1778 
1779 /** calls barrier or interior point algorithm to solve the LP with crossover to simplex basis */
1781  SCIP_LPI* lpi, /**< LP interface structure */
1782  SCIP_Bool crossover /**< perform crossover */
1783  )
1784 {
1785  assert(lpi != 0);
1786  assert(lpi->clp != 0);
1787 
1788  SCIPdebugMessage("calling Clp barrier(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1789 
1790  invalidateSolution(lpi);
1791 
1792  // Check whether we have a factorization, if yes destroy it (Clp doesn't like it ...)
1793  /*
1794  if (lpi->haveFactorization)
1795  lpi->clp->finish();
1796  */
1797 
1798  // call barrier
1799  int status = lpi->clp->barrier(crossover);
1800  lpi->solved = TRUE;
1801 
1802  // We may need to call ClpModel::status()
1803 
1804  // Unfortunately the status of Clp is hard coded ...
1805  // -1 - did not run
1806  // 0 - optimal
1807  // 1 - primal infeasible
1808  // 2 - dual infeasible
1809  // 3 - stopped on iterations or time
1810  // 4 - stopped due to errors
1811  // 5 - stopped by event handler
1812  assert( status != -1 ); // did not run should not occur
1813  assert( status != 5 ); // begin stopped by event handler should not occur
1814  if ( status == 4 || status == 5 || status == -1 )
1815  return SCIP_LPERROR;
1816 
1817  return SCIP_OKAY;
1818 }
1819 
1820 /** start strong branching - call before any strongbranching */
1822  SCIP_LPI* lpi /**< LP interface structure */
1823  )
1824 {
1825  // currently do nothing; in the future: use code as in OSI
1826  return SCIP_OKAY;
1827 }
1828 
1829 /** end strong branching - call after any strongbranching */
1831  SCIP_LPI* lpi /**< LP interface structure */
1832  )
1833 {
1834  // currently do nothing; in the future: use code as in OSI
1835  return SCIP_OKAY;
1836 }
1837 
1838 /** performs strong branching iterations on one arbitrary candidate */
1839 static
1840 SCIP_RETCODE lpiStrongbranch(
1841  SCIP_LPI* lpi, /**< LP interface structure */
1842  int col, /**< column to apply strong branching on */
1843  SCIP_Real psol, /**< current primal solution value of column */
1844  int itlim, /**< iteration limit for strong branchings */
1845  SCIP_Real* down, /**< stores dual bound after branching column down */
1846  SCIP_Real* up, /**< stores dual bound after branching column up */
1847  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
1848  * otherwise, it can only be used as an estimate value */
1849  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
1850  * otherwise, it can only be used as an estimate value */
1851  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
1852  )
1853 {
1854  SCIPdebugMessage("calling SCIPlpiStrongbranch() on variable %d (%d iterations)\n", col, itlim);
1855 
1856  assert(lpi != 0);
1857  assert(lpi->clp != 0);
1858  assert(down != 0);
1859  assert(up != 0);
1860  assert(downvalid != 0);
1861  assert(upvalid != 0);
1862 
1863  ClpSimplex* clp = lpi->clp;
1864 
1865  // set up output arrays
1866  int ncols = clp->numberColumns();
1867  assert( 0 <= col && col < ncols );
1868  double** outputSolution = NULL;
1869  SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2) );
1870  SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[0], ncols) );
1871  SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[1], ncols) );
1872 
1873  int* outputStatus = NULL;
1874  SCIP_ALLOC( BMSallocMemoryArray( &outputStatus, 2) );
1875 
1876  int* outputIterations = NULL;
1877  SCIP_ALLOC( BMSallocMemoryArray( &outputIterations, 2) );
1878 
1879  // set iteration limit
1880  int iterlimit = clp->maximumIterations();
1881  clp->setMaximumIterations(itlim);
1882 
1883  // store objective value
1884  double objval = clp->objectiveValue();
1885 
1886  // store special options for later reset
1887  int specialoptions = clp->specialOptions();
1888 
1889  /** Clp special options:
1890  * 1 - Don't keep changing infeasibility weight
1891  * 2 - Keep nonLinearCost round solves
1892  * 4 - Force outgoing variables to exact bound (primal)
1893  * 8 - Safe to use dense initial factorization
1894  * 16 - Just use basic variables for operation if column generation
1895  * 32 - Create ray even in BAB
1896  * 64 - Treat problem as feasible until last minute (i.e. minimize infeasibilities)
1897  * 128 - Switch off all matrix sanity checks
1898  * 256 - No row copy
1899  * 512 - If not in values pass, solution guaranteed, skip as much as possible
1900  * 1024 - In branch and bound
1901  * 2048 - Don't bother to re-factorize if < 20 iterations
1902  * 4096 - Skip some optimality checks
1903  * 8192 - Do Primal when cleaning up primal
1904  * 16384 - In fast dual (so we can switch off things)
1905  * 32768 - called from Osi
1906  * 65536 - keep arrays around as much as possible (also use maximumR/C)
1907  * 131072 - transposeTimes is -1.0 and can skip basic and fixed
1908  * 262144 - extra copy of scaled matrix
1909  * 524288 - Clp fast dual
1910  * 1048576 - don't need to finish dual (can return 3)
1911  * NOTE - many applications can call Clp but there may be some short cuts
1912  * which are taken which are not guaranteed safe from all applications.
1913  * Vetted applications will have a bit set and the code may test this
1914  * At present I expect a few such applications - if too many I will
1915  * have to re-think. It is up to application owner to change the code
1916  * if she/he needs these short cuts. I will not debug unless in Coin
1917  * repository. See COIN_CLP_VETTED comments.
1918  * 0x01000000 is Cbc (and in branch and bound)
1919  * 0x02000000 is in a different branch and bound
1920  *
1921  * 2048 does not seem to work
1922  * 262144 does not seem to work
1923  */
1924 #ifndef NDEBUG
1925  // in debug mode: leave checks on
1926  clp->setSpecialOptions(64|512|1024);
1927 #else
1928  clp->setSpecialOptions(64|128|512|1024|4096);
1929 #endif
1930 
1931  /* 'startfinish' options for strong branching:
1932  * 1 - do not delete work areas and factorization at end
1933  * 2 - use old factorization if same number of rows
1934  * 4 - skip as much initialization of work areas as possible
1935  * (based on whatsChanged in clpmodel.hpp) ** work in progress
1936  *
1937  * 4 does not seem to work in strong branching ...
1938  */
1939  int startFinishOptions = 1;
1940  if ( lpi->validFactorization )
1941  startFinishOptions = startFinishOptions | 2;
1942 
1943  // set new lower and upper bounds for variable
1944  *down = EPSCEIL(psol - 1.0, 1e-06);
1945  *up = EPSFLOOR(psol + 1.0, 1e-06);
1946 
1947  /** For strong branching. On input lower and upper are new bounds while
1948  * on output they are change in objective function values (>1.0e50
1949  * infeasible). Return code is
1950  * 0 if nothing interesting,
1951  * -1 if infeasible both ways and
1952  * +1 if infeasible one way (check values to see which one(s))
1953  * -2 if bad factorization
1954  * Solutions are filled in as well - even down, odd up - also status and number of iterations
1955  *
1956  * The bools are:
1957  * bool stopOnFirstInfeasible
1958  * bool alwaysFinish
1959  *
1960  * At the moment: we need alwaysFinish to get correct bounds.
1961  */
1962  //int res = clp->strongBranching(1, &col, up, down, outputSolution, outputStatus, outputIterations, false, false, startFinishOptions);
1963  int res = clp->strongBranching(1, &col, up, down, outputSolution, outputStatus, outputIterations, false, true, startFinishOptions);
1964 
1965  // reset special options
1966  clp->setSpecialOptions(specialoptions);
1967 
1968  lpi->validFactorization = true;
1969 
1970  *down += objval;
1971  *up += objval;
1972 
1973  // The bounds returned by CLP seem to be valid using the above options
1974  *downvalid = TRUE;
1975  *upvalid = TRUE;
1976 
1977  // correct iteration count
1978  if (iter)
1979  *iter = outputIterations[0] + outputIterations[1];
1980 
1981  // reset iteration limit
1982  clp->setMaximumIterations(iterlimit);
1983 
1984  // free local memory
1985  BMSfreeMemoryArray( &outputStatus );
1986  BMSfreeMemoryArray( &outputIterations );
1987  BMSfreeMemoryArray( &outputSolution[1] );
1988  BMSfreeMemoryArray( &outputSolution[0] );
1989  BMSfreeMemoryArray( &outputSolution );
1990 
1991  if ( res == -2 )
1992  return SCIP_LPERROR;
1993 
1994  return SCIP_OKAY;
1995 }
1996 
1997 /** performs strong branching iterations on given arbitrary candidates */
1998 static
1999 SCIP_RETCODE lpiStrongbranches(
2000  SCIP_LPI* lpi, /**< LP interface structure */
2001  int* cols, /**< columns to apply strong branching on */
2002  int ncols, /**< number of columns */
2003  SCIP_Real* psols, /**< fractional current primal solution values of columns */
2004  int itlim, /**< iteration limit for strong branchings */
2005  SCIP_Real* down, /**< stores dual bounds after branching columns down */
2006  SCIP_Real* up, /**< stores dual bounds after branching columns up */
2007  SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
2008  * otherwise, they can only be used as an estimate values */
2009  SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
2010  * otherwise, they can only be used as an estimate values */
2011  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2012  )
2013 {
2014  SCIPdebugMessage("calling SCIPlpiStrongbranches() on %d variables (%d iterations)\n", ncols, itlim);
2015 
2016  assert( lpi != 0 );
2017  assert( lpi->clp != 0 );
2018  assert( cols != 0 );
2019  assert( psols != 0 );
2020  assert( down != 0 );
2021  assert( up != 0 );
2022  assert( downvalid != 0 );
2023  assert( upvalid != 0 );
2024 
2025  ClpSimplex* clp = lpi->clp;
2026 
2027  // set up output arrays
2028  int n = clp->numberColumns();
2029  assert( 0 < ncols && ncols <= n );
2030  double** outputSolution = NULL;
2031  SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2*ncols) );
2032  for (int j = 0; j < 2*ncols; ++j)
2033  {
2034  SCIP_ALLOC( BMSallocMemoryArray( &(outputSolution[j]), n) );
2035  }
2036 
2037  int* outputStatus = NULL;
2038  SCIP_ALLOC( BMSallocMemoryArray(&outputStatus, 2*ncols) );
2039 
2040  int* outputIterations = NULL;
2041  SCIP_ALLOC( BMSallocMemoryArray(&outputIterations, 2*ncols) );
2042 
2043  // set iteration limit
2044  int iterlimit = clp->maximumIterations();
2045  clp->setMaximumIterations(itlim);
2046 
2047  // store objective value
2048  double objval = clp->objectiveValue();
2049 
2050  // store special options for later reset
2051  int specialoptions = clp->specialOptions();
2052 
2053  /** Clp special options:
2054  * 1 - Don't keep changing infeasibility weight
2055  * 2 - Keep nonLinearCost round solves
2056  * 4 - Force outgoing variables to exact bound (primal)
2057  * 8 - Safe to use dense initial factorization
2058  * 16 - Just use basic variables for operation if column generation
2059  * 32 - Create ray even in BAB
2060  * 64 - Treat problem as feasible until last minute (i.e. minimize infeasibilities)
2061  * 128 - Switch off all matrix sanity checks
2062  * 256 - No row copy
2063  * 512 - If not in values pass, solution guaranteed, skip as much as possible
2064  * 1024 - In branch and bound
2065  * 2048 - Don't bother to re-factorize if < 20 iterations
2066  * 4096 - Skip some optimality checks
2067  * 8192 - Do Primal when cleaning up primal
2068  * 16384 - In fast dual (so we can switch off things)
2069  * 32768 - called from Osi
2070  * 65536 - keep arrays around as much as possible (also use maximumR/C)
2071  * 131072 - transposeTimes is -1.0 and can skip basic and fixed
2072  * 262144 - extra copy of scaled matrix
2073  * 524288 - Clp fast dual
2074  * 1048576 - don't need to finish dual (can return 3)
2075  * NOTE - many applications can call Clp but there may be some short cuts
2076  * which are taken which are not guaranteed safe from all applications.
2077  * Vetted applications will have a bit set and the code may test this
2078  * At present I expect a few such applications - if too many I will
2079  * have to re-think. It is up to application owner to change the code
2080  * if she/he needs these short cuts. I will not debug unless in Coin
2081  * repository. See COIN_CLP_VETTED comments.
2082  * 0x01000000 is Cbc (and in branch and bound)
2083  * 0x02000000 is in a different branch and bound
2084  *
2085  * 2048 does not seem to work
2086  * 262144 does not seem to work
2087  */
2088 #ifndef NDEBUG
2089  // in debug mode: leave checks on
2090  clp->setSpecialOptions(64|512|1024);
2091 #else
2092  clp->setSpecialOptions(64|128|512|1024|4096);
2093 #endif
2094 
2095  /* 'startfinish' options for strong branching:
2096  * 1 - do not delete work areas and factorization at end
2097  * 2 - use old factorization if same number of rows
2098  * 4 - skip as much initialization of work areas as possible
2099  * (based on whatsChanged in clpmodel.hpp) ** work in progress
2100  *
2101  * 4 does not seem to work in strong branching ...
2102  */
2103  int startFinishOptions = 1;
2104  if ( lpi->validFactorization )
2105  startFinishOptions = startFinishOptions | 2;
2106 
2107  // set new lower and upper bounds for variables
2108  for (int j = 0; j < ncols; ++j)
2109  {
2110  assert( 0 <= cols[j] && cols[j] < n );
2111  down[j] = EPSCEIL(psols[j] - 1.0, 1e-06);
2112  up[j] = EPSFLOOR(psols[j] + 1.0, 1e-06);
2113 
2114  // The bounds returned by CLP seem to be valid using the above options
2115  downvalid[j] = TRUE;
2116  upvalid[j] = TRUE;
2117  }
2118 
2119  /** For strong branching. On input lower and upper are new bounds while
2120  * on output they are change in objective function values (>1.0e50
2121  * infeasible). Return code is
2122  * 0 if nothing interesting,
2123  * -1 if infeasible both ways and
2124  * +1 if infeasible one way (check values to see which one(s))
2125  * -2 if bad factorization
2126  * Solutions are filled in as well - even down, odd up - also status and number of iterations
2127  *
2128  * The bools are:
2129  * bool stopOnFirstInfeasible
2130  * bool alwaysFinish
2131  *
2132  * At the moment: we need alwaysFinish to get correct bounds.
2133  */
2134  int res = clp->strongBranching(ncols, cols, up, down, outputSolution, outputStatus, outputIterations, false, true, startFinishOptions);
2135 
2136  // reset special options
2137  clp->setSpecialOptions(specialoptions);
2138 
2139  lpi->validFactorization = true;
2140 
2141  for (int j = 0; j < ncols; ++j)
2142  {
2143  down[j] += objval;
2144  up[j] += objval;
2145 
2146  // correct iteration count
2147  if (iter)
2148  *iter += outputIterations[2*j] + outputIterations[2*j+1];
2149 
2150  BMSfreeMemoryArray(&outputSolution[2*j]);
2151  BMSfreeMemoryArray(&outputSolution[2*j+1]);
2152  }
2153 
2154  // reset iteration limit
2155  clp->setMaximumIterations(iterlimit);
2156 
2157  // free local memory
2158  BMSfreeMemoryArray( &outputStatus );
2159  BMSfreeMemoryArray( &outputIterations );
2160  BMSfreeMemoryArray( &outputSolution );
2161 
2162  if ( res == -2 )
2163  return SCIP_LPERROR;
2164 
2165  return SCIP_OKAY;
2166 }
2167 
2168 /** performs strong branching iterations on one @b fractional candidate */
2170  SCIP_LPI* lpi, /**< LP interface structure */
2171  int col, /**< column to apply strong branching on */
2172  SCIP_Real psol, /**< current primal solution value of column */
2173  int itlim, /**< iteration limit for strong branchings */
2174  SCIP_Real* down, /**< stores dual bound after branching column down */
2175  SCIP_Real* up, /**< stores dual bound after branching column up */
2176  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
2177  * otherwise, it can only be used as an estimate value */
2178  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
2179  * otherwise, it can only be used as an estimate value */
2180  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2181  )
2182 {
2183  /* pass call on to lpiStrongbranch() */
2184  SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2185 
2186  return SCIP_OKAY;
2187 }
2188 
2189 /** performs strong branching iterations on given @b fractional candidates */
2191  SCIP_LPI* lpi, /**< LP interface structure */
2192  int* cols, /**< columns to apply strong branching on */
2193  int ncols, /**< number of columns */
2194  SCIP_Real* psols, /**< fractional current primal solution values of columns */
2195  int itlim, /**< iteration limit for strong branchings */
2196  SCIP_Real* down, /**< stores dual bounds after branching columns down */
2197  SCIP_Real* up, /**< stores dual bounds after branching columns up */
2198  SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
2199  * otherwise, they can only be used as an estimate values */
2200  SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
2201  * otherwise, they can only be used as an estimate values */
2202  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2203  )
2204 {
2205  if ( iter != NULL )
2206  *iter = 0;
2207 
2208  /* pass call on to lpiStrongbranches() */
2209  SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
2210 
2211  return SCIP_OKAY;
2212 }
2213 
2214 /** performs strong branching iterations on one candidate with @b integral value */
2216  SCIP_LPI* lpi, /**< LP interface structure */
2217  int col, /**< column to apply strong branching on */
2218  SCIP_Real psol, /**< current integral primal solution value of column */
2219  int itlim, /**< iteration limit for strong branchings */
2220  SCIP_Real* down, /**< stores dual bound after branching column down */
2221  SCIP_Real* up, /**< stores dual bound after branching column up */
2222  SCIP_Bool* downvalid, /**< stores whether the returned down value is a valid dual bound;
2223  * otherwise, it can only be used as an estimate value */
2224  SCIP_Bool* upvalid, /**< stores whether the returned up value is a valid dual bound;
2225  * otherwise, it can only be used as an estimate value */
2226  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2227  )
2228 {
2229  /* pass call on to lpiStrongbranch() */
2230  SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2231 
2232  return SCIP_OKAY;
2233 }
2234 
2235 /** performs strong branching iterations on given candidates with @b integral values */
2237  SCIP_LPI* lpi, /**< LP interface structure */
2238  int* cols, /**< columns to apply strong branching on */
2239  int ncols, /**< number of columns */
2240  SCIP_Real* psols, /**< current integral primal solution values of columns */
2241  int itlim, /**< iteration limit for strong branchings */
2242  SCIP_Real* down, /**< stores dual bounds after branching columns down */
2243  SCIP_Real* up, /**< stores dual bounds after branching columns up */
2244  SCIP_Bool* downvalid, /**< stores whether the returned down values are valid dual bounds;
2245  * otherwise, they can only be used as an estimate values */
2246  SCIP_Bool* upvalid, /**< stores whether the returned up values are a valid dual bounds;
2247  * otherwise, they can only be used as an estimate values */
2248  int* iter /**< stores total number of strong branching iterations, or -1; may be NULL */
2249  )
2250 {
2251  if ( iter != NULL )
2252  *iter = 0;
2253 
2254  /* pass call on to lpiStrongbranches() */
2255  SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
2256 
2257  return SCIP_OKAY;
2258 }
2259 
2260 
2261 
2262 
2263 /*
2264  * Solution Information Methods
2265  */
2266 
2267 /**@name Solution Information Methods */
2268 /**@{ */
2269 
2270 /** returns whether a solve method was called after the last modification of the LP */
2272  SCIP_LPI* lpi /**< LP interface structure */
2273  )
2274 {
2275  assert(lpi != NULL);
2276 
2277  return lpi->solved;
2278 }
2279 
2280 /** gets information about primal and dual feasibility of the current LP solution */
2282  SCIP_LPI* lpi, /**< LP interface structure */
2283  SCIP_Bool* primalfeasible, /**< stores primal feasibility status */
2284  SCIP_Bool* dualfeasible /**< stores dual feasibility status */
2285  )
2286 {
2287  SCIPdebugMessage("calling SCIPlpiGetSolFeasibility()\n");
2288 
2289  assert(lpi != 0);
2290  assert(lpi->clp != 0);
2291  assert(primalfeasible != 0);
2292  assert(dualfeasible != 0);
2293 
2294  if ( lpi->clp->primalFeasible() )
2295  *primalfeasible = TRUE;
2296  else
2297  *primalfeasible = FALSE;
2298 
2299  if ( lpi->clp->dualFeasible() )
2300  *dualfeasible = TRUE;
2301  else
2302  *dualfeasible = FALSE;
2303 
2304  // say feasible if deviation is small
2305  if (lpi->clp->status()==0 && ( ! (*primalfeasible) || ! (*dualfeasible)) )
2306  {
2307  if ( !(*primalfeasible) && lpi->clp->sumPrimalInfeasibilities() < SUMINFEASBOUND )
2308  {
2309  lpi->clp->setNumberPrimalInfeasibilities(0);
2310  *primalfeasible = TRUE;
2311  }
2312  if ( !(*dualfeasible) && lpi->clp->sumDualInfeasibilities() < SUMINFEASBOUND)
2313  {
2314  lpi->clp->setNumberDualInfeasibilities(0);
2315  *dualfeasible = TRUE;
2316  }
2317  }
2318 
2319  return SCIP_OKAY;
2320 }
2321 
2322 
2323 /** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point);
2324  * this does not necessarily mean, that the solver knows and can return the primal ray
2325  */
2327  SCIP_LPI* lpi /**< LP interface structure */
2328  )
2329 {
2330  SCIPdebugMessage("calling SCIPlpiExistsPrimalRay()\n");
2331 
2332  assert(lpi != 0);
2333  assert(lpi->clp != 0);
2334 
2335  /* Clp seems to have a primal ray whenever it concludes "dual infeasible" (status == 2)
2336  * (but is not necessarily primal feasible), see ClpModel::unboundedRay(). */
2337  return ( lpi->clp->status() == 2 );
2338 }
2339 
2340 
2341 /** returns TRUE iff LP is proven to have a primal unbounded ray (but not necessary a primal feasible point),
2342  * and the solver knows and can return the primal ray
2343  */
2345  SCIP_LPI* lpi /**< LP interface structure */
2346  )
2347 {
2348  SCIPdebugMessage("calling SCIPlpiHasPrimalRay()\n");
2349 
2350  assert(lpi != 0);
2351  assert(lpi->clp != 0);
2352 
2353  /* Clp seems to have a primal ray whenever it concludes "dual infeasible" (status == 2)
2354  * (but is not necessarily primal feasible), see ClpModel::unboundedRay(). */
2355  return ( lpi->clp->status() == 2 );
2356 }
2357 
2358 
2359 /** returns TRUE iff LP is proven to be primal unbounded */
2361  SCIP_LPI* lpi /**< LP interface structure */
2362  )
2363 {
2364  SCIPdebugMessage("calling SCIPlpiIsPrimalUnbounded()\n");
2365 
2366  assert(lpi != 0);
2367  assert(lpi->clp != 0);
2368 
2369  return ( lpi->clp->isProvenDualInfeasible() && lpi->clp->primalFeasible() );
2370 }
2371 
2372 
2373 /** returns TRUE iff LP is proven to be primal infeasible */
2375  SCIP_LPI* lpi /**< LP interface structure */
2376  )
2377 {
2378  SCIPdebugMessage("calling SCIPlpiIsPrimalInfeasible()\n");
2379 
2380  assert(lpi != 0);
2381  assert(lpi->clp != 0);
2382 
2383  /* Should return ClpModel::isProvenPrimalInfeasible() (which returns status == 1), but the
2384  * following is correct (Clp will not be changed). The secondaryStatus is 1 if the dual simplex
2385  * detects an objective limit exceedence. The primal simplex has no such detection (will never
2386  * stop with objective limit exceedence). Hence we are infeasible only if status == 1 and we have
2387  * not stopped due to the objective limit. */
2388  return ( lpi->clp->status() == 1 && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6) );
2389 }
2390 
2391 
2392 /** returns TRUE iff LP is proven to be primal feasible */
2394  SCIP_LPI* lpi /**< LP interface structure */
2395  )
2396 {
2397  SCIPdebugMessage("calling SCIPlpiIsPrimalFeasible()\n");
2398 
2399  assert(lpi != 0);
2400  assert(lpi->clp != 0);
2401 
2402  return ( lpi->clp->primalFeasible() );
2403 }
2404 
2405 
2406 /** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point);
2407  * this does not necessarily mean, that the solver knows and can return the dual ray
2408  */
2410  SCIP_LPI* lpi /**< LP interface structure */
2411  )
2412 {
2413  SCIPdebugMessage("calling SCIPlpiExistsDualRay()\n");
2414 
2415  assert(lpi != 0);
2416  assert(lpi->clp != 0);
2417 
2418  /* Clp assumes to have a dual ray whenever it concludes "primal infeasible" and the algorithm was
2419  * the dual simplex, (but is not necessarily dual feasible), see ClpModel::infeasibilityRay */
2420  return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->algorithm() < 0 );
2421 }
2422 
2423 
2424 /** returns TRUE iff LP is proven to have a dual unbounded ray (but not necessary a dual feasible point),
2425  * and the solver knows and can return the dual ray
2426  */
2428  SCIP_LPI* lpi /**< LP interface structure */
2429  )
2430 {
2431  SCIPdebugMessage("calling SCIPlpiHasDualRay()\n");
2432 
2433  assert(lpi != 0);
2434  assert(lpi->clp != 0);
2435 
2436  /* Clp assumes to have a dual ray whenever it concludes "primal infeasible" and the algorithm was
2437  * the dual simplex, (but is not necessarily dual feasible), see ClpModel::infeasibilityRay */
2438  if ( lpi->clp->rayExists() )
2439  {
2440  if ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->algorithm() < 0)
2441  return TRUE;
2442  else
2443  {
2444  if ( lpi->clp->status() != 2 || lpi->clp->algorithm() <= 0 )
2445  lpi->clp->deleteRay();
2446  return FALSE;
2447  }
2448  }
2449  else
2450  return FALSE;
2451 }
2452 
2453 
2454 /** returns TRUE iff LP is proven to be dual unbounded */
2456  SCIP_LPI* lpi /**< LP interface structure */
2457  )
2458 {
2459  SCIPdebugMessage("calling SCIPlpiIsDualUnbounded()\n");
2460 
2461  assert(lpi != 0);
2462  assert(lpi->clp != 0);
2463 
2464  /* The dual seems to be unbounded if the status is 1 (primal unbounded), the secondaryStatus is
2465  * not 1 (i.e., the dual simplex has not stopped because of an objective limit exceedence), and
2466  * the dual is feasible. */
2467  return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->dualFeasible() );
2468 }
2469 
2470 
2471 /** returns TRUE iff LP is proven to be dual infeasible */
2473  SCIP_LPI* lpi /**< LP interface structure */
2474  )
2475 {
2476  SCIPdebugMessage("calling SCIPlpiIsDualInfeasible()\n");
2477 
2478  assert(lpi != 0);
2479  assert(lpi->clp != 0);
2480 
2481  return ( lpi->clp->isProvenDualInfeasible() );
2482 }
2483 
2484 
2485 /** returns TRUE iff LP is proven to be dual feasible */
2487  SCIP_LPI* lpi /**< LP interface structure */
2488  )
2489 {
2490  SCIPdebugMessage("calling SCIPlpiIsDualFeasible()\n");
2491 
2492  assert(lpi != 0);
2493  assert(lpi->clp != 0);
2494 
2495  return ( lpi->clp->dualFeasible() );
2496 }
2497 
2498 
2499 /** returns TRUE iff LP was solved to optimality */
2501  SCIP_LPI* lpi /**< LP interface structure */
2502  )
2503 {
2504  SCIPdebugMessage("calling SCIPlpiIsOptimal()\n");
2505 
2506  assert(lpi != 0);
2507  assert(lpi->clp != 0);
2508 
2509  if ( SCIPlpiIsObjlimExc(lpi) )
2510  return FALSE;
2511 
2512  /* secondaryStatus == 6 means that the problem is empty */
2513  return( lpi->clp->isProvenOptimal() && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6));
2514 }
2515 
2516 
2517 /** returns TRUE iff current LP basis is stable */
2519  SCIP_LPI* lpi /**< LP interface structure */
2520  )
2521 {
2522  SCIPdebugMessage("calling SCIPlpiIsStable()\n");
2523 
2524  assert(lpi != 0);
2525  assert(lpi->clp != 0);
2526 
2527  /* We first check if status is ok, i.e., is one of the following:
2528  * 0 - optimal
2529  * 1 - primal infeasible
2530  * 2 - dual infeasible
2531  * 3 - stopped on iterations or time
2532  * 4 - stopped due to errors
2533  * 5 - stopped by event handler (virtual int ClpEventHandler::event())
2534  */
2535 
2536  /* Then we check the secondary status of Clp:
2537  * 0 - none
2538  * 1 - primal infeasible because dual limit reached OR (probably primal infeasible but can't prove it - main status was 4)
2539  * 2 - scaled problem optimal - unscaled problem has primal infeasibilities
2540  * 3 - scaled problem optimal - unscaled problem has dual infeasibilities
2541  * 4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
2542  * 5 - giving up in primal with flagged variables
2543  * 6 - failed due to empty problem check
2544  * 7 - postSolve says not optimal
2545  * 8 - failed due to bad element check
2546  * 9 - status was 3 and stopped on time
2547  * 100 up - translation of enum from ClpEventHandler
2548  */
2549  SCIPdebugMessage("status: %d secondary: %d\n", lpi->clp->status(), lpi->clp->secondaryStatus());
2550  assert( 0 <= lpi->clp->status() && lpi->clp->status() <= 5 );
2551  return( (lpi->clp->status() <= 3) && (lpi->clp->secondaryStatus() <= 1 || lpi->clp->secondaryStatus() == 6 || lpi->clp->secondaryStatus() == 9) );
2552 }
2553 
2554 
2555 /** returns TRUE iff the objective limit was reached */
2557  SCIP_LPI* lpi /**< LP interface structure */
2558  )
2559 {
2560  SCIPdebugMessage("calling SCIPlpiIsObjlimExc()\n");
2561 
2562  assert(lpi != 0);
2563  assert(lpi->clp != 0);
2564 
2565  /* if status == 1 (primal infeasible) and secondaryStatus == 1 then Clp hit the dual bound */
2566  if ( lpi->clp->status() == 1 )
2567  {
2568  if ( lpi->clp->secondaryStatus() == 1 )
2569  return TRUE;
2570  else
2571  return FALSE;
2572  }
2573 
2574  return ( lpi->clp->isObjectiveLimitTestValid() && (lpi->clp->isPrimalObjectiveLimitReached() || lpi->clp->isDualObjectiveLimitReached()) );
2575 
2576  /* The above code is equivalent to the following:
2577  if ( lpi->clp->status() == 0 || (lpi->clp->status() == 1 && lpi->clp->algorithm() < 0) || (lpi->clp->status() == 2 && lpi->clp->algorithm() > 0) )
2578  {
2579  return ( lpi->clp->isPrimalObjectiveLimitReached() || lpi->clp->isDualObjectiveLimitReached() );
2580  }
2581  */
2582 
2583  return FALSE;
2584 }
2585 
2586 
2587 /** returns TRUE iff the iteration limit was reached */
2589  SCIP_LPI* lpi /**< LP interface structure */
2590  )
2591 {
2592  SCIPdebugMessage("calling SCIPlpiIsIterlimExc()\n");
2593 
2594  assert(lpi != 0);
2595  assert(lpi->clp != 0);
2596 
2597  /* status == 3 means that Clp stopped on time or iteration limit
2598  * secondary status == 9 means that status was 3 and Clp stopped on time */
2599  return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() != 9 );
2600 }
2601 
2602 
2603 /** returns TRUE iff the time limit was reached */
2605  SCIP_LPI* lpi /**< LP interface structure */
2606  )
2607 {
2608  SCIPdebugMessage("calling SCIPlpiIsTimelimExc()\n");
2609 
2610  assert(lpi != 0);
2611  assert(lpi->clp != 0);
2612 
2613  /* status == 3 means that Clp stopped on time or iteration limit
2614  * secondary status == 9 means that status was 3 and Clp stopped on time */
2615  return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() == 9 );
2616 }
2617 
2618 
2619 /** returns the internal solution status of the solver */
2621  SCIP_LPI* lpi /**< LP interface structure */
2622  )
2623 {
2624  SCIPdebugMessage("calling SCIPlpiGetInternalStatus()\n");
2625 
2626  assert(lpi != 0);
2627  assert(lpi->clp != 0);
2628 
2629  return lpi->clp->status();
2630 }
2631 
2632 
2633 /** gets objective value of solution */
2635  SCIP_LPI* lpi, /**< LP interface structure */
2636  SCIP_Real* objval /**< stores the objective value */
2637  )
2638 {
2639  SCIPdebugMessage("calling SCIPlpiGetObjval()\n");
2640 
2641  assert(lpi != 0);
2642  assert(lpi->clp != 0);
2643  assert(objval != 0);
2644 
2645  *objval = lpi->clp->objectiveValue();
2646 
2647  return SCIP_OKAY;
2648 }
2649 
2650 
2651 /** gets primal and dual solution vectors */
2653  SCIP_LPI* lpi, /**< LP interface structure */
2654  SCIP_Real* objval, /**< stores the objective value, may be 0 if not needed */
2655  SCIP_Real* primsol, /**< primal solution vector, may be 0 if not needed */
2656  SCIP_Real* dualsol, /**< dual solution vector, may be 0 if not needed */
2657  SCIP_Real* activity, /**< row activity vector, may be 0 if not needed */
2658  SCIP_Real* redcost /**< reduced cost vector, may be 0 if not needed */
2659  )
2660 {
2661  SCIPdebugMessage("calling SCIPlpiGetSol()\n");
2662 
2663  assert(lpi != 0);
2664  assert(lpi->clp != 0);
2665 
2666  ClpSimplex* clp = lpi->clp;
2667  if( objval != 0 )
2668  *objval = clp->objectiveValue();
2669 
2670  if( primsol != 0 )
2671  {
2672  const double* sol = clp->getColSolution();
2673  BMScopyMemoryArray( primsol, sol, clp->numberColumns() );
2674  }
2675  if( dualsol != 0 )
2676  {
2677  const double* dsol = clp->getRowPrice();
2678  BMScopyMemoryArray( dualsol, dsol, clp->numberRows() );
2679  }
2680  if( activity != 0 )
2681  {
2682  const double* act = clp->getRowActivity();
2683  BMScopyMemoryArray( activity, act, clp->numberRows() );
2684  }
2685  if( redcost != 0 )
2686  {
2687  const double* red = clp->getReducedCost();
2688  BMScopyMemoryArray( redcost, red, clp->numberColumns() );
2689  }
2690 
2691  return SCIP_OKAY;
2692 }
2693 
2694 
2695 /** gets primal ray for unbounded LPs */
2697  SCIP_LPI* lpi, /**< LP interface structure */
2698  SCIP_Real* ray /**< primal ray */
2699  )
2700 {
2701  SCIPdebugMessage("calling SCIPlpiGetPrimalRay()\n");
2702 
2703  assert(lpi != 0);
2704  assert(lpi->clp != 0);
2705  assert(ray != 0);
2706 
2707  /** Unbounded ray (NULL returned if none/wrong). Up to user to use delete [] on these arrays. */
2708  const double* clpray = lpi->clp->unboundedRay();
2709 
2710  if ( clpray == 0 )
2711  return SCIP_LPERROR;
2712 
2713  BMScopyMemoryArray( ray, clpray, lpi->clp->numberColumns() );
2714 
2715  delete [] clpray;
2716 
2717  return SCIP_OKAY;
2718 }
2719 
2720 /** gets dual farkas proof for infeasibility */
2722  SCIP_LPI* lpi, /**< LP interface structure */
2723  SCIP_Real* dualfarkas /**< dual farkas row multipliers */
2724  )
2725 {
2726  SCIPdebugMessage("calling SCIPlpiGetDualfarkas()\n");
2727 
2728  assert(lpi != 0);
2729  assert(lpi->clp != 0);
2730  assert(dualfarkas != 0);
2731 
2732  /** Infeasibility ray (NULL returned if none/wrong). Up to user to use delete [] on these arrays. */
2733  const double* dualray = lpi->clp->infeasibilityRay();
2734 
2735  if ( dualray == 0 )
2736  return SCIP_LPERROR;
2737 
2738  BMScopyMemoryArray( dualfarkas, dualray, lpi->clp->numberRows() );
2739 
2740  /* convert sign - this is needed for versions <= 1.10 */
2741  /*
2742  for (int j = 0; j < lpi->clp->numberRows(); ++j)
2743  dualfarkas[j] = -dualfarkas[j];
2744  */
2745 
2746  delete [] dualray;
2747 
2748  return SCIP_OKAY;
2749 }
2750 
2751 
2752 /** gets the number of LP iterations of the last solve call */
2754  SCIP_LPI* lpi, /**< LP interface structure */
2755  int* iterations /**< pointer to store the number of iterations of the last solve call */
2756  )
2757 {
2758  assert(lpi != 0);
2759  assert(iterations != 0);
2760 
2761  *iterations = lpi->clp->numberIterations();
2762 
2763  return SCIP_OKAY;
2764 }
2765 
2766 /** gets information about the quality of an LP solution
2767  *
2768  * Such information is usually only available, if also a (maybe not optimal) solution is available.
2769  * The LPI should return SCIP_INVALID for @p quality, if the requested quantity is not available.
2770  */
2772  SCIP_LPI* lpi, /**< LP interface structure */
2773  SCIP_LPSOLQUALITY qualityindicator, /**< indicates which quality should be returned */
2774  SCIP_Real* quality /**< pointer to store quality number */
2775  )
2776 {
2777  assert(lpi != NULL);
2778  assert(quality != NULL);
2779 
2780  *quality = SCIP_INVALID;
2781 
2782  return SCIP_OKAY;
2783 }
2784 
2785 /**@} */
2786 
2787 
2788 
2789 
2790 /*
2791  * LP Basis Methods
2792  */
2793 
2794 /**@name LP Basis Methods */
2795 /**@{ */
2796 
2797 /** gets current basis status for columns and rows; arrays must be large enough to store the basis status */
2799  SCIP_LPI* lpi, /**< LP interface structure */
2800  int* cstat, /**< array to store column basis status, or 0 */
2801  int* rstat /**< array to store row basis status, or 0 */
2802  )
2803 {
2804  SCIPdebugMessage("calling SCIPlpiGetBase()\n");
2805 
2806  assert(lpi != 0);
2807  assert(lpi->clp != 0);
2808 
2809  ClpSimplex* clp = lpi->clp;
2810 
2811  // slower but easier to understand (and portable)
2812  if( rstat != 0 )
2813  {
2814  for( int i = 0; i < clp->numberRows(); ++i )
2815  {
2816  switch ( clp->getRowStatus(i) )
2817  {
2818  case ClpSimplex::isFree:
2819  rstat[i] = SCIP_BASESTAT_ZERO;
2820  break;
2821  case ClpSimplex::basic:
2822  rstat[i] = SCIP_BASESTAT_BASIC;
2823  break;
2824  case ClpSimplex::atUpperBound:
2825  rstat[i] = SCIP_BASESTAT_UPPER;
2826  break;
2827  case ClpSimplex::atLowerBound:
2828  rstat[i] = SCIP_BASESTAT_LOWER;
2829  break;
2830  case ClpSimplex::superBasic:
2831  rstat[i] = SCIP_BASESTAT_ZERO;
2832  break;
2833  case ClpSimplex::isFixed:
2834  if (clp->getRowPrice()[i] > 0.0)
2835  rstat[i] = SCIP_BASESTAT_LOWER;
2836  else
2837  rstat[i] = SCIP_BASESTAT_UPPER;
2838  break;
2839  default:
2840  SCIPerrorMessage("invalid basis status\n");
2841  SCIPABORT();
2842  return SCIP_INVALIDDATA; /*lint !e527*/
2843  }
2844  }
2845  }
2846 
2847  if( cstat != 0 )
2848  {
2849  for( int j = 0; j < clp->numberColumns(); ++j )
2850  {
2851  switch ( clp->getColumnStatus(j) )
2852  {
2853  case ClpSimplex::isFree:
2854  cstat[j] = SCIP_BASESTAT_ZERO;
2855  break;
2856  case ClpSimplex::basic:
2857  cstat[j] = SCIP_BASESTAT_BASIC;
2858  break;
2859  case ClpSimplex::atUpperBound:
2860  cstat[j] = SCIP_BASESTAT_UPPER;
2861  break;
2862  case ClpSimplex::atLowerBound:
2863  cstat[j] = SCIP_BASESTAT_LOWER;
2864  break;
2865  case ClpSimplex::superBasic:
2866  cstat[j] = SCIP_BASESTAT_ZERO;
2867  break;
2868  case ClpSimplex::isFixed:
2869  if (clp->getReducedCost()[j] > 0.0)
2870  cstat[j] = SCIP_BASESTAT_LOWER;
2871  else
2872  cstat[j] = SCIP_BASESTAT_UPPER;
2873  break;
2874  default: SCIPerrorMessage("invalid basis status\n");
2875  SCIPABORT();
2876  return SCIP_INVALIDDATA; /*lint !e527*/
2877  }
2878  }
2879  }
2880 
2881  return SCIP_OKAY;
2882 }
2883 
2884 
2885 /** sets current basis status for columns and rows */
2887  SCIP_LPI* lpi, /**< LP interface structure */
2888  int* cstat, /**< array with column basis status */
2889  int* rstat /**< array with row basis status */
2890  )
2891 {
2892  SCIPdebugMessage("calling SCIPlpiSetBase()\n");
2893 
2894  assert(lpi != 0);
2895  assert(lpi->clp != 0);
2896 
2897  invalidateSolution(lpi);
2898 
2899  // Adapted from OsiClpSolverInterface::setBasisStatus
2900 
2901  ClpSimplex* clp = lpi->clp;
2902  clp->createStatus();
2903 
2904  const double* lhs = clp->getRowLower();
2905  const double* rhs = clp->getRowUpper();
2906 
2907  assert( rstat != 0 || clp->numberRows() == 0 );
2908  for( int i = 0; i < clp->numberRows(); ++i )
2909  {
2910  int status = rstat[i];
2911  assert( 0 <= status && status <= 3 );
2912  assert( lhs[i] > -COIN_DBL_MAX || status != SCIP_BASESTAT_LOWER); // can't be at lower bound
2913  assert( rhs[i] < COIN_DBL_MAX || status != SCIP_BASESTAT_UPPER); // can't be at upper bound
2914 
2915  switch ( status )
2916  {
2917  case SCIP_BASESTAT_ZERO:
2918  if (lhs[i] <= -COIN_DBL_MAX && rhs[i] >= COIN_DBL_MAX)
2919  clp->setRowStatus(i, ClpSimplex::isFree);
2920  else
2921  clp->setRowStatus(i, ClpSimplex::superBasic);
2922  break;
2923  case SCIP_BASESTAT_BASIC:
2924  clp->setRowStatus(i, ClpSimplex::basic);
2925  break;
2926  case SCIP_BASESTAT_UPPER:
2927  clp->setRowStatus(i, ClpSimplex::atUpperBound);
2928  break;
2929  case SCIP_BASESTAT_LOWER:
2930  if ( EPSEQ(rhs[i], lhs[i], 1e-6) ) // if bounds are equal
2931  clp->setRowStatus(i, ClpSimplex::isFixed);
2932  else
2933  clp->setRowStatus(i, ClpSimplex::atLowerBound);
2934  break;
2935  default:
2936  SCIPerrorMessage("invalid basis status\n");
2937  SCIPABORT();
2938  return SCIP_INVALIDDATA; /*lint !e527*/
2939  }
2940  }
2941 
2942  const double* lb = clp->getColLower();
2943  const double* ub = clp->getColUpper();
2944 
2945  assert( cstat != 0 || clp->numberColumns() == 0 );
2946  for( int j = 0; j < clp->numberColumns(); ++j )
2947  {
2948  int status = cstat[j];
2949  assert( 0 <= status && status <= 3 );
2950  assert( lb[j] > -COIN_DBL_MAX || status != SCIP_BASESTAT_LOWER); // can't be at lower bound
2951  assert( ub[j] < COIN_DBL_MAX || status != SCIP_BASESTAT_UPPER); // can't be at upper bound
2952 
2953  switch ( status )
2954  {
2955  case SCIP_BASESTAT_ZERO:
2956  if (lb[j] <= -COIN_DBL_MAX && ub[j] >= COIN_DBL_MAX)
2957  clp->setColumnStatus(j, ClpSimplex::isFree);
2958  else
2959  clp->setColumnStatus(j, ClpSimplex::superBasic);
2960  break;
2961  case SCIP_BASESTAT_BASIC:
2962  clp->setColumnStatus(j, ClpSimplex::basic);
2963  break;
2964  case SCIP_BASESTAT_UPPER:
2965  clp->setColumnStatus(j, ClpSimplex::atUpperBound);
2966  break;
2967  case SCIP_BASESTAT_LOWER:
2968  if ( EPSEQ(ub[j], lb[j], 1e-6) )
2969  clp->setColumnStatus(j, ClpSimplex::isFixed);
2970  else
2971  clp->setColumnStatus(j, ClpSimplex::atLowerBound);
2972  break;
2973  default:
2974  SCIPerrorMessage("invalid basis status\n");
2975  SCIPABORT();
2976  return SCIP_INVALIDDATA; /*lint !e527*/
2977  }
2978  }
2979 
2980  /** Whats changed since last solve.
2981  * Is only used when startFinishOptions used in dual or primal.
2982  * Bit 1 - number of rows/columns has not changed (so work arrays valid)
2983  * 2 - matrix has not changed
2984  * 4 - if matrix has changed only by adding rows
2985  * 8 - if matrix has changed only by adding columns
2986  * 16 - row lbs not changed
2987  * 32 - row ubs not changed
2988  * 64 - column objective not changed
2989  * 128 - column lbs not changed
2990  * 256 - column ubs not changed
2991  * 512 - basis not changed (up to user to set this to 0)
2992  * top bits may be used internally
2993  */
2994  clp->setWhatsChanged(clp->whatsChanged() & (~512));
2995 
2996  return SCIP_OKAY;
2997 }
2998 
2999 
3000 /** returns the indices of the basic columns and rows; basic column n gives value n, basic row m gives value -1-m */
3001 extern
3003  SCIP_LPI* lpi, /**< LP interface structure */
3004  int* bind /**< pointer to store basis indices ready to keep number of rows entries */
3005  )
3006 {
3007  SCIPdebugMessage("calling SCIPlpiGetBasisInd()\n");
3008 
3009  assert(lpi != 0);
3010  assert(lpi->clp != 0);
3011  assert(bind != 0);
3012 
3013  ClpSimplex* clp = lpi->clp;
3014  int nrows = clp->numberRows();
3015  int ncols = clp->numberColumns();
3016 
3017  int* idx = NULL;
3018  SCIP_ALLOC( BMSallocMemoryArray(&idx, nrows) );
3019 
3020  /* If secondaryStatus == 6, clp says the LP is empty. Mose likely this happened, because the
3021  matrix is empty, i.e., all rows were redundant/empty. In this case, we construct a basis
3022  consisting of slack variables. */
3023  if ( clp->secondaryStatus() == 6 )
3024  {
3025  assert( clp->getNumElements() == 0 );
3026  for (int i = 0; i < nrows; ++i)
3027  idx[i] = ncols + i;
3028  }
3029  else
3030  clp->getBasics(idx);
3031 
3032  for (int i = 0; i < nrows; ++i)
3033  {
3034  if ( idx[i] < ncols )
3035  bind[i] = idx[i];
3036  else
3037  bind[i] = -1 - (idx[i] - ncols);
3038  }
3039 
3040  BMSfreeMemoryArray(&idx);
3041 
3042  return SCIP_OKAY;
3043 }
3044 
3045 
3046 /** get dense row of inverse basis matrix B^-1
3047  *
3048  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3049  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3050  * see also the explanation in lpi.h.
3051  *
3052  * @todo check that the result is in terms of the LP interface definition
3053  */
3055  SCIP_LPI* lpi, /**< LP interface structure */
3056  int r, /**< row number */
3057  SCIP_Real* coef /**< pointer to store the coefficients of the row */
3058  )
3059 {
3060  SCIPdebugMessage("calling SCIPlpiGetBInvRow()\n");
3061 
3062  assert( lpi != 0 );
3063  assert( lpi->clp != 0 );
3064  assert( coef != 0 );
3065  assert( 0 <= r && r <= lpi->clp->numberRows() );
3066 
3067  ClpSimplex* clp = lpi->clp;
3068  clp->getBInvRow(r, coef);
3069 
3070  return SCIP_OKAY;
3071 }
3072 
3073 
3074 /** get dense column of inverse basis matrix B^-1
3075  *
3076  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3077  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3078  * see also the explanation in lpi.h.
3079  *
3080  * @todo check that the result is in terms of the LP interface definition
3081  */
3083  SCIP_LPI* lpi, /**< LP interface structure */
3084  int c, /**< column number of B^-1; this is NOT the number of the column in the LP;
3085  * you have to call SCIPlpiGetBasisInd() to get the array which links the
3086  * B^-1 column numbers to the row and column numbers of the LP!
3087  * c must be between 0 and nrows-1, since the basis has the size
3088  * nrows * nrows */
3089  SCIP_Real* coef /**< pointer to store the coefficients of the column */
3090  )
3091 {
3092  SCIPdebugMessage("calling SCIPlpiGetBInvCol()\n");
3093 
3094  assert( lpi != 0 );
3095  assert( lpi->clp != 0 );
3096  assert( coef != 0 );
3097  assert( 0 <= c && c <= lpi->clp->numberRows() ); /* basis matrix is nrows * nrows */
3098 
3099  ClpSimplex* clp = lpi->clp;
3100  clp->getBInvCol(c, coef);
3101 
3102  return SCIP_OKAY;
3103 }
3104 
3105 
3106 /** get dense row of inverse basis matrix times constraint matrix B^-1 * A
3107  *
3108  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3109  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3110  * see also the explanation in lpi.h.
3111  *
3112  * @todo check that the result is in terms of the LP interface definition
3113  */
3115  SCIP_LPI* lpi, /**< LP interface structure */
3116  int r, /**< row number */
3117  const SCIP_Real* binvrow, /**< row in (A_B)^-1 from prior call to SCIPlpiGetBInvRow(), or 0 */
3118  SCIP_Real* coef /**< vector to return coefficients */
3119  )
3120 {
3121  SCIPdebugMessage("calling SCIPlpiGetBInvARow()\n");
3122 
3123  assert( lpi != 0 );
3124  assert( lpi->clp != 0 );
3125  assert( coef != 0 );
3126  assert( 0 <= r && r <= lpi->clp->numberRows() );
3127 
3128  ClpSimplex* clp = lpi->clp;
3129  clp->getBInvARow(r, coef, 0);
3130 
3131  return SCIP_OKAY;
3132 }
3133 
3134 
3135 /** get dense column of inverse basis matrix times constraint matrix B^-1 * A
3136  *
3137  * @note The LP interface defines slack variables to have coefficient +1. This means that if, internally, the LP solver
3138  * uses a -1 coefficient, then rows associated with slacks variables whose coefficient is -1, should be negated;
3139  * see also the explanation in lpi.h.
3140  *
3141  * @todo check that the result is in terms of the LP interface definition
3142  */
3144  SCIP_LPI* lpi, /**< LP interface structure */
3145  int c, /**< column number */
3146  SCIP_Real* coef /**< vector to return coefficients */
3147  )
3148 {
3149  SCIPdebugMessage("calling SCIPlpiGetBInvACol()\n");
3150 
3151  assert( lpi != 0 );
3152  assert( lpi->clp != 0 );
3153  assert( coef != 0 );
3154  assert( 0 <= c && c <= lpi->clp->numberColumns() );
3155 
3156  ClpSimplex* clp = lpi->clp;
3157  clp->getBInvACol(c, coef);
3158 
3159  return SCIP_OKAY;
3160 }
3161 
3162 
3163 /**@} */
3164 
3165 
3166 
3167 
3168 /*
3169  * LP State Methods
3170  */
3171 
3172 /**@name LP State Methods */
3173 /**@{ */
3174 
3175 /** stores LPi state (like basis information) into lpistate object */
3177  SCIP_LPI* lpi, /**< LP interface structure */
3178  BMS_BLKMEM* blkmem, /**< block memory */
3179  SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
3180  )
3181 {
3182  SCIPdebugMessage("calling SCIPlpiGetState()\n");
3183 
3184  assert(blkmem != 0);
3185  assert(lpi != 0);
3186  assert(lpi->clp != 0);
3187  assert(lpistate != 0);
3188 
3189  int ncols = lpi->clp->numberColumns();
3190  int nrows = lpi->clp->numberRows();
3191  assert(ncols >= 0);
3192  assert(nrows >= 0);
3193 
3194  /* allocate lpistate data */
3195  SCIP_CALL( lpistateCreate(lpistate, blkmem, ncols, nrows) );
3196 
3197  /* allocate enough memory for storing uncompressed basis information */
3198  SCIP_CALL( ensureCstatMem(lpi, ncols) );
3199  SCIP_CALL( ensureRstatMem(lpi, nrows) );
3200 
3201  /* get unpacked basis information */
3202  SCIP_CALL( SCIPlpiGetBase(lpi, lpi->cstat, lpi->rstat) );
3203 
3204  /* pack LPi state data */
3205  (*lpistate)->ncols = ncols;
3206  (*lpistate)->nrows = nrows;
3207  lpistatePack(*lpistate, lpi->cstat, lpi->rstat);
3208 
3209  return SCIP_OKAY;
3210 }
3211 
3212 
3213 /** loads LPi state (like basis information) into solver; note that the LP might have been extended with additional
3214  * columns and rows since the state was stored with SCIPlpiGetState()
3215  */
3217  SCIP_LPI* lpi, /**< LP interface structure */
3218  BMS_BLKMEM* /*blkmem*/, /**< block memory */
3219  SCIP_LPISTATE* lpistate /**< LPi state information (like basis information) */
3220  )
3221 {
3222  int lpncols;
3223  int lpnrows;
3224  int i;
3225 
3226  SCIPdebugMessage("calling SCIPlpiSetState()\n");
3227 
3228  assert(lpi != 0);
3229  assert(lpi->clp != 0);
3230  assert(lpistate != 0);
3231 
3232  lpncols = lpi->clp->numberColumns();
3233  lpnrows = lpi->clp->numberRows();
3234  assert(lpistate->ncols <= lpncols);
3235  assert(lpistate->nrows <= lpnrows);
3236 
3237  /* allocate enough memory for storing uncompressed basis information */
3238  SCIP_CALL( ensureCstatMem(lpi, lpncols) );
3239  SCIP_CALL( ensureRstatMem(lpi, lpnrows) );
3240 
3241  /* unpack LPi state data */
3242  lpistateUnpack(lpistate, lpi->cstat, lpi->rstat);
3243 
3244  /* extend the basis to the current LP beyond the previously existing columns */
3245  for( i = lpistate->ncols; i < lpncols; ++i )
3246  {
3247  SCIP_Real bnd = (lpi->clp->getColLower())[i];
3248  if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
3249  {
3250  /* if lower bound is +/- infinity -> try upper bound */
3251  bnd = (lpi->clp->getColUpper())[i];
3252  if ( SCIPlpiIsInfinity(lpi, REALABS(bnd)) )
3253  lpi->cstat[i] = SCIP_BASESTAT_ZERO; /* variable is free */
3254  else
3255  lpi->cstat[i] = SCIP_BASESTAT_UPPER; /* use finite upper bound */
3256  }
3257  else
3258  lpi->cstat[i] = SCIP_BASESTAT_LOWER; /* use finite lower bound */
3259  }
3260  for( i = lpistate->nrows; i < lpnrows; ++i )
3261  lpi->rstat[i] = SCIP_BASESTAT_BASIC;
3262 
3263  /* load basis information */
3264  SCIP_CALL( SCIPlpiSetBase(lpi, lpi->cstat, lpi->rstat) );
3265 
3266  return SCIP_OKAY;
3267 }
3268 
3269 /** clears current LPi state (like basis information) of the solver */
3271  SCIP_LPI* lpi /**< LP interface structure */
3272  )
3273 {
3274  SCIPdebugMessage("calling SCIPlpiClearState()\n");
3275 
3276  assert(lpi != 0);
3277  assert(lpi->clp != 0);
3278 
3279  lpi->clp->allSlackBasis(true);
3280  lpi->validFactorization = false;
3281 
3282  return SCIP_OKAY;
3283 }
3284 
3285 /** frees LPi state information */
3287  SCIP_LPI* lpi, /**< LP interface structure */
3288  BMS_BLKMEM* blkmem, /**< block memory */
3289  SCIP_LPISTATE** lpistate /**< pointer to LPi state information (like basis information) */
3290  )
3291 {
3292  SCIPdebugMessage("calling SCIPlpiFreeState()\n");
3293 
3294  assert(lpi != 0);
3295  assert(lpistate != NULL);
3296 
3297  if ( *lpistate != NULL )
3298  lpistateFree(lpistate, blkmem);
3299 
3300  return SCIP_OKAY;
3301 }
3302 
3303 /** checks, whether the given LP state contains simplex basis information */
3305  SCIP_LPI* lpi, /**< LP interface structure */
3306  SCIP_LPISTATE* lpistate /**< LP state information (like basis information) */
3307  )
3308 {
3309  return (lpistate != NULL);
3310 }
3311 
3312 /** reads LP state (like basis information) from a file */
3314  SCIP_LPI* lpi, /**< LP interface structure */
3315  const char* fname /**< file name */
3316  )
3317 {
3318  SCIPdebugMessage("calling SCIPlpiReadState()\n");
3319 
3320  /** Read a basis from the given filename,
3321  * returns -1 on file error, 0 if no values, 1 if values
3322  */
3323  if ( lpi->clp->readBasis(fname) < 0 )
3324  return SCIP_READERROR;
3325 
3326  return SCIP_OKAY;
3327 }
3328 
3329 /** writes LP state (like basis information) to a file */
3331  SCIP_LPI* lpi, /**< LP interface structure */
3332  const char* fname /**< file name */
3333  )
3334 {
3335  SCIPdebugMessage("calling SCIPlpiWriteState()\n");
3336 
3337  /** Write the basis in MPS format to the specified file.
3338  * If writeValues true, writes values of structurals
3339  * (and adds VALUES to end of NAME card)
3340  *
3341  * parameters:
3342  * - filename
3343  * - bool writeValues
3344  * - int formatType (0 - normal, 1 - extra accuracy, 2 - IEEE hex)
3345  */
3346  if ( lpi->clp->writeBasis(fname, false, 0) )
3347  return SCIP_WRITEERROR;
3348 
3349  return SCIP_OKAY;
3350 }
3351 
3352 /**@} */
3353 
3354 
3355 
3356 
3357 /*
3358  * LP Pricing Norms Methods
3359  */
3360 
3361 /**@name LP Pricing Norms Methods */
3362 /**@{ */
3363 
3364 /** stores LPi pricing norms information
3365  * @todo should we store norm information?
3366  */
3368  SCIP_LPI* lpi, /**< LP interface structure */
3369  BMS_BLKMEM* blkmem, /**< block memory */
3370  SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information */
3371  )
3372 {
3373  assert(lpinorms != NULL);
3374 
3375  (*lpinorms) = NULL;
3376 
3377  return SCIP_OKAY;
3378 }
3379 
3380 /** loads LPi pricing norms into solver; note that the LP might have been extended with additional
3381  * columns and rows since the state was stored with SCIPlpiGetNorms()
3382  */
3384  SCIP_LPI* lpi, /**< LP interface structure */
3385  BMS_BLKMEM* blkmem, /**< block memory */
3386  SCIP_LPINORMS* lpinorms /**< LPi pricing norms information */
3387  )
3388 {
3389  assert(lpinorms == NULL);
3390 
3391  /* no work necessary */
3392  return SCIP_OKAY;
3393 }
3394 
3395 /** frees pricing norms information */
3397  SCIP_LPI* lpi, /**< LP interface structure */
3398  BMS_BLKMEM* blkmem, /**< block memory */
3399  SCIP_LPINORMS** lpinorms /**< pointer to LPi pricing norms information */
3400  )
3401 {
3402  assert(lpinorms == NULL);
3403 
3404  /* no work necessary */
3405  return SCIP_OKAY;
3406 }
3407 
3408 /**@} */
3409 
3410 
3411 
3412 
3413 /*
3414  * Parameter Methods
3415  */
3416 
3417 /**@name Parameter Methods */
3418 /**@{ */
3419 
3420 /** gets integer parameter of LP */
3422  SCIP_LPI* lpi, /**< LP interface structure */
3423  SCIP_LPPARAM type, /**< parameter number */
3424  int* ival /**< buffer to store the parameter value */
3425  )
3426 {
3427  SCIPdebugMessage("calling SCIPlpiGetIntpar()\n");
3428 
3429  assert(lpi != 0);
3430  assert(lpi->clp != 0);
3431  assert(ival != 0);
3432 
3433  switch( type )
3434  {
3436  *ival = lpi->startscratch;
3437  break;
3438  case SCIP_LPPAR_SCALING:
3439  if( lpi->clp->scalingFlag() != 0 ) // 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later)
3440  *ival = TRUE;
3441  else
3442  *ival = FALSE;
3443  break;
3444  case SCIP_LPPAR_PRICING:
3445  *ival = (int)lpi->pricing; // store pricing method in LPI struct
3446  break;
3447  case SCIP_LPPAR_LPINFO:
3448  *ival = lpi->clp->logLevel() > 0 ? TRUE : FALSE;
3449  break;
3450  case SCIP_LPPAR_LPITLIM:
3451  *ival = lpi->clp->maximumIterations();
3452  break;
3453  case SCIP_LPPAR_FASTMIP:
3454  *ival = lpi->fastmip;
3455  break;
3456  default:
3457  return SCIP_PARAMETERUNKNOWN;
3458  }
3459 
3460  return SCIP_OKAY;
3461 }
3462 
3463 
3464 /** sets integer parameter of LP */
3466  SCIP_LPI* lpi, /**< LP interface structure */
3467  SCIP_LPPARAM type, /**< parameter number */
3468  int ival /**< parameter value */
3469  )
3470 {
3471  SCIPdebugMessage("calling SCIPlpiSetIntpar()\n");
3472 
3473  assert(lpi != 0);
3474  assert(lpi->clp != 0);
3475 
3476  // Handle pricing separately ...
3477  if( type == SCIP_LPPAR_PRICING )
3478  {
3479  // for primal:
3480  // 0 is exact devex,
3481  // 1 full steepest,
3482  // 2 is partial exact devex
3483  // 3 switches between 0 and 2 depending on factorization
3484  // 4 starts as partial dantzig/devex but then may switch between 0 and 2.
3485  // - currently (Clp 1.8) default is 3
3486 
3487  // for dual:
3488  // 0 is uninitialized,
3489  // 1 full,
3490  // 2 is partial uninitialized,
3491  // 3 starts as 2 but may switch to 1.
3492  // - currently (Clp 1.8) default is 3
3493  lpi->pricing = (SCIP_PRICING)ival;
3494  int primalmode = 0;
3495  int dualmode = 0;
3496  switch( (SCIP_PRICING)ival )
3497  {
3498  case SCIP_PRICING_AUTO:
3499  primalmode = 3; dualmode = 3; break;
3500  case SCIP_PRICING_FULL:
3501  primalmode = 0; dualmode = 1; break;
3503  case SCIP_PRICING_STEEP:
3504  primalmode = 1; dualmode = 0; break;
3506  primalmode = 1; dualmode = 2; break;
3507  case SCIP_PRICING_DEVEX:
3508  primalmode = 2; dualmode = 3; break;
3509  default:
3510  SCIPerrorMessage("unkown pricing parameter %d!\n", ival);
3511  SCIPABORT();
3512  return SCIP_INVALIDDATA; /*lint !e527*/
3513  }
3514  ClpPrimalColumnSteepest primalpivot(primalmode);
3515  lpi->clp->setPrimalColumnPivotAlgorithm(primalpivot);
3516  ClpDualRowSteepest dualpivot(dualmode);
3517  lpi->clp->setDualRowPivotAlgorithm(dualpivot);
3518  return SCIP_OKAY;
3519  }
3520 
3521  switch( type )
3522  {
3524  lpi->startscratch = ival;
3525  break;
3526  case SCIP_LPPAR_SCALING:
3527  lpi->clp->scaling(ival == TRUE ? 3 : 0); // 0 -off, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic(later));
3528  break;
3529  case SCIP_LPPAR_PRICING:
3530  /* should not happen - see above */
3531  SCIPABORT();
3532  return SCIP_LPERROR; /*lint !e527*/
3533  case SCIP_LPPAR_LPINFO:
3534  assert(ival == TRUE || ival == FALSE);
3535  /** Amount of print out:
3536  * 0 - none
3537  * 1 - just final
3538  * 2 - just factorizations
3539  * 3 - as 2 plus a bit more
3540  * 4 - verbose
3541  * above that 8,16,32 etc just for selective SCIPdebug
3542  */
3543  if ( ival )
3544  lpi->clp->setLogLevel(2); // lpi->clp->setLogLevel(63);
3545  else
3546  lpi->clp->setLogLevel(0);
3547  break;
3548  case SCIP_LPPAR_LPITLIM:
3549  lpi->clp->setMaximumIterations(ival);
3550  break;
3551  case SCIP_LPPAR_FASTMIP:
3552  assert(ival == TRUE || ival == FALSE);
3553  if( ival )
3554  setFastmipClpParameters(lpi);
3555  else
3556  unsetFastmipClpParameters(lpi);
3557  break;
3558  default:
3559  return SCIP_PARAMETERUNKNOWN;
3560  }
3561 
3562  return SCIP_OKAY;
3563 }
3564 
3565 
3566 /** gets floating point parameter of LP */
3568  SCIP_LPI* lpi, /**< LP interface structure */
3569  SCIP_LPPARAM type, /**< parameter number */
3570  SCIP_Real* dval /**< buffer to store the parameter value */
3571  )
3572 {
3573  SCIPdebugMessage("calling SCIPlpiGetRealpar()\n");
3574 
3575  assert(lpi != 0);
3576  assert(lpi->clp != 0);
3577  assert(dval != 0);
3578 
3579  switch( type )
3580  {
3581  case SCIP_LPPAR_FEASTOL:
3582  *dval = lpi->clp->primalTolerance();
3583  break;
3585  *dval = lpi->clp->dualTolerance();
3586  break;
3588  /**@todo add BARRIERCONVTOL parameter */
3589  return SCIP_PARAMETERUNKNOWN;
3590  case SCIP_LPPAR_LOBJLIM:
3591  if ( lpi->clp->optimizationDirection() > 0 ) // if minimization
3592  *dval = lpi->clp->primalObjectiveLimit();
3593  else
3594  *dval = lpi->clp->dualObjectiveLimit();
3595  break;
3596  case SCIP_LPPAR_UOBJLIM:
3597  if ( lpi->clp->optimizationDirection() > 0 ) // if minimization
3598  *dval = lpi->clp->dualObjectiveLimit();
3599  else
3600  *dval = lpi->clp->primalObjectiveLimit();
3601  break;
3602  case SCIP_LPPAR_LPTILIM:
3603  *dval = lpi->clp->maximumSeconds();
3604  break;
3605  default:
3606  return SCIP_PARAMETERUNKNOWN;
3607  }
3608 
3609  return SCIP_OKAY;
3610 }
3611 
3612 /** sets floating point parameter of LP */
3614  SCIP_LPI* lpi, /**< LP interface structure */
3615  SCIP_LPPARAM type, /**< parameter number */
3616  SCIP_Real dval /**< parameter value */
3617  )
3618 {
3619  SCIPdebugMessage("calling SCIPlpiSetRealpar()\n");
3620  SCIPdebugMessage("setting parameter %d to value %g.\n", type, dval);
3621  assert(lpi != 0);
3622  assert(lpi->clp != 0);
3623 
3624  switch( type )
3625  {
3626  case SCIP_LPPAR_FEASTOL:
3627  lpi->clp->setPrimalTolerance(dval);
3628  break;
3630  lpi->clp->setDualTolerance(dval);
3631  break;
3633  /**@todo add BARRIERCONVTOL parameter */
3634  return SCIP_PARAMETERUNKNOWN;
3635  case SCIP_LPPAR_LOBJLIM:
3636  if ( lpi->clp->optimizationDirection() > 0 ) // if minimization
3637  lpi->clp->setPrimalObjectiveLimit(dval);
3638  else
3639  lpi->clp->setDualObjectiveLimit(dval);
3640  break;
3641  case SCIP_LPPAR_UOBJLIM:
3642  if ( lpi->clp->optimizationDirection() > 0 ) // if minimization
3643  lpi->clp->setDualObjectiveLimit(dval);
3644  else
3645  lpi->clp->setPrimalObjectiveLimit(dval);
3646  break;
3647  case SCIP_LPPAR_LPTILIM:
3648  lpi->clp->setMaximumSeconds(dval);
3649  break;
3650  default:
3651  return SCIP_PARAMETERUNKNOWN;
3652  }
3653 
3654  return SCIP_OKAY;
3655 }
3656 
3657 /**@} */
3658 
3659 
3660 
3661 
3662 /*
3663  * Numerical Methods
3664  */
3665 
3666 /**@name Numerical Methods */
3667 /**@{ */
3668 
3669 /** returns value treated as infinity in the LP solver */
3671  SCIP_LPI* /*lpi*/ /**< LP interface structure */
3672  )
3673 {
3674  SCIPdebugMessage("calling SCIPlpiInfinity()\n");
3675 
3676  return COIN_DBL_MAX;
3677 }
3678 
3679 
3680 /** checks if given value is treated as infinity in the LP solver */
3682  SCIP_LPI* /*lpi*/, /**< LP interface structure */
3683  SCIP_Real val
3684  )
3685 {
3686  SCIPdebugMessage("calling SCIPlpiIsInfinity()\n");
3687 
3688  return (val >= COIN_DBL_MAX);
3689 }
3690 
3691 /**@} */
3692 
3693 
3694 
3695 
3696 /*
3697  * File Interface Methods
3698  */
3699 
3700 /**@name File Interface Methods */
3701 /**@{ */
3702 
3703 /** returns, whether the given file exists */
3704 static
3705 SCIP_Bool fileExists(
3706  const char* filename /**< file name */
3707  )
3708 {
3709  FILE* f;
3710 
3711  f = fopen(filename, "r");
3712  if( f == 0 )
3713  return FALSE;
3714 
3715  fclose(f);
3716 
3717  return TRUE;
3718 }
3719 
3720 /** reads LP from a file */
3722  SCIP_LPI* lpi, /**< LP interface structure */
3723  const char* fname /**< file name */
3724  )
3725 {
3726  SCIPdebugMessage("calling SCIPlpiReadLP()\n");
3727 
3728  assert(lpi != 0);
3729  assert(lpi->clp != 0);
3730 
3731  // WARNING: can only read mps files
3732 
3733  if ( !fileExists(fname) )
3734  return SCIP_NOFILE;
3735 
3736  /** read file in MPS format
3737  * parameters:
3738  * filename
3739  * bool keepNames
3740  * bool ignoreErrors
3741  */
3742  if ( lpi->clp->readMps(fname, true, false) )
3743  return SCIP_READERROR;
3744 
3745  return SCIP_OKAY;
3746 }
3747 
3748 /** writes LP to a file */
3750  SCIP_LPI* lpi, /**< LP interface structure */
3751  const char* fname /**< file name */
3752  )
3753 {
3754  SCIPdebugMessage("calling SCIPlpiWriteLP() - %s\n", fname);
3755 
3756  assert(lpi != 0);
3757  assert(lpi->clp != 0);
3758 
3759  /** write file in MPS format
3760  * parameters:
3761  * filename
3762  * int formatType (0 - normal, 1 - extra accuracy, 2 - IEEE hex)
3763  * int numberAcross (1 or 2 values should be specified on every data line in the MPS file)
3764  * double objSense
3765  */
3766  if ( lpi->clp->writeMps(fname, 0, 2, lpi->clp->optimizationDirection()) )
3767  return SCIP_WRITEERROR;
3768 
3769  return SCIP_OKAY;
3770 }
3771 
3772 /**@} */
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_clp.cpp:2169
SCIP_Bool SCIPlpiIsObjlimExc(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2556
SCIP_RETCODE SCIPlpiWriteLP(SCIP_LPI *lpi, const char *fname)
Definition: lpi_clp.cpp:3749
enum SCIP_LPSolQuality SCIP_LPSOLQUALITY
Definition: type_lpi.h:92
#define ROWS_PER_PACKET
Definition: lpi_clp.cpp:118
SCIP_RETCODE SCIPlpiGetBInvCol(SCIP_LPI *lpi, int c, SCIP_Real *coef)
Definition: lpi_clp.cpp:3082
#define SUMINFEASBOUND
Definition: lpi_clp.cpp:90
SCIP_RETCODE SCIPlpiSolveDual(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:1705
SCIP_RETCODE SCIPlpiGetPrimalRay(SCIP_LPI *lpi, SCIP_Real *ray)
Definition: lpi_clp.cpp:2696
SCIP_Bool SCIPlpiHasPrimalRay(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2344
SCIP_RETCODE SCIPlpiSetBase(SCIP_LPI *lpi, int *cstat, int *rstat)
Definition: lpi_clp.cpp:2886
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_clp.cpp:1379
SCIP_Bool SCIPlpiExistsPrimalRay(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2326
unsigned int SCIP_DUALPACKET
Definition: lpi_grb.c:81
SCIP_RETCODE SCIPlpiGetBInvACol(SCIP_LPI *lpi, int c, SCIP_Real *coef)
Definition: lpi_clp.cpp:3143
SCIP_RETCODE SCIPlpiGetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int *ival)
Definition: lpi_clp.cpp:3421
SCIP_Bool SCIPlpiIsStable(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2518
enum SCIP_ObjSen SCIP_OBJSEN
Definition: type_lpi.h:36
SCIP_RETCODE SCIPlpiGetNCols(SCIP_LPI *lpi, int *ncols)
Definition: lpi_clp.cpp:1273
#define NULL
Definition: lpi_spx.cpp:129
SCIP_RETCODE SCIPlpiSetState(SCIP_LPI *lpi, BMS_BLKMEM *, SCIP_LPISTATE *lpistate)
Definition: lpi_clp.cpp:3216
SCIP_RETCODE SCIPlpiGetColNames(SCIP_LPI *lpi, int firstcol, int lastcol, char **colnames, char *namestorage, int namestoragesize, int *storageleft)
Definition: lpi_clp.cpp:1443
interface methods for specific LP solvers
struct SCIP_Messagehdlr SCIP_MESSAGEHDLR
Definition: type_message.h:50
SCIP_RETCODE SCIPlpiSetIntpar(SCIP_LPI *lpi, SCIP_LPPARAM type, int ival)
Definition: lpi_clp.cpp:3465
#define FALSE
Definition: def.h:52
#define EPSEQ(x, y, eps)
Definition: def.h:147
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_clp.cpp:572
#define TRUE
Definition: def.h:51
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
enum SCIP_LPParam SCIP_LPPARAM
Definition: type_lpi.h:61
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_RETCODE SCIPlpiReadLP(SCIP_LPI *lpi, const char *fname)
Definition: lpi_clp.cpp:3721
enum SCIP_Pricing SCIP_PRICING
Definition: type_lpi.h:74
SCIP_RETCODE SCIPlpiChgObjsen(SCIP_LPI *lpi, SCIP_OBJSEN objsen)
Definition: lpi_clp.cpp:1058
SCIP_RETCODE SCIPlpiGetObjsen(SCIP_LPI *lpi, SCIP_OBJSEN *objsen)
Definition: lpi_clp.cpp:1493
int SCIPlpiGetInternalStatus(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2620
SCIP_RETCODE SCIPlpiGetRealSolQuality(SCIP_LPI *lpi, SCIP_LPSOLQUALITY qualityindicator, SCIP_Real *quality)
Definition: lpi_clp.cpp:2771
SCIP_Bool SCIPlpiIsDualUnbounded(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2455
SCIP_DUALPACKET COLPACKET
Definition: lpi_clp.cpp:115
SCIP_RETCODE SCIPlpiGetBInvARow(SCIP_LPI *lpi, int r, const SCIP_Real *binvrow, SCIP_Real *coef)
Definition: lpi_clp.cpp:3114
SCIP_RETCODE SCIPlpiSolveBarrier(SCIP_LPI *lpi, SCIP_Bool crossover)
Definition: lpi_clp.cpp:1780
SCIP_Bool SCIPlpiHasDualRay(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2427
SCIP_Bool SCIPlpiIsPrimalUnbounded(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2360
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_clp.cpp:2190
SCIP_RETCODE SCIPlpiScaleRow(SCIP_LPI *lpi, int row, SCIP_Real scaleval)
Definition: lpi_clp.cpp:1105
SCIP_Bool SCIPlpiHasStateBasis(SCIP_LPI *lpi, SCIP_LPISTATE *lpistate)
Definition: lpi_clp.cpp:3304
SCIP_RETCODE SCIPlpiCreate(SCIP_LPI **lpi, SCIP_MESSAGEHDLR *messagehdlr, const char *name, SCIP_OBJSEN objsen)
Definition: lpi_clp.cpp:469
SCIP_RETCODE SCIPlpiDelCols(SCIP_LPI *lpi, int firstcol, int lastcol)
Definition: lpi_clp.cpp:705
SCIP_RETCODE SCIPlpiGetBounds(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *lbs, SCIP_Real *ubs)
Definition: lpi_clp.cpp:1536
SCIP_RETCODE SCIPlpiReadState(SCIP_LPI *lpi, const char *fname)
Definition: lpi_clp.cpp:3313
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPlpiGetSides(SCIP_LPI *lpi, int firstrow, int lastrow, SCIP_Real *lhss, SCIP_Real *rhss)
Definition: lpi_clp.cpp:1567
SCIP_RETCODE SCIPlpiFree(SCIP_LPI **lpi)
Definition: lpi_clp.cpp:538
SCIP_RETCODE SCIPlpiIgnoreInstability(SCIP_LPI *lpi, SCIP_Bool *success)
Definition: lpi_clp.cpp:1475
SCIP_DUALPACKET ROWPACKET
Definition: lpi_clp.cpp:117
SCIP_RETCODE SCIPlpiGetRowNames(SCIP_LPI *lpi, int firstrow, int lastrow, char **rownames, char *namestorage, int namestoragesize, int *storageleft)
Definition: lpi_clp.cpp:1459
struct SCIP_LPiState SCIP_LPISTATE
Definition: type_lpi.h:95
SCIP_RETCODE SCIPlpiScaleCol(SCIP_LPI *lpi, int col, SCIP_Real scaleval)
Definition: lpi_clp.cpp:1178
SCIP_RETCODE SCIPlpiEndStrongbranch(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:1830
#define REALABS(x)
Definition: def.h:146
SCIP_RETCODE SCIPlpiSolvePrimal(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:1632
SCIP_RETCODE SCIPlpiDelRowset(SCIP_LPI *lpi, int *dstat)
Definition: lpi_clp.cpp:876
#define SCIP_CALL(x)
Definition: def.h:258
SCIP_RETCODE SCIPlpiGetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real *dval)
Definition: lpi_clp.cpp:3567
void * SCIPlpiGetSolverPointer(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:450
SCIP_RETCODE SCIPlpiGetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
Definition: lpi_clp.cpp:3367
const char * SCIPlpiGetSolverDesc(void)
Definition: lpi_clp.cpp:442
#define EPSCEIL(x, eps)
Definition: def.h:156
SCIP_RETCODE SCIPlpiSetNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS *lpinorms)
Definition: lpi_clp.cpp:3383
SCIP_Bool SCIPlpiExistsDualRay(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2409
SCIP_Bool SCIPlpiIsOptimal(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2500
#define SCIP_Bool
Definition: def.h:49
SCIP_Bool SCIPlpiWasSolved(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2271
SCIP_RETCODE SCIPlpiWriteState(SCIP_LPI *lpi, const char *fname)
Definition: lpi_clp.cpp:3330
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_clp.cpp:1312
SCIP_RETCODE SCIPlpiChgBounds(SCIP_LPI *lpi, int ncols, const int *ind, const SCIP_Real *lb, const SCIP_Real *ub)
Definition: lpi_clp.cpp:941
#define MAX(x, y)
Definition: tclique_def.h:75
SCIP_RETCODE SCIPlpiChgCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real newval)
Definition: lpi_clp.cpp:1035
SCIP_RETCODE SCIPlpiGetObjval(SCIP_LPI *lpi, SCIP_Real *objval)
Definition: lpi_clp.cpp:2634
SCIP_Real SCIPlpiInfinity(SCIP_LPI *)
Definition: lpi_clp.cpp:3670
#define COLS_PER_PACKET
Definition: lpi_clp.cpp:116
SCIP_RETCODE SCIPlpiStartStrongbranch(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:1821
const char * SCIPlpiGetSolverName(void)
Definition: lpi_clp.cpp:433
SCIP_RETCODE SCIPlpiFreeState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
Definition: lpi_clp.cpp:3286
SCIP_RETCODE SCIPlpiGetBasisInd(SCIP_LPI *lpi, int *bind)
Definition: lpi_clp.cpp:3002
SCIP_Bool SCIPlpiIsIterlimExc(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2588
SCIP_RETCODE SCIPlpiGetBase(SCIP_LPI *lpi, int *cstat, int *rstat)
Definition: lpi_clp.cpp:2798
SCIP_RETCODE SCIPlpiSetRealpar(SCIP_LPI *lpi, SCIP_LPPARAM type, SCIP_Real dval)
Definition: lpi_clp.cpp:3613
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_clp.cpp:2236
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_clp.cpp:2215
SCIP_RETCODE SCIPlpiGetSol(SCIP_LPI *lpi, SCIP_Real *objval, SCIP_Real *primsol, SCIP_Real *dualsol, SCIP_Real *activity, SCIP_Real *redcost)
Definition: lpi_clp.cpp:2652
SCIP_RETCODE SCIPlpiClearState(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:3270
SCIP_Bool SCIPlpiIsPrimalFeasible(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2393
SCIP_RETCODE SCIPlpiClear(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:922
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_clp.cpp:782
SCIP_RETCODE SCIPlpiChgObj(SCIP_LPI *lpi, int ncols, int *ind, SCIP_Real *obj)
Definition: lpi_clp.cpp:1078
SCIP_RETCODE SCIPlpiGetSolFeasibility(SCIP_LPI *lpi, SCIP_Bool *primalfeasible, SCIP_Bool *dualfeasible)
Definition: lpi_clp.cpp:2281
SCIP_Bool SCIPlpiIsDualInfeasible(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2472
public methods for message output
SCIP_RETCODE SCIPlpiChgSides(SCIP_LPI *lpi, int nrows, const int *ind, const SCIP_Real *lhs, const SCIP_Real *rhs)
Definition: lpi_clp.cpp:1007
SCIP_Bool SCIPlpiIsDualFeasible(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2486
struct SCIP_LPi SCIP_LPI
Definition: type_lpi.h:94
#define SCIP_Real
Definition: def.h:123
SCIP_RETCODE SCIPlpiGetIterations(SCIP_LPI *lpi, int *iterations)
Definition: lpi_clp.cpp:2753
SCIP_RETCODE SCIPlpiDelRows(SCIP_LPI *lpi, int firstrow, int lastrow)
Definition: lpi_clp.cpp:844
SCIP_Bool SCIPlpiIsInfinity(SCIP_LPI *, SCIP_Real val)
Definition: lpi_clp.cpp:3681
SCIP_RETCODE SCIPlpiGetBInvRow(SCIP_LPI *lpi, int r, SCIP_Real *coef)
Definition: lpi_clp.cpp:3054
SCIP_RETCODE SCIPlpiGetCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real *val)
Definition: lpi_clp.cpp:1598
#define SCIP_INVALID
Definition: def.h:142
#define CLP_VERSION
Definition: lpi_clp.cpp:66
SCIP_RETCODE SCIPlpiGetNNonz(SCIP_LPI *lpi, int *nnonz)
Definition: lpi_clp.cpp:1291
SCIP_RETCODE SCIPlpiGetState(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPISTATE **lpistate)
Definition: lpi_clp.cpp:3176
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_clp.cpp:638
SCIP_RETCODE SCIPlpiFreeNorms(SCIP_LPI *lpi, BMS_BLKMEM *blkmem, SCIP_LPINORMS **lpinorms)
Definition: lpi_clp.cpp:3396
#define EPSFLOOR(x, eps)
Definition: def.h:155
SCIP_RETCODE SCIPlpiGetDualfarkas(SCIP_LPI *lpi, SCIP_Real *dualfarkas)
Definition: lpi_clp.cpp:2721
#define SCIP_ALLOC(x)
Definition: def.h:269
#define SCIPABORT()
Definition: def.h:230
SCIP_Bool SCIPlpiIsTimelimExc(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2604
SCIP_RETCODE SCIPlpiGetObj(SCIP_LPI *lpi, int firstcol, int lastcol, SCIP_Real *vals)
Definition: lpi_clp.cpp:1513
SCIP_RETCODE SCIPlpiGetNRows(SCIP_LPI *lpi, int *nrows)
Definition: lpi_clp.cpp:1255
SCIP_RETCODE SCIPlpiDelColset(SCIP_LPI *lpi, int *dstat)
Definition: lpi_clp.cpp:736
SCIP_Bool SCIPlpiIsPrimalInfeasible(SCIP_LPI *lpi)
Definition: lpi_clp.cpp:2374