Ignore:
Timestamp:
Feb 7, 2003 5:39:18 PM (17 years ago)
Author:
forrest
Message:

Adding Network matrix and PlusMinusOne?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpPackedMatrix.cpp

    r109 r118  
    220220  double zeroTolerance = model->factorization()->zeroTolerance();
    221221  int numberRows = model->numberRows();
    222   const ClpMatrixBase * rowCopy = model->rowCopy();
    223   // make sure row copy is of correct type
    224   // if not we would have to have another transposeTimes
    225   assert (!rowCopy||rowCopy->type()==1);
     222  ClpPackedMatrix* rowCopy =
     223    dynamic_cast< ClpPackedMatrix*>(model->rowCopy());
    226224  if (numberInRowArray>0.3*numberRows||!rowCopy) {
    227225    // do by column
     
    272270      }
    273271    }
    274   } else if (numberInRowArray>2||y->getNumElements()) {
     272    columnArray->setNumElements(numberNonZero);
     273    y->setNumElements(0);
     274  } else {
     275    // do by row
     276    rowCopy->transposeTimesByRow(model, scalar, rowArray, y, columnArray);
     277  }
     278}
     279/* Return <code>x * A + y</code> in <code>z</code>.
     280        Squashes small elements and knows about ClpSimplex */
     281void
     282ClpPackedMatrix::transposeTimesByRow(const ClpSimplex * model, double scalar,
     283                              const CoinIndexedVector * rowArray,
     284                              CoinIndexedVector * y,
     285                              CoinIndexedVector * columnArray) const
     286{
     287  columnArray->clear();
     288  double * pi = rowArray->denseVector();
     289  int numberNonZero=0;
     290  int * index = columnArray->getIndices();
     291  double * array = columnArray->denseVector();
     292  int numberInRowArray = rowArray->getNumElements();
     293  // maybe I need one in OsiSimplex
     294  double zeroTolerance = model->factorization()->zeroTolerance();
     295  const int * column = getIndices();
     296  const CoinBigIndex * rowStart = getVectorStarts();
     297  const double * element = getElements();
     298  const int * whichRow = rowArray->getIndices();
     299  if (numberInRowArray>2||y->getNumElements()) {
    275300    // do by rows
    276301    // ** Row copy is already scaled
     
    294319    }
    295320
    296     const int * column = rowCopy->getIndices();
    297     const CoinBigIndex * rowStart = rowCopy->getVectorStarts();
    298     const double * element = rowCopy->getElements();
    299     const int * whichRow = rowArray->getIndices();
    300321    for (i=0;i<numberInRowArray;i++) {
    301322      iRow = whichRow[i];
     
    330351    numberNonZero=0;
    331352
    332     const int * column = rowCopy->getIndices();
    333     const CoinBigIndex * rowStart = rowCopy->getVectorStarts();
    334     const double * element = rowCopy->getElements();
    335     const int * whichRow = rowArray->getIndices();
    336353    double value;
    337354    iRow = whichRow[0];
     
    371388    int iRow=rowArray->getIndices()[0];
    372389    numberNonZero=0;
    373     const int * column = rowCopy->getIndices();
    374     const CoinBigIndex * rowStart = rowCopy->getVectorStarts();
    375     const double * element = rowCopy->getElements();
    376390    double value = pi[iRow]*scalar;
    377391    CoinBigIndex j;
     
    712726  }
    713727}
    714 // Creates row copy and scales if necessary
    715 ClpMatrixBase *
    716 ClpPackedMatrix::scaledRowCopy(ClpSimplex * model) const
    717 {
    718   ClpMatrixBase * rowCopyBase = reverseOrderedCopy();
    719   ClpPackedMatrix* rowCopy =
    720     dynamic_cast< ClpPackedMatrix*>(rowCopyBase);
    721 
    722   // Make sure it is really a ClpPackedMatrix
    723   assert (rowCopy!=NULL);
    724 
    725   const double * rowScale = model->rowScale();
    726   const double * columnScale = model->columnScale();
    727 
    728   if (rowScale) {
    729     // scale row copy
    730     int numberRows = model->numberRows();
    731     int numberColumns = model->numberColumns();
    732     const int * column = rowCopy->getIndices();
    733     const CoinBigIndex * rowStart = rowCopy->getVectorStarts();
    734     const double * element = rowCopy->getElements();
    735     int iRow;
    736     // need to replace row by row
    737     double * newElement = new double[numberColumns];
    738     // scale row copy
    739     for (iRow=0;iRow<numberRows;iRow++) {
    740       int j;
    741       double scale = rowScale[iRow];
    742       const double * elementsInThisRow = element + rowStart[iRow];
    743       const int * columnsInThisRow = column + rowStart[iRow];
    744       int number = rowStart[iRow+1]-rowStart[iRow];
    745       assert (number<=numberColumns);
    746       for (j=0;j<number;j++) {
    747         int iColumn = columnsInThisRow[j];
    748         newElement[j] = elementsInThisRow[j]*scale*columnScale[iColumn];
    749       }
    750       rowCopy->replaceVector(iRow,number,newElement);
    751     }
    752     delete [] newElement;
    753   }
    754   return rowCopyBase;
    755 }
    756728/* Unpacks a column into an CoinIndexedvector
    757729      Note that model is NOT const.  Bounds and objective could
Note: See TracChangeset for help on using the changeset viewer.