Changeset 1213


Ignore:
Timestamp:
Jun 12, 2008 8:13:14 AM (12 years ago)
Author:
forrest
Message:

for Lou Hafer to update Osi stable

Location:
stable/1.7/Clp/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • stable/1.7/Clp/src/ClpModel.cpp

    r1186 r1213  
    6767  rowScale_(NULL),
    6868  columnScale_(NULL),
     69  inverseRowScale_(NULL),
     70  inverseColumnScale_(NULL),
    6971  scalingFlag_(3),
    7072  status_(NULL),
     
    8890  maximumColumns_(-1),
    8991  maximumRows_(-1),
     92  maximumInternalColumns_(-1),
     93  maximumInternalRows_(-1),
    9094  savedRowScale_(NULL),
    9195  savedColumnScale_(NULL)
     
    645649  maximumColumns_(-1),
    646650  maximumRows_(-1),
     651  maximumInternalColumns_(-1),
     652  maximumInternalRows_(-1),
    647653  savedRowScale_(NULL),
    648654  savedColumnScale_(NULL)
     
    807813    } else {
    808814      // This already has arrays - just copy
     815      savedRowScale_ = NULL;
     816      savedColumnScale_ = NULL;
    809817      startPermanentArrays();
    810818      if (rhs.integerType_) {
     
    868876        assert (savedRowScale_);
    869877        assert (!rowScale_);
    870         ClpDisjointCopyN(rhs.savedRowScale_,2*maximumRows_,savedRowScale_);
    871         ClpDisjointCopyN(rhs.savedColumnScale_,2*maximumColumns_,savedColumnScale_);
     878        ClpDisjointCopyN(rhs.savedRowScale_,4*maximumInternalRows_,savedRowScale_);
     879        ClpDisjointCopyN(rhs.savedColumnScale_,4*maximumInternalColumns_,savedColumnScale_);
    872880      } else {
    873881        assert (!savedRowScale_);
     
    884892  } else {
    885893    savedRowScale_ = rhs.savedRowScale_;
     894    assert (!savedRowScale_);
    886895    savedColumnScale_ = rhs.savedColumnScale_;
    887896    rowActivity_ = rhs.rowActivity_;
     
    910919    status_ = rhs.status_;
    911920  }
     921  inverseRowScale_ = NULL;
     922  inverseColumnScale_ = NULL;
    912923}
    913924// Copy contents - resizing if necessary - otherwise re-use memory
     
    925936  }
    926937#if 0
    927     delete modelPtr_->matrix_;
    928     if (continuousModel_->matrix_) {
    929       modelPtr_->matrix_ = continuousModel_->matrix_->clone();
    930     } else {
    931       modelPtr_->matrix_=NULL;
    932     }
     938  delete modelPtr_->matrix_;
     939  if (continuousModel_->matrix_) {
     940    modelPtr_->matrix_ = continuousModel_->matrix_->clone();
     941  } else {
     942    modelPtr_->matrix_=NULL;
     943  }
    933944#endif
    934945}
     
    959970  savedRowScale_=NULL;
    960971  savedColumnScale_=NULL;
     972  inverseRowScale_ = NULL;
     973  inverseColumnScale_ = NULL;
    961974}
    962975// Return model - nulls all arrays so can be deleted safely
     
    10031016    handler_ = NULL;
    10041017  }
     1018  inverseRowScale_ = NULL;
     1019  inverseColumnScale_ = NULL;
    10051020}
    10061021//#############################################################################
     
    12061221    return; // nothing to do
    12071222  whatsChanged_ = 0;
    1208   rowActivity_ = resizeDouble(rowActivity_,numberRows_,
    1209                               newNumberRows,0.0,true);
    1210   dual_ = resizeDouble(dual_,numberRows_,
    1211                        newNumberRows,0.0,true);
    1212   rowObjective_ = resizeDouble(rowObjective_,numberRows_,
    1213                                newNumberRows,0.0,false);
    1214   rowLower_ = resizeDouble(rowLower_,numberRows_,
    1215                            newNumberRows,-COIN_DBL_MAX,true);
    1216   rowUpper_ = resizeDouble(rowUpper_,numberRows_,
    1217                            newNumberRows,COIN_DBL_MAX,true);
    1218   columnActivity_ = resizeDouble(columnActivity_,numberColumns_,
    1219                                  newNumberColumns,0.0,true);
    1220   reducedCost_ = resizeDouble(reducedCost_,numberColumns_,
    1221                               newNumberColumns,0.0,true);
    1222   savedRowScale_ = resizeDouble(savedRowScale_,2*numberRows_,
    1223                            2*newNumberRows,-COIN_DBL_MAX,false);
    1224   savedColumnScale_ = resizeDouble(savedColumnScale_,2*numberColumns_,
    1225                            2*newNumberColumns,-COIN_DBL_MAX,false);
    1226   if (objective_)
     1223  int numberRows2=newNumberRows;
     1224  int numberColumns2=newNumberColumns;
     1225  if (numberRows2<maximumRows_)
     1226    numberRows2=maximumRows_;
     1227  if (numberColumns2<maximumColumns_)
     1228    numberColumns2=maximumColumns_;
     1229  if (numberRows2>maximumRows_) {
     1230    rowActivity_ = resizeDouble(rowActivity_,numberRows_,
     1231                                newNumberRows,0.0,true);
     1232    dual_ = resizeDouble(dual_,numberRows_,
     1233                         newNumberRows,0.0,true);
     1234    rowObjective_ = resizeDouble(rowObjective_,numberRows_,
     1235                                 newNumberRows,0.0,false);
     1236    rowLower_ = resizeDouble(rowLower_,numberRows_,
     1237                             newNumberRows,-COIN_DBL_MAX,true);
     1238    rowUpper_ = resizeDouble(rowUpper_,numberRows_,
     1239                             newNumberRows,COIN_DBL_MAX,true);
     1240  }
     1241  if (numberColumns2>maximumColumns_) {
     1242    columnActivity_ = resizeDouble(columnActivity_,numberColumns_,
     1243                                   newNumberColumns,0.0,true);
     1244    reducedCost_ = resizeDouble(reducedCost_,numberColumns_,
     1245                                newNumberColumns,0.0,true);
     1246  }
     1247  if (savedRowScale_&&numberRows2>maximumInternalRows_) {
     1248    double * temp;
     1249    temp = new double [4*newNumberRows];
     1250    CoinFillN(temp,4*newNumberRows,1.0);
     1251    CoinMemcpyN(savedRowScale_,numberRows_,temp);
     1252    CoinMemcpyN(savedRowScale_+maximumInternalRows_,numberRows_,temp+newNumberRows);
     1253    CoinMemcpyN(savedRowScale_+2*maximumInternalRows_,numberRows_,temp+2*newNumberRows);
     1254    CoinMemcpyN(savedRowScale_+3*maximumInternalRows_,numberRows_,temp+3*newNumberRows);
     1255    delete [] savedRowScale_;
     1256    savedRowScale_ = temp;
     1257  }
     1258  if (savedColumnScale_&&numberColumns2>maximumInternalColumns_) {
     1259    double * temp;
     1260    temp = new double [4*newNumberColumns];
     1261    CoinFillN(temp,4*newNumberColumns,1.0);
     1262    CoinMemcpyN(savedColumnScale_,numberColumns_,temp);
     1263    CoinMemcpyN(savedColumnScale_+maximumInternalColumns_,numberColumns_,temp+newNumberColumns);
     1264    CoinMemcpyN(savedColumnScale_+2*maximumInternalColumns_,numberColumns_,temp+2*newNumberColumns);
     1265    CoinMemcpyN(savedColumnScale_+3*maximumInternalColumns_,numberColumns_,temp+3*newNumberColumns);
     1266    delete [] savedColumnScale_;
     1267    savedColumnScale_ = temp;
     1268  }
     1269  if (objective_&&numberColumns2>maximumColumns_)
    12271270    objective_->resize(newNumberColumns);
    1228   else
     1271  else if (!objective_)
    12291272    objective_ = new ClpLinearObjective(NULL,newNumberColumns);
    1230   columnLower_ = resizeDouble(columnLower_,numberColumns_,
    1231                               newNumberColumns,0.0,true);
    1232   columnUpper_ = resizeDouble(columnUpper_,numberColumns_,
    1233                               newNumberColumns,COIN_DBL_MAX,true);
     1273  if (numberColumns2>maximumColumns_) {
     1274    columnLower_ = resizeDouble(columnLower_,numberColumns_,
     1275                                newNumberColumns,0.0,true);
     1276    columnUpper_ = resizeDouble(columnUpper_,numberColumns_,
     1277                                newNumberColumns,COIN_DBL_MAX,true);
     1278  }
    12341279  if (newNumberRows<numberRows_) {
    12351280    int * which = new int[numberRows_-newNumberRows];
     
    12511296  if (status_) {
    12521297    if (newNumberColumns+newNumberRows) {
    1253       unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
    1254       unsigned char * tempR = tempC + newNumberColumns;
    1255       memset(tempC,3,newNumberColumns*sizeof(unsigned char));
    1256       memset(tempR,1,newNumberRows*sizeof(unsigned char));
    1257       memcpy(tempC,status_,CoinMin(newNumberColumns,numberColumns_)*sizeof(unsigned char));
    1258       memcpy(tempR,status_+numberColumns_,CoinMin(newNumberRows,numberRows_)*sizeof(unsigned char));
    1259       delete [] status_;
    1260       status_ = tempC;
     1298      if (newNumberColumns+newNumberRows>maximumRows_+maximumColumns_) {
     1299        unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
     1300        unsigned char * tempR = tempC + newNumberColumns;
     1301        memset(tempC,3,newNumberColumns*sizeof(unsigned char));
     1302        memset(tempR,1,newNumberRows*sizeof(unsigned char));
     1303        CoinMemcpyN(status_,CoinMin(newNumberColumns,numberColumns_),tempC);
     1304        CoinMemcpyN(status_+numberColumns_,CoinMin(newNumberRows,numberRows_),tempR);
     1305        delete [] status_;
     1306        status_ = tempC;
     1307      } else if (newNumberColumns<numberColumns_) {
     1308        memmove(status_+newNumberColumns,status_+numberColumns_,
     1309                newNumberRows);
     1310      } else if (newNumberColumns>numberColumns_) {
     1311        memset(status_+numberColumns_,3,newNumberColumns-numberColumns_);
     1312        memmove(status_+newNumberColumns,status_+numberColumns_,
     1313                newNumberRows);
     1314      }
    12611315    } else {
    12621316      // empty model - some systems don't like new [0]
     
    12971351    delete [] which;
    12981352  }
    1299   if (integerType_) {
     1353  if (integerType_&&numberColumns2>maximumColumns_) {
    13001354    char * temp = new char [newNumberColumns];
    13011355    CoinZeroN(temp,newNumberColumns);
     
    13061360  }
    13071361  numberColumns_ = newNumberColumns;
     1362  if ((specialOptions_&65536)!=0) {
     1363    // leave until next create rim to up numbers
     1364  }
     1365  if (maximumRows_>=0) {
     1366    if (numberRows_>maximumRows_)
     1367      printf("resize %d rows, %d old maximum rows\n",
     1368             numberRows_,maximumRows_);
     1369    maximumRows_ = CoinMax(maximumRows_,numberRows_);
     1370    maximumColumns_ = CoinMax(maximumColumns_,numberColumns_);
     1371  }
    13081372}
    13091373// Deletes rows
     
    13151379  whatsChanged_ &= ~(1+2+4+8+16+32); // all except columns changed
    13161380  int newSize=0;
    1317   rowActivity_ = deleteDouble(rowActivity_,numberRows_,
    1318                               number, which, newSize);
    1319   dual_ = deleteDouble(dual_,numberRows_,
    1320                               number, which, newSize);
    1321   rowObjective_ = deleteDouble(rowObjective_,numberRows_,
    1322                               number, which, newSize);
    1323   rowLower_ = deleteDouble(rowLower_,numberRows_,
    1324                               number, which, newSize);
    1325   rowUpper_ = deleteDouble(rowUpper_,numberRows_,
    1326                               number, which, newSize);
    1327   if (matrix_->getNumRows())
    1328     matrix_->deleteRows(number,which);
    1329   //matrix_->removeGaps();
    1330   // status
    1331   if (status_) {
    1332     if (numberColumns_+newSize) {
    1333       unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
    1334                                                             numberRows_,
    1335                                                             number, which, newSize,false);
    1336       unsigned char * tempC = new unsigned char [numberColumns_+newSize];
    1337       memcpy(tempC,status_,numberColumns_*sizeof(unsigned char));
    1338       memcpy(tempC+numberColumns_,tempR,newSize*sizeof(unsigned char));
    1339       delete [] tempR;
    1340       delete [] status_;
    1341       status_ = tempC;
    1342     } else {
    1343       // empty model - some systems don't like new [0]
    1344       delete [] status_;
    1345       status_ = NULL;
    1346     }
     1381  if (maximumRows_<0) {
     1382    rowActivity_ = deleteDouble(rowActivity_,numberRows_,
     1383                                number, which, newSize);
     1384    dual_ = deleteDouble(dual_,numberRows_,
     1385                         number, which, newSize);
     1386    rowObjective_ = deleteDouble(rowObjective_,numberRows_,
     1387                                 number, which, newSize);
     1388    rowLower_ = deleteDouble(rowLower_,numberRows_,
     1389                             number, which, newSize);
     1390    rowUpper_ = deleteDouble(rowUpper_,numberRows_,
     1391                             number, which, newSize);
     1392    if (matrix_->getNumRows())
     1393      matrix_->deleteRows(number,which);
     1394    //matrix_->removeGaps();
     1395    // status
     1396    if (status_) {
     1397      if (numberColumns_+newSize) {
     1398        unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
     1399                                                              numberRows_,
     1400                                                              number, which, newSize,false);
     1401        unsigned char * tempC = new unsigned char [numberColumns_+newSize];
     1402        CoinMemcpyN(status_,numberColumns_,tempC);
     1403        CoinMemcpyN(tempR,newSize,tempC+numberColumns_);
     1404        delete [] tempR;
     1405        delete [] status_;
     1406        status_ = tempC;
     1407      } else {
     1408        // empty model - some systems don't like new [0]
     1409        delete [] status_;
     1410        status_ = NULL;
     1411      }
     1412    }
     1413  } else {
     1414    char * deleted = new char [numberRows_];
     1415    int i;
     1416    int numberDeleted=0;
     1417    CoinZeroN(deleted,numberRows_);
     1418    for (i=0;i<number;i++) {
     1419      int j = which[i];
     1420      if (j>=0&&j<numberRows_&&!deleted[j]) {
     1421        numberDeleted++;
     1422        deleted[j]=1;
     1423      }
     1424    }
     1425    assert (!rowObjective_);
     1426    unsigned char * status2 = status_+numberColumns_;
     1427    for (i=0;i<numberRows_;i++) {
     1428      if (!deleted[i]) {
     1429        rowActivity_[newSize]=rowActivity_[i];
     1430        dual_[newSize] = dual_[i];
     1431        rowLower_[newSize] = rowLower_[i];
     1432        rowUpper_[newSize] = rowUpper_[i];
     1433        status2[newSize] = status2[i];
     1434        newSize++;
     1435      }
     1436    }
     1437    if (matrix_->getNumRows())
     1438      matrix_->deleteRows(number,which);
     1439    //matrix_->removeGaps();
     1440    delete [] deleted;
    13471441  }
    13481442#ifndef CLP_NO_STD
     
    13821476  if (!number)
    13831477    return; // nothing to do
     1478  assert (maximumColumns_<0);
    13841479  whatsChanged_ &= ~(1+2+4+8+64+128+256); // all except rows changed
    13851480  int newSize=0;
     
    14151510                                                            number, which, newSize,false);
    14161511      unsigned char * temp = new unsigned char [numberRows_+newSize];
    1417       memcpy(temp,tempC,newSize*sizeof(unsigned char));
    1418       memcpy(temp+newSize,status_+numberColumns_,
    1419              numberRows_*sizeof(unsigned char));
     1512      CoinMemcpyN(tempC,newSize,temp);
     1513      CoinMemcpyN(status_+numberColumns_,       numberRows_,temp+newSize);
    14201514      delete [] tempC;
    14211515      delete [] status_;
     
    24732567  if (problemStatus_==1&&!secondaryStatus_) {
    24742568    array = ClpCopyOfArray(ray_,numberRows_);
     2569    //#define SWAP_SIGN
     2570#ifdef SWAP_SIGN
     2571    // swap signs to be consistent with norm
     2572    for (int i=0;i<numberRows_;i++)
     2573      ray_[i] = -ray_[i];
     2574#endif
    24752575#if 0
    24762576    // clean up
     
    25262626  if (problemStatus_==3) {
    25272627    secondaryStatus_=0;
    2528     if (CoinCpuTime()>=dblParam_[ClpMaxSeconds])
     2628    if (CoinCpuTime()>=dblParam_[ClpMaxSeconds]&&dblParam_[ClpMaxSeconds]>=0.0)
    25292629      secondaryStatus_=9;
    25302630  }
     
    28742974  if (statusArray) {
    28752975    status_ = new unsigned char [numberRows_+numberColumns_];
    2876     memcpy(status_,statusArray,(numberRows_+numberColumns_)*sizeof(unsigned char));
     2976    CoinMemcpyN(statusArray,(numberRows_+numberColumns_),status_);
    28772977  } else {
    28782978    status_=NULL;
     
    29803080  maximumColumns_(-1),
    29813081  maximumRows_(-1),
     3082  maximumInternalColumns_(-1),
     3083  maximumInternalRows_(-1),
    29823084  savedRowScale_(NULL),
    29833085  savedColumnScale_(NULL)
     
    29943096  maximumColumns_ = -1;
    29953097  maximumRows_ = -1;
     3098  maximumInternalColumns_ = -1;
     3099  maximumInternalRows_ = -1;
    29963100  savedRowScale_ = NULL;
    29973101  savedColumnScale_ = NULL;
     
    31063210  rowScale_ = NULL;
    31073211  columnScale_ = NULL;
     3212  inverseRowScale_ = NULL;
     3213  inverseColumnScale_ = NULL;
    31083214  scalingFlag_ = rhs->scalingFlag_;
    31093215  rowCopy_=NULL;
     
    33143420{
    33153421  secondaryStatus_=6; // so user can see something odd
    3316   // May be in middle of expecting bounds to stay same etc - negate expectations
    3317   whatsChanged_=0;
    33183422  if (printMessage)
    33193423    handler_->message(CLP_EMPTY_PROBLEM,messages_)
     
    37893893ClpModel::startPermanentArrays()
    37903894{
     3895  printf("startperm a %d rows, %d maximum rows\n",
     3896         numberRows_,maximumRows_);
    37913897  if ((specialOptions_&65536)!=0) {
    37923898    if (numberRows_>maximumRows_||numberColumns_>maximumColumns_) {
    37933899      if (numberRows_>maximumRows_)
    3794         maximumRows_ = numberRows_+10+numberRows_/100;
     3900        if (maximumRows_>0)
     3901          maximumRows_ = numberRows_+10+numberRows_/100;
     3902        else
     3903          maximumRows_ = numberRows_;
    37953904      if (numberColumns_>maximumColumns_)
    3796         maximumColumns_ = numberColumns_+10+numberColumns_/100;
     3905        if (maximumColumns_>0)
     3906          maximumColumns_ = numberColumns_+10+numberColumns_/100;
     3907        else
     3908          maximumColumns_ = numberColumns_;
    37973909      // need to make sure numberRows_ OK and size of matrices
    37983910      resize(maximumRows_,maximumColumns_);
     3911      printf("startperm b %d rows, %d maximum rows\n",
     3912             numberRows_,maximumRows_);
    37993913    } else {
    38003914      return;
     
    38043918    maximumRows_ = numberRows_;
    38053919    maximumColumns_ = numberColumns_;
     3920    baseMatrix_ = *matrix();
     3921    baseMatrix_.cleanMatrix();
     3922    baseRowCopy_.setExtraGap(0.0);
     3923    baseRowCopy_.setExtraMajor(0.0);
     3924    baseRowCopy_.reverseOrderedCopyOf(baseMatrix_);
     3925    printf("startperm c %d rows, %d maximum rows\n",
     3926             numberRows_,maximumRows_);
    38063927  }
    38073928}
     
    40024123      }
    40034124    }
     4125#ifndef NDEBUG
    40044126    for (iRow=0;iRow<numberIn;iRow++) {
    40054127      int kRow = eligible[iRow];
    40064128      assert (rotate[kRow]>=2);
    40074129    }
     4130#endif
    40084131    trueNetwork=true;
    40094132    for (iColumn=0;iColumn<numberColumns_;iColumn++) {
     
    40704193  forceFactorization_=-1;
    40714194  scalingFlag_=0;
     4195  specialOptions_=0;
    40724196}
    40734197
     
    40864210  forceFactorization_=rhs.forceFactorization_;
    40874211  scalingFlag_=rhs.scalingFlag_;
     4212  specialOptions_=rhs.specialOptions_;
    40884213}
    40894214
     
    41114236    forceFactorization_=rhs.forceFactorization_;
    41124237    scalingFlag_=rhs.scalingFlag_;
     4238    specialOptions_=rhs.specialOptions_;
    41134239  }
    41144240  return *this;
  • stable/1.7/Clp/src/ClpModel.hpp

    r1150 r1213  
    298298          <li> 0 - normal
    299299          <li> 1 - extra accuracy
    300           <li> 2 - IEEE hex (later)
     300          <li> 2 - IEEE hex
    301301        </ul>
    302302
     
    519519   inline const double * rowScale() const {return rowScale_;}
    520520   inline const double * columnScale() const {return columnScale_;}
     521   inline const double * inverseRowScale() const {return inverseRowScale_;}
     522   inline const double * inverseColumnScale() const {return inverseColumnScale_;}
    521523   inline double * mutableRowScale() const {return rowScale_;}
    522524   inline double * mutableColumnScale() const {return columnScale_;}
     525   inline double * mutableInverseRowScale() const {return inverseRowScale_;}
     526   inline double * mutableInverseColumnScale() const {return inverseColumnScale_;}
    523527   void setRowScale(double * scale) ;
    524528   void setColumnScale(double * scale);
     
    840844      131072 - scale factor arrays have inverse values at end
    841845      262144 - extra copy of scaled matrix
     846      524288 - Clp fast dual
    842847      NOTE - many applications can call Clp but there may be some short cuts
    843848             which are taken which are not guaranteed safe from all applications.
     
    952957  /// Column scale factors
    953958  double * columnScale_;
     959  /// Inverse row scale factors for matrix (end of rowScale_)
     960  double * inverseRowScale_;
     961  /// Inverse column scale factors for matrix (end of columnScale_)
     962  double * inverseColumnScale_;
    954963  /// Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic
    955964  int scalingFlag_;
     
    10221031  /// Maximum number of rows in model
    10231032  int maximumRows_;
     1033  /// Maximum number of columns (internal arrays) in model
     1034  int maximumInternalColumns_;
     1035  /// Maximum number of rows (internal arrays) in model
     1036  int maximumInternalRows_;
    10241037  /// Base packed matrix
    10251038  CoinPackedMatrix baseMatrix_;
     
    10701083  int forceFactorization_;
    10711084  int scalingFlag_;
     1085  unsigned int specialOptions_;
    10721086  //@}
    10731087};
  • stable/1.7/Clp/src/ClpNode.cpp

    r1163 r1213  
    1717ClpNode::ClpNode () :
    1818  branchingValue_(0.5),
     19  objectiveValue_(0.0),
     20  sumInfeasibilities_(0.0),
     21  estimatedSolution_(0.0),
    1922  factorization_(NULL),
    2023  weights_(NULL),
     
    2225  primalSolution_(NULL),
    2326  dualSolution_(NULL),
     27  lower_(NULL),
     28  upper_(NULL),
    2429  pivotVariables_(NULL),
    2530  fixed_(NULL),
    2631  sequence_(1),
    27   numberFixed_(0)
     32  numberInfeasibilities_(0),
     33  numberFixed_(0),
     34  flags_(0),
     35  maximumFixed_(0),
     36  maximumRows_(0),
     37  maximumColumns_(0),
     38  maximumIntegers_(0)
    2839{
    2940 branchState_.firstBranch=0;
     
    3344// Useful Constructor from model
    3445//-------------------------------------------------------------------
    35 ClpNode::ClpNode (const ClpSimplex * model, const ClpNodeStuff * stuff) :
     46ClpNode::ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff, int depth) :
    3647  branchingValue_(0.5),
     48  objectiveValue_(0.0),
     49  sumInfeasibilities_(0.0),
     50  estimatedSolution_(0.0),
    3751  factorization_(NULL),
    3852  weights_(NULL),
     
    4054  primalSolution_(NULL),
    4155  dualSolution_(NULL),
     56  lower_(NULL),
     57  upper_(NULL),
    4258  pivotVariables_(NULL),
    4359  fixed_(NULL),
    4460  sequence_(1),
    45   numberFixed_(0)
     61  numberInfeasibilities_(0),
     62  numberFixed_(0),
     63  flags_(0),
     64  maximumFixed_(0),
     65  maximumRows_(0),
     66  maximumColumns_(0),
     67  maximumIntegers_(0)
    4668{
    4769  branchState_.firstBranch=0;
    4870  branchState_.branch=0;
    49   gutsOfConstructor(model,stuff);
     71  gutsOfConstructor(model,stuff,0,depth);
    5072}
    5173
     
    5476//-------------------------------------------------------------------
    5577void
    56 ClpNode::gutsOfConstructor (const ClpSimplex * model, const ClpNodeStuff * stuff)
    57 {
    58   // save stuff
    59   factorization_ = new ClpFactorization(*model->factorization());
     78ClpNode::gutsOfConstructor (ClpSimplex * model, const ClpNodeStuff * stuff,
     79                            int arraysExist,int depth)
     80{
    6081  int numberRows = model->numberRows();
    6182  int numberColumns = model->numberColumns();
    6283  int numberTotal = numberRows+numberColumns;
    63   status_ = CoinCopyOfArray(model->statusArray(),numberTotal);
    64   primalSolution_ = CoinCopyOfArray(model->solutionRegion(),numberTotal);
    65   dualSolution_ = CoinCopyOfArray(model->djRegion(),numberTotal); //? has duals as well?
    66   pivotVariables_ = CoinCopyOfArray(model->pivotVariable(),numberRows);
    67   ClpDualRowSteepest* pivot =
    68     dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
    69   if (pivot)
    70     weights_ = new ClpDualRowSteepest(*pivot);
     84  int maximumTotal = maximumRows_+maximumColumns_;
     85  // save stuff
     86  objectiveValue_ = model->objectiveValue()*model->optimizationDirection();
     87  estimatedSolution_ = objectiveValue_;
     88  flags_ = 1; //say scaled
     89  if (!arraysExist) {
     90    maximumRows_=CoinMax(maximumRows_,numberRows);
     91    maximumColumns_=CoinMax(maximumColumns_,numberColumns);
     92    maximumTotal = maximumRows_+maximumColumns_;
     93    factorization_ = new ClpFactorization(*model->factorization());
     94    status_ = CoinCopyOfArrayPartial(model->statusArray(),maximumTotal,numberTotal);
     95    primalSolution_ = CoinCopyOfArrayPartial(model->solutionRegion(),maximumTotal,numberTotal);
     96    dualSolution_ = CoinCopyOfArrayPartial(model->djRegion(),maximumTotal,numberTotal); //? has duals as well?
     97    pivotVariables_ = CoinCopyOfArrayPartial(model->pivotVariable(),maximumRows_,numberRows);
     98    //#define DUAL_WEIGHTS
     99#ifdef DUAL_WEIGHTS
     100    ClpDualRowSteepest* pivot =
     101      dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     102    if (pivot) {
     103      assert (!weights_);
     104      weights_ = new ClpDualRowSteepest(*pivot);
     105    }
     106#endif
     107  } else {
     108    if (arraysExist==2)
     109      assert(lower_);
     110    if (numberRows<=maximumRows_&&numberColumns<=maximumColumns_) {
     111      CoinMemcpyN(model->statusArray(),numberTotal,status_);
     112      if (arraysExist==1) {
     113        *factorization_ = *model->factorization();
     114        CoinMemcpyN(model->solutionRegion(),numberTotal,primalSolution_);
     115        CoinMemcpyN(model->djRegion(),numberTotal,dualSolution_); //? has duals as well?
     116#ifdef DUAL_WEIGHTS
     117        ClpDualRowSteepest* pivot =
     118          dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     119        if (pivot) {
     120          if (weights_) {
     121            //if (weights_->numberRows()==pivot->numberRows()) {
     122              weights_->fill(*pivot);
     123              //} else {
     124              //delete weights_;
     125              //weights_ = new ClpDualRowSteepest(*pivot);
     126              //}
     127          } else {
     128            weights_ = new ClpDualRowSteepest(*pivot);
     129          }
     130        }
     131#endif
     132        CoinMemcpyN(model->pivotVariable(),numberRows,pivotVariables_);
     133      } else {
     134        CoinMemcpyN(model->primalColumnSolution(),numberColumns,primalSolution_);
     135        CoinMemcpyN(model->dualColumnSolution(),numberColumns,dualSolution_);
     136        flags_ = 0;
     137        CoinMemcpyN(model->dualRowSolution(),numberRows,dualSolution_+numberColumns);
     138      }
     139    } else {
     140      // size has changed
     141      maximumRows_=CoinMax(maximumRows_,numberRows);
     142      maximumColumns_=CoinMax(maximumColumns_,numberColumns);
     143      maximumTotal = maximumRows_+maximumColumns_;
     144      delete weights_;
     145      weights_ = NULL;
     146      delete [] status_;
     147      delete [] primalSolution_;
     148      delete [] dualSolution_;
     149      delete [] pivotVariables_;
     150      status_ = CoinCopyOfArrayPartial(model->statusArray(),maximumTotal,numberTotal);
     151      primalSolution_ = new double [maximumTotal*sizeof(double)];
     152      dualSolution_ = new double [maximumTotal*sizeof(double)];
     153      if (arraysExist==1) {
     154        *factorization_ = *model->factorization(); // I think this is OK
     155        CoinMemcpyN(model->solutionRegion(),numberTotal,primalSolution_);
     156        CoinMemcpyN(model->djRegion(),numberTotal,dualSolution_); //? has duals as well?
     157#ifdef DUAL_WEIGHTS
     158        ClpDualRowSteepest* pivot =
     159          dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     160        if (pivot) {
     161          assert (!weights_);
     162          weights_ = new ClpDualRowSteepest(*pivot);
     163        }
     164#endif
     165      } else {
     166        CoinMemcpyN(model->primalColumnSolution(),numberColumns,primalSolution_);
     167        CoinMemcpyN(model->dualColumnSolution(),numberColumns,dualSolution_);
     168        flags_ = 0;
     169        CoinMemcpyN(model->dualRowSolution(),numberRows,dualSolution_+numberColumns);
     170      }
     171      pivotVariables_ = new int [maximumRows_];
     172      if (model->pivotVariable())
     173        CoinMemcpyN(model->pivotVariable(),numberRows,pivotVariables_);
     174    }
     175  }
     176  numberFixed_=0;
    71177  const double * lower = model->columnLower();
    72178  const double * upper = model->columnUpper();
    73179  const double * solution = model->primalColumnSolution();
    74180  const char * integerType = model->integerInformation();
     181  const double * columnScale = model->columnScale();
     182  if (!flags_)
     183    columnScale=NULL; // as duals correct
    75184  int iColumn;
    76185  sequence_=-1;
    77186  double integerTolerance = stuff->integerTolerance_;
    78187  double mostAway=integerTolerance;
    79   int numberAway=0;
     188  sumInfeasibilities_ = 0.0;
     189  numberInfeasibilities_ = 0;
     190  int nFix=0;
     191  double gap = CoinMax(model->dualObjectiveLimit()-objectiveValue_,1.0e-4);
     192#define PSEUDO 2
     193#if PSEUDO==1
     194  // Column copy of matrix
     195  ClpPackedMatrix * matrix = model->clpScaledMatrix();
     196  if (!matrix)
     197    matrix = dynamic_cast< ClpPackedMatrix*>(model->clpMatrix());
     198  const double * element = matrix->getElements();
     199  const int * row = matrix->getIndices();
     200  const CoinBigIndex * columnStart = matrix->getVectorStarts();
     201  const int * columnLength = matrix->getVectorLengths();
     202  const double *objective = model->costRegion() ;
     203  double direction = model->optimizationDirection();
     204  const double * dual = dualSolution_+numberColumns;
     205#elif PSEUDO==2
     206  const double * downPseudo = stuff->downPseudo_;
     207  const int * numberDown = stuff->numberDown_;
     208  const int * numberDownInfeasible = stuff->numberDownInfeasible_;
     209  const double * upPseudo = stuff->upPseudo_;
     210  const int * numberUp = stuff->numberUp_;
     211  const int * numberUpInfeasible = stuff->numberUpInfeasible_;
     212#endif
     213  int iInteger=0;
    80214  for (iColumn=0;iColumn<numberColumns;iColumn++) {
    81215    if (integerType[iColumn]) {
     
    84218      value = min(value,(double) upper[iColumn]);
    85219      double nearest = floor(value+0.5);
    86       if (fabs(value-nearest)>integerTolerance)
    87         numberAway++;
    88       if (fabs(value-nearest)>mostAway) {
    89         mostAway=fabs(value-nearest);
    90         sequence_=iColumn;
    91         branchingValue_=value;
    92         branchState_.branch=0;
    93         if (value<=nearest)
    94           branchState_.firstBranch=1; // up
     220      if (fabs(value-nearest)>integerTolerance) {
     221        numberInfeasibilities_++;
     222        sumInfeasibilities_ += fabs(value-nearest);
     223#if PSEUDO==1
     224        double upValue = 0.0;
     225        double downValue = 0.0;
     226        double value2 = direction*objective[iColumn];
     227        if (value2) {
     228          if (value2>0.0)
     229            upValue += value2;
     230          else
     231            downValue -= value2;
     232        }
     233        CoinBigIndex start = columnStart[iColumn];
     234        CoinBigIndex end = columnStart[iColumn]+columnLength[iColumn];
     235        for (CoinBigIndex j=start;j<end;j++) {
     236          int iRow = row[j];
     237          value2 = -dual[iRow];
     238          if (value2) {
     239            value2 *= element[j];
     240            if (value2>0.0)
     241              upValue += value2;
     242            else
     243              downValue -= value2;
     244          }
     245        }
     246        upValue *= ceil(value)-value;
     247        downValue *= value-floor(value);
     248        double infeasibility;
     249        if (depth>1000)
     250          infeasibility = CoinMax(upValue,downValue)+integerTolerance;
    95251        else
    96           branchState_.firstBranch=0; // down
    97       }
    98     }
     252          infeasibility = 0.1*CoinMax(upValue,downValue)+
     253            0.9*CoinMin(upValue,downValue) + integerTolerance;
     254#elif PSEUDO==2
     255        double upValue = (ceil(value)-value)*(upPseudo[iInteger]/(1.0+numberUp[iInteger]+numberUpInfeasible[iInteger]));
     256        double downValue = (value-floor(value))*(downPseudo[iInteger]/(1.0+numberDown[iInteger]+numberDownInfeasible[iInteger]));
     257        double infeasibility;
     258        if (depth>1000)
     259          infeasibility = CoinMax(upValue,downValue)+integerTolerance;
     260        else
     261          infeasibility = 0.1*CoinMax(upValue,downValue)+
     262            0.9*CoinMin(upValue,downValue) + integerTolerance;
     263        estimatedSolution_ += CoinMin(upValue,downValue);
     264#else
     265        double infeasibility = fabs(value-nearest);
     266#endif
     267        if (infeasibility>mostAway) {
     268          mostAway=infeasibility;
     269          sequence_=iColumn;
     270          branchingValue_=value;
     271          branchState_.branch=0;
     272#if PSEUDO>0
     273          if (upValue<=downValue)
     274            branchState_.firstBranch=1; // up
     275          else
     276            branchState_.firstBranch=0; // down
     277#else
     278          if (value<=nearest)
     279            branchState_.firstBranch=1; // up
     280          else
     281            branchState_.firstBranch=0; // down
     282#endif
     283        }
     284      } else if (model->getColumnStatus(iColumn)==ClpSimplex::atLowerBound) {
     285        bool fix=false;
     286        if (columnScale) {
     287          if (dualSolution_[iColumn]>gap*columnScale[iColumn])
     288            fix=true;
     289        } else {
     290          if (dualSolution_[iColumn]>gap)
     291            fix=true;
     292        }
     293        if (fix) {
     294          nFix++;
     295          //printf("fixed %d to zero gap %g dj %g %g\n",iColumn,
     296          // gap,dualSolution_[iColumn], columnScale ? columnScale[iColumn]:1.0);
     297          model->setColumnStatus(iColumn,ClpSimplex::isFixed);
     298        }
     299      } else if (model->getColumnStatus(iColumn)==ClpSimplex::atUpperBound) {
     300        bool fix=false;
     301        if (columnScale) {
     302          if (-dualSolution_[iColumn]>gap*columnScale[iColumn])
     303            fix=true;
     304        } else {
     305          if (-dualSolution_[iColumn]>gap)
     306            fix=true;
     307        }
     308        if (fix) {
     309          nFix++;
     310          //printf("fixed %d to one gap %g dj %g %g\n",iColumn,
     311          // gap,dualSolution_[iColumn], columnScale ? columnScale[iColumn]:1.0);
     312          model->setColumnStatus(iColumn,ClpSimplex::isFixed);
     313        }
     314      }
     315      iInteger++;
     316    }
     317  }
     318  if (lower_) {
     319    // save bounds
     320    if (iInteger>maximumIntegers_) {
     321      delete [] lower_;
     322      delete [] upper_;
     323      maximumIntegers_ = iInteger;
     324      lower_ = new int [maximumIntegers_];
     325      upper_ = new int [maximumIntegers_];
     326    }
     327    iInteger=0;
     328    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     329      if (integerType[iColumn]) {
     330        lower_[iInteger]=(int) lower[iColumn];
     331        upper_[iInteger]=(int) upper[iColumn];
     332        iInteger++;
     333      }
     334    }
     335  }
     336  // Could omit save of fixed if doing full save of bounds
     337  if (sequence_>=0&&nFix) {
     338    if (nFix>maximumFixed_) {
     339      delete [] fixed_;
     340      fixed_ = new int [nFix];
     341      maximumFixed_=nFix;
     342    }
     343    numberFixed_=0;
     344    unsigned char * status = model->statusArray();
     345    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     346      if (status[iColumn]!=status_[iColumn]) {
     347        if (solution[iColumn]<=lower[iColumn]+2.0*integerTolerance) {
     348          model->setColumnUpper(iColumn,lower[iColumn]);
     349          fixed_[numberFixed_++]=iColumn;
     350        } else {
     351          assert (solution[iColumn]>=upper[iColumn]-2.0*integerTolerance);
     352          model->setColumnLower(iColumn,upper[iColumn]);
     353          fixed_[numberFixed_++]=iColumn|0x10000000;
     354        }
     355      }
     356    }
     357    //printf("%d fixed\n",numberFixed_);
    99358  }
    100359}
     
    119378  delete [] primalSolution_;
    120379  delete [] dualSolution_;
     380  delete [] lower_;
     381  delete [] upper_;
    121382  delete [] pivotVariables_;
    122383  delete [] fixed_;
     
    135396  return *this;
    136397}
    137 // Applies node to model
     398// Create odd arrays
    138399void
    139 ClpNode::applyNode(ClpSimplex * model, bool justBounds )
    140 {
    141   // current bound
     400ClpNode::createArrays(ClpSimplex * model)
     401{
     402  int numberColumns = model->numberColumns();
     403  const char * integerType = model->integerInformation();
     404  int iColumn;
     405  int numberIntegers=0;
     406  for (iColumn=0;iColumn<numberColumns;iColumn++) {
     407    if (integerType[iColumn])
     408      numberIntegers++;
     409  }
     410  if (numberIntegers>maximumIntegers_||!lower_) {
     411    delete [] lower_;
     412    delete [] upper_;
     413    maximumIntegers_ = numberIntegers;
     414    lower_ = new int [numberIntegers];
     415    upper_ = new int [numberIntegers];
     416  }
     417}
     418// Clean up as crunch is different model
     419void
     420ClpNode::cleanUpForCrunch()
     421{
     422  delete weights_;
     423  weights_ = NULL;
     424}
     425/* Applies node to model
     426   0 - just tree bounds
     427   1 - tree bounds and basis etc
     428   2 - saved bounds and basis etc
     429*/
     430void
     431ClpNode::applyNode(ClpSimplex * model, int doBoundsEtc )
     432{
     433  int numberColumns = model->numberColumns();
     434  const double * lower = model->columnLower();
     435  const double * upper = model->columnUpper();
     436  if (doBoundsEtc<2) {
     437    // current bound
     438    int way=branchState_.firstBranch;
     439    if (branchState_.branch>0)
     440      way=1-way;
     441    if (!way) {
     442      // This should also do underlying internal bound
     443      model->setColumnUpper(sequence_,floor(branchingValue_));
     444    } else {
     445      // This should also do underlying internal bound
     446      model->setColumnLower(sequence_,ceil(branchingValue_));
     447    }
     448    // apply dj fixings
     449    for (int i=0;i<numberFixed_;i++) {
     450      int iColumn = fixed_[i];
     451      if ((iColumn&0x10000000)!=0) {
     452        iColumn &= 0xfffffff;
     453        model->setColumnLower(iColumn,upper[iColumn]);
     454    } else {
     455        model->setColumnUpper(iColumn,lower[iColumn]);
     456      }
     457    }
     458  } else {
     459    // restore bounds
     460    assert (lower_);
     461    int iInteger=-1;
     462    const char * integerType = model->integerInformation();
     463    for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     464      if (integerType[iColumn]) {
     465        iInteger++;
     466        if (lower_[iInteger]!=(int) lower[iColumn])
     467          model->setColumnLower(iColumn,lower_[iInteger]);
     468        if (upper_[iInteger]!=(int) upper[iColumn])
     469          model->setColumnUpper(iColumn,upper_[iInteger]);
     470      }
     471    }
     472  }
     473  if (doBoundsEtc&&doBoundsEtc<3) {
     474#ifdef DUAL_WEIGHTS
     475    model->copyFactorization(*factorization_);
     476    ClpDualRowSteepest* pivot =
     477      dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     478    if (pivot&&weights_) {
     479      pivot->fill(*weights_);
     480    }
     481#endif
     482    int numberRows = model->numberRows();
     483    int numberTotal = numberRows+numberColumns;
     484    CoinMemcpyN(status_,numberTotal,model->statusArray());
     485    if (doBoundsEtc<2) {
     486      CoinMemcpyN(primalSolution_,numberTotal,model->solutionRegion());
     487      CoinMemcpyN(dualSolution_,numberTotal,model->djRegion());
     488      CoinMemcpyN(pivotVariables_,numberRows,model->pivotVariable());
     489      CoinMemcpyN(dualSolution_+numberColumns,numberRows,model->dualRowSolution());
     490    } else {
     491      CoinMemcpyN(primalSolution_,numberColumns,model->primalColumnSolution());
     492      CoinMemcpyN(dualSolution_,numberColumns,model->dualColumnSolution());
     493      CoinMemcpyN(dualSolution_+numberColumns,numberRows,model->dualRowSolution());
     494      if (model->columnScale()) {
     495        // See if just primal will work
     496        double * solution = model->primalColumnSolution();
     497        const double * columnScale = model->columnScale();
     498        int i;
     499        for (i=0;i<numberColumns;i++) {
     500          solution[i] *= columnScale[i];
     501        }
     502      }
     503    }
     504    model->setObjectiveValue(objectiveValue_);
     505  }
     506}
     507// Fix on reduced costs
     508int
     509ClpNode::fixOnReducedCosts(ClpSimplex * model)
     510{
     511  return 0;
     512}
     513/* Way for integer variable -1 down , +1 up */
     514int
     515ClpNode::way() const
     516{
    142517  int way=branchState_.firstBranch;
    143518  if (branchState_.branch>0)
    144519    way=1-way;
    145   if (!way) {
    146     // This should also do underlying internal bound
    147     model->setColumnUpper(sequence_,floor(branchingValue_));
    148   } else {
    149     // This should also do underlying internal bound
    150     model->setColumnLower(sequence_,ceil(branchingValue_));
    151   }
    152   const double * lower = model->columnLower();
    153   const double * upper = model->columnUpper();
    154   // apply dj fixings
    155   for (int i=0;i<numberFixed_;i++) {
    156     int iColumn = fixed_[i];
    157     if ((iColumn&0x10000000)!=0) {
    158       iColumn &= 0xfffffff;
    159       model->setColumnLower(iColumn,upper[iColumn]);
    160     } else {
    161         model->setColumnUpper(iColumn,lower[iColumn]);
    162     }
    163   }
    164   if (!justBounds) {
    165     model->setFactorization(*factorization_);
    166     ClpDualRowSteepest* pivot =
    167       dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
    168     if (pivot)
    169       *pivot=*weights_; // may be better to copy stuff
    170     int numberRows = model->numberRows();
    171     int numberColumns = model->numberColumns();
    172     int numberTotal = numberRows+numberColumns;
    173     CoinMemcpyN(status_,numberTotal,model->statusArray());
    174     CoinMemcpyN(primalSolution_,numberTotal,model->solutionRegion());
    175     CoinMemcpyN(dualSolution_,numberTotal,model->djRegion()); //? has duals as well?
    176     CoinMemcpyN(pivotVariables_,numberRows,model->pivotVariable());
    177   }
    178 }
    179 // Fix on reduced costs
    180 int
    181 ClpNode::fixOnReducedCosts(ClpSimplex * model)
    182 {
    183   return 0;
    184 }
    185 /* Way for integer variable -1 down , +1 up */
    186 int
    187 ClpNode::way() const
    188 {
    189   int way=branchState_.firstBranch;
    190   if (branchState_.branch>0)
    191     way=1-way;
    192   return way ? -1 : +1;
     520  return way==0 ? -1 : +1;
    193521}
    194522// Return true if branch exhausted
     
    215543ClpNodeStuff::ClpNodeStuff () :
    216544  integerTolerance_(1.0e-7),
    217   integerIncrement_(1.0e-8)
     545  integerIncrement_(1.0e-8),
     546  downPseudo_(NULL),
     547  upPseudo_(NULL),
     548  numberDown_(NULL),
     549  numberUp_(NULL),
     550  numberDownInfeasible_(NULL),
     551  numberUpInfeasible_(NULL),
     552  saveCosts_(NULL),
     553  nodeInfo_(NULL),
     554  large_(NULL),
     555  whichRow_(NULL),
     556  whichColumn_(NULL),
     557  nBound_(0),
     558  saveOptions_(0),
     559  solverOptions_(0),
     560  nDepth_(-1),
     561  nNodes_(0),
     562  numberNodesExplored_(0),
     563  numberIterations_(0),
     564  presolveType_(0)
    218565{
    219566
     
    223570// Copy constructor
    224571//-------------------------------------------------------------------
    225 ClpNodeStuff::ClpNodeStuff (const ClpNodeStuff & source)
     572ClpNodeStuff::ClpNodeStuff (const ClpNodeStuff & rhs)
     573  : integerTolerance_(rhs.integerTolerance_),
     574    integerIncrement_(rhs.integerIncrement_),
     575    downPseudo_(NULL),
     576    upPseudo_(NULL),
     577    numberDown_(NULL),
     578    numberUp_(NULL),
     579    numberDownInfeasible_(NULL),
     580    numberUpInfeasible_(NULL),
     581    saveCosts_(NULL),
     582    nodeInfo_(NULL),
     583    large_(NULL),
     584    whichRow_(NULL),
     585    whichColumn_(NULL),
     586    nBound_(0),
     587    saveOptions_(rhs.saveOptions_),
     588    solverOptions_(rhs.solverOptions_),
     589    nDepth_(rhs.nDepth_),
     590    nNodes_(rhs.nNodes_),
     591    numberNodesExplored_(rhs.numberNodesExplored_),
     592    numberIterations_(rhs.numberIterations_),
     593    presolveType_(rhs.presolveType_)
    226594
    227   printf("ClpNodeStuff copy not implemented\n");
    228   abort();
    229595}
    230596//----------------------------------------------------------------
     
    235601{
    236602  if (this != &rhs) {
    237     printf("ClpNodeStuff = not implemented\n");
    238     abort();
     603    integerTolerance_ = rhs.integerTolerance_;
     604    integerIncrement_ = rhs.integerIncrement_;
     605    downPseudo_ = NULL;
     606    upPseudo_ = NULL;
     607    numberDown_ = NULL;
     608    numberUp_ = NULL;
     609    numberDownInfeasible_ = NULL;
     610    numberUpInfeasible_ = NULL;
     611    saveCosts_ = NULL;
     612    nodeInfo_ = NULL;
     613    large_ = NULL;
     614    whichRow_ = NULL;
     615    whichColumn_ = NULL;
     616    nBound_ = 0;
     617    saveOptions_ = rhs.saveOptions_;
     618    solverOptions_ = rhs.solverOptions_;
     619    if (nDepth_>=0) {
     620      int n = (1<<nDepth_)+1+nDepth_;
     621      for (int i=0;i<n;i++)
     622        delete nodeInfo_[i];
     623      delete [] nodeInfo_;
     624    }
     625    nDepth_ = rhs.nDepth_;
     626    nNodes_ = rhs.nNodes_;
     627    numberNodesExplored_ = rhs.numberNodesExplored_;
     628    numberIterations_ = rhs.numberIterations_;
     629    presolveType_ = rhs.presolveType_;
    239630  }
    240631  return *this;
    241632}
     633// Zaps stuff 1 - arrays, 2 ints, 3 both
     634void
     635ClpNodeStuff::zap(int type)
     636{
     637  if ((type&1)!=0) {
     638    downPseudo_ = NULL;
     639    upPseudo_ = NULL;
     640    numberDown_ = NULL;
     641    numberUp_ = NULL;
     642    numberDownInfeasible_ = NULL;
     643    numberUpInfeasible_ = NULL;
     644    saveCosts_ = NULL;
     645    nodeInfo_ = NULL;
     646    large_ = NULL;
     647    whichRow_ = NULL;
     648    whichColumn_ = NULL;
     649  }
     650  if ((type&2)!=0) {
     651    nBound_ = 0;
     652    saveOptions_ = 0;
     653    solverOptions_ = 0;
     654    nDepth_ = -1;
     655    nNodes_ = 0;
     656    presolveType_ = 0;
     657    numberNodesExplored_ = 0;
     658    numberIterations_ = 0;
     659  }
     660}
    242661
    243662//-------------------------------------------------------------------
     
    246665ClpNodeStuff::~ClpNodeStuff ()
    247666{
    248 }
     667  delete [] downPseudo_;
     668  delete [] upPseudo_;
     669  delete [] numberDown_;
     670  delete [] numberUp_;
     671  delete [] numberDownInfeasible_;
     672  delete [] numberUpInfeasible_;
     673  if (nDepth_>=0) {
     674    int n = (1<<nDepth_)+1+nDepth_;
     675    for (int i=0;i<n;i++)
     676      delete nodeInfo_[i];
     677    delete [] nodeInfo_;
     678  }
     679}
     680/* Fill with pseudocosts */
     681void
     682ClpNodeStuff::fillPseudoCosts(const double * down, const double * up,
     683                              const int * numberDown, const int * numberUp,
     684                              const int * numberDownInfeasible,
     685                              const int * numberUpInfeasible,
     686                              int number)
     687{
     688  delete [] downPseudo_;
     689  delete [] upPseudo_;
     690  delete [] numberDown_;
     691  delete [] numberUp_;
     692  delete [] numberDownInfeasible_;
     693  delete [] numberUpInfeasible_;
     694  downPseudo_ = CoinCopyOfArray(down,number);
     695  upPseudo_ = CoinCopyOfArray(up,number);
     696  numberDown_ = CoinCopyOfArray(numberDown,number);
     697  numberUp_ = CoinCopyOfArray(numberUp,number);
     698  numberDownInfeasible_ = CoinCopyOfArray(numberDownInfeasible,number);
     699  numberUpInfeasible_ = CoinCopyOfArray(numberUpInfeasible,number);
     700  // scale
     701  for (int i=0;i<number;i++) {
     702    int n;
     703    n = numberDown_[i]+numberDownInfeasible_[i];
     704    if (n)
     705      downPseudo_[i] *= n;
     706    n = numberUp_[i]+numberUpInfeasible_[i];
     707    if (n)
     708      upPseudo_[i] *= n;
     709  }
     710}
     711// Update pseudo costs
     712void
     713ClpNodeStuff::update(int way,int sequence,double change,bool feasible)
     714{
     715  if (way<0) {
     716    if (feasible)
     717      numberDown_[sequence]++;
     718    else
     719      numberDownInfeasible_[sequence]++;
     720    downPseudo_[sequence] += CoinMax(change,1.0e-12);
     721  } else {
     722    if (feasible)
     723      numberUp_[sequence]++;
     724    else
     725      numberUpInfeasible_[sequence]++;
     726    upPseudo_[sequence] += CoinMax(change,1.0e-12);
     727  }
     728}
     729//#############################################################################
     730// Constructors / Destructor / Assignment
     731//#############################################################################
     732
     733//-------------------------------------------------------------------
     734// Default Constructor
     735//-------------------------------------------------------------------
     736ClpHashValue::ClpHashValue () :
     737  hash_(NULL),
     738  numberHash_(0),
     739  maxHash_(0),
     740  lastUsed_(-1)
     741{
     742}
     743//-------------------------------------------------------------------
     744// Useful Constructor from model
     745//-------------------------------------------------------------------
     746ClpHashValue::ClpHashValue (ClpSimplex * model) :
     747  hash_(NULL),
     748  numberHash_(0),
     749  maxHash_(0),
     750  lastUsed_(-1)
     751{
     752  maxHash_ = 1000;
     753  int numberColumns = model->numberColumns();
     754  const double * columnLower = model->columnLower();
     755  const double * columnUpper = model->columnUpper();
     756  int numberRows = model->numberRows();
     757  const double * rowLower = model->rowLower();
     758  const double * rowUpper = model->rowUpper();
     759  const double * objective = model->objective();
     760  CoinPackedMatrix * matrix = model->matrix();
     761  const int * columnLength = matrix->getVectorLengths();
     762  const CoinBigIndex * columnStart = matrix->getVectorStarts();
     763  const double * elementByColumn = matrix->getElements();
     764  int i;
     765  int ipos;
     766
     767  hash_ = new CoinHashLink[maxHash_];
     768 
     769  for ( i = 0; i < maxHash_; i++ ) {
     770    hash_[i].value = -1.0e-100;
     771    hash_[i].index = -1;
     772    hash_[i].next = -1;
     773  }
     774  // Put in +0
     775  hash_[0].value=0.0;
     776  hash_[0].index=0;
     777  numberHash_=1;
     778  /*
     779   * Initialize the hash table.  Only the index of the first value that
     780   * hashes to a value is entered in the table; subsequent values that
     781   * collide with it are not entered.
     782   */
     783  for ( i = 0; i < numberColumns; i++ ) {
     784    int length=columnLength[i];
     785    CoinBigIndex start = columnStart[i];
     786    for (CoinBigIndex i=start;i<start+length;i++) {
     787      double value = elementByColumn[i];
     788      ipos = hash ( value);
     789      if ( hash_[ipos].index == -1 ) {
     790        hash_[ipos].index = numberHash_;
     791        numberHash_++;
     792        hash_[ipos].value = elementByColumn[i];
     793      }
     794    }
     795  }
     796 
     797  /*
     798   * Now take care of the values that collided in the preceding loop,
     799   * Also do other stuff
     800   */
     801  for ( i = 0; i < numberRows; i++ ) {
     802    if (numberHash_*2>maxHash_)
     803      resize(true);
     804    double value;
     805    value = rowLower[i];
     806    ipos = index(value);
     807    if (ipos<0)
     808      addValue(value);
     809    value = rowUpper[i];
     810    ipos = index(value);
     811    if (ipos<0)
     812      addValue(value);
     813  }
     814  for ( i = 0; i < numberColumns; i++ ) {
     815    int length=columnLength[i];
     816    CoinBigIndex start = columnStart[i];
     817    if (numberHash_*2>maxHash_)
     818      resize(true);
     819    double value;
     820    value = objective[i];
     821    ipos = index(value);
     822    if (ipos<0)
     823      addValue(value);
     824    value = columnLower[i];
     825    ipos = index(value);
     826    if (ipos<0)
     827      addValue(value);
     828    value = columnUpper[i];
     829    ipos = index(value);
     830    if (ipos<0)
     831      addValue(value);
     832    for (CoinBigIndex j=start;j<start+length;j++) {
     833      if (numberHash_*2>maxHash_)
     834        resize(true);
     835      value = elementByColumn[j];
     836      ipos = index(value);
     837      if (ipos<0)
     838        addValue(value);
     839    }
     840  }
     841  resize(false);
     842}
     843
     844//-------------------------------------------------------------------
     845// Copy constructor
     846//-------------------------------------------------------------------
     847ClpHashValue::ClpHashValue (const ClpHashValue & rhs) :
     848  hash_(NULL),
     849  numberHash_(rhs.numberHash_),
     850  maxHash_(rhs.maxHash_),
     851  lastUsed_(rhs.lastUsed_)
     852
     853  if (maxHash_) {
     854    CoinHashLink * newHash = new CoinHashLink[maxHash_];
     855    int i;
     856    for ( i = 0; i < maxHash_; i++ ) {
     857      newHash[i].value = rhs.hash_[i].value;
     858      newHash[i].index = rhs.hash_[i].index;
     859      newHash[i].next = rhs.hash_[i].next;
     860    }
     861  }
     862}
     863
     864//-------------------------------------------------------------------
     865// Destructor
     866//-------------------------------------------------------------------
     867ClpHashValue::~ClpHashValue ()
     868{
     869  delete [] hash_;
     870}
     871
     872//----------------------------------------------------------------
     873// Assignment operator
     874//-------------------------------------------------------------------
     875ClpHashValue &
     876ClpHashValue::operator=(const ClpHashValue& rhs)
     877{
     878  if (this != &rhs) {
     879    numberHash_ = rhs.numberHash_;
     880    maxHash_ = rhs.maxHash_;
     881    lastUsed_ = rhs.lastUsed_;
     882    delete [] hash_;
     883    if (maxHash_) {
     884      CoinHashLink * newHash = new CoinHashLink[maxHash_];
     885      int i;
     886      for ( i = 0; i < maxHash_; i++ ) {
     887        newHash[i].value = rhs.hash_[i].value;
     888        newHash[i].index = rhs.hash_[i].index;
     889        newHash[i].next = rhs.hash_[i].next;
     890      }
     891    } else {
     892      hash_ = NULL;
     893    }
     894  }
     895  return *this;
     896}
     897// Return index or -1 if not found
     898int
     899ClpHashValue::index(double value) const
     900{
     901  if (!value)
     902    return 0;
     903  int ipos = hash ( value);
     904  int returnCode=-1;
     905  while ( hash_[ipos].index>=0 ) {
     906    if (value==hash_[ipos].value) {
     907      returnCode = hash_[ipos].index;
     908      break;
     909    } else {
     910      int k = hash_[ipos].next;
     911      if ( k == -1 ) {
     912        break;
     913      } else {
     914        ipos = k;
     915      }
     916    }
     917  }
     918  return returnCode;
     919}
     920// Add value to list and return index
     921int
     922ClpHashValue::addValue(double value)
     923{
     924  int ipos = hash ( value);
     925 
     926  assert (value!=hash_[ipos].value);
     927  if (hash_[ipos].index==-1) {
     928    // can put in here
     929    hash_[ipos].index = numberHash_;
     930    numberHash_++;
     931    hash_[ipos].value = value;
     932    return numberHash_-1;
     933  }
     934  int k = hash_[ipos].next;
     935  while (k!=-1) {
     936    ipos = k;
     937    k = hash_[ipos].next;
     938  }
     939  while ( true ) {
     940    ++lastUsed_;
     941    assert (lastUsed_<=maxHash_);
     942    if ( hash_[lastUsed_].index == -1 ) {
     943      break;
     944    }
     945  }
     946  hash_[ipos].next = lastUsed_;
     947  hash_[lastUsed_].index = numberHash_;
     948  numberHash_++;
     949  hash_[lastUsed_].value = value;
     950  return numberHash_-1;
     951}
     952
     953int
     954ClpHashValue::hash ( double value) const
     955{
     956  static int mmult[] = {
     957    262139, 259459, 256889, 254291, 251701, 249133, 246709, 244247,
     958    241667, 239179, 236609, 233983, 231289, 228859, 226357, 223829,
     959    221281, 218849, 216319, 213721, 211093, 208673, 206263, 203773,
     960    201233, 198637, 196159, 193603, 191161, 188701, 186149, 183761,
     961    181303, 178873, 176389, 173897, 171469, 169049, 166471, 163871,
     962    161387, 158941, 156437, 153949, 151531, 149159, 146749, 144299,
     963    141709, 139369, 136889, 134591, 132169, 129641, 127343, 124853,
     964    122477, 120163, 117757, 115361, 112979, 110567, 108179, 105727,
     965    103387, 101021, 98639, 96179, 93911, 91583, 89317, 86939, 84521,
     966    82183, 79939, 77587, 75307, 72959, 70793, 68447, 66103
     967  };
     968  union { double d; char c[8]; } v1;
     969  assert (sizeof(double)==8);
     970  v1.d = value;
     971  int n = 0;
     972  int j;
     973
     974  for ( j = 0; j < 8; ++j ) {
     975    int ichar = v1.c[j];
     976    n += mmult[j] * ichar;
     977  }
     978  return ( abs ( n ) % maxHash_ );      /* integer abs */
     979}
     980void
     981ClpHashValue::resize(bool increaseMax)
     982{
     983  int newSize = increaseMax ? ((3*maxHash_)>>1)+1000 : maxHash_;
     984  CoinHashLink * newHash = new CoinHashLink[newSize];
     985  int i;
     986  for ( i = 0; i < newSize; i++ ) {
     987    newHash[i].value = -1.0e-100;
     988    newHash[i].index = -1;
     989    newHash[i].next = -1;
     990  }
     991  // swap
     992  CoinHashLink * oldHash = hash_;
     993  hash_ = newHash;
     994  int oldSize = maxHash_;
     995  maxHash_ = newSize;
     996  /*
     997   * Initialize the hash table.  Only the index of the first value that
     998   * hashes to a value is entered in the table; subsequent values that
     999   * collide with it are not entered.
     1000   */
     1001  int ipos;
     1002  int n=0;
     1003  for ( i = 0; i < oldSize; i++ ) {
     1004    if (oldHash[i].index>=0) {
     1005      ipos = hash ( oldHash[i].value);
     1006      if ( hash_[ipos].index == -1 ) {
     1007        hash_[ipos].index = n;
     1008        n++;
     1009        hash_[ipos].value = oldHash[i].value;
     1010        // unmark
     1011        oldHash[i].index=-1;
     1012      }
     1013    }
     1014  }
     1015  /*
     1016   * Now take care of the values that collided in the preceding loop,
     1017   * by finding some other entry in the table for them.
     1018   * Since there are as many entries in the table as there are values,
     1019   * there must be room for them.
     1020   */
     1021  lastUsed_ = -1;
     1022  for ( i = 0; i < oldSize; ++i ) {
     1023    if (oldHash[i].index>=0) {
     1024      double value = oldHash[i].value;
     1025      ipos = hash ( value);
     1026      int k;
     1027      while ( true ) {
     1028        assert (value!=hash_[ipos].value);
     1029        k = hash_[ipos].next;
     1030        if ( k == -1 ) {
     1031          while ( true ) {
     1032            ++lastUsed_;
     1033            assert (lastUsed_<=maxHash_);
     1034            if ( hash_[lastUsed_].index == -1 ) {
     1035              break;
     1036            }
     1037          }
     1038          hash_[ipos].next = lastUsed_;
     1039          hash_[lastUsed_].index = n;
     1040          n++;
     1041          hash_[lastUsed_].value = value;
     1042          break;
     1043        } else {
     1044          ipos = k;
     1045        }
     1046      }
     1047    }
     1048  }
     1049  assert (n==numberHash_);
     1050  delete [] oldHash;
     1051}
  • stable/1.7/Clp/src/ClpNode.hpp

    r1163 r1213  
    1919  /**@name Useful methods */
    2020  //@{
    21   /// Applies node to model
    22   void applyNode(ClpSimplex * model, bool justBounds );
     21  /** Applies node to model
     22      0 - just tree bounds
     23      1 - tree bounds and basis etc
     24      2 - saved bounds and basis etc
     25  */
     26  void applyNode(ClpSimplex * model, int doBoundsEtc );
    2327  /// Fix on reduced costs
    2428  int fixOnReducedCosts(ClpSimplex * model);
     29  /// Create odd arrays
     30  void createArrays(ClpSimplex * model);
     31  /// Clean up as crunch is different model
     32  void cleanUpForCrunch();
    2533  //@}
    2634 
    2735  /**@name Gets and sets */
    2836  //@{
     37  /// Objective value
     38  inline double objectiveValue() const
     39  { return objectiveValue_;}
     40  /// Set objective value
     41  inline void setObjectiveValue(double value)
     42  { objectiveValue_=value;}
     43  /// Primal solution
     44  inline const double * primalSolution() const
     45  { return primalSolution_;}
     46  /// Dual solution
     47  inline const double * dualSolution() const
     48  { return dualSolution_;}
    2949  /// Initial value of integer variable
    3050  inline double branchingValue() const
    3151  { return branchingValue_;}
     52  /// Sum infeasibilities
     53  inline double sumInfeasibilities() const
     54  { return sumInfeasibilities_;}
     55  /// Number infeasibilities
     56  inline int numberInfeasibilities() const
     57  { return numberInfeasibilities_;}
     58  /// Estimated solution value
     59  inline double estimatedSolution() const
     60  { return estimatedSolution_;}
    3261  /** Way for integer variable -1 down , +1 up */
    3362  int way() const;
     
    3968  inline int sequence() const
    4069  { return sequence_;}
     70  /// If odd arrays exist
     71  inline bool oddArraysExist() const
     72  { return lower_!=NULL;}
     73  /// Status array
     74  inline const unsigned char * statusArray() const
     75  { return status_; }
    4176  //@}
    4277 
     
    4681  ClpNode();
    4782  /// Constructor from model
    48   ClpNode (const ClpSimplex * model, const ClpNodeStuff * stuff);
     83  ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff,int depth);
    4984  /// Does work of constructor (partly so gdb will work)
    50   void gutsOfConstructor(const ClpSimplex * model, const ClpNodeStuff * stuff);
     85  void gutsOfConstructor(ClpSimplex * model, const ClpNodeStuff * stuff,
     86                         int arraysExist,int depth);
    5187  /** Destructor */
    5288  virtual ~ClpNode();
     
    72108  /// Initial value of integer variable
    73109  double branchingValue_;
     110  /// Value of objective
     111  double objectiveValue_;
     112  /// Sum of infeasibilities
     113  double sumInfeasibilities_;
     114  /// Estimated solution value
     115  double estimatedSolution_;
    74116  /// Factorization
    75117  ClpFactorization * factorization_;
     
    82124  /// Dual solution
    83125  double * dualSolution_;
     126  /// Integer lower bounds (only used in fathomMany)
     127  int * lower_;
     128  /// Integer upper bounds (only used in fathomMany)
     129  int * upper_;
    84130  /// Pivot variables for factorization
    85131  int * pivotVariables_;
     
    90136  /// Sequence number of integer variable (-1 if none)
    91137  int sequence_;
     138  /// Number of infeasibilities
     139  int numberInfeasibilities_;
    92140  /// Number fixed by reduced cost
    93141  int numberFixed_;
     142  /// Flags - 1 duals scaled
     143  int flags_;
     144  /// Maximum number fixed by reduced cost
     145  int maximumFixed_;
     146  /// Maximum rows so far
     147  int maximumRows_;
     148  /// Maximum columns so far
     149  int maximumColumns_;
     150  /// Maximum Integers so far
     151  int maximumIntegers_;
    94152  //@}
    95153};
     
    105163  //@}
    106164 
    107   /**@name Copy methods (at present illegal - will abort) */
     165  /**@name Copy methods (only copies ints etc, nulls arrays) */
    108166  //@{
    109167  /** The copy constructor. */
     
    111169  /// Operator =
    112170  ClpNodeStuff& operator=(const ClpNodeStuff&);
     171  /// Zaps stuff 1 - arrays, 2 ints, 3 both
     172  void zap(int type);
     173  //@}
     174 
     175 
     176  /**@name Fill methods */
     177  //@{
     178  /** Fill with pseudocosts */
     179  void fillPseudoCosts(const double * down, const double * up,
     180                       const int * numberDown, const int * numberUp,
     181                       const int * numberDownInfeasible, const int * numberUpInfeasible,
     182                       int number);
     183  /// Update pseudo costs
     184  void update(int way,int sequence,double change,bool feasible);
    113185  //@}
    114186 
     
    120192  /// Integer increment
    121193  double integerIncrement_;
     194  /// Down pseudo costs
     195  double * downPseudo_;
     196  /// Up pseudo costs
     197  double * upPseudo_;
     198  /// Number of times down
     199  int * numberDown_;
     200  /// Number of times up
     201  int * numberUp_;
     202  /// Number of times down infeasible
     203  int * numberDownInfeasible_;
     204  /// Number of times up infeasible
     205  int * numberUpInfeasible_;
     206  /// Copy of costs (local)
     207  double * saveCosts_;
     208  /// Array of ClpNodes
     209  ClpNode ** nodeInfo_;
     210  /// Large model if crunched
     211  ClpSimplex * large_;
     212  /// Which rows in large model
     213  int * whichRow_;
     214  /// Which columns in large model
     215  int * whichColumn_;
     216  /// Number bounds in large model
     217  int nBound_;
     218  /// Save of specialOptions_ (local)
     219  int saveOptions_;
     220  /** Options to pass to solver
     221      1 - create external reduced costs for columns
     222      2 - create external reduced costs for rows
     223      4 - create external row activity (columns always done)
     224      Above only done if feasible
     225      65536 - set if activated
     226  */
     227  int solverOptions_;
     228  /// Number deep
     229  int nDepth_;
     230  /// Number nodes returned (-1 if fathom aborted)
     231  int nNodes_;
     232  /// Number of nodes explored
     233  int numberNodesExplored_;
     234  /// Number of iterations
     235  int numberIterations_;
     236  /// Type of presolve - 0 none, 1 crunch
     237  int presolveType_;
     238  //@}
     239};
     240class ClpHashValue {
     241 
     242public:
     243  /**@name Useful methods */
     244  //@{
     245  /// Return index or -1 if not found
     246  int index(double value) const;
     247  /// Add value to list and return index
     248  int addValue(double value) ;
     249  /// Number of different entries
     250  inline int numberEntries() const
     251  { return numberHash_;}
     252  //@}
     253
     254  /**@name Constructors, destructor */
     255  //@{
     256  /** Default constructor. */
     257  ClpHashValue();
     258  /** Useful constructor. */
     259  ClpHashValue(ClpSimplex * model);
     260  /** Destructor */
     261  virtual ~ClpHashValue();
     262  //@}
     263 
     264  /**@name Copy method */
     265  //@{
     266  /** The copy constructor. */
     267  ClpHashValue(const ClpHashValue&);
     268  /// =
     269  ClpHashValue& operator=(const ClpHashValue&);
     270  //@}
     271private:
     272  /**@name private stuff */
     273  //@{
     274  /** returns hash */
     275  int hash(double value) const;
     276  /// Resizes
     277  void resize(bool increaseMax);
     278  //@}
     279   
     280protected:
     281  /**@name Data members
     282     The data members are protected to allow access for derived classes. */
     283  //@{
     284  /// Data
     285  // for hashing
     286  typedef struct {
     287    double value;
     288    int index, next;
     289  } CoinHashLink;
     290  /// Hash table
     291  mutable CoinHashLink *hash_;
     292  /// Number of entries in hash table
     293  int numberHash_;
     294  /// Maximum number of entries in hash table i.e. size
     295  int maxHash_;
     296  /// Last used space
     297  int lastUsed_;
    122298  //@}
    123299};
  • stable/1.7/Clp/src/ClpSimplex.cpp

    r1207 r1213  
    96189618  }
    96199619}
     9620// Start Fast dual
     9621int
     9622ClpSimplex::startFastDual2(ClpNodeStuff * info)
     9623{
     9624  abort();
     9625  return 0;
     9626}
     9627// Like Fast dual
     9628int
     9629ClpSimplex::fastDual2(ClpNodeStuff * info)
     9630{
     9631  abort();
     9632  return 0;
     9633}
     9634// Stop Fast dual
     9635void
     9636ClpSimplex::stopFastDual2(ClpNodeStuff * info)
     9637{
     9638  abort();
     9639}
    96209640// Create C++ lines to get to current state
    96219641void
  • stable/1.7/Clp/src/ClpSimplex.hpp

    r1164 r1213  
    2626class ClpDisasterHandler;
    2727class ClpConstraint;
     28class ClpNodeStuff;
    2829
    2930/** This solves LPs using the simplex method
     
    416417                      bool alwaysFinish=false,
    417418                      int startFinishOptions=0);
     419  /// Starts Fast dual2
     420  int startFastDual2(ClpNodeStuff * stuff);
     421  /// Like Fast dual
     422  int fastDual2(ClpNodeStuff * stuff);
     423  /// Stops Fast dual2
     424  void stopFastDual2(ClpNodeStuff * stuff);
    418425  //@}
    419426
  • stable/1.7/Clp/src/ClpSolve.cpp

    r1147 r1213  
    449449#endif
    450450#endif
     451  if (presolve!=ClpSolve::presolveOff) {
     452    bool costedSlacks=false;
     453    int numberPasses=5;
     454    if (presolve==ClpSolve::presolveNumber) {
     455      numberPasses=options.getPresolvePasses();
     456      presolve = ClpSolve::presolveOn;
     457    } else if (presolve==ClpSolve::presolveNumberCost) {
     458      numberPasses=options.getPresolvePasses();
     459      presolve = ClpSolve::presolveOn;
     460      costedSlacks=true;
     461      // switch on singletons to slacks
     462      pinfo.setDoSingletonColumn(true);
     463    }
     464#ifndef CLP_NO_STD
     465    if (presolveToFile) {
     466      // PreSolve to file - not fully tested
     467      printf("Presolving to file - presolve.save\n");
     468      pinfo.presolvedModelToFile(*this,"presolve.save",dblParam_[ClpPresolveTolerance],
     469                           false,numberPasses);
     470      model2=this;
     471    } else {
     472#endif
     473      model2 = pinfo.presolvedModel(*this,dblParam_[ClpPresolveTolerance],
     474                                    false,numberPasses,true,costedSlacks);
     475#ifndef CLP_NO_STD
     476    }
     477#endif
     478    time2 = CoinCpuTime();
     479    timePresolve = time2-timeX;
     480    handler_->message(CLP_INTERVAL_TIMING,messages_)
     481      <<"Presolve"<<timePresolve<<time2-time1
     482      <<CoinMessageEol;
     483    timeX=time2;
     484    if (!model2) {
     485      handler_->message(CLP_INFEASIBLE,messages_)
     486        <<CoinMessageEol;
     487      model2 = this;
     488      problemStatus_=1; // may be unbounded but who cares
     489      if (options.infeasibleReturn()||(moreSpecialOptions_&1)!=0) {
     490        return -1;
     491      }
     492      presolve=ClpSolve::presolveOff;
     493    }
     494    // We may be better off using original (but if dual leave because of bounds)
     495    if (presolve!=ClpSolve::presolveOff&&
     496        numberRows_<1.01*model2->numberRows_&&numberColumns_<1.01*model2->numberColumns_
     497        &&model2!=this) {
     498      if(method!=ClpSolve::useDual||
     499         (numberRows_==model2->numberRows_&&numberColumns_==model2->numberColumns_)) {
     500        delete model2;
     501        model2 = this;
     502        presolve=ClpSolve::presolveOff;
     503      }
     504    }
     505  }
     506  if (interrupt)
     507    currentModel = model2;
    451508  // For below >0 overrides
    452509  // 0 means no, -1 means maybe
     
    456513  int doSlp=0;
    457514  int primalStartup=1;
     515  // switch to primal from automatic if just one cost entry
     516  if (method==ClpSolve::automatic&&model2->numberColumns()>5000&&
     517      (specialOptions_&1024)!=0) {
     518    int numberColumns = model2->numberColumns();
     519    const double * obj = model2->objective();
     520    int nNon=0;
     521    for (int i=0;i<numberColumns;i++) {
     522      if (obj[i])
     523        nNon++;
     524    }
     525    if (nNon==1) {
     526#ifdef COIN_DEVELOP
     527      printf("Forcing primal\n");
     528#endif
     529      method=ClpSolve::usePrimal;
     530    }
     531  }
    458532  if (method!=ClpSolve::useDual&&method!=ClpSolve::useBarrier
    459533      &&method!=ClpSolve::useBarrierNoCross) {
     
    578652  // Just do this number of passes in Sprint
    579653  int maxSprintPass=100;
    580   bool costedSlacks=false;
    581   if (presolve!=ClpSolve::presolveOff) {
    582     int numberPasses=5;
    583     if (presolve==ClpSolve::presolveNumber) {
    584       numberPasses=options.getPresolvePasses();
    585       presolve = ClpSolve::presolveOn;
    586     } else if (presolve==ClpSolve::presolveNumberCost) {
    587       numberPasses=options.getPresolvePasses();
    588       presolve = ClpSolve::presolveOn;
    589       costedSlacks=true;
    590       // switch on singletons to slacks
    591       pinfo.setDoSingletonColumn(true);
    592     }
    593 #ifndef CLP_NO_STD
    594     if (presolveToFile) {
    595       // PreSolve to file - not fully tested
    596       printf("Presolving to file - presolve.save\n");
    597       pinfo.presolvedModelToFile(*this,"presolve.save",dblParam_[ClpPresolveTolerance],
    598                            false,numberPasses);
    599       model2=this;
    600     } else {
    601 #endif
    602       model2 = pinfo.presolvedModel(*this,dblParam_[ClpPresolveTolerance],
    603                                     false,numberPasses,true,costedSlacks);
    604 #ifndef CLP_NO_STD
    605     }
    606 #endif
    607     time2 = CoinCpuTime();
    608     timePresolve = time2-timeX;
    609     handler_->message(CLP_INTERVAL_TIMING,messages_)
    610       <<"Presolve"<<timePresolve<<time2-time1
    611       <<CoinMessageEol;
    612     timeX=time2;
    613     if (!model2) {
    614       handler_->message(CLP_INFEASIBLE,messages_)
    615         <<CoinMessageEol;
    616       model2 = this;
    617       problemStatus_=1; // may be unbounded but who cares
    618       if (options.infeasibleReturn()||(moreSpecialOptions_&1)!=0) {
    619         return -1;
    620       }
    621       presolve=ClpSolve::presolveOff;
    622     }
    623     // We may be better off using original (but if dual leave because of bounds)
    624     if (presolve!=ClpSolve::presolveOff&&
    625         numberRows_<1.01*model2->numberRows_&&numberColumns_<1.01*model2->numberColumns_
    626         &&model2!=this) {
    627       if(method!=ClpSolve::useDual||
    628          (numberRows_==model2->numberRows_&&numberColumns_==model2->numberColumns_)) {
    629         delete model2;
    630         model2 = this;
    631         presolve=ClpSolve::presolveOff;
    632       }
    633     }
    634   }
    635   if (interrupt)
    636     currentModel = model2;
    637654  // See if worth trying +- one matrix
    638655  bool plusMinus=false;
     
    672689    if(numberElements>10000&&(doIdiot||doSprint))
    673690      plusMinus=true;
    674   }
    675   //plusMinus=true;
     691  } else if ((specialOptions_&1024)!=0) {
     692    plusMinus=true;
     693  }
    676694#ifndef SLIM_CLP
    677695  // Statistics (+1,-1, other) - used to decide on strategy if not +-1
     
    691709      ClpPlusMinusOneMatrix * newMatrix = new ClpPlusMinusOneMatrix(*(clpMatrix->matrix()));
    692710      if (newMatrix->getIndices()) {
    693         model2->replaceMatrix(newMatrix);
     711        if ((specialOptions_&1024)==0) {
     712          model2->replaceMatrix(newMatrix);
     713        } else {
     714          // in integer - just use for sprint/idiot
     715          saveMatrix=NULL;
     716          delete newMatrix;
     717        }
    694718      } else {
    695719        handler_->message(CLP_MATRIX_CHANGE,messages_)
     
    714738    model2->setFactorizationFrequency(this->factorizationFrequency());
    715739  }
     740  bool tryItSave = false;
    716741  if (method==ClpSolve::automatic) {
    717742    if (doSprint==0&&doIdiot==0) {
     
    781806          }
    782807        }
    783         bool tryIt= numberRows>200&&numberColumns>2000&&numberColumns>2*numberRows;
     808        bool tryIt= numberRows>200&&numberColumns>2000&&
     809          (numberColumns>2*numberRows||(method==ClpSolve::automatic&&(specialOptions_&1024)!=0));
     810        tryItSave = tryIt;
    784811        if (numberRows<1000&&numberColumns<3000)
    785812          tryIt=false;
     
    10961123      }
    10971124      bool increaseSprint=plusMinus;
     1125      if ((specialOptions_&1024)!=0)
     1126        increaseSprint=false;
    10981127      if (!plusMinus) {
    10991128        // If 90% +- 1 then go for sprint
     
    11011130          increaseSprint=true;
    11021131      }
    1103       bool tryIt= numberRows>200&&numberColumns>2000&&numberColumns>2*numberRows;
     1132      bool tryIt= tryItSave;
    11041133      if (numberRows<1000&&numberColumns<3000)
    11051134        tryIt=false;
     
    11491178          }
    11501179          // If few passes - don't bother
    1151           if (nPasses<=5)
     1180          if (nPasses<=5&&!plusMinus)
    11521181            nPasses=0;
    11531182        } else {
     
    11861215            nPasses = (int) (((double) nPasses)*(ratio/5.0)); // increase if lots of elements per column
    11871216          }
    1188           if (nPasses<=5)
     1217          if (nPasses<=5&&!plusMinus)
    11891218            nPasses=0;
    11901219          //info.setStartingWeight(1.0e-1);
     
    17361765          (!small.numberIterations()&&iPass)||
    17371766          iPass==maxSprintPass-1||small.status()==3) {
    1738        
     1767
    17391768        break; // finished
    17401769      } else {
     
    28142843          }
    28152844        } else {
    2816           // primal - change tolerance 
     2845          // primal - change tolerance
    28172846          if (numberBadTimes_>3)
    28182847            model_->setCurrentPrimalTolerance(model_->currentPrimalTolerance()*1.05);
Note: See TracChangeset for help on using the changeset viewer.