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