CoinPresolveMatrix.hpp
Go to the documentation of this file.
1 /* $Id: CoinPresolveMatrix.hpp 1761 2014-12-10 09:43:07Z forrest $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CoinPresolveMatrix_H
7 #define CoinPresolveMatrix_H
8 
9 #include "CoinPragma.hpp"
10 #include "CoinPackedMatrix.hpp"
11 #include "CoinMessage.hpp"
12 #include "CoinTime.hpp"
13 
14 #include <cmath>
15 #include <cassert>
16 #include <cfloat>
17 #include <cassert>
18 #include <cstdlib>
19 
20 #if PRESOLVE_DEBUG > 0
21 #include "CoinFinite.hpp"
22 #endif
23 
32 #if defined(_MSC_VER)
33 // Avoid MS Compiler problem in recognizing type to delete
34 // by casting to type.
35 // Is this still necessary? -- lh, 111202 --
36 #define deleteAction(array,type) delete [] ((type) array)
37 #else
38 #define deleteAction(array,type) delete [] array
39 #endif
40 
41 /*
42  Define PRESOLVE_DEBUG and PRESOLVE_CONSISTENCY on the configure command
43  line or in a Makefile! See comments in CoinPresolvePsdebug.hpp.
44 */
45 #if PRESOLVE_DEBUG > 0 || PRESOLVE_CONSISTENCY > 0
46 
47 #define PRESOLVE_STMT(s) s
48 
49 #define PRESOLVEASSERT(x) \
50  ((x) ? 1 : ((std::cerr << "FAILED ASSERTION at line " \
51  << __LINE__ << ": " #x "\n"), abort(), 0))
52 
53 inline void DIE(const char *s) { std::cout << s ; abort() ; }
54 
65 #define PRESENT_IN_REDUCED '\377'
66 
67 #else
68 
69 #define PRESOLVEASSERT(x) {}
70 #define PRESOLVE_STMT(s) {}
71 
72 inline void DIE(const char *) {}
73 
74 #endif
75 
76 /*
77  Unclear why these are separate from standard debug.
78 */
79 #ifndef PRESOLVE_DETAIL
80 #define PRESOLVE_DETAIL_PRINT(s) {}
81 #else
82 #define PRESOLVE_DETAIL_PRINT(s) s
83 #endif
84 
89 const double ZTOLDP = 1e-12 ;
94 const double ZTOLDP2 = 1e-10 ;
95 
97 #define PRESOLVE_INF COIN_DBL_MAX
98 #define PRESOLVE_SMALL_INF 1.0e20
100 #define PRESOLVEFINITE(n) (-PRESOLVE_INF < (n) && (n) < PRESOLVE_INF)
102 
103 
104 class CoinPostsolveMatrix ;
105 
156 {
157  public:
164  static void throwCoinError(const char *error, const char *ps_routine)
165  { throw CoinError(error, ps_routine, "CoinPresolve"); }
166 
172 
180  inline void setNext(const CoinPresolveAction *nextAction)
181  { next = nextAction;}
182 
187  virtual const char *name() const = 0;
188 
192  virtual void postsolve(CoinPostsolveMatrix *prob) const = 0;
193 
195  virtual ~CoinPresolveAction() {}
196 };
197 
198 /*
199  These are needed for OSI-aware constructors associated with
200  CoinPrePostsolveMatrix, CoinPresolveMatrix, and CoinPostsolveMatrix.
201 */
202 class ClpSimplex;
203 class OsiSolverInterface;
204 
205 /*
206  CoinWarmStartBasis is required for methods in CoinPrePostsolveMatrix
207  that accept/return a CoinWarmStartBasis object.
208 */
209 class CoinWarmStartBasis ;
210 
266 {
267  public:
268 
278  CoinPrePostsolveMatrix(int ncols_alloc, int nrows_alloc,
279  CoinBigIndex nelems_alloc) ;
280 
286  int ncols_,
287  int nrows_,
289 
295  int ncols_,
296  int nrows_,
297  CoinBigIndex nelems_,
298  double bulkRatio);
299 
303 
313  enum Status {
314  isFree = 0x00,
315  basic = 0x01,
316  atUpperBound = 0x02,
317  atLowerBound = 0x03,
318  superBasic = 0x04
319  };
320 
333 
335  inline void setRowStatus(int sequence, Status status)
336  {
337  unsigned char & st_byte = rowstat_[sequence];
338  st_byte = static_cast<unsigned char>(st_byte & (~7)) ;
339  st_byte = static_cast<unsigned char>(st_byte | status) ;
340  }
342  inline Status getRowStatus(int sequence) const
343  {return static_cast<Status> (rowstat_[sequence]&7);}
345  inline bool rowIsBasic(int sequence) const
346  {return (static_cast<Status> (rowstat_[sequence]&7)==basic);}
348  inline void setColumnStatus(int sequence, Status status)
349  {
350  unsigned char & st_byte = colstat_[sequence];
351  st_byte = static_cast<unsigned char>(st_byte & (~7)) ;
352  st_byte = static_cast<unsigned char>(st_byte | status) ;
353 
354 # ifdef PRESOLVE_DEBUG
355  switch (status)
356  { case isFree:
357  { if (clo_[sequence] > -PRESOLVE_INF || cup_[sequence] < PRESOLVE_INF)
358  { std::cout << "Bad status: Var " << sequence
359  << " isFree, lb = " << clo_[sequence]
360  << ", ub = " << cup_[sequence] << std::endl ; }
361  break ; }
362  case basic:
363  { break ; }
364  case atUpperBound:
365  { if (cup_[sequence] >= PRESOLVE_INF)
366  { std::cout << "Bad status: Var " << sequence
367  << " atUpperBound, lb = " << clo_[sequence]
368  << ", ub = " << cup_[sequence] << std::endl ; }
369  break ; }
370  case atLowerBound:
371  { if (clo_[sequence] <= -PRESOLVE_INF)
372  { std::cout << "Bad status: Var " << sequence
373  << " atLowerBound, lb = " << clo_[sequence]
374  << ", ub = " << cup_[sequence] << std::endl ; }
375  break ; }
376  case superBasic:
377  { if (clo_[sequence] <= -PRESOLVE_INF && cup_[sequence] >= PRESOLVE_INF)
378  { std::cout << "Bad status: Var " << sequence
379  << " superBasic, lb = " << clo_[sequence]
380  << ", ub = " << cup_[sequence] << std::endl ; }
381  break ; }
382  default:
383  { assert(false) ;
384  break ; } }
385 # endif
386  }
388  inline Status getColumnStatus(int sequence) const
389  {return static_cast<Status> (colstat_[sequence]&7);}
391  inline bool columnIsBasic(int sequence) const
392  {return (static_cast<Status> (colstat_[sequence]&7)==basic);}
396  void setRowStatusUsingValue(int iRow);
400  void setColumnStatusUsingValue(int iColumn);
402  void setStructuralStatus(const char *strucStatus, int lenParam) ;
404  void setArtificialStatus(const char *artifStatus, int lenParam) ;
406  void setStatus(const CoinWarmStartBasis *basis) ;
412  const char *columnStatusString(int j) const ;
416  const char *rowStatusString(int i) const ;
418 
426  void setObjOffset(double offset) ;
434  void setObjSense(double objSense) ;
436  void setPrimalTolerance(double primTol) ;
438  void setDualTolerance(double dualTol) ;
440  void setColLower(const double *colLower, int lenParam) ;
442  void setColUpper(const double *colUpper, int lenParam) ;
444  void setColSolution(const double *colSol, int lenParam) ;
446  void setCost(const double *cost, int lenParam) ;
448  void setReducedCost(const double *redCost, int lenParam) ;
450  void setRowLower(const double *rowLower, int lenParam) ;
452  void setRowUpper(const double *rowUpper, int lenParam) ;
454  void setRowPrice(const double *rowSol, int lenParam) ;
456  void setRowActivity(const double *rowAct, int lenParam) ;
458 
461  inline int getNumCols() const
463  { return (ncols_) ; }
465  inline int getNumRows() const
466  { return (nrows_) ; }
468  inline int getNumElems() const
469  { return (nelems_) ; }
471  inline const CoinBigIndex *getColStarts() const
472  { return (mcstrt_) ; }
474  inline const int *getColLengths() const
475  { return (hincol_) ; }
477  inline const int *getRowIndicesByCol() const
478  { return (hrow_) ; }
480  inline const double *getElementsByCol() const
481  { return (colels_) ; }
483  inline const double *getColLower() const
484  { return (clo_) ; }
486  inline const double *getColUpper() const
487  { return (cup_) ; }
489  inline const double *getCost() const
490  { return (cost_) ; }
492  inline const double *getRowLower() const
493  { return (rlo_) ; }
495  inline const double *getRowUpper() const
496  { return (rup_) ; }
498  inline const double *getColSolution() const
499  { return (sol_) ; }
501  inline const double *getRowActivity() const
502  { return (acts_) ; }
504  inline const double *getRowPrice() const
505  { return (rowduals_) ; }
507  inline const double *getReducedCost() const
508  { return (rcosts_) ; }
510  inline int countEmptyCols()
511  { int empty = 0 ;
512  for (int i = 0 ; i < ncols_ ; i++) if (hincol_[i] == 0) empty++ ;
513  return (empty) ; }
515 
516 
519  inline CoinMessageHandler *messageHandler() const
521  { return handler_; }
527  inline void setMessageHandler(CoinMessageHandler *handler)
528  { if (defaultHandler_ == true)
529  { delete handler_ ;
530  defaultHandler_ = false ; }
531  handler_ = handler ; }
533  inline CoinMessages messages() const
534  { return messages_; }
536 
546 
548  int ncols_;
550  int nrows_;
553 
555  int ncols0_;
557  int nrows0_ ;
570  double bulkRatio_;
572 
584  int *hincol_;
586  int *hrow_;
588  double *colels_;
589 
591  double *cost_;
594 
596  double *clo_;
598  double *cup_;
599 
601  double *rlo_;
603  double *rup_;
604 
619 
621  double ztolzb_;
623  double ztoldj_;
624 
630  double maxmin_;
632 
653  double *sol_;
659  double *rowduals_;
665  double *acts_;
671  double *rcosts_;
672 
679  unsigned char *colstat_;
680 
687  unsigned char *rowstat_;
689 
705 
706 };
707 
711 const char *statusName (CoinPrePostsolveMatrix::Status status) ;
712 
713 
739 { public:
740  int pre, suc;
741 } ;
742 
743 #define NO_LINK -66666666
744 
750 inline void PRESOLVE_REMOVE_LINK(presolvehlink *link, int i)
751 {
752  int ipre = link[i].pre;
753  int isuc = link[i].suc;
754  if (ipre >= 0) {
755  link[ipre].suc = isuc;
756  }
757  if (isuc >= 0) {
758  link[isuc].pre = ipre;
759  }
760  link[i].pre = NO_LINK, link[i].suc = NO_LINK;
761 }
762 
768 inline void PRESOLVE_INSERT_LINK(presolvehlink *link, int i, int j)
769 {
770  int isuc = link[j].suc;
771  link[j].suc = i;
772  link[i].pre = j;
773  if (isuc >= 0) {
774  link[isuc].pre = i;
775  }
776  link[i].suc = isuc;
777 }
778 
790 inline void PRESOLVE_MOVE_LINK(presolvehlink *link, int i, int j)
791 {
792  int ipre = link[i].pre;
793  int isuc = link[i].suc;
794  if (ipre >= 0) {
795  link[ipre].suc = j;
796  }
797  if (isuc >= 0) {
798  link[isuc].pre = j;
799  }
800  link[i].pre = NO_LINK, link[i].suc = NO_LINK;
801 }
802 
803 
836 {
837  public:
838 
845  CoinPresolveMatrix(int ncols_alloc, int nrows_alloc,
846  CoinBigIndex nelems_alloc) ;
847 
852  CoinPresolveMatrix(int ncols0,
853  double maxmin,
854  // end prepost members
855 
856  ClpSimplex * si,
857 
858  // rowrep
859  int nrows,
860  CoinBigIndex nelems,
861  bool doStatus,
862  double nonLinearVariable,
863  double bulkRatio);
864 
866  void update_model(ClpSimplex * si,
867  int nrows0,
868  int ncols0,
869  CoinBigIndex nelems0);
874  CoinPresolveMatrix(int ncols0,
875  double maxmin,
876  // end prepost members
877  OsiSolverInterface * si,
878  // rowrep
879  int nrows,
880  CoinBigIndex nelems,
881  bool doStatus,
882  double nonLinearVariable,
883  const char * prohibited,
884  const char * rowProhibited=NULL);
885 
888  int nrows0,
889  int ncols0,
890  CoinBigIndex nelems0);
891 
894 
900  friend void assignPresolveToPostsolve (CoinPresolveMatrix *&preObj) ;
901 
910  void setMatrix(const CoinPackedMatrix *mtx) ;
911 
913  inline int countEmptyRows()
914  { int empty = 0 ;
915  for (int i = 0 ; i < nrows_ ; i++) if (hinrow_[i] == 0) empty++ ;
916  return (empty) ; }
917 
923  inline void setVariableType(int i, int variableType)
924  { if (integerType_ == 0) integerType_ = new unsigned char [ncols0_] ;
925  integerType_[i] = static_cast<unsigned char>(variableType) ; }
926 
932  void setVariableType(const unsigned char *variableType, int lenParam) ;
933 
939  void setVariableType (bool allIntegers, int lenParam) ;
940 
942  inline void setAnyInteger (bool anyInteger = true)
943  { anyInteger_ = anyInteger ; }
945 
949 
951  inline const CoinBigIndex *getRowStarts() const
952  { return (mrstrt_) ; }
954  inline const int *getColIndicesByRow() const
955  { return (hcol_) ; }
957  inline const double *getElementsByRow() const
958  { return (rowels_) ; }
959 
965  inline bool isInteger (int i) const
966  { if (integerType_ == 0)
967  { return (anyInteger_) ; }
968  else
969  if (integerType_[i] == 1)
970  { return (true) ; }
971  else
972  { return (false) ; } }
973 
978  inline bool anyInteger () const
979  { return (anyInteger_) ; }
981  inline int presolveOptions() const
982  { return presolveOptions_;}
984  inline void setPresolveOptions(int value)
985  { presolveOptions_=value;}
987 
1000 
1002  double dobias_ ;
1003 
1005  inline void change_bias(double change_amount)
1006  {
1007  dobias_ += change_amount ;
1008  # if PRESOLVE_DEBUG > 2
1009  assert(fabs(change_amount)<1.0e50) ;
1010  if (change_amount)
1011  PRESOLVE_STMT(printf("changing bias by %g to %g\n",
1012  change_amount, dobias_)) ;
1013  # endif
1014  }
1015 
1027  int *hinrow_;
1029  double *rowels_;
1031  int *hcol_;
1033 
1035  unsigned char *integerType_;
1043  bool tuning_;
1045  void statistics();
1047  double startTime_;
1048 
1052  inline double feasibilityTolerance()
1053  { return (feasibilityTolerance_) ; }
1055  inline void setFeasibilityTolerance (double val)
1056  { feasibilityTolerance_ = val ; }
1057 
1063  int status_;
1065  inline int status()
1066  { return (status_) ; }
1068  inline void setStatus(int status)
1069  { status_ = (status&0x3) ; }
1070 
1078  int pass_;
1080  inline void setPass (int pass = 0)
1081  { pass_ = pass ; }
1082 
1089  inline void setMaximumSubstitutionLevel (int level)
1090  { maxSubstLevel_ = level ; }
1091 
1092 
1116  unsigned char * colChanged_;
1118  int * colsToDo_;
1125 
1135  unsigned char * rowChanged_;
1137  int * rowsToDo_;
1169 
1180  int *usefulRowInt_ ;
1189  double *randomNumber_ ;
1190 
1194  double *sumUp_ ;
1198  double *sumDown_ ;
1200 
1212  int recomputeSums(int whichRow) ;
1213 
1215  void initializeStuff() ;
1217  void deleteStuff() ;
1218 
1221 
1227  void initColsToDo () ;
1228 
1234  int stepColsToDo () ;
1235 
1237  inline int numberColsToDo()
1238  { return (numberColsToDo_) ; }
1239 
1241  inline bool colChanged(int i) const {
1242  return (colChanged_[i]&1)!=0;
1243  }
1245  inline void unsetColChanged(int i) {
1246  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] & (~1)) ;
1247  }
1249  inline void setColChanged(int i) {
1250  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (1)) ;
1251  }
1253  inline void addCol(int i) {
1254  if ((colChanged_[i]&1)==0) {
1255  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (1)) ;
1257  }
1258  }
1260  inline bool colProhibited(int i) const {
1261  return (colChanged_[i]&2)!=0;
1262  }
1269  inline bool colProhibited2(int i) const {
1270  if (!anyProhibited_)
1271  return false;
1272  else
1273  return (colChanged_[i]&2)!=0;
1274  }
1276  inline void setColProhibited(int i) {
1277  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (2)) ;
1278  }
1284  inline bool colUsed(int i) const {
1285  return (colChanged_[i]&4)!=0;
1286  }
1288  inline void setColUsed(int i) {
1289  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (4)) ;
1290  }
1292  inline void unsetColUsed(int i) {
1293  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] & (~4)) ;
1294  }
1296  inline bool colInfinite(int i) const {
1297  return (colChanged_[i]&8)!=0;
1298  }
1300  inline void unsetColInfinite(int i) {
1301  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] & (~8)) ;
1302  }
1304  inline void setColInfinite(int i) {
1305  colChanged_[i] = static_cast<unsigned char>(colChanged_[i] | (8)) ;
1306  }
1307 
1313  void initRowsToDo () ;
1314 
1320  int stepRowsToDo () ;
1321 
1323  inline int numberRowsToDo()
1324  { return (numberRowsToDo_) ; }
1325 
1327  inline bool rowChanged(int i) const {
1328  return (rowChanged_[i]&1)!=0;
1329  }
1331  inline void unsetRowChanged(int i) {
1332  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] & (~1)) ;
1333  }
1335  inline void setRowChanged(int i) {
1336  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (1)) ;
1337  }
1339  inline void addRow(int i) {
1340  if ((rowChanged_[i]&1)==0) {
1341  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (1)) ;
1343  }
1344  }
1346  inline bool rowProhibited(int i) const {
1347  return (rowChanged_[i]&2)!=0;
1348  }
1355  inline bool rowProhibited2(int i) const {
1356  if (!anyProhibited_)
1357  return false;
1358  else
1359  return (rowChanged_[i]&2)!=0;
1360  }
1362  inline void setRowProhibited(int i) {
1363  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (2)) ;
1364  }
1370  inline bool rowUsed(int i) const {
1371  return (rowChanged_[i]&4)!=0;
1372  }
1374  inline void setRowUsed(int i) {
1375  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] | (4)) ;
1376  }
1378  inline void unsetRowUsed(int i) {
1379  rowChanged_[i] = static_cast<unsigned char>(rowChanged_[i] & (~4)) ;
1380  }
1381 
1382 
1384  inline bool anyProhibited() const
1385  { return anyProhibited_;}
1387  inline void setAnyProhibited(bool val = true)
1388  { anyProhibited_ = val ; }
1390 
1391 };
1392 
1422 {
1423  public:
1424 
1431  CoinPostsolveMatrix(int ncols_alloc, int nrows_alloc,
1432  CoinBigIndex nelems_alloc) ;
1433 
1434 
1440 
1441  int ncols0,
1442  int nrows0,
1443  CoinBigIndex nelems0,
1444 
1445  double maxmin_,
1446  // end prepost members
1447 
1448  double *sol,
1449  double *acts,
1450 
1451  unsigned char *colstat,
1452  unsigned char *rowstat);
1453 
1459 
1460  int ncols0,
1461  int nrows0,
1462  CoinBigIndex nelems0,
1463 
1464  double maxmin_,
1465  // end prepost members
1466 
1467  double *sol,
1468  double *acts,
1469 
1470  unsigned char *colstat,
1471  unsigned char *rowstat);
1472 
1484 
1487 
1499 
1509 
1511 
1519  char *cdone_;
1520  char *rdone_;
1522 
1524  void check_nbasic();
1525 
1526 };
1527 
1528 
1535 
1540 void presolve_make_memlists(/*CoinBigIndex *starts,*/ int *lengths,
1541  presolvehlink *link, int n);
1542 
1550 bool presolve_expand_major(CoinBigIndex *majstrts, double *majels,
1551  int *minndxs, int *majlens,
1552  presolvehlink *majlinks, int nmaj, int k) ;
1553 
1559 inline bool presolve_expand_col(CoinBigIndex *mcstrt, double *colels,
1560  int *hrow, int *hincol,
1561  presolvehlink *clink, int ncols, int colx)
1562 { return presolve_expand_major(mcstrt,colels,
1563  hrow,hincol,clink,ncols,colx) ; }
1564 
1570 inline bool presolve_expand_row(CoinBigIndex *mrstrt, double *rowels,
1571  int *hcol, int *hinrow,
1572  presolvehlink *rlink, int nrows, int rowx)
1573 { return presolve_expand_major(mrstrt,rowels,
1574  hcol,hinrow,rlink,nrows,rowx) ; }
1575 
1576 
1586  CoinBigIndex ks, CoinBigIndex ke,
1587  const int *minndxs)
1588 { CoinBigIndex k ;
1589  for (k = ks ; k < ke ; k++)
1590 #ifndef NDEBUG
1591  { if (minndxs[k] == tgt)
1592  return (k) ; }
1593  DIE("FIND_MINOR") ;
1594 
1595  abort () ; return -1;
1596 #else
1597  { if (minndxs[k] == tgt)
1598  break ; }
1599  return (k) ;
1600 #endif
1601 }
1602 
1610  CoinBigIndex kce, const int *hrow)
1611 { return presolve_find_minor(row,kcs,kce,hrow) ; }
1612 
1620  CoinBigIndex kre, const int *hcol)
1621 { return presolve_find_minor(col,krs,kre,hcol) ; }
1622 
1623 
1633  const int *minndxs);
1634 
1642  CoinBigIndex kce, const int *hrow)
1643 { return presolve_find_minor1(row,kcs,kce,hrow) ; }
1644 
1652  CoinBigIndex kre, const int *hcol)
1653 { return presolve_find_minor1(col,krs,kre,hcol) ; }
1654 
1663 CoinBigIndex presolve_find_minor2(int tgt, CoinBigIndex ks, int majlen,
1664  const int *minndxs,
1665  const CoinBigIndex *majlinks) ;
1666 
1674 inline CoinBigIndex presolve_find_row2(int row, CoinBigIndex kcs, int collen,
1675  const int *hrow,
1676  const CoinBigIndex *clinks)
1677 { return presolve_find_minor2(row,kcs,collen,hrow,clinks) ; }
1678 
1687 CoinBigIndex presolve_find_minor3(int tgt, CoinBigIndex ks, int majlen,
1688  const int *minndxs,
1689  const CoinBigIndex *majlinks) ;
1690 
1698 inline CoinBigIndex presolve_find_row3(int row, CoinBigIndex kcs, int collen,
1699  const int *hrow,
1700  const CoinBigIndex *clinks)
1701 { return presolve_find_minor3(row,kcs,collen,hrow,clinks) ; }
1702 
1712 inline void presolve_delete_from_major(int majndx, int minndx,
1713  const CoinBigIndex *majstrts,
1714  int *majlens, int *minndxs, double *els)
1715 {
1716  const CoinBigIndex ks = majstrts[majndx] ;
1717  const CoinBigIndex ke = ks+majlens[majndx] ;
1718 
1719  const CoinBigIndex kmi = presolve_find_minor(minndx,ks,ke,minndxs) ;
1720 
1721  minndxs[kmi] = minndxs[ke-1] ;
1722  els[kmi] = els[ke-1] ;
1723  majlens[majndx]-- ;
1724 
1725  return ;
1726 }
1727 
1734 inline void presolve_delete_many_from_major(int majndx, char *marked,
1735  const CoinBigIndex *majstrts,
1736  int *majlens, int *minndxs, double *els)
1737 {
1738  const CoinBigIndex ks = majstrts[majndx] ;
1739  const CoinBigIndex ke = ks+majlens[majndx] ;
1740  CoinBigIndex put = ks ;
1741  for (CoinBigIndex k = ks ; k < ke ; k++) {
1742  int iMinor = minndxs[k] ;
1743  if (!marked[iMinor]) {
1744  minndxs[put] = iMinor ;
1745  els[put++] = els[k] ;
1746  } else {
1747  marked[iMinor] = 0 ;
1748  }
1749  }
1750  majlens[majndx] = put-ks ;
1751  return ;
1752 }
1753 
1764 inline void presolve_delete_from_col(int row, int col,
1765  const CoinBigIndex *mcstrt,
1766  int *hincol, int *hrow, double *colels)
1767 { presolve_delete_from_major(col,row,mcstrt,hincol,hrow,colels) ; }
1768 
1779 inline void presolve_delete_from_row(int row, int col,
1780  const CoinBigIndex *mrstrt,
1781  int *hinrow, int *hcol, double *rowels)
1782 { presolve_delete_from_major(row,col,mrstrt,hinrow,hcol,rowels) ; }
1783 
1794 void presolve_delete_from_major2 (int majndx, int minndx,
1795  CoinBigIndex *majstrts, int *majlens,
1796  int *minndxs, int *majlinks,
1797  CoinBigIndex *free_listp) ;
1798 
1809 inline void presolve_delete_from_col2(int row, int col, CoinBigIndex *mcstrt,
1810  int *hincol, int *hrow,
1811  int *clinks, CoinBigIndex *free_listp)
1812 { presolve_delete_from_major2(col,row,mcstrt,hincol,hrow,clinks,free_listp) ; }
1813 
1815 
1821 
1833 double *presolve_dupmajor(const double *elems, const int *indices,
1834  int length, CoinBigIndex offset, int tgt = -1);
1835 
1837 void coin_init_random_vec(double *work, int n);
1838 
1840 
1841 
1842 #endif
int status()
Returns problem status (0 = feasible, 1 = infeasible, 2 = unbounded)
bool defaultHandler_
Indicates if the current handler_ is default (true) or not (false).
int CoinBigIndex
void setRowStatus(int sequence, Status status)
Set row status (i.e., status of artificial for this row)
bool tuning_
Print statistics for tuning.
~CoinPostsolveMatrix()
Destructor.
void coin_init_random_vec(double *work, int n)
Initialize a vector with random numbers.
bool colInfinite(int i) const
Has column infinite ub (originally)
bool colChanged(int i) const
Has column been changed?
void setReducedCost(const double *redCost, int lenParam)
Set reduced costs.
const char * rowStatusString(int i) const
Return a print string for status of a row (artificial variable)
double startTime_
Start time of presolve.
const char * statusName(CoinPrePostsolveMatrix::Status status)
Generate a print string for a status code.
void update_model(ClpSimplex *si, int nrows0, int ncols0, CoinBigIndex nelems0)
Update the model held by a Clp OSI.
void presolve_delete_from_major2(int majndx, int minndx, CoinBigIndex *majstrts, int *majlens, int *minndxs, int *majlinks, CoinBigIndex *free_listp)
Delete the entry for a minor index from a major vector in a threaded matrix.
double dobias_
Objective function offset introduced during presolve.
void setStructuralStatus(const char *strucStatus, int lenParam)
Set column (structural variable) status vector.
int status_
Output status: 0 = feasible, 1 = infeasible, 2 = unbounded.
int * hcol_
Column indices (positional correspondence with rowels_)
void change_bias(double change_amount)
Adjust objective function constant offset.
CoinPresolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
`Native&#39; constructor
bool presolve_expand_row(CoinBigIndex *mrstrt, double *rowels, int *hcol, int *hinrow, presolvehlink *rlink, int nrows, int rowx)
Make sure a row (rowx) in a row-major matrix has room for one more coefficient.
int getNumRows() const
Get current number of rows.
void setColInfinite(int i)
Mark column as infinite ub (originally)
void setAnyInteger(bool anyInteger=true)
Set a flag for presence (true) or absence (false) of integer variables.
bool anyInteger_
Flag to say if any variables are integer.
const double * getRowPrice() const
Get row solution (dual variables)
const char * columnStatusString(int j) const
Return a print string for status of a column (structural variable)
const double * getColSolution() const
Get column solution (primal variable values)
double * sumDown_
Work array for sum of finite contributions to row lhs lower bound.
void setObjSense(double objSense)
Set the objective sense (max/min)
const double * getElementsByCol() const
Get vector of elements for column-major packed matrix.
int numberColsToDo_
Length of colsToDo_.
void setRowLower(const double *rowLower, int lenParam)
Set row lower bounds.
void setNext(const CoinPresolveAction *nextAction)
modify next (when building rather than passing)
Base class for message handling.
int * hrow_
Row indices (positional correspondence with colels_)
int * rowsToDo_
Input list of rows to process.
void addRow(int i)
Mark row as changed and add to list of rows to process next.
void setStatus(const CoinWarmStartBasis *basis)
Set the status of all variables from a basis.
const double * getRowUpper() const
Get row upper bounds.
const double * getReducedCost() const
Get reduced costs.
Collects all the information about the problem that is needed in both presolve and postsolve...
void setColSolution(const double *colSol, int lenParam)
Set column solution.
int * originalColumn_
Original column numbers.
CoinBigIndex presolve_find_minor3(int tgt, CoinBigIndex ks, int majlen, const int *minndxs, const CoinBigIndex *majlinks)
Find position of a minor index in a major vector in a threaded matrix.
Status
Enum for status of various sorts.
CoinBigIndex presolve_find_col(int col, CoinBigIndex krs, CoinBigIndex kre, const int *hcol)
Find position of a column in a row in a row-major matrix.
int numberRowsToDo()
Return the number of rows on the rowsToDo_ list.
CoinMessageHandler * messageHandler() const
Return message handler.
Augments CoinPrePostsolveMatrix with information about the problem that is only needed during postsol...
CoinBigIndex presolve_find_minor1(int tgt, CoinBigIndex ks, CoinBigIndex ke, const int *minndxs)
Find position of a minor index in a major vector.
Augments CoinPrePostsolveMatrix with information about the problem that is only needed during presolv...
void addCol(int i)
Mark column as changed and add to list of columns to process next.
double * sumUp_
Work array for sum of finite contributions to row lhs upper bound.
const double * getCost() const
Get objective coefficients.
CoinBigIndex * mcstrt_
Vector of column start positions in hrow_, colels_.
void assignPresolveToPostsolve(CoinPresolveMatrix *&preObj)
Load an empty CoinPostsolveMatrix from a CoinPresolveMatrix.
const double ZTOLDP
Zero tolerance.
int numberNextColsToDo_
Length of nextColsToDo_.
virtual void postsolve(CoinPostsolveMatrix *prob) const =0
Apply the postsolve transformation for this particular presolve action.
unsigned char * rowChanged_
Row change status information.
CoinMessageHandler * handler_
Message handler.
double * cost_
Objective coefficients.
const int * getColIndicesByRow() const
Get vector of column indices for row-major packed matrix.
void setRowActivity(const double *rowAct, int lenParam)
Set row activity.
int * hincol_
Vector of column lengths.
void setDualTolerance(double dualTol)
Set the dual feasibility tolerance.
double * usefulRowDouble_
Preallocated scratch work array, 2*nrows_.
~CoinPrePostsolveMatrix()
Destructor.
CoinBigIndex presolve_find_row2(int row, CoinBigIndex kcs, int collen, const int *hrow, const CoinBigIndex *clinks)
Find position of a row in a column in a column-major threaded matrix.
int ncols_
current number of columns
void setPresolveOptions(int value)
Sets any special options (see presolveOptions_)
int pass_
Presolve pass number.
int * originalRow_
Original row numbers.
const CoinBigIndex * getColStarts() const
Get column start vector for column-major packed matrix.
void DIE(const char *)
CoinPostsolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
`Native&#39; constructor
CoinBigIndex nelems0_
Allocated number of coefficients.
int nrows0_
Allocated number of rows.
int nrows_
current number of rows
void setRowPrice(const double *rowSol, int lenParam)
Set row solution.
double * rowduals_
Vector of dual variable values.
bool presolve_expand_major(CoinBigIndex *majstrts, double *majels, int *minndxs, int *majlens, presolvehlink *majlinks, int nmaj, int k)
Make sure a major-dimension vector k has room for one more coefficient.
double * usefulColumnDouble_
Preallocated scratch work array, ncols_.
double maxmin_
Maximization/minimization.
presolvehlink * clink_
Linked list for the column-major representation.
Sparse Matrix Base Class.
#define PRESOLVE_INF
The usual finite infinity.
Status getColumnStatus(int sequence) const
Get column (structural variable) status.
int numberNextRowsToDo_
Length of nextRowsToDo_.
Status getRowStatus(int sequence) const
Get row status.
const double * getRowLower() const
Get row lower bounds.
CoinWarmStartBasis * getStatus()
Get status in the form of a CoinWarmStartBasis.
void presolve_delete_many_from_major(int majndx, char *marked, const CoinBigIndex *majstrts, int *majlens, int *minndxs, double *els)
Delete marked entries.
void setColUpper(const double *colUpper, int lenParam)
Set column upper bounds.
CoinBigIndex presolve_find_col1(int col, CoinBigIndex krs, CoinBigIndex kre, const int *hcol)
Find position of a column in a row in a row-major matrix.
CoinBigIndex free_list_
First entry in free entries thread.
void setRowUsed(int i)
Mark row as used.
void setColUsed(int i)
Mark column as used.
int * infiniteUp_
Work array for count of infinite contributions to row lhs upper bound.
int recomputeSums(int whichRow)
Recompute row lhs bounds.
double bulkRatio_
Ratio of bulk0_ to nelems0_; default is 2.
void unsetColInfinite(int i)
Mark column as not infinite ub (originally)
CoinMessage messages_
Standard COIN messages.
void setRowStatusUsingValue(int iRow)
Set status of row (artificial variable) to the correct nonbasic status given bounds and current value...
void presolve_delete_from_col2(int row, int col, CoinBigIndex *mcstrt, int *hincol, int *hrow, int *clinks, CoinBigIndex *free_listp)
Delete the entry for row row from column col in a column-major threaded matrix.
#define PRESOLVE_STMT(s)
CoinBigIndex presolve_find_row1(int row, CoinBigIndex kcs, CoinBigIndex kce, const int *hrow)
Find position of a row in a column in a column-major matrix.
int * usefulRowInt_
Preallocated scratch work array, 3*nrows_.
void setVariableType(int i, int variableType)
Set variable type information for a single variable.
unsigned char * integerType_
Tracks integrality of columns (1 for integer, 0 for continuous)
bool colUsed(int i) const
Test if column is marked as used.
void setRowChanged(int i)
Mark row as changed.
void setMessageHandler(CoinMessageHandler *handler)
Set message handler.
CoinMessages messages() const
Return messages.
double * rlo_
Row (constraint) lower bounds.
void unsetRowUsed(int i)
Mark row as unused.
void setColProhibited(int i)
Mark column as ineligible for preprocessing.
void setArtificialStatus(const char *artifStatus, int lenParam)
Set row (artificial variable) status vector.
void setColLower(const double *colLower, int lenParam)
Set column lower bounds.
CoinPresolveAction(const CoinPresolveAction *next)
Construct a postsolve object and add it to the transformation list.
void setAnyProhibited(bool val=true)
Set a flag for presence of prohibited rows or columns.
unsigned char * colChanged_
Column change status information.
int countEmptyCols()
Count empty columns.
void initRowsToDo()
Initialise the row ToDo lists.
void setFeasibilityTolerance(double val)
Set feasibility tolerance.
void setColumnStatus(int sequence, Status status)
Set column status (i.e., status of primal variable)
void setColChanged(int i)
Mark column as changed.
const CoinBigIndex * getRowStarts() const
Get row start vector for row-major packed matrix.
double * acts_
Vector of constraint left-hand-side values (row activity)
bool rowIsBasic(int sequence) const
Check if artificial for this row is basic.
void presolve_delete_from_row(int row, int col, const CoinBigIndex *mrstrt, int *hinrow, int *hcol, double *rowels)
Delete the entry for column col from row row in a row-major matrix.
int * usefulColumnInt_
Preallocated scratch work array, 2*ncols_.
const double * getColLower() const
Get column lower bounds.
unsigned char * rowstat_
Status of constraints.
void setMaximumSubstitutionLevel(int level)
Set Maximum substitution level (normally 3)
void setRowProhibited(int i)
Mark row as ineligible for preprocessing.
double * cup_
Column (primal variable) upper bounds.
Abstract base class of all presolve routines.
bool colProhibited2(int i) const
Test if column is eligible for preprocessing.
void setPrimalTolerance(double primTol)
Set the primal feasibility tolerance.
bool anyProhibited() const
Check if there are any prohibited rows or columns.
int numberColsToDo()
Return the number of columns on the colsToDo_ list.
CoinBigIndex presolve_find_row3(int row, CoinBigIndex kcs, int collen, const int *hrow, const CoinBigIndex *clinks)
Find position of a row in a column in a column-major threaded matrix.
Abstract Base Class for describing an interface to a solver.
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:70
const double * getRowActivity() const
Get row activity (constraint lhs values)
CoinBigIndex presolve_find_minor(int tgt, CoinBigIndex ks, CoinBigIndex ke, const int *minndxs)
Find position of a minor index in a major vector.
void setMatrix(const CoinPackedMatrix *mtx)
Load the cofficient matrix.
int * hinrow_
Vector of row lengths.
int presolveOptions() const
Picks up any special options.
double * presolve_dupmajor(const double *elems, const int *indices, int length, CoinBigIndex offset, int tgt=-1)
Duplicate a major-dimension vector; optionally omit the entry with minor index tgt.
void unsetColChanged(int i)
Mark column as not changed.
bool columnIsBasic(int sequence) const
Check if column (structural variable) is basic.
int presolveOptions_
Fine control over presolve actions.
void initializeStuff()
Allocate scratch arrays.
double * rcosts_
Vector of reduced costs.
int ncols0_
Allocated number of columns.
const double * getColUpper() const
Get column upper bounds.
Class to hold and manipulate an array of massaged messages.
double ztolzb_
Primal feasibility tolerance.
double * clo_
Column (primal variable) lower bounds.
int getNumElems() const
Get current number of non-zero coefficients.
void setObjOffset(double offset)
Set the objective function offset for the original system.
int stepRowsToDo()
Step row ToDo lists.
double * colels_
Coefficients (positional correspondence with hrow_)
bool presolve_expand_col(CoinBigIndex *mcstrt, double *colels, int *hrow, int *hincol, presolvehlink *clink, int ncols, int colx)
Make sure a column (colx) in a column-major matrix has room for one more coefficient.
int getNumCols() const
Get current number of columns.
Error Class thrown by an exception.
Definition: CoinError.hpp:42
double ztoldj_
Dual feasibility tolerance.
void unsetColUsed(int i)
Mark column as unused.
bool rowChanged(int i) const
Has row been changed?
CoinBigIndex bulk0_
Allocated size of bulk storage for row indices and coefficients.
CoinBigIndex presolve_find_minor2(int tgt, CoinBigIndex ks, int majlen, const int *minndxs, const CoinBigIndex *majlinks)
Find position of a minor index in a major vector in a threaded matrix.
void initColsToDo()
Initialise the column ToDo lists.
virtual ~CoinPresolveAction()
Virtual destructor.
unsigned char * colstat_
Status of primal variables.
int maxlink_
Allocated size of link_.
virtual const char * name() const =0
A name for debug printing.
presolvehlink * rlink_
Linked list for the row-major representation.
void setRowUpper(const double *rowUpper, int lenParam)
Set row upper bounds.
void presolve_delete_from_col(int row, int col, const CoinBigIndex *mcstrt, int *hincol, int *hrow, double *colels)
Delete the entry for row row from column col in a column-major matrix.
void check_nbasic()
debug
friend void assignPresolveToPostsolve(CoinPresolveMatrix *&preObj)
Initialize a CoinPostsolveMatrix object, destroying the CoinPresolveMatrix object.
double originalOffset_
Original objective offset.
bool rowProhibited(int i) const
Test if row is eligible for preprocessing.
const int * getColLengths() const
Get column length vector for column-major packed matrix.
void unsetRowChanged(int i)
Mark row as not changed.
~CoinPresolveMatrix()
Destructor.
void presolve_make_memlists(int *lengths, presolvehlink *link, int n)
Initialise linked list for major vector order in bulk storage.
void setColumnStatusUsingValue(int iColumn)
Set status of column (structural variable) to the correct nonbasic status given bounds and current va...
#define NO_LINK
CoinBigIndex nelems_
current number of coefficients
static void throwCoinError(const char *error, const char *ps_routine)
Stub routine to throw exceptions.
CoinBigIndex presolve_find_row(int row, CoinBigIndex kcs, CoinBigIndex kce, const int *hrow)
Find position of a row in a column in a column-major matrix.
CoinPrePostsolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
`Native&#39; constructor
bool anyInteger() const
Check if there are any integer variables.
bool rowProhibited2(int i) const
Test if row is eligible for preprocessing.
void presolve_delete_from_major(int majndx, int minndx, const CoinBigIndex *majstrts, int *majlens, int *minndxs, double *els)
Delete the entry for a minor index from a major vector.
double * randomNumber_
Array of random numbers (max row,column)
CoinBigIndex * mrstrt_
Vector of row start positions in #hcol, rowels_.
void setPass(int pass=0)
Set pass number.
int * infiniteDown_
Work array for count of infinite contributions to row lhs lower bound.
bool colProhibited(int i) const
Test if column is eligible for preprocessing.
CoinBigIndex * link_
Thread array.
int countEmptyRows()
Count number of empty rows.
double feasibilityTolerance()
Return feasibility tolerance.
void deleteStuff()
Free scratch arrays.
void statistics()
Say we want statistics - also set time.
bool rowUsed(int i) const
Test if row is marked as used.
bool isInteger(int i) const
Check for integrality of the specified variable.
double * sol_
Vector of primal variable values.
The standard set of Coin messages.
Definition: CoinMessage.hpp:80
int numberRowsToDo_
Length of rowsToDo_.
const double * getElementsByRow() const
Get vector of elements for row-major packed matrix.
int maxSubstLevel_
Maximum substitution level.
int * nextColsToDo_
Output list of columns to process next.
double * rowels_
Coefficients (positional correspondence with hcol_)
const double ZTOLDP2
Alternate zero tolerance.
The default COIN simplex (basis-oriented) warm start class.
int * colsToDo_
Input list of columns to process.
double feasibilityTolerance_
Bounds can be moved by this to retain feasibility.
int * nextRowsToDo_
Output list of rows to process next.
double * rup_
Row (constraint) upper bounds.
void setCost(const double *cost, int lenParam)
Set objective coefficients.
int stepColsToDo()
Step column ToDo lists.
const CoinPresolveAction * next
The next presolve transformation.
void setStatus(int status)
Set problem status.
const int * getRowIndicesByCol() const
Get vector of row indices for column-major packed matrix.