Changeset 465


Ignore:
Timestamp:
Oct 6, 2004 12:02:30 PM (15 years ago)
Author:
forrest
Message:

For empty matrices

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpModel.cpp

    r453 r465  
    709709  columnScale_ = NULL;
    710710  if (status_) {
    711     unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
    712     unsigned char * tempR = tempC + newNumberColumns;
    713     memset(tempC,0,(newNumberColumns+newNumberRows)*sizeof(unsigned char));
    714     memcpy(tempC,status_,CoinMin(newNumberColumns,numberColumns_)*sizeof(unsigned char));
    715     memcpy(tempR,status_+numberColumns_,CoinMin(newNumberRows,numberRows_)*sizeof(unsigned char));
    716     delete [] status_;
    717     status_ = tempC;
     711    if (newNumberColumns+newNumberRows) {
     712      unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
     713      unsigned char * tempR = tempC + newNumberColumns;
     714      memset(tempC,0,(newNumberColumns+newNumberRows)*sizeof(unsigned char));
     715      memcpy(tempC,status_,CoinMin(newNumberColumns,numberColumns_)*sizeof(unsigned char));
     716      memcpy(tempR,status_+numberColumns_,CoinMin(newNumberRows,numberRows_)*sizeof(unsigned char));
     717      delete [] status_;
     718      status_ = tempC;
     719    } else {
     720      // empty model - some systems don't like new [0]
     721      delete [] status_;
     722      status_ = NULL;
     723    }
    718724  }
    719725  numberRows_ = newNumberRows;
    720   if (newNumberColumns<numberColumns_) {
     726  if (newNumberColumns<numberColumns_&&matrix_->getNumCols()) {
    721727    int * which = new int[numberColumns_-newNumberColumns];
    722728    int i;
     
    755761  rowUpper_ = deleteDouble(rowUpper_,numberRows_,
    756762                              number, which, newSize);
    757   matrix_->deleteRows(number,which);
     763  if (matrix_->getNumRows())
     764    matrix_->deleteRows(number,which);
    758765  //matrix_->removeGaps();
    759766  // status
    760767  if (status_) {
    761     unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
    762                                         numberRows_,
    763                                         number, which, newSize,false);
    764     unsigned char * tempC = new unsigned char [numberColumns_+newSize];
    765     memcpy(tempC,status_,numberColumns_*sizeof(unsigned char));
    766     memcpy(tempC+numberColumns_,tempR,newSize*sizeof(unsigned char));
    767     delete [] tempR;
    768     delete [] status_;
    769     status_ = tempC;
     768    if (numberColumns_+newSize) {
     769      unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
     770                                                            numberRows_,
     771                                                            number, which, newSize,false);
     772      unsigned char * tempC = new unsigned char [numberColumns_+newSize];
     773      memcpy(tempC,status_,numberColumns_*sizeof(unsigned char));
     774      memcpy(tempC+numberColumns_,tempR,newSize*sizeof(unsigned char));
     775      delete [] tempR;
     776      delete [] status_;
     777      status_ = tempC;
     778    } else {
     779      // empty model - some systems don't like new [0]
     780      delete [] status_;
     781      status_ = NULL;
     782    }
    770783  }
    771784#if 1
     
    832845  // status
    833846  if (status_) {
    834     unsigned char * tempC  = (unsigned char *) deleteChar((char *)status_,
    835                                         numberColumns_,
    836                                         number, which, newSize,false);
    837     unsigned char * temp = new unsigned char [numberRows_+newSize];
    838     memcpy(temp,tempC,newSize*sizeof(unsigned char));
    839     memcpy(temp+newSize,status_+numberColumns_,
    840            numberRows_*sizeof(unsigned char));
    841     delete [] tempC;
    842     delete [] status_;
    843     status_ = temp;
     847    if (numberRows_+newSize) {
     848      unsigned char * tempC  = (unsigned char *) deleteChar((char *)status_,
     849                                                            numberColumns_,
     850                                                            number, which, newSize,false);
     851      unsigned char * temp = new unsigned char [numberRows_+newSize];
     852      memcpy(temp,tempC,newSize*sizeof(unsigned char));
     853      memcpy(temp+newSize,status_+numberColumns_,
     854             numberRows_*sizeof(unsigned char));
     855      delete [] tempC;
     856      delete [] status_;
     857      status_ = temp;
     858    } else {
     859      // empty model - some systems don't like new [0]
     860      delete [] status_;
     861      status_ = NULL;
     862    }
    844863  }
    845864  integerType_ = deleteChar(integerType_,numberColumns_,
  • trunk/Test/unitTest.cpp

    r462 r465  
    934934    nel=0;
    935935    int iRow , iColumn;
    936     double * lower = solution.columnLower();
    937     double * upper = solution.columnUpper();
    938     double * objective = solution.objective();
     936    const double * lower = m.getColLower();
     937    const double * upper = m.getColUpper();
     938    const double * objective = m.getObjCoefficients();
    939939    startM = m.getMatrixByCol()->getVectorStarts();
    940940    lengthM = m.getMatrixByCol()->getVectorLengths();
     
    963963    solution.dual();
    964964    assert(eq(solution.objectiveValue(),1.5185098965e+03));
     965    // Delete all columns and add back
     966    n=0;
     967    nel=0;
     968    starts[0]=0;
     969    lower = m.getColLower();
     970    upper = m.getColUpper();
     971    objective = m.getObjCoefficients();
     972    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     973      saveObj[n]=objective[iColumn];
     974      saveLower[n]=lower[iColumn];
     975      saveUpper[n]=upper[iColumn];
     976      int j;
     977      for (j=startM[iColumn];j<startM[iColumn]+lengthM[iColumn];j++) {
     978        index[nel]=indexM[j];
     979        element[nel++]=elementM[j];
     980      }
     981      which[n++]=iColumn;
     982      starts[n]=nel;
     983    }
     984    solution.deleteColumns(n,which);
     985    solution.dual();
     986    // Put back
     987    solution.addColumns(n,saveLower,saveUpper,saveObj,
     988                        starts,index,element);
     989    solution.dual();
     990    assert(eq(solution.objectiveValue(),1.5185098965e+03));
    965991
    966992    // reload with original
     
    971997    n=0;
    972998    nel=0;
    973     lower = solution.rowLower();
    974     upper = solution.rowUpper();
     999    lower = m.getRowLower();
     1000    upper = m.getRowUpper();
    9751001    startM = m.getMatrixByRow()->getVectorStarts();
    9761002    lengthM = m.getMatrixByRow()->getVectorLengths();
     
    9981024    solution.dual();
    9991025    assert(eq(solution.objectiveValue(),1.5185098965e+03));
     1026    solution.writeMps("yy.mps");
     1027    // Delete all rows
     1028    n=0;
     1029    nel=0;
     1030    lower = m.getRowLower();
     1031    upper = m.getRowUpper();
     1032    starts[0]=0;
     1033    for (iRow=0;iRow<numberRows;iRow++) {
     1034      saveLower[n]=lower[iRow];
     1035      saveUpper[n]=upper[iRow];
     1036      int j;
     1037      for (j=startM[iRow];j<startM[iRow]+lengthM[iRow];j++) {
     1038        index[nel]=indexM[j];
     1039        element[nel++]=elementM[j];
     1040      }
     1041      which[n++]=iRow;
     1042      starts[n]=nel;
     1043    }
     1044    solution.deleteRows(n,which);
     1045    solution.dual();
     1046    // Put back
     1047    solution.addRows(n,saveLower,saveUpper,
     1048                        starts,index,element);
     1049    solution.dual();
     1050    solution.writeMps("xx.mps");
     1051    assert(eq(solution.objectiveValue(),1.5185098965e+03));
    10001052    // Zero out status array to give some interest
    10011053    memset(solution.statusArray()+numberColumns,0,numberRows);
    10021054    solution.primal(1);
    10031055    assert(eq(solution.objectiveValue(),1.5185098965e+03));
     1056    // Delete all columns and rows
     1057    n=0;
     1058    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     1059      which[n++]=iColumn;
     1060      starts[n]=nel;
     1061    }
     1062    solution.deleteColumns(n,which);
     1063    n=0;
     1064    for (iRow=0;iRow<numberRows;iRow++) {
     1065      which[n++]=iRow;
     1066      starts[n]=nel;
     1067    }
     1068    solution.deleteRows(n,which);
    10041069
    10051070    delete [] saveObj;
Note: See TracChangeset for help on using the changeset viewer.