Ignore:
Timestamp:
Jun 26, 2007 3:00:48 AM (13 years ago)
Author:
forrest
Message:

moving branches/devel to trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:externals
      •  

        old new  
        11MSVisualStudio   https://projects.coin-or.org/svn/MSVisualStudio/trunk/ExternalsDirs/Clp
        22BuildTools    https://projects.coin-or.org/svn/BuildTools/trunk
        3 Data/Netlib   https://projects.coin-or.org/svn/Data/trunk/Netlib
        4 Data/Sample   https://projects.coin-or.org/svn/Data/trunk/Sample
        5 CoinUtils     https://projects.coin-or.org/svn/CoinUtils/stable/2.0/CoinUtils
         3ThirdParty/Blas https://projects.coin-or.org/svn/BuildTools/ThirdParty/Blas/stable/1.0
         4ThirdParty/Lapack https://projects.coin-or.org/svn/BuildTools/ThirdParty/Lapack/stable/1.0
         5Data/Netlib   https://projects.coin-or.org/svn/Data/stable/1.0/Netlib
         6Data/Sample   https://projects.coin-or.org/svn/Data/stable/1.0/Sample
         7CoinUtils     https://projects.coin-or.org/svn/CoinUtils/trunk/CoinUtils
  • trunk/Clp/src/ClpModel.cpp

    r1015 r1034  
    4141
    4242//#############################################################################
    43 
    44 ClpModel::ClpModel () :
     43ClpModel::ClpModel (bool emptyMessages) :
    4544
    4645  optimizationDirection_(1),
     
    7776  lengthNames_(0),
    7877  numberThreads_(0),
     78  specialOptions_(0),
    7979#ifndef CLP_NO_STD
    8080  defaultHandler_(true),
     
    103103  handler_->setLogLevel(1);
    104104  eventHandler_ = new ClpEventHandler();
    105   messages_ = ClpMessage();
    106   coinMessages_ = CoinMessage();
     105  if (!emptyMessages) {
     106    messages_ = ClpMessage();
     107    coinMessages_ = CoinMessage();
     108  }
    107109  CoinSeedRandom(1234567);
    108110}
     
    157159  eventHandler_=NULL;
    158160  whatsChanged_=0;
     161  specialOptions_ = 0;
    159162}
    160163//#############################################################################
     
    288291  gutsOfLoadModel(numrows, numcols,
    289292                  collb, colub, obj, rowlb, rowub, rowObjective);
    290   CoinPackedMatrix matrix(true,numrows,numcols,start[numcols],
     293  int numberElements = start ? start[numcols] : 0;
     294  CoinPackedMatrix matrix(true,numrows,numrows ? numcols : 0,numberElements,
    291295                              value,index,start,NULL);
    292296  matrix_ = new ClpPackedMatrix(matrix);
     
    319323ClpModel::loadProblem (  CoinModel & modelObject,bool tryPlusMinusOne)
    320324{
    321   if (modelObject.numberElements()==0)
     325  if (modelObject.numberColumns()==0&&modelObject.numberRows()==0)
    322326    return 0;
    323327  int numberErrors = 0;
     
    675679  userPointer_ = rhs.userPointer_;
    676680  scalingFlag_ = rhs.scalingFlag_;
     681  specialOptions_ = rhs.specialOptions_;
    677682  if (trueCopy) {
    678683#ifndef CLP_NO_STD
     
    707712    rowUpper_ = ClpCopyOfArray ( rhs.rowUpper_, numberRows_ );
    708713    columnLower_ = ClpCopyOfArray ( rhs.columnLower_, numberColumns_ );
     714    int scaleLength = ((specialOptions_&131072)==0) ? 1 : 2;
    709715    columnUpper_ = ClpCopyOfArray ( rhs.columnUpper_, numberColumns_ );
    710     rowScale_ = ClpCopyOfArray(rhs.rowScale_,numberRows_);
    711     columnScale_ = ClpCopyOfArray(rhs.columnScale_,numberColumns_);
     716    rowScale_ = ClpCopyOfArray(rhs.rowScale_,numberRows_*scaleLength);
     717    columnScale_ = ClpCopyOfArray(rhs.columnScale_,numberColumns_*scaleLength);
    712718    if (rhs.objective_)
    713719      objective_  = rhs.objective_->clone();
     
    830836      return false;
    831837    break;
    832   case ClpLastIntParam:
     838  default:
    833839    return false;
    834840  }
     
    875881    break;
    876882   
    877   case ClpLastDblParam:
     883  default:
    878884    return false;
    879885  }
     
    893899    break;
    894900
    895   case ClpLastStrParam:
     901  default:
    896902    return false;
    897903  }
     
    986992  CoinPackedMatrix matrix2;
    987993  matrix_=new ClpPackedMatrix(matrix2);
     994}
     995/* Really clean up matrix.
     996   a) eliminate all duplicate AND small elements in matrix
     997   b) remove all gaps and set extraGap_ and extraMajor_ to 0.0
     998   c) reallocate arrays and make max lengths equal to lengths
     999   d) orders elements
     1000   returns number of elements eliminated or -1 if not ClpMatrix
     1001*/
     1002int
     1003ClpModel::cleanMatrix(double threshold)
     1004{
     1005  ClpPackedMatrix * matrix = (dynamic_cast< ClpPackedMatrix*>(matrix_));
     1006  if (matrix) {
     1007    return matrix->getPackedMatrix()->cleanMatrix(threshold);
     1008  } else {
     1009    return -1;
     1010  }
    9881011}
    9891012// Resizes
     
    13051328    }
    13061329#endif
    1307     if (elements)
    1308       matrix_->appendMatrix(number,0,rowStarts,columns,elements);
     1330    //if (elements)
     1331    matrix_->appendMatrix(number,0,rowStarts,columns,elements);
    13091332  }
    13101333}
     
    17861809    }
    17871810#endif
    1788     if (elements)
    1789       matrix_->appendMatrix(number,1,columnStarts,rows,elements);
     1811    //if (elements)
     1812    matrix_->appendMatrix(number,1,columnStarts,rows,elements);
    17901813  }
    17911814}
     
    22582281{
    22592282  double * array = NULL;
    2260   if (problemStatus_==1&&!secondaryStatus_)
     2283  if (problemStatus_==1&&!secondaryStatus_) {
    22612284    array = ClpCopyOfArray(ray_,numberRows_);
     2285#if 0
     2286    // clean up
     2287    double largest=1.0e-30;
     2288    double smallest=COIN_DBL_MAX;
     2289    int i;
     2290    for (i=0;i<numberRows_;i++) {
     2291      double value = fabs(array[i]);
     2292      smallest = CoinMin(smallest,value);
     2293      largest = CoinMax(largest,value);
     2294    }
     2295#endif
     2296  }
    22622297  return array;
    22632298}
     
    23622397  }
    23632398  m.messageHandler()->setPrefix(savePrefix);
    2364   if (!status||ignoreErrors) {
     2399  if (!status||(ignoreErrors&&(status>0&&status<100000))) {
    23652400    loadProblem(*m.getMatrixByCol(),
    23662401                m.getColLower(),m.getColUpper(),
     
    27652800  strParam_[ClpProbName] = rhs->strParam_[ClpProbName];
    27662801#endif
    2767 
     2802  specialOptions_ = rhs->specialOptions_;
    27682803  optimizationDirection_ = rhs->optimizationDirection_;
    27692804  objectiveValue_=rhs->objectiveValue_;
     
    30083043  int iRow;
    30093044  for (iRow=first; iRow<last;iRow++) {
    3010     rowNames_[iRow]= rowNames[iRow-first];
    3011     maxLength = CoinMax(maxLength,(unsigned int) strlen(rowNames[iRow-first]));
     3045    if (rowNames[iRow-first]&&strlen(rowNames[iRow-first])) {
     3046      rowNames_[iRow]= rowNames[iRow-first];
     3047      maxLength = CoinMax(maxLength,(unsigned int) strlen(rowNames[iRow-first]));
     3048    } else {
     3049      maxLength = CoinMax(maxLength,(unsigned int) 8);
     3050      char name[9];
     3051      sprintf(name,"R%7.7d",iRow);
     3052      rowNames_[iRow]=name;
     3053    }
    30123054  }
    30133055  // May be too big - but we would have to check both rows and columns to be exact
     
    30243066  int iColumn;
    30253067  for (iColumn=first; iColumn<last;iColumn++) {
    3026     columnNames_[iColumn]= columnNames[iColumn-first];
    3027     maxLength = CoinMax(maxLength,(unsigned int) strlen(columnNames[iColumn-first]));
     3068    if (columnNames[iColumn-first]&&strlen(columnNames[iColumn-first])) {
     3069      columnNames_[iColumn]= columnNames[iColumn-first];
     3070      maxLength = CoinMax(maxLength,(unsigned int) strlen(columnNames[iColumn-first]));
     3071    } else {
     3072      maxLength = CoinMax(maxLength,(unsigned int) 8);
     3073      char name[9];
     3074      sprintf(name,"C%7.7d",iColumn);
     3075      columnNames_[iColumn]=name;
     3076    }
    30283077  }
    30293078  // May be too big - but we would have to check both rows and columns to be exact
     
    34163465  columnScale_ = NULL;
    34173466}
     3467void
     3468ClpModel::setSpecialOptions(unsigned int value)
     3469{
     3470  specialOptions_=value;
     3471}
     3472/* This creates a coinModel object
     3473 */
     3474CoinModel *
     3475ClpModel::createCoinModel() const
     3476{
     3477  CoinModel * coinModel = new CoinModel();
     3478  CoinPackedMatrix matrixByRow;
     3479  matrixByRow.reverseOrderedCopyOf(*matrix());
     3480  coinModel->setObjectiveOffset(objectiveOffset());
     3481  coinModel->setProblemName(problemName().c_str());
     3482
     3483  // Build by row from scratch
     3484  const double * element = matrixByRow.getElements();
     3485  const int * column = matrixByRow.getIndices();
     3486  const CoinBigIndex * rowStart = matrixByRow.getVectorStarts();
     3487  const int * rowLength = matrixByRow.getVectorLengths();
     3488  int i;
     3489  for (i=0;i<numberRows_;i++) {
     3490    coinModel->addRow(rowLength[i],column+rowStart[i],
     3491                      element+rowStart[i],rowLower_[i],rowUpper_[i]);
     3492  }
     3493  // Now do column part
     3494  const double * objective = this->objective();
     3495  for (i=0;i<numberColumns_;i++) {
     3496    coinModel->setColumnBounds(i,columnLower_[i],columnUpper_[i]);
     3497    coinModel->setColumnObjective(i,objective[i]);
     3498  }
     3499  for ( i=0;i<numberColumns_;i++) {
     3500    if (isInteger(i))
     3501      coinModel->setColumnIsInteger(i,true);
     3502  }
     3503  // do names
     3504  for (i=0;i<numberRows_;i++) {
     3505    char temp[30];
     3506    strcpy(temp,rowName(i).c_str());
     3507    int length = strlen(temp);
     3508    for (int j=0;j<length;j++) {
     3509      if (temp[j]=='-')
     3510        temp[j]='_';
     3511    }
     3512    coinModel->setRowName(i,temp);
     3513  }
     3514  for (i=0;i<numberColumns_;i++) {
     3515    char temp[30];
     3516    strcpy(temp,columnName(i).c_str());
     3517    int length = strlen(temp);
     3518    for (int j=0;j<length;j++) {
     3519      if (temp[j]=='-')
     3520        temp[j]='_';
     3521    }
     3522    coinModel->setColumnName(i,temp);
     3523  }
     3524  ClpQuadraticObjective * obj = (dynamic_cast< ClpQuadraticObjective*>(objective_));
     3525  if (obj) {
     3526    const CoinPackedMatrix * quadObj = obj->quadraticObjective();
     3527    // add in quadratic
     3528    const double * element = quadObj->getElements();
     3529    const int * row = quadObj->getIndices();
     3530    const CoinBigIndex * columnStart = quadObj->getVectorStarts();
     3531    const int * columnLength = quadObj->getVectorLengths();
     3532    for (i=0;i<numberColumns_;i++) {
     3533      int nels = columnLength[i];
     3534      if (nels) {
     3535        CoinBigIndex start = columnStart[i];
     3536        double constant = coinModel->getColumnObjective(i);
     3537        char temp[100000];
     3538        char temp2[30];
     3539        sprintf(temp,"%g",constant);
     3540        for (CoinBigIndex k=start;k<start+nels;k++) {
     3541          int kColumn = row[k];
     3542          double value = element[k];
     3543#if 1
     3544          // ampl gives twice with assumed 0.5
     3545          if (kColumn<i)
     3546            continue;
     3547          else if (kColumn==i)
     3548            value *= 0.5;
     3549#endif
     3550          if (value==1.0)
     3551            sprintf(temp2,"+%s",coinModel->getColumnName(kColumn));
     3552          else if (value==-1.0)
     3553            sprintf(temp2,"-%s",coinModel->getColumnName(kColumn));
     3554          else if (value>0.0)
     3555            sprintf(temp2,"+%g*%s",value,coinModel->getColumnName(kColumn));
     3556          else
     3557            sprintf(temp2,"%g*%s",value,coinModel->getColumnName(kColumn));
     3558          strcat(temp,temp2);
     3559          assert (strlen(temp)<100000);
     3560        }
     3561        coinModel->setObjective(i,temp);
     3562        if (logLevel()>2)
     3563          printf("el for objective column %s is %s\n",coinModel->getColumnName(i),temp);
     3564      }
     3565    }
     3566  }
     3567  return coinModel;
     3568}
    34183569//#############################################################################
    34193570// Constructors / Destructor / Assignment
Note: See TracChangeset for help on using the changeset viewer.