Changeset 470


Ignore:
Timestamp:
Oct 8, 2004 1:24:29 PM (15 years ago)
Author:
forrest
Message:

Extra functions

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpModel.cpp

    r466 r470  
    292292    lower=rowLower_[iRow];
    293293}
     294//------------------------------------------------------------------
     295/* Set an objective function coefficient */
     296void
     297ClpModel::setObjectiveCoefficient( int elementIndex, double elementValue )
     298{
     299#ifndef NDEBUG
     300  if (elementIndex<0||elementIndex>=numberColumns_) {
     301    indexError(elementIndex,"setObjectiveCoefficient");
     302  }
     303#endif
     304  objective()[elementIndex] = elementValue;
     305}
     306/* Set a single row lower bound<br>
     307   Use -DBL_MAX for -infinity. */
     308void
     309ClpModel::setRowLower( int elementIndex, double elementValue ) {
     310  if (elementValue<-1.0e27)
     311    elementValue=-COIN_DBL_MAX;
     312  rowLower_[elementIndex] = elementValue;
     313}
     314     
     315/* Set a single row upper bound<br>
     316   Use DBL_MAX for infinity. */
     317void
     318ClpModel::setRowUpper( int elementIndex, double elementValue ) {
     319  if (elementValue>1.0e27)
     320    elementValue=COIN_DBL_MAX;
     321  rowUpper_[elementIndex] = elementValue;
     322}
     323   
     324/* Set a single row lower and upper bound */
     325void
     326ClpModel::setRowBounds( int elementIndex,
     327              double lower, double upper ) {
     328  if (lower<-1.0e27)
     329    lower=-COIN_DBL_MAX;
     330  if (upper>1.0e27)
     331    upper=COIN_DBL_MAX;
     332  assert (upper>=lower);
     333  rowLower_[elementIndex] = lower;
     334  rowUpper_[elementIndex] = upper;
     335}
     336void ClpModel::setRowSetBounds(const int* indexFirst,
     337                                            const int* indexLast,
     338                                            const double* boundList)
     339{
     340#ifndef NDEBUG
     341  int n = numberRows_;
     342#endif
     343  double * lower = rowLower_;
     344  double * upper = rowUpper_;
     345  while (indexFirst != indexLast) {
     346    const int iRow=*indexFirst++;
     347#ifndef NDEBUG
     348    if (iRow<0||iRow>=n) {
     349      indexError(iRow,"setRowSetBounds");
     350    }
     351#endif
     352    lower[iRow]= *boundList++;
     353    upper[iRow]= *boundList++;
     354    if (lower[iRow]<-1.0e27)
     355      lower[iRow]=-COIN_DBL_MAX;
     356    if (upper[iRow]>1.0e27)
     357      upper[iRow]=COIN_DBL_MAX;
     358    assert (upper[iRow]>=lower[iRow]);
     359  }
     360}
     361//-----------------------------------------------------------------------------
     362/* Set a single column lower bound<br>
     363   Use -DBL_MAX for -infinity. */
     364void
     365ClpModel::setColumnLower( int elementIndex, double elementValue )
     366{
     367#ifndef NDEBUG
     368  int n = numberColumns_;
     369  if (elementIndex<0||elementIndex>=n) {
     370    indexError(elementIndex,"setColumnLower");
     371  }
     372#endif
     373  if (elementValue<-1.0e27)
     374    elementValue=-COIN_DBL_MAX;
     375  columnLower_[elementIndex] = elementValue;
     376}
     377     
     378/* Set a single column upper bound<br>
     379   Use DBL_MAX for infinity. */
     380void
     381ClpModel::setColumnUpper( int elementIndex, double elementValue )
     382{
     383#ifndef NDEBUG
     384  int n = numberColumns_;
     385  if (elementIndex<0||elementIndex>=n) {
     386    indexError(elementIndex,"setColumnUpper");
     387  }
     388#endif
     389  if (elementValue>1.0e27)
     390    elementValue=COIN_DBL_MAX;
     391  columnUpper_[elementIndex] = elementValue;
     392}
     393
     394/* Set a single column lower and upper bound */
     395void
     396ClpModel::setColumnBounds( int elementIndex,
     397                                     double lower, double upper )
     398{
     399#ifndef NDEBUG
     400  int n = numberColumns_;
     401  if (elementIndex<0||elementIndex>=n) {
     402    indexError(elementIndex,"setColumnBounds");
     403  }
     404#endif
     405  if (lower<-1.0e27)
     406    lower=-COIN_DBL_MAX;
     407  if (upper>1.0e27)
     408    upper=COIN_DBL_MAX;
     409  columnLower_[elementIndex] = lower;
     410  columnUpper_[elementIndex] = upper;
     411  assert (upper>=lower);
     412}
     413void ClpModel::setColumnSetBounds(const int* indexFirst,
     414                                            const int* indexLast,
     415                                            const double* boundList)
     416{
     417  double * lower = columnLower_;
     418  double * upper = columnUpper_;
     419#ifndef NDEBUG
     420  int n = numberColumns_;
     421#endif
     422  while (indexFirst != indexLast) {
     423    const int iColumn=*indexFirst++;
     424#ifndef NDEBUG
     425    if (iColumn<0||iColumn>=n) {
     426      indexError(iColumn,"setColumnSetBounds");
     427    }
     428#endif
     429    lower[iColumn]= *boundList++;
     430    upper[iColumn]= *boundList++;
     431    assert (upper[iColumn]>=lower[iColumn]);
     432    if (lower[iColumn]<-1.0e27)
     433      lower[iColumn]=-COIN_DBL_MAX;
     434    if (upper[iColumn]>1.0e27)
     435      upper[iColumn]=COIN_DBL_MAX;
     436  }
     437}
     438//-----------------------------------------------------------------------------
    294439//#############################################################################
    295440// Copy constructor.
     
    17201865  lengthNames_=(int) maxLength;
    17211866}
     1867// Copies in Row names - modifies names first .. last-1
     1868void
     1869ClpModel::copyRowNames(const std::vector<std::string> & rowNames, int first, int last)
     1870{
     1871  unsigned int maxLength=lengthNames_;
     1872  int size = rowNames_.size();
     1873  if (size!=numberRows_)
     1874    rowNames_.resize(numberRows_);
     1875  int iRow;
     1876  for (iRow=first; iRow<last;iRow++) {
     1877    rowNames_[iRow]= rowNames[iRow-first];
     1878    maxLength = CoinMax(maxLength,(unsigned int) strlen(rowNames_[iRow].c_str()));
     1879  }
     1880  // May be too big - but we would have to check both rows and columns to be exact
     1881  lengthNames_=(int) maxLength;
     1882}
     1883// Copies in Column names - modifies names first .. last-1
     1884void
     1885ClpModel::copyColumnNames(const std::vector<std::string> & columnNames, int first, int last)
     1886{
     1887  unsigned int maxLength=lengthNames_;
     1888  int size = columnNames_.size();
     1889  if (size!=numberColumns_)
     1890    columnNames_.resize(numberColumns_);
     1891  int iColumn;
     1892  for (iColumn=first; iColumn<last;iColumn++) {
     1893    columnNames_[iColumn]= columnNames[iColumn-first];
     1894    maxLength = CoinMax(maxLength,(unsigned int) strlen(columnNames_[iColumn].c_str()));
     1895  }
     1896  // May be too big - but we would have to check both rows and columns to be exact
     1897  lengthNames_=(int) maxLength;
     1898}
     1899// Primal objective limit
     1900void
     1901ClpModel::setPrimalObjectiveLimit(double value)
     1902{
     1903  dblParam_[ClpPrimalObjectiveLimit]=value;
     1904}
    17221905// Dual objective limit
    17231906void
     
    17461929  pivotTolerance_=0.0;
    17471930  perturbation_ = 0;
     1931  forceFactorization_=-1;
    17481932}
    17491933
     
    17581942  sparseThreshold_ = rhs.sparseThreshold_;
    17591943  perturbation_ = rhs.perturbation_;
     1944  forceFactorization_=rhs.forceFactorization_;
    17601945}
    17611946
     
    17801965    sparseThreshold_ = rhs.sparseThreshold_;
    17811966    perturbation_ = rhs.perturbation_;
     1967    forceFactorization_=rhs.forceFactorization_;
    17821968  }
    17831969  return *this;
  • trunk/include/ClpModel.hpp

    r468 r470  
    182182  void copyNames(std::vector<std::string> & rowNames,
    183183                 std::vector<std::string> & columnNames);
     184  /// Copies in Row names - modifies names first .. last-1
     185  void copyRowNames(const std::vector<std::string> & rowNames,int first, int last);
     186  /// Copies in Column names - modifies names first .. last-1
     187  void copyColumnNames(const std::vector<std::string> & columnNames, int first, int last);
    184188 
    185189    /** Write the problem in MPS format to the specified file.
     
    223227   inline double dualTolerance() const  { return dblParam_[ClpDualTolerance]; }
    224228   void setDualTolerance( double value) ;
     229  /// Primal objective limit
     230  inline double primalObjectiveLimit() const { return dblParam_[ClpPrimalObjectiveLimit];}
     231  void setPrimalObjectiveLimit(double value);
    225232  /// Dual objective limit
    226233  inline double dualObjectiveLimit() const { return dblParam_[ClpDualObjectiveLimit];}
     
    313320   inline double* rowUpper() const              { return rowUpper_; }
    314321   inline const double* getRowUpper() const     { return rowUpper_; }
     322    //-------------------------------------------------------------------------
     323    /**@name Changing bounds on variables and constraints */
     324    //@{
     325       /** Set an objective function coefficient */
     326       void setObjectiveCoefficient( int elementIndex, double elementValue );
     327       /** Set an objective function coefficient */
     328       inline void setObjCoeff( int elementIndex, double elementValue )
     329       { setObjectiveCoefficient( elementIndex, elementValue);};
     330
     331      /** Set a single column lower bound<br>
     332          Use -DBL_MAX for -infinity. */
     333       void setColumnLower( int elementIndex, double elementValue );
     334     
     335      /** Set a single column upper bound<br>
     336          Use DBL_MAX for infinity. */
     337       void setColumnUpper( int elementIndex, double elementValue );
     338
     339      /** Set a single column lower and upper bound */
     340      void setColumnBounds( int elementIndex,
     341        double lower, double upper );
     342
     343      /** Set the bounds on a number of columns simultaneously<br>
     344          The default implementation just invokes setColLower() and
     345          setColUpper() over and over again.
     346          @param indexFirst,indexLast pointers to the beginning and after the
     347                 end of the array of the indices of the variables whose
     348                 <em>either</em> bound changes
     349          @param boundList the new lower/upper bound pairs for the variables
     350      */
     351      void setColumnSetBounds(const int* indexFirst,
     352                                   const int* indexLast,
     353                                   const double* boundList);
     354     
     355      /** Set a single column lower bound<br>
     356          Use -DBL_MAX for -infinity. */
     357       inline void setColLower( int elementIndex, double elementValue )
     358       { setColumnLower(elementIndex, elementValue);};
     359      /** Set a single column upper bound<br>
     360          Use DBL_MAX for infinity. */
     361       inline void setColUpper( int elementIndex, double elementValue )
     362       { setColumnUpper(elementIndex, elementValue);};
     363
     364      /** Set a single column lower and upper bound */
     365      inline void setColBounds( int elementIndex,
     366        double lower, double upper )
     367       { setColumnBounds(elementIndex, lower, upper);};
     368
     369      /** Set the bounds on a number of columns simultaneously<br>
     370          @param indexFirst,indexLast pointers to the beginning and after the
     371                 end of the array of the indices of the variables whose
     372                 <em>either</em> bound changes
     373          @param boundList the new lower/upper bound pairs for the variables
     374      */
     375      inline void setColSetBounds(const int* indexFirst,
     376                                   const int* indexLast,
     377                                   const double* boundList)
     378      { setColumnSetBounds(indexFirst, indexLast, boundList);};
     379     
     380      /** Set a single row lower bound<br>
     381          Use -DBL_MAX for -infinity. */
     382      void setRowLower( int elementIndex, double elementValue );
     383     
     384      /** Set a single row upper bound<br>
     385          Use DBL_MAX for infinity. */
     386      void setRowUpper( int elementIndex, double elementValue ) ;
     387   
     388      /** Set a single row lower and upper bound */
     389      void setRowBounds( int elementIndex,
     390                                 double lower, double upper ) ;
     391   
     392      /** Set the bounds on a number of rows simultaneously<br>
     393          @param indexFirst,indexLast pointers to the beginning and after the
     394                 end of the array of the indices of the constraints whose
     395                 <em>either</em> bound changes
     396          @param boundList the new lower/upper bound pairs for the constraints
     397      */
     398      void setRowSetBounds(const int* indexFirst,
     399                                   const int* indexLast,
     400                                   const double* boundList);
     401   
     402    //@}
    315403   /// Scaling
    316404   inline const double * rowScale() const {return rowScale_;};
     
    411499   double * infeasibilityRay() const;
    412500   double * unboundedRay() const;
    413   /// See if status array exists (partly for OsiClp)
     501  /// See if status (i.e. basis) array exists (partly for OsiClp)
    414502  inline bool statusExists() const
    415503  { return (status_!=NULL);};
    416   /// Return address of status array (char[numberRows+numberColumns])
     504  /// Return address of status (i.e. basis) array (char[numberRows+numberColumns])
    417505  inline unsigned char *  statusArray() const
    418506  { return status_;};
    419   /** Return copy of status array (char[numberRows+numberColumns]),
     507  /** Return copy of status (i.e. basis) array (char[numberRows+numberColumns]),
    420508      use delete [] */
    421509  unsigned char *  statusCopy() const;
    422   /// Copy in status vector
     510  /// Copy in status (basis) vector
    423511  void copyinStatus(const unsigned char * statusArray);
    424512
     
    632720  /// Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic
    633721  int scalingFlag_;
    634   /** Status Region.  I know that not all algorithms need a status
     722  /** Status (i.e. basis) Region.  I know that not all algorithms need a status
    635723      array, but it made sense for things like crossover and put
    636724      all permanent stuff in one place.  No assumption is made
Note: See TracChangeset for help on using the changeset viewer.