Changeset 23


Ignore:
Timestamp:
Sep 19, 2002 12:42:59 PM (17 years ago)
Author:
forrest
Message:

Allowing for bad matrices

Location:
branches/devel-1
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-1/ClpMessage.cpp

    r21 r23  
    4040  {CLP_RIMSTATISTICS2,21,2,"Absolute values of scaled bounds range from %g to %g, minimum gap %g"},
    4141  {CLP_RIMSTATISTICS3,22,2,"Absolute values of scaled rhs range from %g to %g, minimum gap %g"},
     42  {CLP_POSSIBLELOOP,23,2,"Possible loop - %d matches (%x) after %d checks"},
     43  {CLP_SMALLELEMENTS,24,0,"Matrix will be packed to eliminate %d small elements"},
    4244  {CLP_SIMPLEX_HOUSE1,101,32,"dirOut %d, dirIn %d, theta %g, out %g, dj %g, alpha %g"},
    4345  {CLP_SIMPLEX_HOUSE2,102,4,"%d %g In: %c%d Out: %c%d%? dj ratio %g distance %g%? dj %g distance %g"},
     
    5456  {CLP_UNABLE_OPEN,6001,0,"Unable to open file %s for reading"},
    5557  {CLP_BAD_BOUNDS,6002,0,"%d bad bound pairs were found - first at %c%d"},
    56   {CLP_BAD_MATRIX,6003,0,"Matrix has bad values"},
     58  {CLP_BAD_MATRIX,6003,0,"Matrix has %d large values, first at column %d, row %d is %g"},
     59  {CLP_LOOP,6004,0,"Can't get out of loop - stopping"},
    5760  {CLP_IMPORT_RESULT,18,1,"Model was imported from %s in %g seconds"},
    5861  {CLP_IMPORT_ERRORS,3001,1," There were %d errors when importing model from %s"},
  • branches/devel-1/ClpPackedMatrix.cpp

    r21 r23  
    691691    if (model->rowCopy()) {
    692692      // need to replace row by row
    693       double * newElement = new double[numberColumns];
     693      double * newElement = new double[numberRows];
    694694      // scale row copy
    695695      for (iRow=0;iRow<numberRows;iRow++) {
     
    713713  }
    714714}
     715// Creates row copy and scales if necessary
     716ClpMatrixBase *
     717ClpPackedMatrix::scaledRowCopy(ClpSimplex * model) const
     718{
     719  ClpMatrixBase * rowCopyBase = reverseOrderedCopy();
     720  ClpPackedMatrix* rowCopy =
     721    dynamic_cast< ClpPackedMatrix*>(rowCopyBase);
     722
     723  // Make sure it is really a ClpPackedMatrix
     724  assert (rowCopy!=NULL);
     725
     726  const double * rowScale = model->rowScale();
     727  const double * columnScale = model->columnScale();
     728
     729  if (rowScale) {
     730    // scale row copy
     731    int numberRows = model->numberRows();
     732    int numberColumns = model->numberColumns();
     733    const int * column = rowCopy->getIndices();
     734    const int * rowStart = rowCopy->getVectorStarts();
     735    const double * element = rowCopy->getElements();
     736    int iRow;
     737    // need to replace row by row
     738    double * newElement = new double[numberColumns];
     739    // scale row copy
     740    for (iRow=0;iRow<numberRows;iRow++) {
     741      int j;
     742      double scale = rowScale[iRow];
     743      const double * elementsInThisRow = element + rowStart[iRow];
     744      const int * columnsInThisRow = column + rowStart[iRow];
     745      int number = rowStart[iRow+1]-rowStart[iRow];
     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}
    715756/* Unpacks a column into an CoinIndexedvector
    716757      Note that model is NOT const.  Bounds and objective could
     
    775816*/
    776817bool
    777 ClpPackedMatrix::allElementsInRange(double smallest, double largest)
     818ClpPackedMatrix::allElementsInRange(ClpSimplex * model,
     819                                    double smallest, double largest)
    778820{
    779821  int iColumn;
    780   int numberBad=0;;
     822  int numberLarge=0;;
     823  int numberSmall=0;;
     824  int firstBadColumn=-1;
     825  int firstBadRow=-1;
     826  double firstBadElement=0.0;
    781827  // get matrix data pointers
    782   //const int * row = matrix_->getIndices();
     828  const int * row = matrix_->getIndices();
    783829  const int * columnStart = matrix_->getVectorStarts();
    784830  const int * columnLength = matrix_->getVectorLengths();
     
    790836         j<columnStart[iColumn]+columnLength[iColumn];j++) {
    791837      double value = fabs(elementByColumn[j]);
    792       if (value<smallest||value>largest)
    793         numberBad++;
    794     }
    795   }
    796   return (numberBad==0);
    797 }
    798 
    799 
     838      if (value<smallest) {
     839        numberSmall++;
     840      } else if (value>largest) {
     841        numberLarge++;
     842        if (firstBadColumn<0) {
     843          firstBadColumn=iColumn;
     844          firstBadRow=row[j];
     845          firstBadElement=elementByColumn[j];
     846        }
     847      }
     848    }
     849  }
     850  if (numberLarge) {
     851    model->messageHandler()->message(CLP_BAD_MATRIX,model->messages())
     852      <<numberLarge
     853      <<firstBadColumn<<firstBadRow<<firstBadElement
     854      <<CoinMessageEol;
     855    return false;
     856  }
     857  if (numberSmall) {
     858    model->messageHandler()->message(CLP_SMALLELEMENTS,model->messages())
     859      <<numberSmall
     860      <<CoinMessageEol;
     861    matrix_->compress(smallest);
     862  }
     863  return true;
     864}
     865
     866
  • branches/devel-1/ClpSimplex.cpp

    r21 r23  
    16191619  }
    16201620}
    1621 void
     1621bool
    16221622ClpSimplex::createRim(int what,bool makeRowCopy)
    16231623{
     1624  bool goodMatrix=true;
    16241625  if ((what&16)!=0) {
    16251626    // move information to work arrays
     
    16401641             numberRows_*sizeof(double));
    16411642    }
    1642    
     1643    //check matrix
     1644    if (!matrix_->allElementsInRange(this,1.0e-20,1.0e20)) {
     1645      problemStatus_=4;
     1646      goodMatrix= false;
     1647    }
    16431648    if (makeRowCopy) {
    16441649      delete rowCopy_;
     
    17401745  }
    17411746 
     1747  if ((what&16)!=0) {
     1748    // check rim of problem okay
     1749    if (!sanityCheck())
     1750      goodMatrix=false;
     1751  }
    17421752  // we need to treat matrix as if each element by rowScaleIn and columnScaleout??
    17431753  // maybe we need to move scales to SimplexModel for factorization?
     
    17701780    }   
    17711781  }
    1772 
     1782  return goodMatrix;
    17731783}
    17741784void
     
    27842794    numberMatched=0;
    27852795  if (numberMatched) {
    2786     printf("Possible loop - %d matches (%x) after %d checks\n",
    2787            numberMatched,matched,numberTimes_);
     2796    model_->messageHandler()->message(CLP_POSSIBLELOOP,model_->messages())
     2797      <<numberMatched
     2798      <<matched
     2799      <<numberTimes_
     2800      <<CoinMessageEol;
    27882801    numberBadTimes_++;
    27892802    if (numberBadTimes_<10) {
     
    27962809      }
    27972810    } else {
     2811      model_->messageHandler()->message(CLP_LOOP,model_->messages())
     2812        <<CoinMessageEol;
    27982813      // look at solution and maybe declare victory
    27992814      if (infeasibility<1.0e-4)
     
    28092824ClpSimplex::sanityCheck()
    28102825{
    2811   int badProblem=0;
    28122826  int numberBad , numberBadBounds;
    28132827  double largestBound, smallestBound, minimumGap;
     
    29282942    return false;
    29292943  }
    2930   //check matrix
    2931   if (!matrix_->allElementsInRange(1.0e-20,1.0e20)) {
    2932     handler_->message(CLP_BAD_MATRIX,messages_)
    2933       <<CoinMessageEol;
    2934     problemStatus_=4;
    2935     return false;
    2936   }
    29372944  if (modifiedBounds)
    29382945    handler_->message(CLP_MODIFIEDBOUNDS,messages_)
  • branches/devel-1/ClpSimplexDual.cpp

    r21 r23  
    107107#include <stdio.h>
    108108#include <iostream>
     109#define CHECK_DJ
    109110// This returns a non const array filled with input from scalar
    110111// or actual array
     
    242243  // put in standard form (and make row copy)
    243244  // create modifiable copies of model rim and do optional scaling
    244   createRim(7+8+16,true);
     245  bool goodMatrix = createRim(7+8+16,true);
    245246
    246247  // save dual bound
     
    251252  int saveSparse = factorization_->sparseThreshold();
    252253
    253   if (sanityCheck()) {
     254  if (goodMatrix) {
    254255    // Problem looks okay
    255256    int iRow,iColumn;
     
    597598            rowArray_[1]->clear();
    598599            columnArray_[0]->clear();
     600            // make sure dual feasible
     601            // look at all rows and columns
     602            CoinIotaN(rowArray_[0]->getIndices(),numberRows_,0);
     603            rowArray_[0]->setNumElements(numberRows_);
     604            CoinIotaN(columnArray_[0]->getIndices(),numberColumns_,0);
     605            columnArray_[0]->setNumElements(numberColumns_);
     606            double objectiveChange=0.0;
     607            updateDualsInDual(rowArray_[0],columnArray_[0],rowArray_[1],
     608                              0.0,objectiveChange);
    599609            continue;
    600610          }
     
    11921202        break;
    11931203      case ClpSimplex::atUpperBound:
     1204#ifdef CHECK_DJ
     1205        // For Debug so we can find out where problem is
     1206        perturbation_ = iSequence+addSequence;
     1207#endif
    11941208        assert (oldValue<=dualTolerance_*1.0001);
    11951209        if (value>newTolerance) {
     
    12011215        break;
    12021216      case ClpSimplex::atLowerBound:
     1217#ifdef CHECK_DJ
     1218        // For Debug so we can find out where problem is
     1219        perturbation_ = iSequence+addSequence;
     1220#endif
    12031221        assert (oldValue>=-dualTolerance_*1.0001);
    12041222        if (value<-newTolerance) {
     
    19291947          ray_ = NULL;
    19301948        }
     1949
    19311950      }
    19321951    } else {
  • branches/devel-1/ClpSimplexPrimal.cpp

    r21 r23  
    223223  // put in standard form (and make row copy)
    224224  // create modifiable copies of model rim and do optional scaling
    225   createRim(7+8+16,true);
     225  bool goodMatrix=createRim(7+8+16,true);
    226226
    227227  // save infeasibility cost
     
    232232  int saveSparse = factorization_->sparseThreshold();
    233233
    234   if (sanityCheck()) {
     234  if (goodMatrix) {
    235235    // Model looks okay
    236236    int iRow,iColumn;
  • branches/devel-1/include/ClpMatrixBase.hpp

    r21 r23  
    8282  virtual int scale(ClpSimplex * model) const
    8383  { return 1;};
     84  /// Creates row copy and scales if necessary
     85  virtual ClpMatrixBase * scaledRowCopy(ClpSimplex * model) const
     86  { return reverseOrderedCopy();};
    8487
    8588  /** Checks if all elements are in valid range.  Can just
     
    8891      small elements.
    8992  */
    90   virtual bool allElementsInRange(double smallest, double largest)
     93  virtual bool allElementsInRange(ClpSimplex * model,
     94                                  double smallest, double largest)
    9195  { return true;};
    9296
  • branches/devel-1/include/ClpMessage.hpp

    r21 r23  
    3939  CLP_RIMSTATISTICS2,
    4040  CLP_RIMSTATISTICS3,
     41  CLP_POSSIBLELOOP,
     42  CLP_SMALLELEMENTS,
    4143  CLP_SIMPLEX_HOUSE1,
    4244  CLP_SIMPLEX_HOUSE2,
     
    5456  CLP_BAD_BOUNDS,
    5557  CLP_BAD_MATRIX,
     58  CLP_LOOP,
    5659  CLP_IMPORT_RESULT,
    5760  CLP_IMPORT_ERRORS,
  • branches/devel-1/include/ClpPackedMatrix.hpp

    r21 r23  
    7979      returns non-zero if no scaling done */
    8080  virtual int scale(ClpSimplex * model) const ;
     81  /// Creates row copy and scales if necessary
     82  virtual ClpMatrixBase * scaledRowCopy(ClpSimplex * model) const;
    8183  /** Checks if all elements are in valid range.  Can just
    8284      return true if you are not paranoid.  For Clp I will
     
    8486      small elements.
    8587  */
    86   virtual bool allElementsInRange(double smallest, double largest);
     88  virtual bool allElementsInRange(ClpSimplex * model,
     89                                  double smallest, double largest);
    8790
    8891  /** Unpacks a column into an CoinIndexedvector
  • branches/devel-1/include/ClpSimplex.hpp

    r21 r23  
    351351      Also creates scaling arrays if needed.  It does scaling if needed.
    352352      16 also moves solutions etc in to work arrays
    353   */
    354   void createRim(int what,bool makeRowCopy=false);
     353      On 16 returns false if problem "bad" i.e. matrix or bounds bad
     354  */
     355  bool createRim(int what,bool makeRowCopy=false);
    355356  /// releases above arrays and does solution scaling out
    356357  void deleteRim();
    357   /// Sanity check on input data (after scaling) - returns true if okay
     358  /// Sanity check on input rim data (after scaling) - returns true if okay
    358359  bool sanityCheck();
    359360  //@}
Note: See TracChangeset for help on using the changeset viewer.