Changeset 1106


Ignore:
Timestamp:
Sep 14, 2007 9:43:58 AM (12 years ago)
Author:
forrest
Message:

fix plusminus leak

Location:
trunk/Clp/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/ClpPlusMinusOneMatrix.cpp

    r901 r1106  
    2727{
    2828  setType(12);
    29   elements_ = NULL;
     29  matrix_ = NULL;
    3030  startPositive_ = NULL;
    3131  startNegative_ = NULL;
     
    4343: ClpMatrixBase(rhs)
    4444
    45   elements_ = NULL;
     45  matrix_ = NULL;
    4646  startPositive_ = NULL;
    4747  startNegative_ = NULL;
     
    7575{
    7676  setType(12);
    77   elements_ = NULL;
     77  matrix_ = NULL;
    7878  lengths_=NULL;
    7979  numberRows_=numberRows;
     
    9393
    9494  setType(12);
    95   elements_ = NULL;
     95  matrix_ = NULL;
    9696  startPositive_ = NULL;
    9797  startNegative_ = NULL;
     
    174174ClpPlusMinusOneMatrix::~ClpPlusMinusOneMatrix ()
    175175{
    176   delete [] elements_;
     176  delete matrix_;
    177177  delete [] startPositive_;
    178178  delete [] startNegative_;
     
    189189  if (this != &rhs) {
    190190    ClpMatrixBase::operator=(rhs);
    191     delete [] elements_;
     191    delete matrix_;
    192192    delete [] startPositive_;
    193193    delete [] startNegative_;
    194194    delete [] lengths_;
    195195    delete [] indices_;
    196     elements_ = NULL;
     196    matrix_ = NULL;
    197197    startPositive_ = NULL;
    198198    lengths_=NULL;
     
    238238: ClpMatrixBase(rhs)
    239239
    240   elements_ = NULL;
     240  matrix_ = NULL;
    241241  startPositive_ = NULL;
    242242  startNegative_ = NULL;
     
    10421042ClpPlusMinusOneMatrix::getPackedMatrix() const
    10431043{
    1044   int numberMinor = (!columnOrdered_) ? numberColumns_ : numberRows_;
    1045   int numberMajor = (columnOrdered_) ? numberColumns_ : numberRows_;
    1046   return new CoinPackedMatrix(columnOrdered_,numberMinor,numberMajor,
     1044  if (!matrix_) {
     1045    int numberMinor = (!columnOrdered_) ? numberColumns_ : numberRows_;
     1046    int numberMajor = (columnOrdered_) ? numberColumns_ : numberRows_;
     1047    int numberElements = startPositive_[numberMajor];
     1048    double * elements = new double [numberElements];
     1049    CoinBigIndex j=0;
     1050    int i;
     1051    for (i=0;i<numberMajor;i++) {
     1052      for (;j<startNegative_[i];j++) {
     1053        elements[j]=1.0;
     1054      }
     1055      for (;j<startPositive_[i+1];j++) {
     1056        elements[j]=-1.0;
     1057      }
     1058    }
     1059    matrix_ =  new CoinPackedMatrix(columnOrdered_,numberMinor,numberMajor,
    10471060                              getNumElements(),
    1048                               getElements(),indices_,
     1061                              elements,indices_,
    10491062                              startPositive_,getVectorLengths());
    1050 
     1063    delete [] elements;
     1064  }
     1065  return matrix_;
    10511066}
    10521067/* A vector containing the elements in the packed matrix. Note that there
     
    10571072ClpPlusMinusOneMatrix::getElements() const
    10581073{
    1059   if (!elements_) {
    1060     int numberMajor = (columnOrdered_) ? numberColumns_ : numberRows_;
    1061     int numberElements = startPositive_[numberMajor];
    1062     elements_ = new double [numberElements];
    1063     CoinBigIndex j=0;
    1064     int i;
    1065     for (i=0;i<numberMajor;i++) {
    1066       for (;j<startNegative_[i];j++) {
    1067         elements_[j]=1.0;
    1068       }
    1069       for (;j<startPositive_[i+1];j++) {
    1070         elements_[j]=-1.0;
    1071       }
    1072     }
    1073   }
    1074   return elements_;
     1074  if (!matrix_)
     1075    getPackedMatrix();
     1076  return matrix_->getElements();
    10751077}
    10761078
     
    11231125  delete [] lengths_;
    11241126  lengths_=NULL;
    1125   delete [] elements_;
    1126   elements_= NULL;
     1127  delete matrix_;
     1128  matrix_= NULL;
    11271129  CoinBigIndex * newPositive = new CoinBigIndex [newNumber+1];
    11281130  CoinBigIndex * newNegative = new CoinBigIndex [newNumber];
     
    11911193  delete [] lengths_;
    11921194  lengths_=NULL;
    1193   delete [] elements_;
    1194   elements_= NULL;
     1195  delete matrix_;
     1196  matrix_= NULL;
    11951197  int * newIndices = new int [newSize];
    11961198  newSize=0;
     
    13341336  delete [] lengths_;
    13351337  lengths_=NULL;
    1336   delete [] elements_;
    1337   elements_= NULL;
     1338  delete matrix_;
     1339  matrix_= NULL;
    13381340  int numberNow = startPositive_[numberColumns_];
    13391341  CoinBigIndex * temp;
     
    14041406  delete [] lengths_;
    14051407  lengths_=NULL;
    1406   delete [] elements_;
    1407   elements_= NULL;
     1408  delete matrix_;
     1409  matrix_= NULL;
    14081410  int numberNow = startPositive_[numberColumns_];
    14091411  int * newIndices = new int [numberNow+size];
     
    16321634ClpPlusMinusOneMatrix::releasePackedMatrix() const
    16331635{
    1634   delete [] elements_;
     1636  delete matrix_;
    16351637  delete [] lengths_;
    1636   elements_=NULL;
     1638  matrix_=NULL;
    16371639  lengths_=NULL;
    16381640}
  • trunk/Clp/src/ClpPlusMinusOneMatrix.hpp

    r1055 r1106  
    254254   //@{
    255255  /// For fake CoinPackedMatrix
    256   mutable double * elements_;
     256  mutable CoinPackedMatrix * matrix_;
    257257  mutable int * lengths_;
    258258  /// Start of +1's for each
  • trunk/Clp/src/ClpSolve.cpp

    r1088 r1106  
    672672      plusMinus=true;
    673673  }
     674  //plusMinus=true;
    674675#ifndef SLIM_CLP
    675676  // Statistics (+1,-1, other) - used to decide on strategy if not +-1
     
    22182219    time2=0.0;
    22192220  }
    2220   if (saveMatrix&&model2==this) {
    2221     // delete and replace
    2222     delete model2->clpMatrix();
    2223     model2->replaceMatrix(saveMatrix);
     2221  if (saveMatrix) {
     2222    if (model2==this) {
     2223      // delete and replace
     2224      delete model2->clpMatrix();
     2225      model2->replaceMatrix(saveMatrix);
     2226    } else {
     2227      delete saveMatrix;
     2228    }
    22242229  }
    22252230  numberIterations = model2->numberIterations();
Note: See TracChangeset for help on using the changeset viewer.