Changeset 1197


Ignore:
Timestamp:
Apr 28, 2008 11:38:45 AM (12 years ago)
Author:
forrest
Message:

many changes to try and improve performance

Location:
trunk/Clp/src
Files:
47 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/src/CbcOrClpParam.cpp

    r1160 r1197  
    15581558#ifdef COIN_HAS_CBC
    15591559  parameters[numberParameters++]=
     1560    CbcOrClpParam("diveO!pt","Diving options",
     1561                  -1,200,DIVEOPT,false);
     1562  parameters[numberParameters-1].setLonghelp
     1563    (
     1564     "If >2 && <7 then modify diving options"
     1565     );
     1566  parameters[numberParameters-1].setIntValue(-1);
     1567  parameters[numberParameters++]=
    15601568      CbcOrClpParam("Diving","Whether to try Diving heuristics",
    15611569                    "off",DIVING);
     
    16841692     "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    16851693     );
     1694#ifdef COIN_HAS_CBC
     1695  parameters[numberParameters++]=
     1696    CbcOrClpParam("exp!eriment","Whether to use testing features",
     1697                  -1,200,EXPERIMENT,false);
     1698  parameters[numberParameters-1].setLonghelp
     1699    (
     1700     "If >0 then use some dubious scheme (for testing)"
     1701     );
     1702  parameters[numberParameters-1].setIntValue(-1);
     1703#endif
    16861704  parameters[numberParameters++]=
    16871705    CbcOrClpParam("export","Export model as mps file",
     
    17081726  parameters[numberParameters++]=
    17091727    CbcOrClpParam("extra4","Extra integer parameter 4",
    1710                   -1,COIN_INT_MAX,EXTRA4,false);
     1728                  -COIN_INT_MAX,COIN_INT_MAX,EXTRA4,false);
    17111729  parameters[numberParameters-1].setIntValue(-1);
    17121730#endif
     
    22632281  parameters[numberParameters-1].append("strategy");
    22642282  parameters[numberParameters-1].append("aggregate");
     2283  parameters[numberParameters-1].append("forcesos");
    22652284  parameters[numberParameters-1].setLonghelp
    22662285    (
     
    28932912        double * temp = new double [CoinMax(numberRowsFile,numberColumnsFile)];
    28942913        fread(temp,sizeof(double),numberRowsFile,fp);
    2895         memcpy(primalRowSolution,temp,numberRows*sizeof(double));
     2914 CoinMemcpyN(temp,numberRows,primalRowSolution);
    28962915        fread(temp,sizeof(double),numberRowsFile,fp);
    2897         memcpy(dualRowSolution,temp,numberRows*sizeof(double));
     2916 CoinMemcpyN(temp,numberRows,dualRowSolution);
    28982917        fread(temp,sizeof(double),numberColumnsFile,fp);
    2899         memcpy(primalColumnSolution,temp,numberColumns*sizeof(double));
     2918 CoinMemcpyN(temp,numberColumns,primalColumnSolution);
    29002919        fread(temp,sizeof(double),numberColumnsFile,fp);
    2901         memcpy(dualColumnSolution,temp,numberColumns*sizeof(double));
     2920 CoinMemcpyN(temp,numberColumns,dualColumnSolution);
    29022921        delete [] temp;
    29032922      }
  • trunk/Clp/src/CbcOrClpParam.hpp

    r1160 r1197  
    6666    NUMBERMINI,MIPOPTIONS,MOREMIPOPTIONS,MAXHOTITS,FPUMPITS,MAXSOLS,
    6767    FPUMPTUNE,TESTOSI,EXTRA1,EXTRA2,EXTRA3,EXTRA4,CUTPASSINTREE,
    68     THREADS,CUTPASS,VUBTRY,DENSE,
     68    THREADS,CUTPASS,VUBTRY,DENSE,EXPERIMENT,DIVEOPT,
    6969#ifdef COIN_HAS_CBC
    7070    LOGLEVEL ,
  • trunk/Clp/src/ClpCholeskyBase.cpp

    r894 r1197  
    9191  workInteger_ = ClpCopyOfArray(rhs.workInteger_,numberRows_);
    9292  clique_ = ClpCopyOfArray(rhs.clique_,numberRows_);
    93   memcpy(integerParameters_,rhs.integerParameters_,64*sizeof(int));
    94   memcpy(doubleParameters_,rhs.doubleParameters_,64*sizeof(double));
     93  CoinMemcpyN(rhs.integerParameters_,64,integerParameters_);
     94  CoinMemcpyN(rhs.doubleParameters_,64,doubleParameters_);
    9595  rowCopy_ = rhs.rowCopy_->clone();
    9696  whichDense_ = NULL;
     
    793793        used[np++]=originalRow;
    794794    }
    795     memcpy(permute_+nn,used,np*sizeof(int));
     795    CoinMemcpyN(used,np,permute_+nn);
    796796    for (iRow=0;iRow<numberRows_;iRow++)
    797797      permuteInverse_[permute_[iRow]]=iRow;
     
    12141214      }
    12151215      if (!noMemory)  {
    1216         memcpy(indices,choleskyRow_,sizeIndex_*sizeof(int));
     1216 CoinMemcpyN(choleskyRow_,sizeIndex_,indices);
    12171217        delete [] choleskyRow_;
    12181218        choleskyRow_=indices;
  • trunk/Clp/src/ClpCholeskyDense.cpp

    r1034 r1197  
    424424  sparseFactor_=diagonal_ + numberRows_;
    425425  //memcpy(sparseFactor_,xx,sizeFactor_*sizeof(double));
    426   memcpy(sparseFactor_,xx,40000*sizeof(double));
    427   memcpy(diagonal_,yy,numberRows_*sizeof(double));
     426  CoinMemcpyN(xx,40000,sparseFactor_);
     427  CoinMemcpyN(yy,numberRows_,diagonal_);
    428428  int numberDropped=0;
    429429  double largest=0.0;
  • trunk/Clp/src/ClpCholeskyTaucs.cpp

    r754 r1197  
    4545  if (matrix_) {
    4646    choleskyStartT_ = (int *) malloc((numberRows_+1)*sizeof(int));
    47     memcpy(choleskyStartT_,rhs.choleskyStartT_,(numberRows_+1)*sizeof(int));
     47    CoinMemcpyN(rhs.choleskyStartT_,(numberRows_+1),choleskyStartT_);
    4848    choleskyRowT_ = (int *) malloc(sizeFactorT_*sizeof(int));
    49     memcpy(choleskyRowT_,rhs.choleskyRowT_,sizeFactorT_*sizeof(int));
     49    CoinMemcpyN(rhs.choleskyRowT_,sizeFactorT_,choleskyRowT_);
    5050    sparseFactorT_ = (double *) malloc(sizeFactorT_*sizeof(double));
    51     memcpy(sparseFactorT_,rhs.sparseFactorT_,sizeFactorT_*sizeof(double));
     51    CoinMemcpyN(rhs.sparseFactorT_,sizeFactorT_,sparseFactorT_);
    5252    matrix_->colptr = choleskyStartT_;
    5353    matrix_->rowind = choleskyRowT_;
     
    9090    if (matrix_) {
    9191      choleskyStartT_ = (int *) malloc((numberRows_+1)*sizeof(int));
    92       memcpy(choleskyStartT_,rhs.choleskyStartT_,(numberRows_+1)*sizeof(int));
     92      CoinMemcpyN(rhs.choleskyStartT_,(numberRows_+1),choleskyStartT_);
    9393      choleskyRowT_ = (int *) malloc(sizeFactorT_*sizeof(int));
    94       memcpy(choleskyRowT_,rhs.choleskyRowT_,sizeFactorT_*sizeof(int));
     94      CoinMemcpyN(rhs.choleskyRowT_,sizeFactorT_,choleskyRowT_);
    9595      sparseFactorT_ = (double *) malloc(sizeFactorT_*sizeof(double));
    96       memcpy(sparseFactorT_,rhs.sparseFactorT_,sizeFactorT_*sizeof(double));
     96      CoinMemcpyN(rhs.sparseFactorT_,sizeFactorT_,sparseFactorT_);
    9797      matrix_->colptr = choleskyStartT_;
    9898      matrix_->rowind = choleskyRowT_;
     
    220220  else
    221221    taucs_ccs_order(matrix_,&perm,&invp,(const char *) "identity");
    222   memcpy(permuteInverse_,perm,numberRows_*sizeof(int));
     222  CoinMemcpyN(perm,numberRows_,permuteInverse_);
    223223  free(perm);
    224   memcpy(permute_,invp,numberRows_*sizeof(int));
     224  CoinMemcpyN(invp,numberRows_,permute_);
    225225  free(invp);
    226226  // need to permute
  • trunk/Clp/src/ClpCholeskyUfl.cpp

    r980 r1197  
    4747#ifdef CLP_USE_CHOLMOD
    4848  cholmod_free_factor (&L_, &c_) ;
    49   cholmod_finish (&c_) ;               
     49  cholmod_finish (&c_) ;
    5050#endif
    5151}
  • trunk/Clp/src/ClpConstraintLinear.cpp

    r1035 r1197  
    126126  functionValue = functionValue_;
    127127  offset=0.0;
    128   memcpy(gradient,lastGradient_,numberColumns_*sizeof(double));
     128  CoinMemcpyN(lastGradient_,numberColumns_,gradient);
    129129  return 0;
    130130}
  • trunk/Clp/src/ClpConstraintQuadratic.cpp

    r1059 r1197  
    180180  functionValue = functionValue_;
    181181  offset = offset_;
    182   memcpy(gradient,lastGradient_,numberColumns_*sizeof(double));
     182  CoinMemcpyN(lastGradient_,numberColumns_,gradient);
    183183  return 0;
    184184}
  • trunk/Clp/src/ClpDualRowDantzig.cpp

    r754 r1197  
    55#include "ClpSimplex.hpp"
    66#include "ClpDualRowDantzig.hpp"
     7#include "ClpFactorization.hpp"
    78#include "CoinIndexedVector.hpp"
    89#include "CoinHelperFunctions.hpp"
     
    7778  return chosenRow;
    7879}
    79 // Returns pivot alpha
     80// FT update and returns pivot alpha
    8081double
    8182ClpDualRowDantzig::updateWeights(CoinIndexedVector * input,
    8283                                  CoinIndexedVector * spare,
     84                                 CoinIndexedVector * spare2,
    8385                                  CoinIndexedVector * updatedColumn)
    8486{
     87  // Do FT update
     88  model_->factorization()->updateColumnFT(spare,updatedColumn);
    8589  // pivot element
    8690  double alpha=0.0;
  • trunk/Clp/src/ClpDualRowDantzig.hpp

    r754 r1197  
    2424  virtual int pivotRow();
    2525 
    26   /// Updates weights and returns pivot alpha
     26  /** Updates weights and returns pivot alpha.
     27      Also does FT update */
    2728  virtual double updateWeights(CoinIndexedVector * input,
    2829                             CoinIndexedVector * spare,
     30                             CoinIndexedVector * spare2,
    2931                             CoinIndexedVector * updatedColumn);
    3032  /** Updates primal solution (and maybe list of candidates)
  • trunk/Clp/src/ClpDualRowPivot.hpp

    r1055 r1197  
    2727  virtual int pivotRow() = 0;
    2828 
    29   /// Updates weights and returns pivot alpha
     29  /** Updates weights and returns pivot alpha.
     30      Also does FT update */
    3031  virtual double updateWeights(CoinIndexedVector * input,
    3132                             CoinIndexedVector * spare,
     33                             CoinIndexedVector * spare2,
    3234                             CoinIndexedVector * updatedColumn) = 0;
    3335 
  • trunk/Clp/src/ClpDualRowSteepest.cpp

    r1175 r1197  
    147147  return *this;
    148148}
     149// Fill most values
     150void
     151ClpDualRowSteepest::fill(const ClpDualRowSteepest& rhs)
     152{
     153  state_=rhs.state_;
     154  mode_ = rhs.mode_;
     155  persistence_ = rhs.persistence_;
     156  assert (model_->numberRows()==rhs.model_->numberRows());
     157  model_ = rhs.model_;
     158  assert(model_);
     159  int number = model_->numberRows();
     160  if (rhs.savedWeights_)
     161    number = CoinMin(number,rhs.savedWeights_->capacity());
     162  if (rhs.infeasible_!=NULL) {
     163    if (!infeasible_)
     164      infeasible_= new CoinIndexedVector(rhs.infeasible_);
     165    else
     166      *infeasible_ = *rhs.infeasible_;
     167  } else {
     168    delete infeasible_;
     169    infeasible_=NULL;
     170  }
     171  if (rhs.weights_!=NULL) {
     172    if (!weights_)
     173      weights_= new double[number];
     174    ClpDisjointCopyN(rhs.weights_,number,weights_);
     175  } else {
     176    delete [] weights_;
     177    weights_=NULL;
     178  }
     179  if (rhs.alternateWeights_!=NULL) {
     180    if (!alternateWeights_)
     181      alternateWeights_= new CoinIndexedVector(rhs.alternateWeights_);
     182    else
     183      *alternateWeights_ = *rhs.alternateWeights_;
     184  } else {
     185    delete alternateWeights_;
     186    alternateWeights_=NULL;
     187  }
     188  if (rhs.savedWeights_!=NULL) {
     189    if (!savedWeights_)
     190      savedWeights_= new CoinIndexedVector(rhs.savedWeights_);
     191    else
     192      *savedWeights_ = *rhs.savedWeights_;
     193  } else {
     194    delete savedWeights_;
     195    savedWeights_=NULL;
     196  }
     197  if (rhs.dubiousWeights_) {
     198    assert(model_);
     199    int number = model_->numberRows();
     200    if (!dubiousWeights_)
     201      dubiousWeights_= new int[number];
     202    ClpDisjointCopyN(rhs.dubiousWeights_,number,dubiousWeights_);
     203  } else {
     204    delete [] dubiousWeights_;
     205    dubiousWeights_=NULL;
     206  }
     207}
    149208// Returns pivot row, -1 if none
    150209int
     
    160219  int chosenRow=-1;
    161220  int lastPivotRow = model_->pivotRow();
     221  assert (lastPivotRow<model_->numberRows());
    162222  double tolerance=model_->currentPrimalTolerance();
    163223  // we can't really trust infeasibilities if there is primal error
     
    176236  //#define COLUMN_BIAS 4.0
    177237  //#define FIXED_BIAS 10.0
    178   if (lastPivotRow>=0) {
     238  if (lastPivotRow>=0&&lastPivotRow<model_->numberRows()) {
     239#if defined (__MINGW32__) || defined(__CYGWIN32__)
     240    if (model_->numberIterations()<0)
     241      printf("aab_p it %d\n",model_->numberIterations());
     242#endif
    179243#if defined (__MINGW32__) || defined(__CYGWIN32__)
    180244    if (model_->numberIterations()<0)
     
    329393  return chosenRow;
    330394}
    331 // Updates weights and returns pivot alpha
     395#if 0
     396static double ft_count=0.0;
     397static double up_count=0.0;
     398static double ft_count_in=0.0;
     399static double up_count_in=0.0;
     400static int xx_count=0;
     401#endif
     402/* Updates weights and returns pivot alpha.
     403   Also does FT update */
    332404double
    333405ClpDualRowSteepest::updateWeights(CoinIndexedVector * input,
    334406                                  CoinIndexedVector * spare,
     407                                  CoinIndexedVector * spare2,
    335408                                  CoinIndexedVector * updatedColumn)
    336409{
     410  //#define CLP_DEBUG 3
    337411#if CLP_DEBUG>2
    338412  // Very expensive debug
     
    417491    }
    418492    spare->setNumElements ( numberNonZero );
    419     // Only one array active as already permuted
    420     model_->factorization()->updateColumn(spare,spare,true);
     493    // Do FT update
     494#if 0
     495    ft_count_in+= updatedColumn->getNumElements();
     496    up_count_in+= spare->getNumElements();
     497#endif
     498    if (permute) {
     499#if CLP_DEBUG>2
     500      printf("REGION before %d els\n",spare->getNumElements());
     501      spare->print();
     502#endif
     503      model_->factorization()->updateTwoColumnsFT(spare2,updatedColumn,
     504                                                  spare,true);
     505#if CLP_DEBUG>2
     506      printf("REGION after %d els\n",spare->getNumElements());
     507      spare->print();
     508#endif
     509   } else {
     510      // Leave as old way
     511      model_->factorization()->updateColumnFT(spare2,updatedColumn);
     512      model_->factorization()->updateColumn(spare2,spare,false);
     513    }
     514#undef CLP_DEBUG
     515#if 0
     516    ft_count+= updatedColumn->getNumElements();
     517    up_count+= spare->getNumElements();
     518    xx_count++;
     519    if ((xx_count%1000)==0)
     520      printf("zz %d ft %g up %g (in %g %g)\n",xx_count,ft_count,up_count,
     521             ft_count_in,up_count_in);
     522#endif
    421523    numberNonZero = spare->getNumElements();
    422524    // alternateWeights_ should still be empty
     
    453555      which3[nSave++]=iRow;
    454556      // transform to match spare
    455       int jRow = pivotColumn[iRow];
     557      int jRow = permute ? pivotColumn[iRow] : iRow;
    456558      double value = work2[jRow];
    457559      devex +=  theta * (theta*norm+value * multiplier);
     
    472574#endif
    473575  } else {
     576    // Do FT update
     577    model_->factorization()->updateColumnFT(spare,updatedColumn);
    474578    // clear other region
    475579    alternateWeights_->clear();
     
    803907      if (mode!=4) {
    804908        // save
    805         memcpy(savedWeights_->getIndices(),which,
    806                numberRows*sizeof(int));
    807         memcpy(savedWeights_->denseVector(),weights_,
    808                numberRows*sizeof(double));
     909 CoinMemcpyN(which,     numberRows,savedWeights_->getIndices());
     910 CoinMemcpyN(weights_,  numberRows,savedWeights_->denseVector());
    809911      } else {
    810912        // restore
  • trunk/Clp/src/ClpDualRowSteepest.hpp

    r1055 r1197  
    2626  virtual int pivotRow();
    2727 
    28   /// Updates weights and returns pivot alpha
     28  /** Updates weights and returns pivot alpha.
     29      Also does FT update */
    2930  virtual double updateWeights(CoinIndexedVector * input,
    3031                             CoinIndexedVector * spare,
     32                             CoinIndexedVector * spare2,
    3133                             CoinIndexedVector * updatedColumn);
    3234 
     
    8486  ClpDualRowSteepest & operator=(const ClpDualRowSteepest& rhs);
    8587 
     88  /// Fill most values
     89  void fill(const ClpDualRowSteepest& rhs);
     90 
    8691  /// Destructor
    8792  virtual ~ClpDualRowSteepest ();
  • trunk/Clp/src/ClpDynamicExampleMatrix.cpp

    r1088 r1197  
    160160    status_ = ClpCopyOfArray(status,numberSets_);
    161161    assert (dynamicStatus);
    162     memcpy(dynamicStatus_,dynamicStatus,numberIds);
     162    CoinMemcpyN(dynamicStatus,numberIds,dynamicStatus_);
    163163    assert (numberIds);
    164164  } else {
     
    312312    status_ = ClpCopyOfArray(status,numberSets_);
    313313    assert (dynamicStatus);
    314     memcpy(dynamicStatus_,dynamicStatus,numberIds);
     314    CoinMemcpyN(dynamicStatus,numberIds,dynamicStatus_);
    315315    assert (numberIds);
    316316  } else {
  • trunk/Clp/src/ClpDynamicMatrix.cpp

    r1088 r1197  
    690690          printf("** bad effective %d - true %g old %g\n",iRow,rhs[iRow],rhsOffset_[iRow]);
    691691      }
    692       memcpy(saveE,rhs,numberRows*sizeof(double));
     692      CoinMemcpyN(rhs,numberRows,saveE);
    693693      delete [] rhs;
    694694    }
     
    12151215        columnLower[firstAvailable_]=0.0;
    12161216        columnUpper[firstAvailable_]=COIN_DBL_MAX;
    1217        
     1217
    12181218        // not really in small problem
    12191219        int iBig=id_[sequenceIn-firstDynamic_];
     
    22542254    j = next_[j];
    22552255  }
    2256        
     2256
    22572257  if (numberGubColumns_==maximumGubColumns_||
    22582258      startColumn_[numberGubColumns_]+numberEntries>maximumElements_) {
     
    23152315  }
    23162316  CoinBigIndex start = startColumn_[numberGubColumns_];
    2317   memcpy(row_+start,row,numberEntries*sizeof(int));
    2318   memcpy(element_+start,element,numberEntries*sizeof(float));
     2317  CoinMemcpyN(row,numberEntries,row_+start);
     2318  CoinMemcpyN(element,numberEntries,element_+start);
    23192319  startColumn_[numberGubColumns_+1]=start+numberEntries;
    23202320  cost_[numberGubColumns_]=cost;
  • trunk/Clp/src/ClpFactorization.cpp

    r1152 r1197  
    2020const static bool doCheck=false;
    2121#endif
     22#endif
     23//#define CLP_FACTORIZATION_INSTRUMENT
     24#ifdef CLP_FACTORIZATION_INSTRUMENT
     25#include "CoinTime.hpp"
     26double factorization_instrument(int type)
     27{
     28  static int times[10]={0,0,0,0,0,0,0,0,0,0};
     29  static double startTime=0.0;
     30  static double totalTimes [10]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
     31  if (type<0) {
     32    assert (!startTime);
     33    startTime=CoinCpuTime();
     34    return 0.0;
     35  } else if (type>0) {
     36    times[type]++;
     37    double difference = CoinCpuTime()-startTime;
     38    totalTimes[type] += difference;
     39    startTime=0.0;
     40    return difference;
     41  } else {
     42    // report
     43    const char * types[10]=
     44      {"","fac=rhs_etc","factorize","replace","update_FT",
     45       "update","update_transpose","gosparse","getWeights!","update2_FT"};
     46    double total=0.0;
     47    for (int i=1;i<10;i++) {
     48      if (times[i]) {
     49        printf("%s was called %d times taking %g seconds\n",
     50               types[i],times[i],totalTimes[i]);
     51        total += totalTimes[i];
     52        times[i]=0;
     53        totalTimes[i]=0.0;
     54      }
     55    }
     56    return total;
     57  }
     58}
    2259#endif
    2360//#############################################################################
     
    75112ClpFactorization::operator=(const ClpFactorization& rhs)
    76113{
     114#ifdef CLP_FACTORIZATION_INSTRUMENT
     115  factorization_instrument(-1);
     116#endif
    77117  if (this != &rhs) {
    78118    CoinFactorization::operator=(rhs);
     
    85125#endif
    86126  }
     127#ifdef CLP_FACTORIZATION_INSTRUMENT
     128  factorization_instrument(1);
     129#endif
    87130  return *this;
    88131}
     
    103146                              int solveType, bool valuesPass)
    104147{
     148#ifdef CLP_FACTORIZATION_INSTRUMENT
     149  factorization_instrument(-1);
     150#endif
    105151  ClpMatrixBase * matrix = model->clpMatrix();
    106152  int numberRows = model->numberRows();
     
    305351        if (model->numberIterations())
    306352          numberRowBasic = numberBasic - numberColumnBasic;
    307         numberElements = 3 * numberBasic + 3 * numberElements + 10000;
     353        numberElements = 3 * numberBasic + 3 * numberElements + 20000;
    308354#if 0
    309355        // If iteration not zero then may be compressed
     
    652698  }
    653699#endif
     700#ifdef CLP_FACTORIZATION_INSTRUMENT
     701  factorization_instrument(2);
     702#endif
    654703  return status_;
    655704}
     
    669718                                  bool checkBeforeModifying)
    670719{
     720  int returnCode;
    671721#ifndef SLIM_CLP
    672722  if (!networkBasis_) {
     723#endif
     724#ifdef CLP_FACTORIZATION_INSTRUMENT
     725    factorization_instrument(-1);
    673726#endif
    674727    // see if FT
    675728    if (doForrestTomlin_) {
    676       int returnCode= CoinFactorization::replaceColumn(regionSparse,
     729      returnCode= CoinFactorization::replaceColumn(regionSparse,
    677730                                              pivotRow,
    678731                                              pivotCheck,
    679732                                              checkBeforeModifying);
    680       return returnCode;
    681733    } else {
    682       return CoinFactorization::replaceColumnPFI(tableauColumn,
     734      returnCode= CoinFactorization::replaceColumnPFI(tableauColumn,
    683735                                              pivotRow,pivotCheck); // Note array
    684736    }
     737#ifdef CLP_FACTORIZATION_INSTRUMENT
     738    factorization_instrument(3);
     739#endif
    685740
    686741#ifndef SLIM_CLP
    687742  } else {
    688743    if (doCheck) {
    689       int returnCode = CoinFactorization::replaceColumn(regionSparse,
     744      returnCode = CoinFactorization::replaceColumn(regionSparse,
    690745                                                        pivotRow,
    691746                                                        pivotCheck,
     
    693748      networkBasis_->replaceColumn(regionSparse,
    694749                                   pivotRow);
    695       return returnCode;
    696750    } else {
    697751      // increase number of pivots
    698752      numberPivots_++;
    699       return networkBasis_->replaceColumn(regionSparse,
     753      returnCode = networkBasis_->replaceColumn(regionSparse,
    700754                                   pivotRow);
    701755    }
    702756  }
    703757#endif
     758  return returnCode;
    704759}
    705760
     
    719774  if (!networkBasis_) {
    720775#endif
     776#ifdef CLP_FACTORIZATION_INSTRUMENT
     777    factorization_instrument(-1);
     778#endif
    721779    collectStatistics_ = true;
    722     int returnValue= CoinFactorization::updateColumnFT(regionSparse,
     780    int returnCode= CoinFactorization::updateColumnFT(regionSparse,
    723781                                                       regionSparse2);
    724782    collectStatistics_ = false;
    725     return returnValue;
     783#ifdef CLP_FACTORIZATION_INSTRUMENT
     784    factorization_instrument(4);
     785#endif
     786    return returnCode;
    726787#ifndef SLIM_CLP
    727788  } else {
     
    783844  if (!networkBasis_) {
    784845#endif
     846#ifdef CLP_FACTORIZATION_INSTRUMENT
     847    factorization_instrument(-1);
     848#endif
    785849    collectStatistics_ = true;
    786     int returnValue= CoinFactorization::updateColumn(regionSparse,
     850    int returnCode= CoinFactorization::updateColumn(regionSparse,
    787851                                                     regionSparse2,
    788852                                                     noPermute);
    789853    collectStatistics_ = false;
    790     return returnValue;
     854#ifdef CLP_FACTORIZATION_INSTRUMENT
     855    factorization_instrument(5);
     856#endif
     857    return returnCode;
    791858#ifndef SLIM_CLP
    792859  } else {
     
    833900}
    834901/* Updates one column (FTRAN) from region2
     902   Tries to do FT update
     903   number returned is negative if no room.
     904   Also updates region3
     905   region1 starts as zero and is zero at end */
     906int
     907ClpFactorization::updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
     908                                       CoinIndexedVector * regionSparse2,
     909                                       CoinIndexedVector * regionSparse3,
     910                                       bool noPermuteRegion3)
     911{
     912  int returnCode=updateColumnFT(regionSparse1,regionSparse2);
     913  updateColumn(regionSparse1,regionSparse3,noPermuteRegion3);
     914  return returnCode;
     915}
     916/* Updates one column (FTRAN) from region2
    835917   number returned is negative if no room
    836918   region1 starts as zero and is zero at end */
     
    845927    return 0;
    846928  collectStatistics_ = false;
    847   int returnValue= CoinFactorization::updateColumn(regionSparse,
     929  int returnCode= CoinFactorization::updateColumn(regionSparse,
    848930                                                   regionSparse2,
    849931                                                   noPermute);
    850   return returnValue;
     932  return returnCode;
    851933}
    852934/* Updates one column (BTRAN) from region2
     
    861943  if (!networkBasis_) {
    862944#endif
     945#ifdef CLP_FACTORIZATION_INSTRUMENT
     946    factorization_instrument(-1);
     947#endif
    863948    collectStatistics_ = true;
    864     int returnValue = CoinFactorization::updateColumnTranspose(regionSparse,
     949    int returnCode = CoinFactorization::updateColumnTranspose(regionSparse,
    865950                                                    regionSparse2);
    866951    collectStatistics_ = false;
    867     return returnValue;
     952#ifdef CLP_FACTORIZATION_INSTRUMENT
     953    factorization_instrument(6);
     954#endif
     955    return returnCode;
    868956#ifndef SLIM_CLP
    869957  } else {
     
    911999ClpFactorization::goSparse()
    9121000{
     1001#ifdef CLP_FACTORIZATION_INSTRUMENT
     1002  factorization_instrument(-1);
     1003#endif
    9131004#ifndef SLIM_CLP
    9141005  if (!networkBasis_)
    9151006#endif
    9161007    CoinFactorization::goSparse();
     1008#ifdef CLP_FACTORIZATION_INSTRUMENT
     1009  factorization_instrument(7);
     1010#endif
    9171011}
    9181012// Cleans up i.e. gets rid of network basis
     
    9461040ClpFactorization::getWeights(int * weights) const
    9471041{
     1042#ifdef CLP_FACTORIZATION_INSTRUMENT
     1043  factorization_instrument(-1);
     1044#endif
    9481045#ifndef SLIM_CLP
    9491046  if (networkBasis_) {
     
    9981095    }
    9991096  }
     1097#ifdef CLP_FACTORIZATION_INSTRUMENT
     1098  factorization_instrument(8);
     1099#endif
    10001100}
    10011101#else
     
    10141114  coinFactorizationB_ = NULL;
    10151115  //coinFactorizationB_ = new CoinDenseFactorization();
     1116  goDenseThreshold_ = -1;
    10161117}
    10171118
     
    10211122ClpFactorization::ClpFactorization (const ClpFactorization & rhs)
    10221123{
     1124#ifdef CLP_FACTORIZATION_INSTRUMENT
     1125  factorization_instrument(-1);
     1126#endif
    10231127#ifndef SLIM_CLP
    10241128  if (rhs.networkBasis_)
     
    10351139  else
    10361140    coinFactorizationB_=NULL;
     1141  goDenseThreshold_ = rhs.goDenseThreshold_;
     1142#ifdef CLP_FACTORIZATION_INSTRUMENT
     1143  factorization_instrument(1);
     1144#endif
    10371145}
    10381146
    10391147ClpFactorization::ClpFactorization (const CoinFactorization & rhs)
    10401148{
     1149#ifdef CLP_FACTORIZATION_INSTRUMENT
     1150  factorization_instrument(-1);
     1151#endif
    10411152#ifndef SLIM_CLP
    10421153  networkBasis_=NULL;
     
    10441155  coinFactorizationA_ = new CoinFactorization(rhs);
    10451156  coinFactorizationB_=NULL;
     1157#ifdef CLP_FACTORIZATION_INSTRUMENT
     1158  factorization_instrument(1);
     1159  goDenseThreshold_ = -1;
     1160#endif
    10461161}
    10471162
    10481163ClpFactorization::ClpFactorization (const CoinDenseFactorization & rhs)
    10491164{
     1165#ifdef CLP_FACTORIZATION_INSTRUMENT
     1166  factorization_instrument(-1);
     1167#endif
    10501168#ifndef SLIM_CLP
    10511169  networkBasis_=NULL;
     
    10531171  coinFactorizationA_ = NULL;
    10541172  coinFactorizationB_ = new CoinDenseFactorization(rhs);
     1173  goDenseThreshold_ = -1;
     1174#ifdef CLP_FACTORIZATION_INSTRUMENT
     1175  factorization_instrument(1);
     1176#endif
    10551177}
    10561178
     
    10731195ClpFactorization::operator=(const ClpFactorization& rhs)
    10741196{
     1197#ifdef CLP_FACTORIZATION_INSTRUMENT
     1198  factorization_instrument(-1);
     1199#endif
    10751200  if (this != &rhs) {
    10761201#ifndef SLIM_CLP
     
    10921217      coinFactorizationB_=NULL;
    10931218  }
     1219#ifdef CLP_FACTORIZATION_INSTRUMENT
     1220  factorization_instrument(1);
     1221#endif
    10941222  return *this;
    10951223}
     
    11021230  coinFactorizationA_ = NULL;
    11031231  coinFactorizationB_ = new CoinDenseFactorization();
     1232  //printf("going dense\n");
    11041233}
    11051234int
     
    11121241  if (!numberRows)
    11131242    return 0;
     1243#ifdef CLP_FACTORIZATION_INSTRUMENT
     1244  factorization_instrument(-1);
     1245#endif
    11141246  if (coinFactorizationB_) {
    11151247    setStatus(-99);
     
    11971329                                          numberColumnBasic);
    11981330      // Not needed for dense
    1199       numberElements = 3 * numberBasic + 3 * numberElements + 10000;
     1331      numberElements = 3 * numberBasic + 3 * numberElements + 20000;
    12001332      coinFactorizationB_->getAreas ( numberRows,
    12011333                                      numberRowBasic+numberColumnBasic, numberElements,
     
    12081340      int * numberInRow;
    12091341      int * numberInColumn;
    1210       double slackValue;
    12111342      elementU = coinFactorizationB_->elements();
    12121343      indexRowU = coinFactorizationB_->indices();
    12131344      startColumnU = coinFactorizationB_->starts();
     1345#ifndef COIN_FAST_CODE
     1346      double slackValue;
    12141347      slackValue = coinFactorizationB_->slackValue();
     1348#else
     1349#define slackValue -1.0
     1350#endif
    12151351      // At present we don't need counts
    12161352      numberInRow = coinFactorizationB_->intWorkArea();
     
    13641500      region2B.clear();
    13651501    }
     1502#endif
     1503#ifdef CLP_FACTORIZATION_INSTRUMENT
     1504    factorization_instrument(2);
    13661505#endif
    13671506    return coinFactorizationB_->status();
     
    15641703        if (model->numberIterations())
    15651704          numberRowBasic = numberBasic - numberColumnBasic;
    1566         numberElements = 3 * numberBasic + 3 * numberElements + 10000;
     1705        numberElements = 3 * numberBasic + 3 * numberElements + 20000;
    15671706        coinFactorizationA_->getAreas ( numberRows,
    15681707                   numberRowBasic+numberColumnBasic, numberElements,
     
    15771716        int * indexRowU = coinFactorizationA_->indexRowU();
    15781717        CoinBigIndex * startColumnU = coinFactorizationA_->startColumnU();
     1718#ifndef COIN_FAST_CODE
    15791719        double slackValue = coinFactorizationA_->slackValue();
     1720#endif
    15801721        for (i=0;i<numberRowBasic;i++) {
    15811722          int iRow = pivotTemp[i];
     
    18812022  }
    18822023#endif
     2024#ifdef CLP_FACTORIZATION_INSTRUMENT
     2025  factorization_instrument(2);
     2026#endif
    18832027  return coinFactorizationA_->status();
    18842028}
     
    19012045  if (!networkBasis_) {
    19022046#endif
     2047#ifdef CLP_FACTORIZATION_INSTRUMENT
     2048    factorization_instrument(-1);
     2049#endif
     2050    int returnCode;
    19032051    // see if FT
    19042052    if (!coinFactorizationA_||coinFactorizationA_->forrestTomlin()) {
    1905       int returnCode;
    19062053      if (coinFactorizationA_) {
    19072054        returnCode = coinFactorizationA_->replaceColumn(regionSparse,
     
    19382085#endif
    19392086      }
     2087    } else {
     2088      returnCode = coinFactorizationA_->replaceColumnPFI(tableauColumn,
     2089                                              pivotRow,pivotCheck); // Note array
     2090    }
     2091#ifdef CLP_FACTORIZATION_INSTRUMENT
     2092      factorization_instrument(3);
     2093#endif
    19402094      return returnCode;
    1941     } else {
    1942       return coinFactorizationA_->replaceColumnPFI(tableauColumn,
    1943                                               pivotRow,pivotCheck); // Note array
    1944     }
    19452095
    19462096#ifndef SLIM_CLP
     
    19792129  if (!networkBasis_) {
    19802130#endif
     2131#ifdef CLP_FACTORIZATION_INSTRUMENT
     2132    factorization_instrument(-1);
     2133#endif
     2134    int returnCode;
    19812135    if (coinFactorizationA_) {
    19822136      coinFactorizationA_->setCollectStatistics(true);
    1983       int returnValue= coinFactorizationA_->updateColumnFT(regionSparse,
     2137      returnCode= coinFactorizationA_->updateColumnFT(regionSparse,
    19842138                                                           regionSparse2);
    19852139      coinFactorizationA_->setCollectStatistics(false);
    1986       return returnValue;
    19872140    } else {
    1988       int returnValue= coinFactorizationB_->updateColumn(regionSparse,
     2141      returnCode= coinFactorizationB_->updateColumn(regionSparse,
    19892142                                                         regionSparse2);
    1990       return returnValue;
    1991     }
     2143    }
     2144#ifdef CLP_FACTORIZATION_INSTRUMENT
     2145    factorization_instrument(4);
     2146#endif
     2147    return returnCode;
    19922148#ifndef SLIM_CLP
    19932149  } else {
     
    20502206  if (!networkBasis_) {
    20512207#endif
     2208#ifdef CLP_FACTORIZATION_INSTRUMENT
     2209    factorization_instrument(-1);
     2210#endif
     2211    int returnCode;
    20522212    if (coinFactorizationA_) {
    20532213      coinFactorizationA_->setCollectStatistics(true);
    2054       int returnValue= coinFactorizationA_->updateColumn(regionSparse,
     2214      returnCode= coinFactorizationA_->updateColumn(regionSparse,
    20552215                                                         regionSparse2,
    20562216                                                         noPermute);
    20572217      coinFactorizationA_->setCollectStatistics(false);
    2058       return returnValue;
    20592218    } else {
    2060       int returnValue= coinFactorizationB_->updateColumn(regionSparse,
     2219      returnCode= coinFactorizationB_->updateColumn(regionSparse,
    20612220                                                         regionSparse2,
    20622221                                                         noPermute);
    2063       return returnValue;
    2064     }
     2222    }
     2223#ifdef CLP_FACTORIZATION_INSTRUMENT
     2224    factorization_instrument(5);
     2225#endif
     2226    return returnCode;
    20652227#ifndef SLIM_CLP
    20662228  } else {
     
    21082270}
    21092271/* Updates one column (FTRAN) from region2
     2272   Tries to do FT update
     2273   number returned is negative if no room.
     2274   Also updates region3
     2275   region1 starts as zero and is zero at end */
     2276int
     2277ClpFactorization::updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
     2278                                       CoinIndexedVector * regionSparse2,
     2279                                       CoinIndexedVector * regionSparse3,
     2280                                       bool noPermuteRegion3)
     2281{
     2282#ifdef CLP_DEBUG
     2283  regionSparse1->checkClear();
     2284#endif
     2285  if (!numberRows())
     2286    return 0;
     2287  int returnCode=0;
     2288#ifndef SLIM_CLP
     2289  if (!networkBasis_) {
     2290#endif
     2291#ifdef CLP_FACTORIZATION_INSTRUMENT
     2292    factorization_instrument(-1);
     2293#endif
     2294    if (coinFactorizationA_) {
     2295      coinFactorizationA_->setCollectStatistics(true);
     2296      if (coinFactorizationA_->spaceForForrestTomlin()) {
     2297        assert (regionSparse2->packedMode());
     2298        assert (!regionSparse3->packedMode());
     2299        returnCode= coinFactorizationA_->updateTwoColumnsFT(regionSparse1,
     2300                                                            regionSparse2,
     2301                                                            regionSparse3,
     2302                                                            noPermuteRegion3);
     2303      } else {
     2304        returnCode= coinFactorizationA_->updateColumnFT(regionSparse1,
     2305                                                        regionSparse2);
     2306        coinFactorizationA_->updateColumn(regionSparse1,
     2307                                          regionSparse3,
     2308                                          noPermuteRegion3);
     2309      }
     2310      coinFactorizationA_->setCollectStatistics(false);
     2311    } else {
     2312      returnCode= coinFactorizationB_->updateColumn(regionSparse1,
     2313                                                     regionSparse2);
     2314      coinFactorizationB_->updateColumn(regionSparse1,
     2315                                        regionSparse3,
     2316                                        noPermuteRegion3);
     2317    }
     2318#ifdef CLP_FACTORIZATION_INSTRUMENT
     2319    factorization_instrument(9);
     2320#endif
     2321    return returnCode;
     2322#ifndef SLIM_CLP
     2323  } else {
     2324    returnCode=updateColumnFT(regionSparse1,regionSparse2);
     2325    updateColumn(regionSparse1,regionSparse3,noPermuteRegion3);
     2326  }
     2327#endif
     2328  return returnCode;
     2329}
     2330/* Updates one column (FTRAN) from region2
    21102331   number returned is negative if no room
    21112332   region1 starts as zero and is zero at end */
     
    21202341    return 0;
    21212342  coinFactorizationA_->setCollectStatistics(false);
    2122   int returnValue= coinFactorizationA_->updateColumn(regionSparse,
     2343  int returnCode= coinFactorizationA_->updateColumn(regionSparse,
    21232344                                                   regionSparse2,
    21242345                                                   noPermute);
    2125   return returnValue;
     2346  return returnCode;
    21262347}
    21272348/* Updates one column (BTRAN) from region2
     
    21362357  if (!networkBasis_) {
    21372358#endif
     2359#ifdef CLP_FACTORIZATION_INSTRUMENT
     2360    factorization_instrument(-1);
     2361#endif
     2362    int returnCode;
    21382363    if (coinFactorizationA_) {
    21392364      coinFactorizationA_->setCollectStatistics(true);
    2140       int returnValue =  coinFactorizationA_->updateColumnTranspose(regionSparse,
     2365      returnCode =  coinFactorizationA_->updateColumnTranspose(regionSparse,
    21412366                                                    regionSparse2);
    21422367      coinFactorizationA_->setCollectStatistics(false);
    2143       return returnValue;
    21442368    } else {
    2145       int returnValue= coinFactorizationB_->updateColumnTranspose(regionSparse,
     2369      returnCode= coinFactorizationB_->updateColumnTranspose(regionSparse,
    21462370                                                         regionSparse2);
    2147       return returnValue;
    2148     }
     2371    }
     2372#ifdef CLP_FACTORIZATION_INSTRUMENT
     2373    factorization_instrument(6);
     2374#endif
     2375    return returnCode;
    21492376#ifndef SLIM_CLP
    21502377  } else {
     
    21942421{
    21952422#ifndef SLIM_CLP
    2196   if (!networkBasis_)
    2197 #endif
    2198     if (coinFactorizationA_)
    2199     coinFactorizationA_->goSparse();
     2423  if (!networkBasis_) {
     2424#endif
     2425    if (coinFactorizationA_) {
     2426#ifdef CLP_FACTORIZATION_INSTRUMENT
     2427      factorization_instrument(-1);
     2428#endif
     2429      coinFactorizationA_->goSparse();
     2430#ifdef CLP_FACTORIZATION_INSTRUMENT
     2431      factorization_instrument(7);
     2432#endif
     2433    }
     2434  }
    22002435}
    22012436// Cleans up i.e. gets rid of network basis
     
    22302465ClpFactorization::getWeights(int * weights) const
    22312466{
     2467#ifdef CLP_FACTORIZATION_INSTRUMENT
     2468  factorization_instrument(-1);
     2469#endif
    22322470#ifndef SLIM_CLP
    22332471  if (networkBasis_) {
     
    22862524    }
    22872525  }
    2288 }
    2289 #endif
     2526#ifdef CLP_FACTORIZATION_INSTRUMENT
     2527  factorization_instrument(8);
     2528#endif
     2529}
     2530#endif
  • trunk/Clp/src/ClpFactorization.hpp

    r1152 r1197  
    1111class ClpSimplex;
    1212class ClpNetworkBasis;
    13 //#define CLP_MULTIPLE_FACTORIZATIONS   
     13#define CLP_MULTIPLE_FACTORIZATIONS   
    1414#ifdef CLP_MULTIPLE_FACTORIZATIONS   
    1515#include "CoinDenseFactorization.hpp"
     
    9393  int updateColumnFT ( CoinIndexedVector * regionSparse,
    9494                       CoinIndexedVector * regionSparse2);
     95  /** Updates one column (FTRAN) from region2
     96      region1 starts as zero and is zero at end */
    9597  int updateColumn ( CoinIndexedVector * regionSparse,
    9698                     CoinIndexedVector * regionSparse2,
    9799                     bool noPermute=false) const;
     100  /** Updates one column (FTRAN) from region2
     101      Tries to do FT update
     102      number returned is negative if no room.
     103      Also updates region3
     104      region1 starts as zero and is zero at end */
     105  int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1,
     106                           CoinIndexedVector * regionSparse2,
     107                           CoinIndexedVector * regionSparse3,
     108                           bool noPermuteRegion3=false) ;
    98109  /// For debug (no statistics update)
    99110  int updateColumnForDebug ( CoinIndexedVector * regionSparse,
     
    245256  inline void setDefaultValues() {
    246257    if (coinFactorizationA_) {
    247       coinFactorizationA_->increasingRows(2);
    248258      // row activities have negative sign
     259#ifndef COIN_FAST_CODE
    249260      coinFactorizationA_->slackValue(-1.0);
     261#endif
    250262      coinFactorizationA_->zeroTolerance(1.0e-13);
    251263    }
    252264  }
     265  /// Get switch to dense if number rows <= this
     266  inline int goDenseThreshold() const
     267  { return goDenseThreshold_;}
     268  /// Set switch to dense if number rows <= this
     269  inline void setGoDenseThreshold(int value)
     270  { goDenseThreshold_ = value;}
    253271  /// Go over to dense code
    254272  void goDense() ;
     273  /// Return 1 if dense code
     274  inline int isDense() const
     275  { return coinFactorizationB_ ? 1 : 0;}
    255276#else
    256277  inline bool timeToRefactorize() const
     
    262283  /// Sets default values
    263284  inline void setDefaultValues() {
    264     increasingRows(2);
    265285    // row activities have negative sign
     286#ifndef COIN_FAST_CODE
    266287    slackValue(-1.0);
     288#endif
    267289    zeroTolerance(1.0e-13);
    268290  }
     
    307329  /// Pointer to CoinDenseFactorization
    308330  CoinDenseFactorization * coinFactorizationB_;
     331  /// Switch to dense if number rows <= this
     332  int goDenseThreshold_;
    309333#endif
    310334  //@}
  • trunk/Clp/src/ClpGubDynamicMatrix.cpp

    r1088 r1197  
    363363        assert (model->getStatus(iBasic)==ClpSimplex::basic);
    364364        djMod=0.0;
    365        
     365
    366366        for (j=startColumn[iBasic];
    367367             j<startColumn[iBasic]+length[iBasic];j++) {
     
    707707      }
    708708      // move to next_
    709       memcpy(next_+firstDynamic_,temp+firstDynamic_,(firstAvailable_-firstDynamic_)*sizeof(int));
     709      CoinMemcpyN(temp+firstDynamic_,(firstAvailable_-firstDynamic_),next_+firstDynamic_);
    710710      // if odd iterations may be one out so adjust currentNumber
    711711      currentNumber=CoinMin(currentNumber+1,lastDynamic_);
     
    16781678          printf("** bad effective %d - true %g old %g\n",iRow,rhs[iRow],rhsOffset_[iRow]);
    16791679      }
    1680       memcpy(saveE,rhs,numberRows*sizeof(double));
     1680      CoinMemcpyN(rhs,numberRows,saveE);
    16811681      delete [] rhs;
    16821682    }
  • trunk/Clp/src/ClpGubMatrix.cpp

    r1054 r1197  
    842842            toIndex_[iSet]=jColumn;
    843843            fromIndex_[numberTouched++]=iSet;
    844           }     
     844          }
    845845        }
    846846      }
     
    867867            toIndex_[iSet]=jColumn;
    868868            fromIndex_[numberTouched++]=iSet;
    869           }     
     869          }
    870870        }
    871871      }
     
    16021602                assert (model->getStatus(iBasic)==ClpSimplex::basic);
    16031603                djMod=0.0;
    1604                
     1604
    16051605                for (j=startColumn[iBasic];
    16061606                     j<startColumn[iBasic]+length[iBasic];j++) {
     
    26852685        int iExtra = pivotRow-numberRows;
    26862686        //const int * length = matrix_->getVectorLengths();
    2687        
     2687
    26882688        assert (sequenceOut>=numberRows+numberColumns||
    26892689                sequenceOut==keyVariable_[iSetOut]);
     
    29382938    {
    29392939      synchronize(model,0);
    2940       memcpy(saveStatus_,status_,numberSets_);
    2941       memcpy(savedKeyVariable_,keyVariable_,numberSets_*sizeof(int));
     2940      CoinMemcpyN(status_,numberSets_,saveStatus_);
     2941      CoinMemcpyN(keyVariable_,numberSets_,savedKeyVariable_);
    29422942    }
    29432943    break;
     
    29452945  case 6:
    29462946    {
    2947       memcpy(status_,saveStatus_,numberSets_);
    2948       memcpy(keyVariable_,savedKeyVariable_,numberSets_*sizeof(int));
     2947      CoinMemcpyN(saveStatus_,numberSets_,status_);
     2948      CoinMemcpyN(savedKeyVariable_,numberSets_,keyVariable_);
    29492949      // restore firstAvailable_
    29502950      synchronize(model,7);
  • trunk/Clp/src/ClpInterior.cpp

    r1171 r1197  
    538538  delete [] solution_;
    539539  solution_ = new double[nTotal];
    540   memcpy(solution_,columnActivity_,
    541          numberColumns_*sizeof(double));
    542   memcpy(solution_+numberColumns_,rowActivity_,
    543          numberRows_*sizeof(double));
     540  CoinMemcpyN(columnActivity_,  numberColumns_,solution_);
     541  CoinMemcpyN(rowActivity_,     numberRows_,solution_+numberColumns_);
    544542  delete [] cost_;
    545543  cost_ = new double[nTotal];
     
    566564  rowUpperWork_ = upper_+numberColumns_;
    567565  columnUpperWork_ = upper_;
    568   memcpy(rowLowerWork_,rowLower_,numberRows_*sizeof(double));
    569   memcpy(rowUpperWork_,rowUpper_,numberRows_*sizeof(double));
    570   memcpy(columnLowerWork_,columnLower_,numberColumns_*sizeof(double));
    571   memcpy(columnUpperWork_,columnUpper_,numberColumns_*sizeof(double));
     566  CoinMemcpyN(rowLower_,numberRows_,rowLowerWork_);
     567  CoinMemcpyN(rowUpper_,numberRows_,rowUpperWork_);
     568  CoinMemcpyN(columnLower_,numberColumns_,columnLowerWork_);
     569  CoinMemcpyN(columnUpper_,numberColumns_,columnUpperWork_);
    572570  // clean up any mismatches on infinity
    573571  for (i=0;i<numberColumns_;i++) {
  • trunk/Clp/src/ClpModel.cpp

    r1185 r1197  
    6767  rowScale_(NULL),
    6868  columnScale_(NULL),
     69  inverseRowScale_(NULL),
     70  inverseColumnScale_(NULL),
    6971  scalingFlag_(3),
    7072  status_(NULL),
     
    8890  maximumColumns_(-1),
    8991  maximumRows_(-1),
     92  maximumInternalColumns_(-1),
     93  maximumInternalRows_(-1),
    9094  savedRowScale_(NULL),
    9195  savedColumnScale_(NULL)
     
    645649  maximumColumns_(-1),
    646650  maximumRows_(-1),
     651  maximumInternalColumns_(-1),
     652  maximumInternalRows_(-1),
    647653  savedRowScale_(NULL),
    648654  savedColumnScale_(NULL)
     
    807813    } else {
    808814      // This already has arrays - just copy
     815      savedRowScale_ = NULL;
     816      savedColumnScale_ = NULL;
    809817      startPermanentArrays();
    810818      if (rhs.integerType_) {
     
    868876        assert (savedRowScale_);
    869877        assert (!rowScale_);
    870         ClpDisjointCopyN(rhs.savedRowScale_,2*maximumRows_,savedRowScale_);
    871         ClpDisjointCopyN(rhs.savedColumnScale_,2*maximumColumns_,savedColumnScale_);
     878        ClpDisjointCopyN(rhs.savedRowScale_,4*maximumInternalRows_,savedRowScale_);
     879        ClpDisjointCopyN(rhs.savedColumnScale_,4*maximumInternalColumns_,savedColumnScale_);
    872880      } else {
    873881        assert (!savedRowScale_);
     
    884892  } else {
    885893    savedRowScale_ = rhs.savedRowScale_;
     894    assert (!savedRowScale_);
    886895    savedColumnScale_ = rhs.savedColumnScale_;
    887896    rowActivity_ = rhs.rowActivity_;
     
    910919    status_ = rhs.status_;
    911920  }
     921  inverseRowScale_ = NULL;
     922  inverseColumnScale_ = NULL;
    912923}
    913924// Copy contents - resizing if necessary - otherwise re-use memory
     
    925936  }
    926937#if 0
    927     delete modelPtr_->matrix_;
    928     if (continuousModel_->matrix_) {
    929       modelPtr_->matrix_ = continuousModel_->matrix_->clone();
    930     } else {
    931       modelPtr_->matrix_=NULL;
    932     }
     938  delete modelPtr_->matrix_;
     939  if (continuousModel_->matrix_) {
     940    modelPtr_->matrix_ = continuousModel_->matrix_->clone();
     941  } else {
     942    modelPtr_->matrix_=NULL;
     943  }
    933944#endif
    934945}
     
    959970  savedRowScale_=NULL;
    960971  savedColumnScale_=NULL;
     972  inverseRowScale_ = NULL;
     973  inverseColumnScale_ = NULL;
    961974}
    962975// Return model - nulls all arrays so can be deleted safely
     
    10031016    handler_ = NULL;
    10041017  }
     1018  inverseRowScale_ = NULL;
     1019  inverseColumnScale_ = NULL;
    10051020}
    10061021//#############################################################################
     
    12061221    return; // nothing to do
    12071222  whatsChanged_ = 0;
    1208   rowActivity_ = resizeDouble(rowActivity_,numberRows_,
    1209                               newNumberRows,0.0,true);
    1210   dual_ = resizeDouble(dual_,numberRows_,
    1211                        newNumberRows,0.0,true);
    1212   rowObjective_ = resizeDouble(rowObjective_,numberRows_,
    1213                                newNumberRows,0.0,false);
    1214   rowLower_ = resizeDouble(rowLower_,numberRows_,
    1215                            newNumberRows,-COIN_DBL_MAX,true);
    1216   rowUpper_ = resizeDouble(rowUpper_,numberRows_,
    1217                            newNumberRows,COIN_DBL_MAX,true);
    1218   columnActivity_ = resizeDouble(columnActivity_,numberColumns_,
    1219                                  newNumberColumns,0.0,true);
    1220   reducedCost_ = resizeDouble(reducedCost_,numberColumns_,
    1221                               newNumberColumns,0.0,true);
    1222   savedRowScale_ = resizeDouble(savedRowScale_,2*numberRows_,
    1223                            2*newNumberRows,-COIN_DBL_MAX,false);
    1224   savedColumnScale_ = resizeDouble(savedColumnScale_,2*numberColumns_,
    1225                            2*newNumberColumns,-COIN_DBL_MAX,false);
    1226   if (objective_)
     1223  int numberRows2=newNumberRows;
     1224  int numberColumns2=newNumberColumns;
     1225  if (numberRows2<maximumRows_)
     1226    numberRows2=maximumRows_;
     1227  if (numberColumns2<maximumColumns_)
     1228    numberColumns2=maximumColumns_;
     1229  if (numberRows2>maximumRows_) {
     1230    rowActivity_ = resizeDouble(rowActivity_,numberRows_,
     1231                                newNumberRows,0.0,true);
     1232    dual_ = resizeDouble(dual_,numberRows_,
     1233                         newNumberRows,0.0,true);
     1234    rowObjective_ = resizeDouble(rowObjective_,numberRows_,
     1235                                 newNumberRows,0.0,false);
     1236    rowLower_ = resizeDouble(rowLower_,numberRows_,
     1237                             newNumberRows,-COIN_DBL_MAX,true);
     1238    rowUpper_ = resizeDouble(rowUpper_,numberRows_,
     1239                             newNumberRows,COIN_DBL_MAX,true);
     1240  }
     1241  if (numberColumns2>maximumColumns_) {
     1242    columnActivity_ = resizeDouble(columnActivity_,numberColumns_,
     1243                                   newNumberColumns,0.0,true);
     1244    reducedCost_ = resizeDouble(reducedCost_,numberColumns_,
     1245                                newNumberColumns,0.0,true);
     1246  }
     1247  if (savedRowScale_&&numberRows2>maximumInternalRows_) {
     1248    double * temp;
     1249    temp = new double [4*newNumberRows];
     1250    CoinFillN(temp,4*newNumberRows,1.0);
     1251    CoinMemcpyN(savedRowScale_,numberRows_,temp);
     1252    CoinMemcpyN(savedRowScale_+maximumInternalRows_,numberRows_,temp+newNumberRows);
     1253    CoinMemcpyN(savedRowScale_+2*maximumInternalRows_,numberRows_,temp+2*newNumberRows);
     1254    CoinMemcpyN(savedRowScale_+3*maximumInternalRows_,numberRows_,temp+3*newNumberRows);
     1255    delete [] savedRowScale_;
     1256    savedRowScale_ = temp;
     1257  }
     1258  if (savedColumnScale_&&numberColumns2>maximumInternalColumns_) {
     1259    double * temp;
     1260    temp = new double [4*newNumberColumns];
     1261    CoinFillN(temp,4*newNumberColumns,1.0);
     1262    CoinMemcpyN(savedColumnScale_,numberColumns_,temp);
     1263    CoinMemcpyN(savedColumnScale_+maximumInternalColumns_,numberColumns_,temp+newNumberColumns);
     1264    CoinMemcpyN(savedColumnScale_+2*maximumInternalColumns_,numberColumns_,temp+2*newNumberColumns);
     1265    CoinMemcpyN(savedColumnScale_+3*maximumInternalColumns_,numberColumns_,temp+3*newNumberColumns);
     1266    delete [] savedColumnScale_;
     1267    savedColumnScale_ = temp;
     1268  }
     1269  if (objective_&&numberColumns2>maximumColumns_)
    12271270    objective_->resize(newNumberColumns);
    1228   else
     1271  else if (!objective_)
    12291272    objective_ = new ClpLinearObjective(NULL,newNumberColumns);
    1230   columnLower_ = resizeDouble(columnLower_,numberColumns_,
    1231                               newNumberColumns,0.0,true);
    1232   columnUpper_ = resizeDouble(columnUpper_,numberColumns_,
    1233                               newNumberColumns,COIN_DBL_MAX,true);
     1273  if (numberColumns2>maximumColumns_) {
     1274    columnLower_ = resizeDouble(columnLower_,numberColumns_,
     1275                                newNumberColumns,0.0,true);
     1276    columnUpper_ = resizeDouble(columnUpper_,numberColumns_,
     1277                                newNumberColumns,COIN_DBL_MAX,true);
     1278  }
    12341279  if (newNumberRows<numberRows_) {
    12351280    int * which = new int[numberRows_-newNumberRows];
     
    12511296  if (status_) {
    12521297    if (newNumberColumns+newNumberRows) {
    1253       unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
    1254       unsigned char * tempR = tempC + newNumberColumns;
    1255       memset(tempC,3,newNumberColumns*sizeof(unsigned char));
    1256       memset(tempR,1,newNumberRows*sizeof(unsigned char));
    1257       memcpy(tempC,status_,CoinMin(newNumberColumns,numberColumns_)*sizeof(unsigned char));
    1258       memcpy(tempR,status_+numberColumns_,CoinMin(newNumberRows,numberRows_)*sizeof(unsigned char));
    1259       delete [] status_;
    1260       status_ = tempC;
     1298      if (newNumberColumns+newNumberRows>maximumRows_+maximumColumns_) {
     1299        unsigned char * tempC = new unsigned char [newNumberColumns+newNumberRows];
     1300        unsigned char * tempR = tempC + newNumberColumns;
     1301        memset(tempC,3,newNumberColumns*sizeof(unsigned char));
     1302        memset(tempR,1,newNumberRows*sizeof(unsigned char));
     1303        CoinMemcpyN(status_,CoinMin(newNumberColumns,numberColumns_),tempC);
     1304        CoinMemcpyN(status_+numberColumns_,CoinMin(newNumberRows,numberRows_),tempR);
     1305        delete [] status_;
     1306        status_ = tempC;
     1307      } else if (newNumberColumns<numberColumns_) {
     1308        memmove(status_+newNumberColumns,status_+numberColumns_,
     1309                newNumberRows);
     1310      } else if (newNumberColumns>numberColumns_) {
     1311        memset(status_+numberColumns_,3,newNumberColumns-numberColumns_);
     1312        memmove(status_+newNumberColumns,status_+numberColumns_,
     1313                newNumberRows);
     1314      }
    12611315    } else {
    12621316      // empty model - some systems don't like new [0]
     
    12971351    delete [] which;
    12981352  }
    1299   if (integerType_) {
     1353  if (integerType_&&numberColumns2>maximumColumns_) {
    13001354    char * temp = new char [newNumberColumns];
    13011355    CoinZeroN(temp,newNumberColumns);
     
    13061360  }
    13071361  numberColumns_ = newNumberColumns;
     1362  if ((specialOptions_&65536)!=0) {
     1363    // leave until next create rim to up numbers
     1364  }
     1365  if (maximumRows_>=0) {
     1366    if (numberRows_>maximumRows_)
     1367      printf("resize %d rows, %d old maximum rows\n",
     1368             numberRows_,maximumRows_);
     1369    maximumRows_ = CoinMax(maximumRows_,numberRows_);
     1370    maximumColumns_ = CoinMax(maximumColumns_,numberColumns_);
     1371  }
    13081372}
    13091373// Deletes rows
     
    13151379  whatsChanged_ &= ~(1+2+4+8+16+32); // all except columns changed
    13161380  int newSize=0;
    1317   rowActivity_ = deleteDouble(rowActivity_,numberRows_,
    1318                               number, which, newSize);
    1319   dual_ = deleteDouble(dual_,numberRows_,
    1320                               number, which, newSize);
    1321   rowObjective_ = deleteDouble(rowObjective_,numberRows_,
    1322                               number, which, newSize);
    1323   rowLower_ = deleteDouble(rowLower_,numberRows_,
    1324                               number, which, newSize);
    1325   rowUpper_ = deleteDouble(rowUpper_,numberRows_,
    1326                               number, which, newSize);
    1327   if (matrix_->getNumRows())
    1328     matrix_->deleteRows(number,which);
    1329   //matrix_->removeGaps();
    1330   // status
    1331   if (status_) {
    1332     if (numberColumns_+newSize) {
    1333       unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
    1334                                                             numberRows_,
    1335                                                             number, which, newSize,false);
    1336       unsigned char * tempC = new unsigned char [numberColumns_+newSize];
    1337       memcpy(tempC,status_,numberColumns_*sizeof(unsigned char));
    1338       memcpy(tempC+numberColumns_,tempR,newSize*sizeof(unsigned char));
    1339       delete [] tempR;
    1340       delete [] status_;
    1341       status_ = tempC;
    1342     } else {
    1343       // empty model - some systems don't like new [0]
    1344       delete [] status_;
    1345       status_ = NULL;
    1346     }
     1381  if (maximumRows_<0) {
     1382    rowActivity_ = deleteDouble(rowActivity_,numberRows_,
     1383                                number, which, newSize);
     1384    dual_ = deleteDouble(dual_,numberRows_,
     1385                         number, which, newSize);
     1386    rowObjective_ = deleteDouble(rowObjective_,numberRows_,
     1387                                 number, which, newSize);
     1388    rowLower_ = deleteDouble(rowLower_,numberRows_,
     1389                             number, which, newSize);
     1390    rowUpper_ = deleteDouble(rowUpper_,numberRows_,
     1391                             number, which, newSize);
     1392    if (matrix_->getNumRows())
     1393      matrix_->deleteRows(number,which);
     1394    //matrix_->removeGaps();
     1395    // status
     1396    if (status_) {
     1397      if (numberColumns_+newSize) {
     1398        unsigned char * tempR  = (unsigned char *) deleteChar((char *)status_+numberColumns_,
     1399                                                              numberRows_,
     1400                                                              number, which, newSize,false);
     1401        unsigned char * tempC = new unsigned char [numberColumns_+newSize];
     1402        CoinMemcpyN(status_,numberColumns_,tempC);
     1403        CoinMemcpyN(tempR,newSize,tempC+numberColumns_);
     1404        delete [] tempR;
     1405        delete [] status_;
     1406        status_ = tempC;
     1407      } else {
     1408        // empty model - some systems don't like new [0]
     1409        delete [] status_;
     1410        status_ = NULL;
     1411      }
     1412    }
     1413  } else {
     1414    char * deleted = new char [numberRows_];
     1415    int i;
     1416    int numberDeleted=0;
     1417    CoinZeroN(deleted,numberRows_);
     1418    for (i=0;i<number;i++) {
     1419      int j = which[i];
     1420      if (j>=0&&j<numberRows_&&!deleted[j]) {
     1421        numberDeleted++;
     1422        deleted[j]=1;
     1423      }
     1424    }
     1425    assert (!rowObjective_);
     1426    unsigned char * status2 = status_+numberColumns_;
     1427    for (i=0;i<numberRows_;i++) {
     1428      if (!deleted[i]) {
     1429        rowActivity_[newSize]=rowActivity_[i];
     1430        dual_[newSize] = dual_[i];
     1431        rowLower_[newSize] = rowLower_[i];
     1432        rowUpper_[newSize] = rowUpper_[i];
     1433        status2[newSize] = status2[i];
     1434        newSize++;
     1435      }
     1436    }
     1437    if (matrix_->getNumRows())
     1438      matrix_->deleteRows(number,which);
     1439    //matrix_->removeGaps();
     1440    delete [] deleted;
    13471441  }
    13481442#ifndef CLP_NO_STD
     
    13821476  if (!number)
    13831477    return; // nothing to do
     1478  assert (maximumColumns_<0);
    13841479  whatsChanged_ &= ~(1+2+4+8+64+128+256); // all except rows changed
    13851480  int newSize=0;
     
    14151510                                                            number, which, newSize,false);
    14161511      unsigned char * temp = new unsigned char [numberRows_+newSize];
    1417       memcpy(temp,tempC,newSize*sizeof(unsigned char));
    1418       memcpy(temp+newSize,status_+numberColumns_,
    1419              numberRows_*sizeof(unsigned char));
     1512      CoinMemcpyN(tempC,newSize,temp);
     1513      CoinMemcpyN(status_+numberColumns_,       numberRows_,temp+newSize);
    14201514      delete [] tempC;
    14211515      delete [] status_;
     
    25262620  if (problemStatus_==3) {
    25272621    secondaryStatus_=0;
    2528     if (CoinCpuTime()>=dblParam_[ClpMaxSeconds])
     2622    if (CoinCpuTime()>=dblParam_[ClpMaxSeconds]&&dblParam_[ClpMaxSeconds]>=0.0)
    25292623      secondaryStatus_=9;
    25302624  }
     
    28742968  if (statusArray) {
    28752969    status_ = new unsigned char [numberRows_+numberColumns_];
    2876     memcpy(status_,statusArray,(numberRows_+numberColumns_)*sizeof(unsigned char));
     2970    CoinMemcpyN(statusArray,(numberRows_+numberColumns_),status_);
    28772971  } else {
    28782972    status_=NULL;
     
    29803074  maximumColumns_(-1),
    29813075  maximumRows_(-1),
     3076  maximumInternalColumns_(-1),
     3077  maximumInternalRows_(-1),
    29823078  savedRowScale_(NULL),
    29833079  savedColumnScale_(NULL)
     
    29943090  maximumColumns_ = -1;
    29953091  maximumRows_ = -1;
     3092  maximumInternalColumns_ = -1;
     3093  maximumInternalRows_ = -1;
    29963094  savedRowScale_ = NULL;
    29973095  savedColumnScale_ = NULL;
     
    31063204  rowScale_ = NULL;
    31073205  columnScale_ = NULL;
     3206  inverseRowScale_ = NULL;
     3207  inverseColumnScale_ = NULL;
    31083208  scalingFlag_ = rhs->scalingFlag_;
    31093209  rowCopy_=NULL;
     
    33143414{
    33153415  secondaryStatus_=6; // so user can see something odd
    3316   // May be in middle of expecting bounds to stay same etc - negate expectations
    3317   whatsChanged_=0;
    33183416  if (printMessage)
    33193417    handler_->message(CLP_EMPTY_PROBLEM,messages_)
     
    37893887ClpModel::startPermanentArrays()
    37903888{
     3889  printf("startperm a %d rows, %d maximum rows\n",
     3890         numberRows_,maximumRows_);
    37913891  if ((specialOptions_&65536)!=0) {
    37923892    if (numberRows_>maximumRows_||numberColumns_>maximumColumns_) {
    37933893      if (numberRows_>maximumRows_)
    3794         maximumRows_ = numberRows_+10+numberRows_/100;
     3894        if (maximumRows_>0)
     3895          maximumRows_ = numberRows_+10+numberRows_/100;
     3896        else
     3897          maximumRows_ = numberRows_;
    37953898      if (numberColumns_>maximumColumns_)
    3796         maximumColumns_ = numberColumns_+10+numberColumns_/100;
     3899        if (maximumColumns_>0)
     3900          maximumColumns_ = numberColumns_+10+numberColumns_/100;
     3901        else
     3902          maximumColumns_ = numberColumns_;
    37973903      // need to make sure numberRows_ OK and size of matrices
    37983904      resize(maximumRows_,maximumColumns_);
     3905      printf("startperm b %d rows, %d maximum rows\n",
     3906             numberRows_,maximumRows_);
    37993907    } else {
    38003908      return;
     
    38043912    maximumRows_ = numberRows_;
    38053913    maximumColumns_ = numberColumns_;
     3914    baseMatrix_ = *matrix();
     3915    baseMatrix_.cleanMatrix();
     3916    baseRowCopy_.setExtraGap(0.0);
     3917    baseRowCopy_.setExtraMajor(0.0);
     3918    baseRowCopy_.reverseOrderedCopyOf(baseMatrix_);
     3919    printf("startperm c %d rows, %d maximum rows\n",
     3920             numberRows_,maximumRows_);
    38063921  }
    38073922}
     
    40024117      }
    40034118    }
     4119#ifndef NDEBUG
    40044120    for (iRow=0;iRow<numberIn;iRow++) {
    40054121      int kRow = eligible[iRow];
    40064122      assert (rotate[kRow]>=2);
    40074123    }
     4124#endif
    40084125    trueNetwork=true;
    40094126    for (iColumn=0;iColumn<numberColumns_;iColumn++) {
  • trunk/Clp/src/ClpModel.hpp

    r1150 r1197  
    298298          <li> 0 - normal
    299299          <li> 1 - extra accuracy
    300           <li> 2 - IEEE hex (later)
     300          <li> 2 - IEEE hex
    301301        </ul>
    302302
     
    519519   inline const double * rowScale() const {return rowScale_;}
    520520   inline const double * columnScale() const {return columnScale_;}
     521   inline const double * inverseRowScale() const {return inverseRowScale_;}
     522   inline const double * inverseColumnScale() const {return inverseColumnScale_;}
    521523   inline double * mutableRowScale() const {return rowScale_;}
    522524   inline double * mutableColumnScale() const {return columnScale_;}
     525   inline double * mutableInverseRowScale() const {return inverseRowScale_;}
     526   inline double * mutableInverseColumnScale() const {return inverseColumnScale_;}
    523527   void setRowScale(double * scale) ;
    524528   void setColumnScale(double * scale);
     
    840844      131072 - scale factor arrays have inverse values at end
    841845      262144 - extra copy of scaled matrix
     846      524288 - Clp fast dual
    842847      NOTE - many applications can call Clp but there may be some short cuts
    843848             which are taken which are not guaranteed safe from all applications.
     
    952957  /// Column scale factors
    953958  double * columnScale_;
     959  /// Inverse row scale factors for matrix (end of rowScale_)
     960  double * inverseRowScale_;
     961  /// Inverse column scale factors for matrix (end of columnScale_)
     962  double * inverseColumnScale_;
    954963  /// Scale flag, 0 none, 1 equilibrium, 2 geometric, 3, auto, 4 dynamic
    955964  int scalingFlag_;
     
    10221031  /// Maximum number of rows in model
    10231032  int maximumRows_;
     1033  /// Maximum number of columns (internal arrays) in model
     1034  int maximumInternalColumns_;
     1035  /// Maximum number of rows (internal arrays) in model
     1036  int maximumInternalRows_;
    10241037  /// Base packed matrix
    10251038  CoinPackedMatrix baseMatrix_;
  • trunk/Clp/src/ClpNetworkBasis.cpp

    r754 r1197  
    1919ClpNetworkBasis::ClpNetworkBasis ()
    2020{
     21#ifndef COIN_FAST_CODE
    2122  slackValue_=-1.0;
     23#endif
    2224  numberRows_=0;
    2325  numberColumns_=0;
     
    4446                                 const int * indexRow, const double * element)
    4547{
     48#ifndef COIN_FAST_CODE
    4649  slackValue_=-1.0;
     50#endif
    4751  numberRows_=numberRows;
    4852  numberColumns_=numberRows;
     
    136140ClpNetworkBasis::ClpNetworkBasis (const ClpNetworkBasis & rhs)
    137141{
     142#ifndef COIN_FAST_CODE
    138143  slackValue_=rhs.slackValue_;
     144#endif
    139145  numberRows_=rhs.numberRows_;
    140146  numberColumns_=rhs.numberColumns_;
    141147  if (rhs.parent_) {
    142148    parent_ = new int [numberRows_+1];
    143     memcpy(parent_,rhs.parent_,(numberRows_+1)*sizeof(int));
     149    CoinMemcpyN(rhs.parent_,(numberRows_+1),parent_);
    144150  } else {
    145151    parent_ = NULL;
     
    147153  if (rhs.descendant_) {
    148154    descendant_ = new int [numberRows_+1];
    149     memcpy(descendant_,rhs.descendant_,(numberRows_+1)*sizeof(int));
     155    CoinMemcpyN(rhs.descendant_,(numberRows_+1),descendant_);
    150156  } else {
    151157    descendant_ = NULL;
     
    153159  if (rhs.pivot_) {
    154160    pivot_ = new int [numberRows_+1];
    155     memcpy(pivot_,rhs.pivot_,(numberRows_+1)*sizeof(int));
     161    CoinMemcpyN(rhs.pivot_,(numberRows_+1),pivot_);
    156162  } else {
    157163    pivot_ = NULL;
     
    159165  if (rhs.rightSibling_) {
    160166    rightSibling_ = new int [numberRows_+1];
    161     memcpy(rightSibling_,rhs.rightSibling_,(numberRows_+1)*sizeof(int));
     167    CoinMemcpyN(rhs.rightSibling_,(numberRows_+1),rightSibling_);
    162168  } else {
    163169    rightSibling_ = NULL;
     
    165171  if (rhs.leftSibling_) {
    166172    leftSibling_ = new int [numberRows_+1];
    167     memcpy(leftSibling_,rhs.leftSibling_,(numberRows_+1)*sizeof(int));
     173    CoinMemcpyN(rhs.leftSibling_,(numberRows_+1),leftSibling_);
    168174  } else {
    169175    leftSibling_ = NULL;
     
    171177  if (rhs.sign_) {
    172178    sign_ = new double [numberRows_+1];
    173     memcpy(sign_,rhs.sign_,(numberRows_+1)*sizeof(double));
     179    CoinMemcpyN(rhs.sign_,(numberRows_+1),sign_);
    174180  } else {
    175181    sign_ = NULL;
     
    177183  if (rhs.stack_) {
    178184    stack_ = new int [numberRows_+1];
    179     memcpy(stack_,rhs.stack_,(numberRows_+1)*sizeof(int));
     185    CoinMemcpyN(rhs.stack_,(numberRows_+1),stack_);
    180186  } else {
    181187    stack_ = NULL;
     
    183189  if (rhs.permute_) {
    184190    permute_ = new int [numberRows_+1];
    185     memcpy(permute_,rhs.permute_,(numberRows_+1)*sizeof(int));
     191    CoinMemcpyN(rhs.permute_,(numberRows_+1),permute_);
    186192  } else {
    187193    permute_ = NULL;
     
    189195  if (rhs.permuteBack_) {
    190196    permuteBack_ = new int [numberRows_+1];
    191     memcpy(permuteBack_,rhs.permuteBack_,(numberRows_+1)*sizeof(int));
     197    CoinMemcpyN(rhs.permuteBack_,(numberRows_+1),permuteBack_);
    192198  } else {
    193199    permuteBack_ = NULL;
     
    195201  if (rhs.stack2_) {
    196202    stack2_ = new int [numberRows_+1];
    197     memcpy(stack2_,rhs.stack2_,(numberRows_+1)*sizeof(int));
     203    CoinMemcpyN(rhs.stack2_,(numberRows_+1),stack2_);
    198204  } else {
    199205    stack2_ = NULL;
     
    201207  if (rhs.depth_) {
    202208    depth_ = new int [numberRows_+1];
    203     memcpy(depth_,rhs.depth_,(numberRows_+1)*sizeof(int));
     209    CoinMemcpyN(rhs.depth_,(numberRows_+1),depth_);
    204210  } else {
    205211    depth_ = NULL;
     
    207213  if (rhs.mark_) {
    208214    mark_ = new char [numberRows_+1];
    209     memcpy(mark_,rhs.mark_,(numberRows_+1)*sizeof(char));
     215    CoinMemcpyN(rhs.mark_,(numberRows_+1),mark_);
    210216  } else {
    211217    mark_ = NULL;
     
    252258    delete [] depth_;
    253259    delete [] mark_;
     260#ifndef COIN_FAST_CODE
    254261    slackValue_=rhs.slackValue_;
     262#endif
    255263    numberRows_=rhs.numberRows_;
    256264    numberColumns_=rhs.numberColumns_;
    257265    if (rhs.parent_) {
    258266      parent_ = new int [numberRows_+1];
    259       memcpy(parent_,rhs.parent_,(numberRows_+1)*sizeof(int));
     267      CoinMemcpyN(rhs.parent_,(numberRows_+1),parent_);
    260268    } else {
    261269      parent_ = NULL;
     
    263271    if (rhs.descendant_) {
    264272      descendant_ = new int [numberRows_+1];
    265       memcpy(descendant_,rhs.descendant_,(numberRows_+1)*sizeof(int));
     273      CoinMemcpyN(rhs.descendant_,(numberRows_+1),descendant_);
    266274    } else {
    267275      descendant_ = NULL;
     
    269277    if (rhs.pivot_) {
    270278      pivot_ = new int [numberRows_+1];
    271       memcpy(pivot_,rhs.pivot_,(numberRows_+1)*sizeof(int));
     279      CoinMemcpyN(rhs.pivot_,(numberRows_+1),pivot_);
    272280    } else {
    273281      pivot_ = NULL;
     
    275283    if (rhs.rightSibling_) {
    276284      rightSibling_ = new int [numberRows_+1];
    277       memcpy(rightSibling_,rhs.rightSibling_,(numberRows_+1)*sizeof(int));
     285      CoinMemcpyN(rhs.rightSibling_,(numberRows_+1),rightSibling_);
    278286    } else {
    279287      rightSibling_ = NULL;
     
    281289    if (rhs.leftSibling_) {
    282290      leftSibling_ = new int [numberRows_+1];
    283       memcpy(leftSibling_,rhs.leftSibling_,(numberRows_+1)*sizeof(int));
     291      CoinMemcpyN(rhs.leftSibling_,(numberRows_+1),leftSibling_);
    284292    } else {
    285293      leftSibling_ = NULL;
     
    287295    if (rhs.sign_) {
    288296      sign_ = new double [numberRows_+1];
    289       memcpy(sign_,rhs.sign_,(numberRows_+1)*sizeof(double));
     297      CoinMemcpyN(rhs.sign_,(numberRows_+1),sign_);
    290298    } else {
    291299      sign_ = NULL;
     
    293301    if (rhs.stack_) {
    294302      stack_ = new int [numberRows_+1];
    295       memcpy(stack_,rhs.stack_,(numberRows_+1)*sizeof(int));
     303      CoinMemcpyN(rhs.stack_,(numberRows_+1),stack_);
    296304    } else {
    297305      stack_ = NULL;
     
    299307    if (rhs.permute_) {
    300308      permute_ = new int [numberRows_+1];
    301       memcpy(permute_,rhs.permute_,(numberRows_+1)*sizeof(int));
     309      CoinMemcpyN(rhs.permute_,(numberRows_+1),permute_);
    302310    } else {
    303311      permute_ = NULL;
     
    305313    if (rhs.permuteBack_) {
    306314      permuteBack_ = new int [numberRows_+1];
    307       memcpy(permuteBack_,rhs.permuteBack_,(numberRows_+1)*sizeof(int));
     315      CoinMemcpyN(rhs.permuteBack_,(numberRows_+1),permuteBack_);
    308316    } else {
    309317      permuteBack_ = NULL;
     
    311319    if (rhs.stack2_) {
    312320      stack2_ = new int [numberRows_+1];
    313       memcpy(stack2_,rhs.stack2_,(numberRows_+1)*sizeof(int));
     321      CoinMemcpyN(rhs.stack2_,(numberRows_+1),stack2_);
    314322    } else {
    315323      stack2_ = NULL;
     
    317325    if (rhs.depth_) {
    318326      depth_ = new int [numberRows_+1];
    319       memcpy(depth_,rhs.depth_,(numberRows_+1)*sizeof(int));
     327      CoinMemcpyN(rhs.depth_,(numberRows_+1),depth_);
    320328    } else {
    321329      depth_ = NULL;
     
    323331    if (rhs.mark_) {
    324332      mark_ = new char [numberRows_+1];
    325       memcpy(mark_,rhs.mark_,(numberRows_+1)*sizeof(char));
     333      CoinMemcpyN(rhs.mark_,(numberRows_+1),mark_);
    326334    } else {
    327335      mark_ = NULL;
     
    929937  int i;
    930938  int numberNonZero=0;
    931   memcpy(region,region2,numberRows_*sizeof(double));
     939  CoinMemcpyN(region2,numberRows_,region);
    932940  for (i=0;i<numberRows_;i++) {
    933941    double value = region[i];
  • trunk/Clp/src/ClpNetworkBasis.hpp

    r754 r1197  
    104104  /**@name data */
    105105  //@{
     106#ifndef COIN_FAST_CODE
    106107  /// Whether slack value is  +1 or -1
    107108  double slackValue_;
     109#endif
    108110  /// Number of Rows in factorization
    109111  int numberRows_;
  • trunk/Clp/src/ClpNetworkMatrix.cpp

    r1111 r1197  
    7676  if (numberColumns_) {
    7777    indices_ = new int [ 2*numberColumns_];
    78     memcpy(indices_,rhs.indices_,2*numberColumns_*sizeof(int));
     78    CoinMemcpyN(rhs.indices_,2*numberColumns_,indices_);
    7979  }
    8080  int numberRows = getNumRows();
     
    209209    if (numberColumns_) {
    210210      indices_ = new int [ 2*numberColumns_];
    211       memcpy(indices_,rhs.indices_,2*numberColumns_*sizeof(int));
     211      CoinMemcpyN(rhs.indices_,2*numberColumns_,indices_);
    212212    }
    213213  }
     
    899899        int iRowM,iRowP;
    900900        ClpSimplex::Status status = model->getStatus(iSequence);
    901        
     901
    902902        switch(status) {
    903903         
     
    10101010        int iRowM,iRowP;
    10111011        ClpSimplex::Status status = model->getStatus(iSequence);
    1012        
     1012
    10131013        switch(status) {
    10141014         
     
    11381138  CoinBigIndex size = 2*number;
    11391139  int * temp2 = new int [numberColumns_*2+size];
    1140   memcpy(temp2,indices_,numberColumns_*2*sizeof(int));
     1140  CoinMemcpyN(indices_,numberColumns_*2,temp2);
    11411141  delete [] indices_;
    11421142  indices_= temp2;
  • trunk/Clp/src/ClpNode.cpp

    r1163 r1197  
    1717ClpNode::ClpNode () :
    1818  branchingValue_(0.5),
     19  objectiveValue_(0.0),
     20  sumInfeasibilities_(0.0),
     21  estimatedSolution_(0.0),
    1922  factorization_(NULL),
    2023  weights_(NULL),
     
    2225  primalSolution_(NULL),
    2326  dualSolution_(NULL),
     27  lower_(NULL),
     28  upper_(NULL),
    2429  pivotVariables_(NULL),
    2530  fixed_(NULL),
    2631  sequence_(1),
    27   numberFixed_(0)
     32  numberInfeasibilities_(0),
     33  numberFixed_(0),
     34  flags_(0),
     35  maximumFixed_(0),
     36  maximumRows_(0),
     37  maximumColumns_(0),
     38  maximumIntegers_(0)
    2839{
    2940 branchState_.firstBranch=0;
     
    3344// Useful Constructor from model
    3445//-------------------------------------------------------------------
    35 ClpNode::ClpNode (const ClpSimplex * model, const ClpNodeStuff * stuff) :
     46ClpNode::ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff, int depth) :
    3647  branchingValue_(0.5),
     48  objectiveValue_(0.0),
     49  sumInfeasibilities_(0.0),
     50  estimatedSolution_(0.0),
    3751  factorization_(NULL),
    3852  weights_(NULL),
     
    4054  primalSolution_(NULL),
    4155  dualSolution_(NULL),
     56  lower_(NULL),
     57  upper_(NULL),
    4258  pivotVariables_(NULL),
    4359  fixed_(NULL),
    4460  sequence_(1),
    45   numberFixed_(0)
     61  numberInfeasibilities_(0),
     62  numberFixed_(0),
     63  flags_(0),
     64  maximumFixed_(0),
     65  maximumRows_(0),
     66  maximumColumns_(0),
     67  maximumIntegers_(0)
    4668{
    4769  branchState_.firstBranch=0;
    4870  branchState_.branch=0;
    49   gutsOfConstructor(model,stuff);
     71  gutsOfConstructor(model,stuff,0,depth);
    5072}
    5173
     
    5476//-------------------------------------------------------------------
    5577void
    56 ClpNode::gutsOfConstructor (const ClpSimplex * model, const ClpNodeStuff * stuff)
    57 {
    58   // save stuff
    59   factorization_ = new ClpFactorization(*model->factorization());
     78ClpNode::gutsOfConstructor (ClpSimplex * model, const ClpNodeStuff * stuff,
     79                            int arraysExist,int depth)
     80{
    6081  int numberRows = model->numberRows();
    6182  int numberColumns = model->numberColumns();
    6283  int numberTotal = numberRows+numberColumns;
    63   status_ = CoinCopyOfArray(model->statusArray(),numberTotal);
    64   primalSolution_ = CoinCopyOfArray(model->solutionRegion(),numberTotal);
    65   dualSolution_ = CoinCopyOfArray(model->djRegion(),numberTotal); //? has duals as well?
    66   pivotVariables_ = CoinCopyOfArray(model->pivotVariable(),numberRows);
    67   ClpDualRowSteepest* pivot =
    68     dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
    69   if (pivot)
    70     weights_ = new ClpDualRowSteepest(*pivot);
     84  int maximumTotal = maximumRows_+maximumColumns_;
     85  // save stuff
     86  objectiveValue_ = model->objectiveValue()*model->optimizationDirection();
     87  estimatedSolution_ = objectiveValue_;
     88  flags_ = 1; //say scaled
     89  if (!arraysExist) {
     90    maximumRows_=CoinMax(maximumRows_,numberRows);
     91    maximumColumns_=CoinMax(maximumColumns_,numberColumns);
     92    maximumTotal = maximumRows_+maximumColumns_;
     93    factorization_ = new ClpFactorization(*model->factorization());
     94    status_ = CoinCopyOfArrayPartial(model->statusArray(),maximumTotal,numberTotal);
     95    primalSolution_ = CoinCopyOfArrayPartial(model->solutionRegion(),maximumTotal,numberTotal);
     96    dualSolution_ = CoinCopyOfArrayPartial(model->djRegion(),maximumTotal,numberTotal); //? has duals as well?
     97    pivotVariables_ = CoinCopyOfArrayPartial(model->pivotVariable(),maximumRows_,numberRows);
     98    ClpDualRowSteepest* pivot =
     99      dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     100    if (pivot) {
     101      assert (!weights_);
     102      weights_ = new ClpDualRowSteepest(*pivot);
     103    }
     104  } else {
     105    if (arraysExist==2)
     106      assert(lower_);
     107    if (numberRows<=maximumRows_&&numberColumns<=maximumColumns_) {
     108      CoinMemcpyN(model->statusArray(),numberTotal,status_);
     109      if (arraysExist==1) {
     110        *factorization_ = *model->factorization();
     111        CoinMemcpyN(model->solutionRegion(),numberTotal,primalSolution_);
     112        CoinMemcpyN(model->djRegion(),numberTotal,dualSolution_); //? has duals as well?
     113        ClpDualRowSteepest* pivot =
     114          dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     115        if (pivot) {
     116          if (weights_) {
     117            //if (weights_->numberRows()==pivot->numberRows()) {
     118              weights_->fill(*pivot);
     119              //} else {
     120              //delete weights_;
     121              //weights_ = new ClpDualRowSteepest(*pivot);
     122              //}
     123          } else {
     124            weights_ = new ClpDualRowSteepest(*pivot);
     125          }
     126        }
     127        CoinMemcpyN(model->pivotVariable(),numberRows,pivotVariables_);
     128      } else {
     129        CoinMemcpyN(model->primalColumnSolution(),numberColumns,primalSolution_);
     130        CoinMemcpyN(model->dualColumnSolution(),numberColumns,dualSolution_);
     131        flags_ = 0;
     132        CoinMemcpyN(model->dualRowSolution(),numberRows,dualSolution_+numberColumns);
     133      }
     134    } else {
     135      // size has changed
     136      maximumRows_=CoinMax(maximumRows_,numberRows);
     137      maximumColumns_=CoinMax(maximumColumns_,numberColumns);
     138      maximumTotal = maximumRows_+maximumColumns_;
     139      delete weights_;
     140      weights_ = NULL;
     141      delete [] status_;
     142      delete [] primalSolution_;
     143      delete [] dualSolution_;
     144      delete [] pivotVariables_;
     145      status_ = CoinCopyOfArrayPartial(model->statusArray(),maximumTotal,numberTotal);
     146      primalSolution_ = new double [maximumTotal*sizeof(double)];
     147      dualSolution_ = new double [maximumTotal*sizeof(double)];
     148      if (arraysExist==1) {
     149        *factorization_ = *model->factorization(); // I think this is OK
     150        CoinMemcpyN(model->solutionRegion(),numberTotal,primalSolution_);
     151        CoinMemcpyN(model->djRegion(),numberTotal,dualSolution_); //? has duals as well?
     152        ClpDualRowSteepest* pivot =
     153          dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     154        if (pivot) {
     155          assert (!weights_);
     156          weights_ = new ClpDualRowSteepest(*pivot);
     157        }
     158      } else {
     159        CoinMemcpyN(model->primalColumnSolution(),numberColumns,primalSolution_);
     160        CoinMemcpyN(model->dualColumnSolution(),numberColumns,dualSolution_);
     161        flags_ = 0;
     162        CoinMemcpyN(model->dualRowSolution(),numberRows,dualSolution_+numberColumns);
     163      }
     164      pivotVariables_ = new int [maximumRows_];
     165      if (model->pivotVariable())
     166        CoinMemcpyN(model->pivotVariable(),numberRows,pivotVariables_);
     167    }
     168  }
     169  numberFixed_=0;
    71170  const double * lower = model->columnLower();
    72171  const double * upper = model->columnUpper();
    73172  const double * solution = model->primalColumnSolution();
    74173  const char * integerType = model->integerInformation();
     174  const double * columnScale = model->columnScale();
     175  if (!flags_)
     176    columnScale=NULL; // as duals correct
    75177  int iColumn;
    76178  sequence_=-1;
    77179  double integerTolerance = stuff->integerTolerance_;
    78180  double mostAway=integerTolerance;
    79   int numberAway=0;
     181  sumInfeasibilities_ = 0.0;
     182  numberInfeasibilities_ = 0;
     183  int nFix=0;
     184  double gap = CoinMax(model->dualObjectiveLimit()-objectiveValue_,1.0e-4);
     185#define PSEUDO 2
     186#if PSEUDO==1
     187  // Column copy of matrix
     188  ClpPackedMatrix * matrix = model->clpScaledMatrix();
     189  if (!matrix)
     190    matrix = dynamic_cast< ClpPackedMatrix*>(model->clpMatrix());
     191  const double * element = matrix->getElements();
     192  const int * row = matrix->getIndices();
     193  const CoinBigIndex * columnStart = matrix->getVectorStarts();
     194  const int * columnLength = matrix->getVectorLengths();
     195  const double *objective = model->costRegion() ;
     196  double direction = model->optimizationDirection();
     197  const double * dual = dualSolution_+numberColumns;
     198#elif PSEUDO==2
     199  const double * downPseudo = stuff->downPseudo_;
     200  const int * numberDown = stuff->numberDown_;
     201  const int * numberDownInfeasible = stuff->numberDownInfeasible_;
     202  const double * upPseudo = stuff->upPseudo_;
     203  const int * numberUp = stuff->numberUp_;
     204  const int * numberUpInfeasible = stuff->numberUpInfeasible_;
     205#endif
     206  int iInteger=0;
    80207  for (iColumn=0;iColumn<numberColumns;iColumn++) {
    81208    if (integerType[iColumn]) {
     
    84211      value = min(value,(double) upper[iColumn]);
    85212      double nearest = floor(value+0.5);
    86       if (fabs(value-nearest)>integerTolerance)
    87         numberAway++;
    88       if (fabs(value-nearest)>mostAway) {
    89         mostAway=fabs(value-nearest);
    90         sequence_=iColumn;
    91         branchingValue_=value;
    92         branchState_.branch=0;
    93         if (value<=nearest)
    94           branchState_.firstBranch=1; // up
     213      if (fabs(value-nearest)>integerTolerance) {
     214        numberInfeasibilities_++;
     215        sumInfeasibilities_ += fabs(value-nearest);
     216#if PSEUDO==1
     217        double upValue = 0.0;
     218        double downValue = 0.0;
     219        double value2 = direction*objective[iColumn];
     220        if (value2) {
     221          if (value2>0.0)
     222            upValue += value2;
     223          else
     224            downValue -= value2;
     225        }
     226        CoinBigIndex start = columnStart[iColumn];
     227        CoinBigIndex end = columnStart[iColumn]+columnLength[iColumn];
     228        for (CoinBigIndex j=start;j<end;j++) {
     229          int iRow = row[j];
     230          value2 = -dual[iRow];
     231          if (value2) {
     232            value2 *= element[j];
     233            if (value2>0.0)
     234              upValue += value2;
     235            else
     236              downValue -= value2;
     237          }
     238        }
     239        upValue *= ceil(value)-value;
     240        downValue *= value-floor(value);
     241        double infeasibility;
     242        if (depth>1000)
     243          infeasibility = CoinMax(upValue,downValue)+integerTolerance;
    95244        else
    96           branchState_.firstBranch=0; // down
    97       }
    98     }
     245          infeasibility = 0.1*CoinMax(upValue,downValue)+
     246            0.9*CoinMin(upValue,downValue) + integerTolerance;
     247#elif PSEUDO==2
     248        double upValue = (ceil(value)-value)*(upPseudo[iInteger]/(1.0+numberUp[iInteger]+numberUpInfeasible[iInteger]));
     249        double downValue = (value-floor(value))*(downPseudo[iInteger]/(1.0+numberDown[iInteger]+numberDownInfeasible[iInteger]));
     250        double infeasibility;
     251        if (depth>1000)
     252          infeasibility = CoinMax(upValue,downValue)+integerTolerance;
     253        else
     254          infeasibility = 0.1*CoinMax(upValue,downValue)+
     255            0.9*CoinMin(upValue,downValue) + integerTolerance;
     256        estimatedSolution_ += CoinMin(upValue,downValue);
     257#else
     258        double infeasibility = fabs(value-nearest);
     259#endif
     260        if (infeasibility>mostAway) {
     261          mostAway=infeasibility;
     262          sequence_=iColumn;
     263          branchingValue_=value;
     264          branchState_.branch=0;
     265#if PSEUDO>0
     266          if (upValue<=downValue)
     267            branchState_.firstBranch=1; // up
     268          else
     269            branchState_.firstBranch=0; // down
     270#else
     271          if (value<=nearest)
     272            branchState_.firstBranch=1; // up
     273          else
     274            branchState_.firstBranch=0; // down
     275#endif
     276        }
     277      } else if (model->getColumnStatus(iColumn)==ClpSimplex::atLowerBound) {
     278        bool fix=false;
     279        if (columnScale) {
     280          if (dualSolution_[iColumn]>gap*columnScale[iColumn])
     281            fix=true;
     282        } else {
     283          if (dualSolution_[iColumn]>gap)
     284            fix=true;
     285        }
     286        if (fix) {
     287          nFix++;
     288          //printf("fixed %d to zero gap %g dj %g %g\n",iColumn,
     289          // gap,dualSolution_[iColumn], columnScale ? columnScale[iColumn]:1.0);
     290          model->setColumnStatus(iColumn,ClpSimplex::isFixed);
     291        }
     292      } else if (model->getColumnStatus(iColumn)==ClpSimplex::atUpperBound) {
     293        bool fix=false;
     294        if (columnScale) {
     295          if (-dualSolution_[iColumn]>gap*columnScale[iColumn])
     296            fix=true;
     297        } else {
     298          if (-dualSolution_[iColumn]>gap)
     299            fix=true;
     300        }
     301        if (fix) {
     302          nFix++;
     303          //printf("fixed %d to one gap %g dj %g %g\n",iColumn,
     304          // gap,dualSolution_[iColumn], columnScale ? columnScale[iColumn]:1.0);
     305          model->setColumnStatus(iColumn,ClpSimplex::isFixed);
     306        }
     307      }
     308      iInteger++;
     309    }
     310  }
     311  if (lower_) {
     312    // save bounds
     313    if (iInteger>maximumIntegers_) {
     314      delete [] lower_;
     315      delete [] upper_;
     316      maximumIntegers_ = iInteger;
     317      lower_ = new int [maximumIntegers_];
     318      upper_ = new int [maximumIntegers_];
     319    }
     320    iInteger=0;
     321    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     322      if (integerType[iColumn]) {
     323        lower_[iInteger]=(int) lower[iColumn];
     324        upper_[iInteger]=(int) upper[iColumn];
     325        iInteger++;
     326      }
     327    }
     328  }
     329  // Could omit save of fixed if doing full save of bounds
     330  if (sequence_>=0&&nFix) {
     331    if (nFix>maximumFixed_) {
     332      delete [] fixed_;
     333      fixed_ = new int [nFix];
     334      maximumFixed_=nFix;
     335    }
     336    numberFixed_=0;
     337    unsigned char * status = model->statusArray();
     338    for (iColumn=0;iColumn<numberColumns;iColumn++) {
     339      if (status[iColumn]!=status_[iColumn]) {
     340        if (solution[iColumn]<=lower[iColumn]+2.0*integerTolerance) {
     341          model->setColumnUpper(iColumn,lower[iColumn]);
     342          fixed_[numberFixed_++]=iColumn;
     343        } else {
     344          assert (solution[iColumn]>=upper[iColumn]-2.0*integerTolerance);
     345          model->setColumnLower(iColumn,upper[iColumn]);
     346          fixed_[numberFixed_++]=iColumn|0x10000000;
     347        }
     348      }
     349    }
     350    //printf("%d fixed\n",numberFixed_);
    99351  }
    100352}
     
    119371  delete [] primalSolution_;
    120372  delete [] dualSolution_;
     373  delete [] lower_;
     374  delete [] upper_;
    121375  delete [] pivotVariables_;
    122376  delete [] fixed_;
     
    135389  return *this;
    136390}
    137 // Applies node to model
     391// Create odd arrays
    138392void
    139 ClpNode::applyNode(ClpSimplex * model, bool justBounds )
    140 {
    141   // current bound
     393ClpNode::createArrays(ClpSimplex * model)
     394{
     395  int numberColumns = model->numberColumns();
     396  const char * integerType = model->integerInformation();
     397  int iColumn;
     398  int numberIntegers=0;
     399  for (iColumn=0;iColumn<numberColumns;iColumn++) {
     400    if (integerType[iColumn])
     401      numberIntegers++;
     402  }
     403  if (numberIntegers>maximumIntegers_||!lower_) {
     404    delete [] lower_;
     405    delete [] upper_;
     406    maximumIntegers_ = numberIntegers;
     407    lower_ = new int [numberIntegers];
     408    upper_ = new int [numberIntegers];
     409  }
     410}
     411// Clean up as crunch is different model
     412void
     413ClpNode::cleanUpForCrunch()
     414{
     415  delete weights_;
     416  weights_ = NULL;
     417}
     418/* Applies node to model
     419   0 - just tree bounds
     420   1 - tree bounds and basis etc
     421   2 - saved bounds and basis etc
     422*/
     423void
     424ClpNode::applyNode(ClpSimplex * model, int doBoundsEtc )
     425{
     426  int numberColumns = model->numberColumns();
     427  const double * lower = model->columnLower();
     428  const double * upper = model->columnUpper();
     429  if (doBoundsEtc<2) {
     430    // current bound
     431    int way=branchState_.firstBranch;
     432    if (branchState_.branch>0)
     433      way=1-way;
     434    if (!way) {
     435      // This should also do underlying internal bound
     436      model->setColumnUpper(sequence_,floor(branchingValue_));
     437    } else {
     438      // This should also do underlying internal bound
     439      model->setColumnLower(sequence_,ceil(branchingValue_));
     440    }
     441    // apply dj fixings
     442    for (int i=0;i<numberFixed_;i++) {
     443      int iColumn = fixed_[i];
     444      if ((iColumn&0x10000000)!=0) {
     445        iColumn &= 0xfffffff;
     446        model->setColumnLower(iColumn,upper[iColumn]);
     447    } else {
     448        model->setColumnUpper(iColumn,lower[iColumn]);
     449      }
     450    }
     451  } else {
     452    // restore bounds
     453    assert (lower_);
     454    int iInteger=-1;
     455    const char * integerType = model->integerInformation();
     456    for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     457      if (integerType[iColumn]) {
     458        iInteger++;
     459        if (lower_[iInteger]!=(int) lower[iColumn])
     460          model->setColumnLower(iColumn,lower_[iInteger]);
     461        if (upper_[iInteger]!=(int) upper[iColumn])
     462          model->setColumnUpper(iColumn,upper_[iInteger]);
     463      }
     464    }
     465  }
     466  if (doBoundsEtc&&doBoundsEtc<3) {
     467    //model->copyFactorization(*factorization_);
     468    model->copyFactorization(*factorization_);
     469    ClpDualRowSteepest* pivot =
     470      dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
     471    if (pivot&&weights_) {
     472      pivot->fill(*weights_);
     473    }
     474    int numberRows = model->numberRows();
     475    int numberTotal = numberRows+numberColumns;
     476    CoinMemcpyN(status_,numberTotal,model->statusArray());
     477    if (doBoundsEtc<2) {
     478      CoinMemcpyN(primalSolution_,numberTotal,model->solutionRegion());
     479      CoinMemcpyN(dualSolution_,numberTotal,model->djRegion());
     480      CoinMemcpyN(pivotVariables_,numberRows,model->pivotVariable());
     481      CoinMemcpyN(dualSolution_+numberColumns,numberRows,model->dualRowSolution());
     482    } else {
     483      CoinMemcpyN(primalSolution_,numberColumns,model->primalColumnSolution());
     484      CoinMemcpyN(dualSolution_,numberColumns,model->dualColumnSolution());
     485      CoinMemcpyN(dualSolution_+numberColumns,numberRows,model->dualRowSolution());
     486      if (model->columnScale()) {
     487        // See if just primal will work
     488        double * solution = model->primalColumnSolution();
     489        const double * columnScale = model->columnScale();
     490        int i;
     491        for (i=0;i<numberColumns;i++) {
     492          solution[i] *= columnScale[i];
     493        }
     494      }
     495    }
     496    model->setObjectiveValue(objectiveValue_);
     497  }
     498}
     499// Fix on reduced costs
     500int
     501ClpNode::fixOnReducedCosts(ClpSimplex * model)
     502{
     503  return 0;
     504}
     505/* Way for integer variable -1 down , +1 up */
     506int
     507ClpNode::way() const
     508{
    142509  int way=branchState_.firstBranch;
    143510  if (branchState_.branch>0)
    144511    way=1-way;
    145   if (!way) {
    146     // This should also do underlying internal bound
    147     model->setColumnUpper(sequence_,floor(branchingValue_));
    148   } else {
    149     // This should also do underlying internal bound
    150     model->setColumnLower(sequence_,ceil(branchingValue_));
    151   }
    152   const double * lower = model->columnLower();
    153   const double * upper = model->columnUpper();
    154   // apply dj fixings
    155   for (int i=0;i<numberFixed_;i++) {
    156     int iColumn = fixed_[i];
    157     if ((iColumn&0x10000000)!=0) {
    158       iColumn &= 0xfffffff;
    159       model->setColumnLower(iColumn,upper[iColumn]);
    160     } else {
    161         model->setColumnUpper(iColumn,lower[iColumn]);
    162     }
    163   }
    164   if (!justBounds) {
    165     model->setFactorization(*factorization_);
    166     ClpDualRowSteepest* pivot =
    167       dynamic_cast< ClpDualRowSteepest*>(model->dualRowPivot());
    168     if (pivot)
    169       *pivot=*weights_; // may be better to copy stuff
    170     int numberRows = model->numberRows();
    171     int numberColumns = model->numberColumns();
    172     int numberTotal = numberRows+numberColumns;
    173     CoinMemcpyN(status_,numberTotal,model->statusArray());
    174     CoinMemcpyN(primalSolution_,numberTotal,model->solutionRegion());
    175     CoinMemcpyN(dualSolution_,numberTotal,model->djRegion()); //? has duals as well?
    176     CoinMemcpyN(pivotVariables_,numberRows,model->pivotVariable());
    177   }
    178 }
    179 // Fix on reduced costs
    180 int
    181 ClpNode::fixOnReducedCosts(ClpSimplex * model)
    182 {
    183   return 0;
    184 }
    185 /* Way for integer variable -1 down , +1 up */
    186 int
    187 ClpNode::way() const
    188 {
    189   int way=branchState_.firstBranch;
    190   if (branchState_.branch>0)
    191     way=1-way;
    192   return way ? -1 : +1;
     512  return way==0 ? -1 : +1;
    193513}
    194514// Return true if branch exhausted
     
    215535ClpNodeStuff::ClpNodeStuff () :
    216536  integerTolerance_(1.0e-7),
    217   integerIncrement_(1.0e-8)
     537  integerIncrement_(1.0e-8),
     538  downPseudo_(NULL),
     539  upPseudo_(NULL),
     540  numberDown_(NULL),
     541  numberUp_(NULL),
     542  numberDownInfeasible_(NULL),
     543  numberUpInfeasible_(NULL),
     544  saveCosts_(NULL),
     545  nodeInfo_(NULL),
     546  large_(NULL),
     547  whichRow_(NULL),
     548  whichColumn_(NULL),
     549  nBound_(0),
     550  saveOptions_(0),
     551  solverOptions_(0),
     552  nDepth_(-1),
     553  nNodes_(0),
     554  numberNodesExplored_(0),
     555  numberIterations_(0),
     556  presolveType_(0)
    218557{
    219558
     
    223562// Copy constructor
    224563//-------------------------------------------------------------------
    225 ClpNodeStuff::ClpNodeStuff (const ClpNodeStuff & source)
     564ClpNodeStuff::ClpNodeStuff (const ClpNodeStuff & rhs)
     565  : integerTolerance_(rhs.integerTolerance_),
     566    integerIncrement_(rhs.integerIncrement_),
     567    downPseudo_(NULL),
     568    upPseudo_(NULL),
     569    numberDown_(NULL),
     570    numberUp_(NULL),
     571    numberDownInfeasible_(NULL),
     572    numberUpInfeasible_(NULL),
     573    saveCosts_(NULL),
     574    nodeInfo_(NULL),
     575    large_(NULL),
     576    whichRow_(NULL),
     577    whichColumn_(NULL),
     578    nBound_(0),
     579    saveOptions_(rhs.saveOptions_),
     580    solverOptions_(rhs.solverOptions_),
     581    nDepth_(rhs.nDepth_),
     582    nNodes_(rhs.nNodes_),
     583    numberNodesExplored_(rhs.numberNodesExplored_),
     584    numberIterations_(rhs.numberIterations_),
     585    presolveType_(rhs.presolveType_)
    226586
    227   printf("ClpNodeStuff copy not implemented\n");
    228   abort();
    229587}
    230588//----------------------------------------------------------------
     
    235593{
    236594  if (this != &rhs) {
    237     printf("ClpNodeStuff = not implemented\n");
    238     abort();
     595    integerTolerance_ = rhs.integerTolerance_;
     596    integerIncrement_ = rhs.integerIncrement_;
     597    downPseudo_ = NULL;
     598    upPseudo_ = NULL;
     599    numberDown_ = NULL;
     600    numberUp_ = NULL;
     601    numberDownInfeasible_ = NULL;
     602    numberUpInfeasible_ = NULL;
     603    saveCosts_ = NULL;
     604    nodeInfo_ = NULL;
     605    large_ = NULL;
     606    whichRow_ = NULL;
     607    whichColumn_ = NULL;
     608    nBound_ = 0;
     609    saveOptions_ = rhs.saveOptions_;
     610    solverOptions_ = rhs.solverOptions_;
     611    if (nDepth_>=0) {
     612      int n = (1<<nDepth_)+1+nDepth_;
     613      for (int i=0;i<n;i++)
     614        delete nodeInfo_[i];
     615      delete [] nodeInfo_;
     616    }
     617    nDepth_ = rhs.nDepth_;
     618    nNodes_ = rhs.nNodes_;
     619    numberNodesExplored_ = rhs.numberNodesExplored_;
     620    numberIterations_ = rhs.numberIterations_;
     621    presolveType_ = rhs.presolveType_;
    239622  }
    240623  return *this;
    241624}
     625// Zaps stuff 1 - arrays, 2 ints, 3 both
     626void
     627ClpNodeStuff::zap(int type)
     628{
     629  if ((type&1)!=0) {
     630    downPseudo_ = NULL;
     631    upPseudo_ = NULL;
     632    numberDown_ = NULL;
     633    numberUp_ = NULL;
     634    numberDownInfeasible_ = NULL;
     635    numberUpInfeasible_ = NULL;
     636    saveCosts_ = NULL;
     637    nodeInfo_ = NULL;
     638    large_ = NULL;
     639    whichRow_ = NULL;
     640    whichColumn_ = NULL;
     641  }
     642  if ((type&2)!=0) {
     643    nBound_ = 0;
     644    saveOptions_ = 0;
     645    solverOptions_ = 0;
     646    nDepth_ = -1;
     647    nNodes_ = 0;
     648    presolveType_ = 0;
     649    numberNodesExplored_ = 0;
     650    numberIterations_ = 0;
     651  }
     652}
    242653
    243654//-------------------------------------------------------------------
     
    246657ClpNodeStuff::~ClpNodeStuff ()
    247658{
    248 }
     659  delete [] downPseudo_;
     660  delete [] upPseudo_;
     661  delete [] numberDown_;
     662  delete [] numberUp_;
     663  delete [] numberDownInfeasible_;
     664  delete [] numberUpInfeasible_;
     665  if (nDepth_>=0) {
     666    int n = (1<<nDepth_)+1+nDepth_;
     667    for (int i=0;i<n;i++)
     668      delete nodeInfo_[i];
     669    delete [] nodeInfo_;
     670  }
     671}
     672/* Fill with pseudocosts */
     673void
     674ClpNodeStuff::fillPseudoCosts(const double * down, const double * up,
     675                              const int * numberDown, const int * numberUp,
     676                              const int * numberDownInfeasible,
     677                              const int * numberUpInfeasible,
     678                              int number)
     679{
     680  delete [] downPseudo_;
     681  delete [] upPseudo_;
     682  delete [] numberDown_;
     683  delete [] numberUp_;
     684  delete [] numberDownInfeasible_;
     685  delete [] numberUpInfeasible_;
     686  downPseudo_ = CoinCopyOfArray(down,number);
     687  upPseudo_ = CoinCopyOfArray(up,number);
     688  numberDown_ = CoinCopyOfArray(numberDown,number);
     689  numberUp_ = CoinCopyOfArray(numberUp,number);
     690  numberDownInfeasible_ = CoinCopyOfArray(numberDownInfeasible,number);
     691  numberUpInfeasible_ = CoinCopyOfArray(numberUpInfeasible,number);
     692  // scale
     693  for (int i=0;i<number;i++) {
     694    int n;
     695    n = numberDown_[i]+numberDownInfeasible_[i];
     696    if (n)
     697      downPseudo_[i] *= n;
     698    n = numberUp_[i]+numberUpInfeasible_[i];
     699    if (n)
     700      upPseudo_[i] *= n;
     701  }
     702}
     703// Update pseudo costs
     704void
     705ClpNodeStuff::update(int way,int sequence,double change,bool feasible)
     706{
     707  if (way<0) {
     708    if (feasible)
     709      numberDown_[sequence]++;
     710    else
     711      numberDownInfeasible_[sequence]++;
     712    downPseudo_[sequence] += CoinMax(change,1.0e-12);
     713  } else {
     714    if (feasible)
     715      numberUp_[sequence]++;
     716    else
     717      numberUpInfeasible_[sequence]++;
     718    upPseudo_[sequence] += CoinMax(change,1.0e-12);
     719  }
     720}
     721//#############################################################################
     722// Constructors / Destructor / Assignment
     723//#############################################################################
     724
     725//-------------------------------------------------------------------
     726// Default Constructor
     727//-------------------------------------------------------------------
     728ClpHashValue::ClpHashValue () :
     729  hash_(NULL),
     730  numberHash_(0),
     731  maxHash_(0),
     732  lastUsed_(-1)
     733{
     734}
     735//-------------------------------------------------------------------
     736// Useful Constructor from model
     737//-------------------------------------------------------------------
     738ClpHashValue::ClpHashValue (ClpSimplex * model) :
     739  hash_(NULL),
     740  numberHash_(0),
     741  maxHash_(0),
     742  lastUsed_(-1)
     743{
     744  maxHash_ = 1000;
     745  int numberColumns = model->numberColumns();
     746  const double * columnLower = model->columnLower();
     747  const double * columnUpper = model->columnUpper();
     748  int numberRows = model->numberRows();
     749  const double * rowLower = model->rowLower();
     750  const double * rowUpper = model->rowUpper();
     751  const double * objective = model->objective();
     752  CoinPackedMatrix * matrix = model->matrix();
     753  const int * columnLength = matrix->getVectorLengths();
     754  const CoinBigIndex * columnStart = matrix->getVectorStarts();
     755  const double * elementByColumn = matrix->getElements();
     756  int i;
     757  int ipos;
     758
     759  hash_ = new CoinHashLink[maxHash_];
     760 
     761  for ( i = 0; i < maxHash_; i++ ) {
     762    hash_[i].value = 0.0;
     763    hash_[i].index = -1;
     764    hash_[i].next = -1;
     765  }
     766
     767  /*
     768   * Initialize the hash table.  Only the index of the first value that
     769   * hashes to a value is entered in the table; subsequent values that
     770   * collide with it are not entered.
     771   */
     772  for ( i = 0; i < numberColumns; i++ ) {
     773    int length=columnLength[i];
     774    CoinBigIndex start = columnStart[i];
     775    for (CoinBigIndex i=start;i<start+length;i++) {
     776      ipos = hash ( elementByColumn[i]);
     777      if ( hash_[ipos].index == -1 ) {
     778        hash_[ipos].index = numberHash_;
     779        numberHash_++;
     780        hash_[ipos].value = elementByColumn[i];
     781      }
     782    }
     783  }
     784 
     785  /*
     786   * Now take care of the values that collided in the preceding loop,
     787   * Also do other stuff
     788   */
     789  for ( i = 0; i < numberRows; i++ ) {
     790    if (numberHash_*2>maxHash_)
     791      resize(true);
     792    double value;
     793    value = rowLower[i];
     794    ipos = index(value);
     795    if (ipos<0)
     796      addValue(value);
     797    value = rowUpper[i];
     798    ipos = index(value);
     799    if (ipos<0)
     800      addValue(value);
     801  }
     802  for ( i = 0; i < numberColumns; i++ ) {
     803    int length=columnLength[i];
     804    CoinBigIndex start = columnStart[i];
     805    if (numberHash_*2>maxHash_)
     806      resize(true);
     807    double value;
     808    value = objective[i];
     809    ipos = index(value);
     810    if (ipos<0)
     811      addValue(value);
     812    value = columnLower[i];
     813    ipos = index(value);
     814    if (ipos<0)
     815      addValue(value);
     816    value = columnUpper[i];
     817    ipos = index(value);
     818    if (ipos<0)
     819      addValue(value);
     820    for (CoinBigIndex j=start;j<start+length;j++) {
     821      if (numberHash_*2>maxHash_)
     822        resize(true);
     823      value = elementByColumn[j];
     824      ipos = index(value);
     825      if (ipos<0)
     826        addValue(value);
     827    }
     828  }
     829  resize(false);
     830}
     831
     832//-------------------------------------------------------------------
     833// Copy constructor
     834//-------------------------------------------------------------------
     835ClpHashValue::ClpHashValue (const ClpHashValue & rhs) :
     836  hash_(NULL),
     837  numberHash_(rhs.numberHash_),
     838  maxHash_(rhs.maxHash_),
     839  lastUsed_(rhs.lastUsed_)
     840
     841  if (maxHash_) {
     842    CoinHashLink * newHash = new CoinHashLink[maxHash_];
     843    int i;
     844    for ( i = 0; i < maxHash_; i++ ) {
     845      newHash[i].value = rhs.hash_[i].value;
     846      newHash[i].index = rhs.hash_[i].index;
     847      newHash[i].next = rhs.hash_[i].next;
     848    }
     849  }
     850}
     851
     852//-------------------------------------------------------------------
     853// Destructor
     854//-------------------------------------------------------------------
     855ClpHashValue::~ClpHashValue ()
     856{
     857  delete [] hash_;
     858}
     859
     860//----------------------------------------------------------------
     861// Assignment operator
     862//-------------------------------------------------------------------
     863ClpHashValue &
     864ClpHashValue::operator=(const ClpHashValue& rhs)
     865{
     866  if (this != &rhs) {
     867    numberHash_ = rhs.numberHash_;
     868    maxHash_ = rhs.maxHash_;
     869    lastUsed_ = rhs.lastUsed_;
     870    delete [] hash_;
     871    if (maxHash_) {
     872      CoinHashLink * newHash = new CoinHashLink[maxHash_];
     873      int i;
     874      for ( i = 0; i < maxHash_; i++ ) {
     875        newHash[i].value = rhs.hash_[i].value;
     876        newHash[i].index = rhs.hash_[i].index;
     877        newHash[i].next = rhs.hash_[i].next;
     878      }
     879    } else {
     880      hash_ = NULL;
     881    }
     882  }
     883  return *this;
     884}
     885// Return index or -1 if not found
     886int
     887ClpHashValue::index(double value) const
     888{
     889  int ipos = hash ( value);
     890  int returnCode=-1;
     891  while ( hash_[ipos].index>=0 ) {
     892    if (value==hash_[ipos].value) {
     893      returnCode = hash_[ipos].index;
     894      break;
     895    } else {
     896      int k = hash_[ipos].next;
     897      if ( k == -1 ) {
     898        break;
     899      } else {
     900        ipos = k;
     901      }
     902    }
     903  }
     904  return returnCode;
     905}
     906// Add value to list and return index
     907int
     908ClpHashValue::addValue(double value)
     909{
     910  int ipos = hash ( value);
     911 
     912  assert (value!=hash_[ipos].value);
     913  int k = hash_[ipos].next;
     914  while (k!=-1) {
     915    ipos = k;
     916    k = hash_[ipos].next;
     917  }
     918  while ( true ) {
     919    ++lastUsed_;
     920    assert (lastUsed_<=maxHash_);
     921    if ( hash_[lastUsed_].index == -1 ) {
     922      break;
     923    }
     924  }
     925  hash_[ipos].next = lastUsed_;
     926  hash_[lastUsed_].index = numberHash_;
     927  numberHash_++;
     928  hash_[lastUsed_].value = value;
     929  return numberHash_-1;
     930}
     931
     932int
     933ClpHashValue::hash ( double value) const
     934{
     935  static int mmult[] = {
     936    262139, 259459, 256889, 254291, 251701, 249133, 246709, 244247,
     937    241667, 239179, 236609, 233983, 231289, 228859, 226357, 223829,
     938    221281, 218849, 216319, 213721, 211093, 208673, 206263, 203773,
     939    201233, 198637, 196159, 193603, 191161, 188701, 186149, 183761,
     940    181303, 178873, 176389, 173897, 171469, 169049, 166471, 163871,
     941    161387, 158941, 156437, 153949, 151531, 149159, 146749, 144299,
     942    141709, 139369, 136889, 134591, 132169, 129641, 127343, 124853,
     943    122477, 120163, 117757, 115361, 112979, 110567, 108179, 105727,
     944    103387, 101021, 98639, 96179, 93911, 91583, 89317, 86939, 84521,
     945    82183, 79939, 77587, 75307, 72959, 70793, 68447, 66103
     946  };
     947  union { double d; char c[8]; } v1;
     948  assert (sizeof(double)==8);
     949  v1.d = value;
     950  int n = 0;
     951  int j;
     952
     953  for ( j = 0; j < 8; ++j ) {
     954    int ichar = v1.c[j];
     955    n += mmult[j] * ichar;
     956  }
     957  return ( abs ( n ) % maxHash_ );      /* integer abs */
     958}
     959void
     960ClpHashValue::resize(bool increaseMax)
     961{
     962  int newSize = increaseMax ? ((3*maxHash_)>>1)+1000 : maxHash_;
     963  CoinHashLink * newHash = new CoinHashLink[newSize];
     964  int i;
     965  for ( i = 0; i < newSize; i++ ) {
     966    newHash[i].value = 0.0;
     967    newHash[i].index = -1;
     968    newHash[i].next = -1;
     969  }
     970  // swap
     971  CoinHashLink * oldHash = hash_;
     972  hash_ = newHash;
     973  int oldSize = maxHash_;
     974  maxHash_ = newSize;
     975  /*
     976   * Initialize the hash table.  Only the index of the first value that
     977   * hashes to a value is entered in the table; subsequent values that
     978   * collide with it are not entered.
     979   */
     980  int ipos;
     981  int n=0;
     982  for ( i = 0; i < oldSize; i++ ) {
     983    if (oldHash[i].index>=0) {
     984      ipos = hash ( oldHash[i].value);
     985      if ( hash_[ipos].index == -1 ) {
     986        hash_[ipos].index = n;
     987        n++;
     988        hash_[ipos].value = hash_[i].value;
     989      }
     990    }
     991  }
     992  /*
     993   * Now take care of the values that collided in the preceding loop,
     994   * by finding some other entry in the table for them.
     995   * Since there are as many entries in the table as there are values,
     996   * there must be room for them.
     997   */
     998  lastUsed_ = -1;
     999  for ( i = 0; i < oldSize; ++i ) {
     1000    if (oldHash[i].index>=0) {
     1001      double value = oldHash[i].value;
     1002      ipos = hash ( value);
     1003      int k;
     1004      while ( true ) {
     1005        if (value==hash_[ipos].value)
     1006          break;
     1007        else
     1008          k = hash_[ipos].next;
     1009       
     1010        if ( k == -1 ) {
     1011          while ( true ) {
     1012            ++lastUsed_;
     1013            assert (lastUsed_<=maxHash_);
     1014            if ( hash_[lastUsed_].index == -1 ) {
     1015              break;
     1016            }
     1017          }
     1018          hash_[ipos].next = lastUsed_;
     1019          hash_[lastUsed_].index = n;
     1020          n++;
     1021          hash_[lastUsed_].value = value;
     1022          break;
     1023        } else {
     1024          ipos = k;
     1025        }
     1026      }
     1027    }
     1028  }
     1029  assert (n==numberHash_);
     1030}
  • trunk/Clp/src/ClpNode.hpp

    r1163 r1197  
    1919  /**@name Useful methods */
    2020  //@{
    21   /// Applies node to model
    22   void applyNode(ClpSimplex * model, bool justBounds );
     21  /** Applies node to model
     22      0 - just tree bounds
     23      1 - tree bounds and basis etc
     24      2 - saved bounds and basis etc
     25  */
     26  void applyNode(ClpSimplex * model, int doBoundsEtc );
    2327  /// Fix on reduced costs
    2428  int fixOnReducedCosts(ClpSimplex * model);
     29  /// Create odd arrays
     30  void createArrays(ClpSimplex * model);
     31  /// Clean up as crunch is different model
     32  void cleanUpForCrunch();
    2533  //@}
    2634 
    2735  /**@name Gets and sets */
    2836  //@{
     37  /// Objective value
     38  inline double objectiveValue() const
     39  { return objectiveValue_;}
     40  /// Set objective value
     41  inline void setObjectiveValue(double value)
     42  { objectiveValue_=value;}
     43  /// Primal solution
     44  inline const double * primalSolution() const
     45  { return primalSolution_;}
     46  /// Dual solution
     47  inline const double * dualSolution() const
     48  { return dualSolution_;}
    2949  /// Initial value of integer variable
    3050  inline double branchingValue() const
    3151  { return branchingValue_;}
     52  /// Sum infeasibilities
     53  inline double sumInfeasibilities() const
     54  { return sumInfeasibilities_;}
     55  /// Number infeasibilities
     56  inline int numberInfeasibilities() const
     57  { return numberInfeasibilities_;}
     58  /// Estimated solution value
     59  inline double estimatedSolution() const
     60  { return estimatedSolution_;}
    3261  /** Way for integer variable -1 down , +1 up */
    3362  int way() const;
     
    3968  inline int sequence() const
    4069  { return sequence_;}
     70  /// If odd arrays exist
     71  inline bool oddArraysExist() const
     72  { return lower_!=NULL;}
     73  /// Status array
     74  inline const unsigned char * statusArray() const
     75  { return status_; }
    4176  //@}
    4277 
     
    4681  ClpNode();
    4782  /// Constructor from model
    48   ClpNode (const ClpSimplex * model, const ClpNodeStuff * stuff);
     83  ClpNode (ClpSimplex * model, const ClpNodeStuff * stuff,int depth);
    4984  /// Does work of constructor (partly so gdb will work)
    50   void gutsOfConstructor(const ClpSimplex * model, const ClpNodeStuff * stuff);
     85  void gutsOfConstructor(ClpSimplex * model, const ClpNodeStuff * stuff,
     86                         int arraysExist,int depth);
    5187  /** Destructor */
    5288  virtual ~ClpNode();
     
    72108  /// Initial value of integer variable
    73109  double branchingValue_;
     110  /// Value of objective
     111  double objectiveValue_;
     112  /// Sum of infeasibilities
     113  double sumInfeasibilities_;
     114  /// Estimated solution value
     115  double estimatedSolution_;
    74116  /// Factorization
    75117  ClpFactorization * factorization_;
     
    82124  /// Dual solution
    83125  double * dualSolution_;
     126  /// Integer lower bounds (only used in fathomMany)
     127  int * lower_;
     128  /// Integer upper bounds (only used in fathomMany)
     129  int * upper_;
    84130  /// Pivot variables for factorization
    85131  int * pivotVariables_;
     
    90136  /// Sequence number of integer variable (-1 if none)
    91137  int sequence_;
     138  /// Number of infeasibilities
     139  int numberInfeasibilities_;
    92140  /// Number fixed by reduced cost
    93141  int numberFixed_;
     142  /// Flags - 1 duals scaled
     143  int flags_;
     144  /// Maximum number fixed by reduced cost
     145  int maximumFixed_;
     146  /// Maximum rows so far
     147  int maximumRows_;
     148  /// Maximum columns so far
     149  int maximumColumns_;
     150  /// Maximum Integers so far
     151  int maximumIntegers_;
    94152  //@}
    95153};
     
    105163  //@}
    106164 
    107   /**@name Copy methods (at present illegal - will abort) */
     165  /**@name Copy methods (only copies ints etc, nulls arrays) */
    108166  //@{
    109167  /** The copy constructor. */
     
    111169  /// Operator =
    112170  ClpNodeStuff& operator=(const ClpNodeStuff&);
     171  /// Zaps stuff 1 - arrays, 2 ints, 3 both
     172  void zap(int type);
     173  //@}
     174 
     175 
     176  /**@name Fill methods */
     177  //@{
     178  /** Fill with pseudocosts */
     179  void fillPseudoCosts(const double * down, const double * up,
     180                       const int * numberDown, const int * numberUp,
     181                       const int * numberDownInfeasible, const int * numberUpInfeasible,
     182                       int number);
     183  /// Update pseudo costs
     184  void update(int way,int sequence,double change,bool feasible);
    113185  //@}
    114186 
     
    120192  /// Integer increment
    121193  double integerIncrement_;
     194  /// Down pseudo costs
     195  double * downPseudo_;
     196  /// Up pseudo costs
     197  double * upPseudo_;
     198  /// Number of times down
     199  int * numberDown_;
     200  /// Number of times up
     201  int * numberUp_;
     202  /// Number of times down infeasible
     203  int * numberDownInfeasible_;
     204  /// Number of times up infeasible
     205  int * numberUpInfeasible_;
     206  /// Copy of costs (local)
     207  double * saveCosts_;
     208  /// Array of ClpNodes
     209  ClpNode ** nodeInfo_;
     210  /// Large model if crunched
     211  ClpSimplex * large_;
     212  /// Which rows in large model
     213  int * whichRow_;
     214  /// Which columns in large model
     215  int * whichColumn_;
     216  /// Number bounds in large model
     217  int nBound_;
     218  /// Save of specialOptions_ (local)
     219  int saveOptions_;
     220  /** Options to pass to solver
     221      1 - create external reduced costs for columns
     222      2 - create external reduced costs for rows
     223      4 - create external row activity (columns always done)
     224      Above only done if feasible
     225      65536 - set if activated
     226  */
     227  int solverOptions_;
     228  /// Number deep
     229  int nDepth_;
     230  /// Number nodes returned (-1 if fathom aborted)
     231  int nNodes_;
     232  /// Number of nodes explored
     233  int numberNodesExplored_;
     234  /// Number of iterations
     235  int numberIterations_;
     236  /// Type of presolve - 0 none, 1 crunch
     237  int presolveType_;
     238  //@}
     239};
     240class ClpHashValue {
     241 
     242public:
     243  /**@name Useful methods */
     244  //@{
     245  /// Return index or -1 if not found
     246  int index(double value) const;
     247  /// Add value to list and return index
     248  int addValue(double value) ;
     249  //@}
     250
     251  /**@name Constructors, destructor */
     252  //@{
     253  /** Default constructor. */
     254  ClpHashValue();
     255  /** Useful constructor. */
     256  ClpHashValue(ClpSimplex * model);
     257  /** Destructor */
     258  virtual ~ClpHashValue();
     259  //@}
     260 
     261  /**@name Copy method */
     262  //@{
     263  /** The copy constructor. */
     264  ClpHashValue(const ClpHashValue&);
     265  /// =
     266  ClpHashValue& operator=(const ClpHashValue&);
     267  //@}
     268private:
     269  /**@name private stuff */
     270  //@{
     271  /** returns hash */
     272  int hash(double value) const;
     273  /// Resizes
     274  void resize(bool increaseMax);
     275  //@}
     276   
     277protected:
     278  /**@name Data members
     279     The data members are protected to allow access for derived classes. */
     280  //@{
     281  /// Data
     282  // for hashing
     283  typedef struct {
     284    double value;
     285    int index, next;
     286  } CoinHashLink;
     287  /// Hash table
     288  mutable CoinHashLink *hash_;
     289  /// Number of entries in hash table
     290  int numberHash_;
     291  /// Maximum number of entries in hash table i.e. size
     292  int maxHash_;
     293  /// Last used space
     294  int lastUsed_;
    122295  //@}
    123296};
  • trunk/Clp/src/ClpNonLinearCost.cpp

    r1034 r1197  
    231231  memset(cost+numberColumns_,0,numberRows_*sizeof(double));
    232232  // copy column costs
    233   memcpy(cost,columnCosts,numberColumns_*sizeof(double));
     233  CoinMemcpyN(columnCosts,numberColumns_,cost);
    234234  if ((method_&1)!=0) {
    235235    for (int iSequence=0;iSequence<numberRows_+numberColumns_;iSequence++) {
     
    427427    if (CLP_METHOD1) {
    428428      start_ = new int [numberTotal+1];
    429       memcpy(start_,rhs.start_,(numberTotal+1)*sizeof(int));
     429      CoinMemcpyN(rhs.start_,(numberTotal+1),start_);
    430430      whichRange_ = new int [numberTotal];
    431       memcpy(whichRange_,rhs.whichRange_,numberTotal*sizeof(int));
     431      CoinMemcpyN(rhs.whichRange_,numberTotal,whichRange_);
    432432      offset_ = new int [numberTotal];
    433       memcpy(offset_,rhs.offset_,numberTotal*sizeof(int));
     433      CoinMemcpyN(rhs.offset_,numberTotal,offset_);
    434434      int numberEntries = start_[numberTotal];
    435435      lower_ = new double [numberEntries];
    436       memcpy(lower_,rhs.lower_,numberEntries*sizeof(double));
     436      CoinMemcpyN(rhs.lower_,numberEntries,lower_);
    437437      cost_ = new double [numberEntries];
    438       memcpy(cost_,rhs.cost_,numberEntries*sizeof(double));
     438      CoinMemcpyN(rhs.cost_,numberEntries,cost_);
    439439      infeasible_ = new unsigned int[(numberEntries+31)>>5];
    440       memcpy(infeasible_,rhs.infeasible_,
    441              ((numberEntries+31)>>5)*sizeof(unsigned int));
     440      CoinMemcpyN(rhs.infeasible_,((numberEntries+31)>>5),infeasible_);
    442441    }
    443442    if (CLP_METHOD2) {
     
    496495      if (CLP_METHOD1) {
    497496        start_ = new int [numberTotal+1];
    498         memcpy(start_,rhs.start_,(numberTotal+1)*sizeof(int));
     497        CoinMemcpyN(rhs.start_,(numberTotal+1),start_);
    499498        whichRange_ = new int [numberTotal];
    500         memcpy(whichRange_,rhs.whichRange_,numberTotal*sizeof(int));
     499        CoinMemcpyN(rhs.whichRange_,numberTotal,whichRange_);
    501500        offset_ = new int [numberTotal];
    502         memcpy(offset_,rhs.offset_,numberTotal*sizeof(int));
     501        CoinMemcpyN(rhs.offset_,numberTotal,offset_);
    503502        int numberEntries = start_[numberTotal];
    504503        lower_ = new double [numberEntries];
    505         memcpy(lower_,rhs.lower_,numberEntries*sizeof(double));
     504        CoinMemcpyN(rhs.lower_,numberEntries,lower_);
    506505        cost_ = new double [numberEntries];
    507         memcpy(cost_,rhs.cost_,numberEntries*sizeof(double));
     506        CoinMemcpyN(rhs.cost_,numberEntries,cost_);
    508507        infeasible_ = new unsigned int[(numberEntries+31)>>5];
    509         memcpy(infeasible_,rhs.infeasible_,
    510                ((numberEntries+31)>>5)*sizeof(unsigned int));
     508        CoinMemcpyN(rhs.infeasible_,((numberEntries+31)>>5),infeasible_);
    511509      }
    512510      if (CLP_METHOD2) {
  • trunk/Clp/src/ClpPackedMatrix.cpp

    r1154 r1197  
    5757: ClpMatrixBase(rhs)
    5858
    59   matrix_ = new CoinPackedMatrix(*(rhs.matrix_));
     59  matrix_ = new CoinPackedMatrix(*(rhs.matrix_),-1,-1);
    6060  numberActiveColumns_ = rhs.numberActiveColumns_;
    61   flags_ = rhs.flags_;
     61  flags_ = rhs.flags_&(~2);
    6262  int numberRows = getNumRows();
    6363  if (rhs.rhsOffset_&&numberRows) {
     
    7979  }
    8080}
    81 
    8281//-------------------------------------------------------------------
    8382// assign matrix (for space reasons)
     
    8786
    8887  matrix_ = rhs;
    89   flags_ = 2;
     88  flags_ = matrix_->hasGaps() ? 2 : 0;
    9089  numberActiveColumns_ = matrix_->getNumCols();
    9190  rowCopy_ = NULL;
     
    9897: ClpMatrixBase()
    9998
    100   matrix_ = new CoinPackedMatrix(rhs);
     99  matrix_ = new CoinPackedMatrix(rhs,-1,-1);
    101100  numberActiveColumns_ = matrix_->getNumCols();
    102101  rowCopy_ = NULL;
    103   flags_ = 2;
     102  flags_ = 0;
    104103  columnCopy_=NULL;
    105104  setType(1);
     
    184183  numberActiveColumns_ = matrix_->getNumCols();
    185184  rowCopy_ = NULL;
    186   flags_ = rhs.flags_;
     185  flags_ = rhs.flags_&(~2); // no gaps
    187186  columnCopy_=NULL;
    188187}
     
    442441#endif
    443442  bool packed = rowArray->packedMode();
    444   double factor = 0.30;
     443  double factor = (numberRows<100) ? 0.25 : 0.35;
    445444  // We may not want to do by row if there may be cache problems
    446445  // It would be nice to find L2 cache size - for moment 512K
     
    691690        }
    692691      }
    693 #if 0
    694       double value = 0.0;
    695       CoinBigIndex j;
    696       CoinBigIndex end = columnStart[1];
    697       for (j=columnStart[0]; j<end;j++) {
    698         int iRow = row[j];
    699         value += pi[iRow]*elementByColumn[j];
    700       }
    701       for (iColumn=0;iColumn<numberActiveColumns_-1;iColumn++) {
    702         CoinBigIndex start = end;
    703         end = columnStart[iColumn+2];
    704         if (fabs(value)>zeroTolerance) {
    705           array[numberNonZero]=value;
    706           index[numberNonZero++]=iColumn;
    707         }
    708         value = 0.0;
    709         for (j=start; j<end;j++) {
    710           int iRow = row[j];
    711           value += pi[iRow]*elementByColumn[j];
    712         }
    713       }
    714       if (fabs(value)>zeroTolerance) {
    715         array[numberNonZero]=value;
    716         index[numberNonZero++]=iColumn;
    717       }
    718 #else
    719       if (!columnCopy_)
    720         gutsOfTransposeTimesUnscaled(pi,columnArray,zeroTolerance);
    721       else
     692      if (!columnCopy_) {
     693        numberNonZero=gutsOfTransposeTimesUnscaled(pi,columnArray->getIndices(),
     694                                           columnArray->denseVector(),
     695                                           zeroTolerance);
     696        columnArray->setNumElements(numberNonZero);
     697      } else {
    722698        columnCopy_->transposeTimes(model,pi,columnArray);
    723       numberNonZero = columnArray->getNumElements();
    724 #endif
     699        numberNonZero = columnArray->getNumElements();
     700      }
    725701    } else {
    726702      // scaled
     
    738714      }
    739715      const double * columnScale = model->columnScale();
    740 #if 0
    741       double value = 0.0;
    742       double scale=columnScale[0];
    743       CoinBigIndex j;
    744       CoinBigIndex end = columnStart[1];
    745       for (j=columnStart[0]; j<end;j++) {
    746         int iRow = row[j];
    747         value += pi[iRow]*elementByColumn[j];
    748       }
    749       for (iColumn=0;iColumn<numberActiveColumns_-1;iColumn++) {
    750         value *= scale;
    751         CoinBigIndex start = end;
    752         scale = columnScale[iColumn+1];
    753         end = columnStart[iColumn+2];
    754         if (fabs(value)>zeroTolerance) {
    755           array[numberNonZero]=value;
    756           index[numberNonZero++]=iColumn;
    757         }
    758         value = 0.0;
    759         if (model->getColumnStatus(iColumn+1)!=ClpSimplex::basic) {
    760           for (j=start; j<end;j++) {
    761             int iRow = row[j];
    762             value += pi[iRow]*elementByColumn[j];
    763           }
    764         }
    765       }
    766       value *= scale;
    767       if (fabs(value)>zeroTolerance) {
    768         array[numberNonZero]=value;
    769         index[numberNonZero++]=iColumn;
    770       }
    771 #else
    772       if (!columnCopy_)
    773         gutsOfTransposeTimesScaled(pi,columnScale,columnArray,zeroTolerance);
    774       else
     716      if (!columnCopy_) {
     717        numberNonZero=gutsOfTransposeTimesScaled(pi,columnScale,
     718                                                 columnArray->getIndices(),
     719                                                 columnArray->denseVector(),
     720                                                 zeroTolerance);
     721        columnArray->setNumElements(numberNonZero);
     722      } else {
    775723        columnCopy_->transposeTimes(model,pi,columnArray);
    776       numberNonZero = columnArray->getNumElements();
    777 #endif
     724        numberNonZero = columnArray->getNumElements();
     725      }
    778726    }
    779727    // zero out
     
    940888    int numberOriginal = 0;
    941889    if (packed) {
    942 #if 0
    943       numberNonZero=0;
    944       // and set up mark as char array
    945       char * marked = (char *) (index+columnArray->capacity());
    946       double * array2 = y->denseVector();
    947 #ifdef CLP_DEBUG
    948       for (i=0;i<numberActiveColumns_;i++) {
    949         assert(!marked[i]);
    950         assert(!array2[i]);
    951       }
    952 #endif     
    953       for (i=0;i<numberInRowArray;i++) {
    954         iRow = whichRow[i];
    955         double value = pi[i]*scalar;
    956         CoinBigIndex j;
    957         for (j=rowStart[iRow];j<rowStart[iRow+1];j++) {
    958           int iColumn = column[j];
    959           if (!marked[iColumn]) {
    960             marked[iColumn]=1;
    961             index[numberNonZero++]=iColumn;
    962           }
    963           array2[iColumn] += value*element[j];
    964         }
    965       }
    966       // get rid of tiny values and zero out marked
    967       numberOriginal=numberNonZero;
    968       numberNonZero=0;
    969       for (i=0;i<numberOriginal;i++) {
    970         int iColumn = index[i];
    971         if (marked[iColumn]) {
    972           double value = array2[iColumn];
    973           array2[iColumn]=0.0;
    974           marked[iColumn]=0;
    975           if (fabs(value)>zeroTolerance) {
    976             array[numberNonZero]=value;
    977             index[numberNonZero++]=iColumn;
    978           }
    979         }
    980       }
    981 #else
    982       gutsOfTransposeTimesByRowGE3(rowArray,columnArray,y,zeroTolerance,scalar);
    983       numberNonZero = columnArray->getNumElements();
    984 #endif
     890      int * index = columnArray->getIndices();
     891      double * array = columnArray->denseVector();
     892      assert (!y->getNumElements());
     893      int * lookup = (int *) y->denseVector();
     894#ifndef NDEBUG
     895      int numberColumns = matrix_->getNumCols();
     896      for (int i=0;i<numberColumns;i++)
     897        assert(!lookup[i]);
     898#endif
     899      numberNonZero=gutsOfTransposeTimesByRowGE3(rowArray,index,array,
     900                                                 lookup,zeroTolerance,scalar);
     901      columnArray->setNumElements(numberNonZero);
    985902    } else {
    986903      double * markVector = y->denseVector();
     
    1028945    double value;
    1029946    if (packed) {
    1030 #if 0
    1031       int iRow0 = whichRow[0];
    1032       int iRow1 = whichRow[1];
    1033       double pi0 = pi[0];
    1034       double pi1 = pi[1];
    1035       if (rowStart[iRow0+1]-rowStart[iRow0]>
    1036           rowStart[iRow1+1]-rowStart[iRow1]) {
    1037         // do one with fewer first
    1038         iRow0=iRow1;
    1039         iRow1=whichRow[0];
    1040         pi0=pi1;
    1041         pi1=pi[0];
    1042       }
    1043       // and set up mark as char array
    1044       char * marked = (char *) (index+columnArray->capacity());
    1045       int * lookup = y->getIndices();
    1046       value = pi0*scalar;
    1047       for (j=rowStart[iRow0];j<rowStart[iRow0+1];j++) {
    1048         int iColumn = column[j];
    1049         double value2 = value*element[j];
    1050         array[numberNonZero] = value2;
    1051         marked[iColumn]=1;
    1052         lookup[iColumn]=numberNonZero;
    1053         index[numberNonZero++]=iColumn;
    1054       }
    1055       numberOriginal = numberNonZero;
    1056       value = pi1*scalar;
    1057       for (j=rowStart[iRow1];j<rowStart[iRow1+1];j++) {
    1058         int iColumn = column[j];
    1059         double value2 = value*element[j];
    1060         // I am assuming no zeros in matrix
    1061         if (marked[iColumn]) {
    1062           int iLookup = lookup[iColumn];
    1063           array[iLookup] += value2;
    1064         } else {
    1065           if (fabs(value2)>zeroTolerance) {
    1066             array[numberNonZero] = value2;
    1067             index[numberNonZero++]=iColumn;
    1068           }
    1069         }
    1070       }
    1071       // get rid of tiny values and zero out marked
    1072       int nDelete=0;
    1073       for (i=0;i<numberOriginal;i++) {
    1074         int iColumn = index[i];
    1075         marked[iColumn]=0;
    1076         if (fabs(array[i])<=zeroTolerance)
    1077           nDelete++;
    1078       }
    1079       if (nDelete) {
    1080         numberOriginal=numberNonZero;
    1081         numberNonZero=0;
    1082         for (i=0;i<numberOriginal;i++) {
    1083           int iColumn = index[i];
    1084           double value = array[i];
    1085           array[i]=0.0;
    1086           if (fabs(value)>zeroTolerance) {
    1087             array[numberNonZero]=value;
    1088             index[numberNonZero++]=iColumn;
    1089           }
    1090         }
    1091       }
    1092 #else
    1093947      gutsOfTransposeTimesByRowEQ2(rowArray,columnArray,y,zeroTolerance,scalar);
    1094948      numberNonZero = columnArray->getNumElements();
    1095 #endif
    1096949    } else {
    1097950      int iRow = whichRow[0];
     
    1133986    CoinBigIndex j;
    1134987    if (packed) {
    1135 #if 0
    1136       double value = pi[0]*scalar;
    1137       for (j=rowStart[iRow];j<rowStart[iRow+1];j++) {
    1138         int iColumn = column[j];
    1139         double value2 = value*element[j];
    1140         if (fabs(value2)>zeroTolerance) {
    1141           array[numberNonZero] = value2;
    1142           index[numberNonZero++]=iColumn;
    1143         }
    1144       }
    1145 #else
    1146988      gutsOfTransposeTimesByRowEQ1(rowArray,columnArray,zeroTolerance,scalar);
    1147989      numberNonZero = columnArray->getNumElements();
    1148 #endif
    1149990    } else {
    1150991      double value = pi[iRow]*scalar;
     
    11631004}
    11641005// Meat of transposeTimes by column when not scaled
    1165 void
    1166 ClpPackedMatrix::gutsOfTransposeTimesUnscaled(const double * pi,CoinIndexedVector * output, const double zeroTolerance) const
     1006int
     1007ClpPackedMatrix::gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
     1008                                    int * COIN_RESTRICT index,
     1009                                    double * COIN_RESTRICT array,
     1010                                    const double zeroTolerance) const
    11671011{
    11681012  int numberNonZero=0;
    1169   int * index = output->getIndices();
    1170   double * array = output->denseVector();
    11711013  // get matrix data pointers
    11721014  const int * row = matrix_->getIndices();
     
    11981040    index[numberNonZero++]=iColumn;
    11991041  }
    1200   output->setNumElements(numberNonZero);
     1042  return numberNonZero;
    12011043}
    12021044// Meat of transposeTimes by column when scaled
    1203 void
    1204 ClpPackedMatrix::gutsOfTransposeTimesScaled(const double * pi,const double * columnScale,
    1205                                            CoinIndexedVector * output, const double zeroTolerance) const
     1045int
     1046ClpPackedMatrix::gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
     1047                                 const double * COIN_RESTRICT columnScale,
     1048                                 int * COIN_RESTRICT index,
     1049                                 double * COIN_RESTRICT array,
     1050                                 const double zeroTolerance) const
    12061051{
    12071052  int numberNonZero=0;
    1208   int * index = output->getIndices();
    1209   double * array = output->denseVector();
    12101053  // get matrix data pointers
    12111054  const int * row = matrix_->getIndices();
     
    12411084    index[numberNonZero++]=iColumn;
    12421085  }
    1243   output->setNumElements(numberNonZero);
    1244 }
    1245 // Meat of transposeTimes by row n > 2 if packed
    1246 void
    1247 ClpPackedMatrix::gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    1248                                              CoinIndexedVector * spareVector, const double tolerance, const double scalar) const
    1249 {
    1250   double * pi = piVector->denseVector();
     1086  return numberNonZero;
     1087}
     1088// Meat of transposeTimes by row n > 2 if packed - returns number nonzero
     1089int
     1090ClpPackedMatrix::gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
     1091                                              int * COIN_RESTRICT index,
     1092                                              double * COIN_RESTRICT output,
     1093                                              int * COIN_RESTRICT lookup,
     1094                                              const double tolerance,
     1095                                              const double scalar) const
     1096{
     1097  const double * pi = piVector->denseVector();
    12511098  int numberNonZero=0;
    1252   int * index = output->getIndices();
    1253   double * array = output->denseVector();
    12541099  int numberInRowArray = piVector->getNumElements();
    12551100  const int * column = getIndices();
     
    12601105  int iRow;
    12611106  int i;
    1262   // and set up mark as char array
    1263   char * marked = (char *) (index+output->capacity());
    1264   int * lookup = spareVector->getIndices();
    1265 #if 1
    12661107  for (i=0;i<numberInRowArray;i++) {
    12671108    iRow = whichRow[i];
     
    12711112      int iColumn = column[j];
    12721113      double elValue = element[j];
    1273       if (!marked[iColumn]) {
    1274         marked[iColumn]=1;
     1114      int k = lookup[iColumn];
     1115      elValue *= value;
     1116      if (k) {
     1117        output[k-1] += elValue;
     1118      } else {
     1119        output[numberNonZero] = elValue;
     1120        index[numberNonZero++]=iColumn;
    12751121        lookup[iColumn]=numberNonZero;
    1276         array[numberNonZero] = value*elValue;
    1277         index[numberNonZero++]=iColumn;
    1278       } else {
    1279         int k = lookup[iColumn];
    1280         array[k] += value*elValue;
    1281       }
    1282     }
    1283   }
    1284 #else
    1285   int nextRow = whichRow[0];
    1286   CoinBigIndex nextStart = rowStart[nextRow];
    1287   CoinBigIndex nextEnd = rowStart[nextRow+1];
    1288   whichRow[numberInRowArray]=0; // for electricfence etc
    1289   for (i=0;i<numberInRowArray;i++) {
    1290     iRow = nextRow;
    1291     nextRow = whichRow[i+1];
    1292     CoinBigIndex start = nextStart;
    1293     CoinBigIndex end = nextEnd;
    1294     double value = pi[i]*scalar;
    1295     CoinBigIndex j;
    1296     nextRow = whichRow[i+1];
    1297     nextStart = rowStart[nextRow];
    1298     nextEnd = rowStart[nextRow+1];
    1299     for (j=start;j<end;j++) {
    1300       int iColumn = column[j];
    1301       double elValue = element[j];
    1302       if (!marked[iColumn]) {
    1303         marked[iColumn]=1;
    1304         lookup[iColumn]=numberNonZero;
    1305         array[numberNonZero] = value*elValue;
    1306         index[numberNonZero++]=iColumn;
    1307       } else {
    1308         int k = lookup[iColumn];
    1309         array[k] += value*elValue;
    1310       }
    1311     }
    1312   }
    1313 #endif
    1314   // get rid of tiny values and zero out marked
     1122      }
     1123    }
     1124  }
     1125#ifndef NDEBUG
     1126  int saveN = numberNonZero;
     1127#endif
     1128  // get rid of tiny values and zero out lookup
    13151129  for (i=0;i<numberNonZero;i++) {
    13161130    int iColumn = index[i];
    1317     marked[iColumn]=0;
    1318     double value = array[i];
    1319     while (fabs(value)<=tolerance) {
    1320       numberNonZero--;
    1321       value = array[numberNonZero];
    1322       iColumn = index[numberNonZero];
    1323       marked[iColumn]=0;
    1324       if (i<numberNonZero) {
    1325         array[numberNonZero]=0.0;
    1326         array[i] = value;
    1327         index[i] = iColumn;
    1328       } else {
    1329         array[i]=0.0;
    1330         value =1.0; // to force end of while
    1331       }
    1332     }
    1333   }
    1334   output->setNumElements(numberNonZero);
    1335   spareVector->setNumElements(0);
     1131    lookup[iColumn]=0;
     1132    double value = output[i];
     1133    if (fabs(value)<=tolerance) {
     1134      while (fabs(value)<=tolerance) {
     1135        numberNonZero--;
     1136        value = output[numberNonZero];
     1137        iColumn = index[numberNonZero];
     1138        lookup[iColumn]=0;
     1139        if (i<numberNonZero) {
     1140          output[numberNonZero]=0.0;
     1141          output[i] = value;
     1142          index[i] = iColumn;
     1143        } else {
     1144          output[i]=0.0;
     1145          value =1.0; // to force end of while
     1146        }
     1147      }
     1148    }
     1149  }
     1150#ifndef NDEBUG
     1151  for (i=numberNonZero;i<saveN;i++)
     1152    assert(!output[i]);
     1153#endif
     1154  return numberNonZero;
    13361155}
    13371156// Meat of transposeTimes by row n == 2 if packed
     
    20921911  }
    20931912}
     1913//static int scale_stats[5]={0,0,0,0,0};
    20941914// Creates scales for column copy (rowCopy in model may be modified)
    20951915int
     
    21311951  //assert (!model->rowScale());
    21321952  bool arraysExist;
     1953  double * inverseRowScale = NULL;
     1954  double * inverseColumnScale = NULL;
    21331955  if (!model->rowScale()) {
    21341956    rowScale = new double [numberRows*scaleLength];
    21351957    columnScale = new double [numberColumns*scaleLength];
     1958    if (scaleLength==2) {
     1959      inverseRowScale = rowScale+numberRows;
     1960      inverseColumnScale = columnScale+numberColumns;
     1961    }
    21361962    arraysExist=false;
    21371963  } else {
    21381964    rowScale=model->mutableRowScale();
    21391965    columnScale=model->mutableColumnScale();
     1966    inverseRowScale = model->mutableInverseRowScale();
     1967    inverseColumnScale = model->mutableInverseColumnScale();
    21401968    arraysExist=true;
    21411969  }
     
    21521980  for (iRow=0;iRow<numberRows;iRow++) {
    21531981#ifndef LEAVE_FIXED
    2154     usefulRow[iRow]=0;
    21551982    if (rowUpper[iRow]<1.0e20||
    21561983        rowLower[iRow]>-1.0e20)
    2157 #endif
    21581984      usefulRow[iRow]=1;
     1985    else
     1986      usefulRow[iRow]=0;
     1987#else
     1988      usefulRow[iRow]=1;
     1989#endif
    21591990  }
    21601991  // mark empty and fixed columns
    21611992  // also see if worth scaling
    21621993  assert (model->scalingFlag()<=4);
     1994  //  scale_stats[model->scalingFlag()]++;
    21631995  double largest=0.0;
    21641996  double smallest=1.0e50;
     
    22122044    int scalingMethod = model->scalingFlag();
    22132045    if (scalingMethod==4) {
    2214       // Aas auto
     2046      // As auto
    22152047      scalingMethod=3;
    22162048    }
     
    22502082        assert (numberRows>=numberRows2);
    22512083        assert (baseModel->rowScale());
    2252         memcpy(rowScale,baseModel->rowScale(),numberRows2*sizeof(double));
    2253         memcpy(columnScale,baseModel->columnScale(),numberColumns*sizeof(double));
     2084        CoinMemcpyN(baseModel->rowScale(),numberRows2,rowScale);
     2085        CoinMemcpyN(baseModel->columnScale(),numberColumns,columnScale);
    22542086        if (numberRows>numberRows2) {
    22552087          numberPass=1;
     
    22702102                }
    22712103                rowScale[iRow]=1.0/largest;
    2272                 overallLargest = CoinMax(overallLargest,largest);
    2273                 overallSmallest = CoinMin(overallSmallest,largest);
     2104#ifdef COIN_DEVELOP
     2105                if (model->logLevel()>2) {
     2106                  overallLargest = CoinMax(overallLargest,largest);
     2107                  overallSmallest = CoinMin(overallSmallest,largest);
     2108                }
     2109#endif
    22742110              }
    22752111            }
     
    22972133                if (iRow>=numberRows2) {
    22982134                  rowScale[iRow]=1.0/sqrt(smallest*largest);
    2299                   rowScale[iRow]=CoinMax(1.0e-10,CoinMin(1.0e10,rowScale[iRow]));
     2135                  //rowScale[iRow]=CoinMax(1.0e-10,CoinMin(1.0e10,rowScale[iRow]));
    23002136                }
    2301                 overallLargest = CoinMax(largest*rowScale[iRow],overallLargest);
    2302                 overallSmallest = CoinMin(smallest*rowScale[iRow],overallSmallest);
     2137#ifdef COIN_DEVELOP
     2138                if (model->logLevel()>2) {
     2139                  overallLargest = CoinMax(largest*rowScale[iRow],overallLargest);
     2140                  overallSmallest = CoinMin(smallest*rowScale[iRow],overallSmallest);
     2141                }
     2142#endif
    23032143              }
    23042144            }
     
    23242164            }
    23252165            rowScale[iRow]=1.0/largest;
    2326             overallLargest = CoinMax(overallLargest,largest);
    2327             overallSmallest = CoinMin(overallSmallest,largest);
     2166#ifdef COIN_DEVELOP
     2167            if (model->logLevel()>2) {
     2168              overallLargest = CoinMax(overallLargest,largest);
     2169              overallSmallest = CoinMin(overallSmallest,largest);
     2170            }
     2171#endif
    23282172          }
    23292173        }
     
    23322176        // This will be used to help get scale factors
    23332177        double * objective = new double[numberColumns];
    2334         memcpy(objective,model->costRegion(1),numberColumns*sizeof(double));
     2178        CoinMemcpyN(model->costRegion(1),numberColumns,objective);
    23352179        double objScale=1.0;
    23362180#endif
     
    23572201                }
    23582202              }
     2203             
    23592204              rowScale[iRow]=1.0/sqrt(smallest*largest);
    2360               rowScale[iRow]=CoinMax(1.0e-10,CoinMin(1.0e10,rowScale[iRow]));
    2361               overallLargest = CoinMax(largest*rowScale[iRow],overallLargest);
    2362               overallSmallest = CoinMin(smallest*rowScale[iRow],overallSmallest);
     2205              //rowScale[iRow]=CoinMax(1.0e-10,CoinMin(1.0e10,rowScale[iRow]));
     2206#ifdef COIN_DEVELOP
     2207              if (model->logLevel()>2) {
     2208                overallLargest = CoinMax(largest*rowScale[iRow],overallLargest);
     2209                overallSmallest = CoinMin(smallest*rowScale[iRow],overallSmallest);
     2210              }
     2211#endif
    23632212            }
    23642213          }
     
    24112260#endif
    24122261              columnScale[iColumn]=1.0/sqrt(smallest*largest);
    2413               columnScale[iColumn]=CoinMax(1.0e-10,CoinMin(1.0e10,columnScale[iColumn]));
     2262              //columnScale[iColumn]=CoinMax(1.0e-10,CoinMin(1.0e10,columnScale[iColumn]));
    24142263            }
    24152264          }
     
    25222371        }
    25232372        columnScale[iColumn]=overallLargest/largest;
    2524         columnScale[iColumn]=CoinMax(1.0e-10,CoinMin(1.0e10,columnScale[iColumn]));
     2373        //columnScale[iColumn]=CoinMax(1.0e-10,CoinMin(1.0e10,columnScale[iColumn]));
    25252374#ifdef RANDOMIZE
    25262375        double value = 0.5-randomNumberGenerator_.randomDouble();//between -0.5 to + 0.5
     
    26122461    }
    26132462#endif
    2614     if (scaleLength>1) {
    2615       // make copy
    2616       double * inverseScale = rowScale + numberRows;
     2463    if (inverseRowScale) {
     2464      // make copy (could do faster by using previous values)
     2465      // could just do partial
    26172466      for (iRow=0;iRow<numberRows;iRow++)
    2618         inverseScale[iRow] = 1.0/rowScale[iRow] ;
    2619       inverseScale = columnScale + numberColumns;
     2467        inverseRowScale[iRow] = 1.0/rowScale[iRow] ;
    26202468      for (iColumn=0;iColumn<numberColumns;iColumn++)
    2621         inverseScale[iColumn] = 1.0/columnScale[iColumn] ;
     2469        inverseColumnScale[iColumn] = 1.0/columnScale[iColumn] ;
    26222470    }
    26232471    if (!arraysExist) {
     
    28762724  flags_ &= ~2;
    28772725  if (check==14||check==10) {
    2878     for (iColumn=0;iColumn<numberColumns;iColumn++) {
    2879       CoinBigIndex start = columnStart[iColumn];
    2880       CoinBigIndex end = start + columnLength[iColumn];
    2881       if (end!=columnStart[iColumn+1]) {
    2882         flags_ |= 2;
    2883         break;
    2884       }
     2726    if (matrix_->getNumElements()<columnStart[numberColumns]) {
     2727      // pack down!
     2728#if 0
     2729      matrix_->removeGaps();
     2730#else
     2731      flags_ |= 2;
     2732#endif
     2733#ifdef COIN_DEVELOP
     2734      //printf("flags set to 2\n");
     2735#endif
     2736    } else if (numberColumns) {
     2737      assert(columnStart[numberColumns]==
     2738             columnStart[numberColumns-1]+columnLength[numberColumns-1]);
    28852739    }
    28862740    return true;
     
    31012955        double value;
    31022956        ClpSimplex::Status status = model->getStatus(iSequence);
    3103        
     2957
    31042958        switch(status) {
    31052959         
     
    32073061        double value;
    32083062        ClpSimplex::Status status = model->getStatus(iSequence);
    3209        
     3063
    32103064        switch(status) {
    32113065         
     
    34573311  // may now have gaps
    34583312  flags_ |= 2;
    3459   matrix_->setExtraGap(1.0e-50);
     3313  matrix_->setExtraGap(0.0);
    34603314}
    34613315/* Delete the rows whose indices are listed in <code>indDel</code>. */
     
    34693323  // may now have gaps
    34703324  flags_ |= 2;
    3471   matrix_->setExtraGap(1.0e-50);
     3325  matrix_->setExtraGap(0.0);
    34723326}
    34733327#ifndef CLP_NO_VECTOR
     
    35783432// Check validity
    35793433void
    3580 ClpPackedMatrix::checkFlags() const
     3434ClpPackedMatrix::checkFlags(int type) const
    35813435{
    35823436  int iColumn;
     
    36003454        abort();
    36013455      }
     3456    }
     3457  }
     3458  if (type) {
     3459    if ((flags_&2)!=0) {
     3460      bool ok=true;
     3461      for (iColumn=0;iColumn<numberActiveColumns_;iColumn++) {
     3462        if (columnStart[iColumn+1]!=columnStart[iColumn]+columnLength[iColumn]) {
     3463          ok=false;
     3464          break;
     3465        }
     3466      }
     3467      if (ok)
     3468        printf("flags_ could be 0\n");
    36023469    }
    36033470  }
  • trunk/Clp/src/ClpPackedMatrix.hpp

    r1154 r1197  
    276276  inline bool wantsSpecialColumnCopy() const
    277277  { return ((flags_&8)!=0);}
     278  /// Flags
     279  inline int flags() const
     280  { return flags_;}
    278281   //@}
    279282
     
    324327private:
    325328  /// Meat of transposeTimes by column when not scaled
    326   void gutsOfTransposeTimesUnscaled(const double * pi,CoinIndexedVector * output, const double tolerance) const;
     329  int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
     330                                    int * COIN_RESTRICT index,
     331                                    double * COIN_RESTRICT array,
     332                                    const double tolerance) const;
    327333  /// Meat of transposeTimes by column when scaled
    328   void gutsOfTransposeTimesScaled(const double * pi,const double * columnScale, CoinIndexedVector * output, const double tolerance) const;
    329   /// Meat of transposeTimes by row n > 2 if packed
    330   void gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    331                                    CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
     334  int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
     335                                 const double * COIN_RESTRICT columnScale,
     336                                 int * COIN_RESTRICT index,
     337                                 double * COIN_RESTRICT array,
     338                                 const double tolerance) const;
     339  /// Meat of transposeTimes by row n > 2 if packed - returns number nonzero
     340  int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
     341                                   int * COIN_RESTRICT index,
     342                                   double * COIN_RESTRICT output,
     343                                   int * COIN_RESTRICT lookup,
     344                                   const double tolerance,
     345                                   const double scalar) const;
    332346  /// Meat of transposeTimes by row n == 2 if packed
    333347  void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
     
    342356protected:
    343357  /// Check validity
    344   void checkFlags() const;
     358  void checkFlags(int type) const;
    345359   /**@name Data members
    346360      The data members are protected to allow access for derived classes. */
  • trunk/Clp/src/ClpPdco.cpp

    r1171 r1197  
    497497  // Initialize other things.
    498498
    499   bool  precon   = true;       
     499  bool  precon   = true; 
    500500  double PDitns    = 0;
    501501  bool converged = false;
     
    602602          rhs[n+k] = r1_elts[k]*(1.0/d2);
    603603        double damp    = 0;
    604        
     604
    605605        if (precon){    // Construct diagonal preconditioner for LSQR
    606606          matPrecon(d2, Pr, D);
     
    610610        info.atolmin = atolmin;
    611611        info.r3norm  = fmerit;  // Must be the 2-norm here.
    612        
     612
    613613        [ dy, istop, itncg, outfo ] = ...
    614614            pdxxxlsqr( nb,m,"pdxxxlsqrmat",Aname,rw,rhs,damp, ...
    615615                       atol,btol,conlim,itnlim,show,info );
    616        
     616
    617617
    618618        thisLsqr.input->rhs_vec = &rhs;
    619619        thisLsqr.input->sol_vec = &dy;
    620         thisLsqr.input->rel_mat_err = atol;     
     620        thisLsqr.input->rel_mat_err = atol;
    621621        thisLsqr.do_lsqr(this);
    622622        */
  • trunk/Clp/src/ClpPlusMinusOneMatrix.cpp

    r1111 r1197  
    5454    CoinBigIndex numberElements = rhs.startPositive_[numberColumns_];
    5555    indices_ = new int [ numberElements];
    56     memcpy(indices_,rhs.indices_,numberElements*sizeof(int));
     56    CoinMemcpyN(rhs.indices_,numberElements,indices_);
    5757    startPositive_ = new CoinBigIndex [ numberColumns_+1];
    58     memcpy(startPositive_,rhs.startPositive_,(numberColumns_+1)*sizeof(CoinBigIndex));
     58    CoinMemcpyN(rhs.startPositive_,(numberColumns_+1),startPositive_);
    5959    startNegative_ = new CoinBigIndex [ numberColumns_];
    60     memcpy(startNegative_,rhs.startNegative_,numberColumns_*sizeof(CoinBigIndex));
     60    CoinMemcpyN(rhs.startNegative_,numberColumns_,startNegative_);
    6161  }
    6262  int numberRows = getNumRows();
     
    204204      CoinBigIndex numberElements = rhs.startPositive_[numberColumns_];
    205205      indices_ = new int [ numberElements];
    206       memcpy(indices_,rhs.indices_,numberElements*sizeof(int));
     206      CoinMemcpyN(rhs.indices_,numberElements,indices_);
    207207      startPositive_ = new CoinBigIndex [ numberColumns_+1];
    208       memcpy(startPositive_,rhs.startPositive_,(numberColumns_+1)*sizeof(CoinBigIndex));
     208      CoinMemcpyN(rhs.startPositive_,(numberColumns_+1),startPositive_);
    209209      startNegative_ = new CoinBigIndex [ numberColumns_];
    210       memcpy(startNegative_,rhs.startNegative_,numberColumns_*sizeof(CoinBigIndex));
     210      CoinMemcpyN(rhs.startNegative_,numberColumns_,startNegative_);
    211211    }
    212212  }
     
    13431343  CoinBigIndex * temp;
    13441344  temp = new CoinBigIndex [numberColumns_+1+number];
    1345   memcpy(temp,startPositive_,(numberColumns_+1)*sizeof(CoinBigIndex ));
     1345  CoinMemcpyN(startPositive_,(numberColumns_+1),temp);
    13461346  delete [] startPositive_;
    13471347  startPositive_= temp;
    13481348  temp = new CoinBigIndex [numberColumns_+number];
    1349   memcpy(temp,startNegative_,numberColumns_*sizeof(CoinBigIndex ));
     1349  CoinMemcpyN(startNegative_,numberColumns_,temp);
    13501350  delete [] startNegative_;
    13511351  startNegative_= temp;
    13521352  int * temp2 = new int [numberNow+size];
    1353   memcpy(temp2,indices_,numberNow*sizeof(int));
     1353  CoinMemcpyN(indices_,numberNow,temp2);
    13541354  delete [] indices_;
    13551355  indices_= temp2;
     
    14231423    n = countPositive[iColumn];
    14241424    startPositive_[iColumn] += numberAdded;
    1425     memcpy(indices_+now,newIndices+startPositive_[iColumn],move*sizeof(int));
     1425    CoinMemcpyN(newIndices+startPositive_[iColumn],move,indices_+now);
    14261426    countPositive[iColumn]= startNegative_[iColumn]+numberAdded;
    14271427    numberAdded += n;
     
    14301430    n = countNegative[iColumn];
    14311431    startNegative_[iColumn] += numberAdded;
    1432     memcpy(indices_+now,newIndices+startNegative_[iColumn],move*sizeof(int));
     1432    CoinMemcpyN(newIndices+startNegative_[iColumn],move,indices_+now);
    14331433    countNegative[iColumn]= startPositive_[iColumn+1]+numberAdded;
    14341434    numberAdded += n;
     
    15251525     
    15261526      switch(status) {
    1527        
     1527
    15281528      case ClpSimplex::basic:
    15291529      case ClpSimplex::isFixed:
     
    19081908    CoinBigIndex end = startPositive_[length];
    19091909    temp = new CoinBigIndex [number+1];
    1910     memcpy(temp,startPositive_,(length+1)*sizeof(CoinBigIndex));
     1910    CoinMemcpyN(startPositive_,(length+1),temp);
    19111911    delete [] startPositive_;
    19121912    for (i=length+1;i<number+1;i++)
     
    19141914    startPositive_=temp;
    19151915    temp = new CoinBigIndex [number];
    1916     memcpy(temp,startNegative_,length*sizeof(CoinBigIndex));
     1916    CoinMemcpyN(startNegative_,length,temp);
    19171917    delete [] startNegative_;
    19181918    for (i=length;i<number;i++)
  • trunk/Clp/src/ClpPredictorCorrector.cpp

    r1060 r1197  
    517517      printf("mu %g, papermu %g, affmu %g, sigma %g sigmamu %g\n",
    518518             mu_,papermu,affmu,sigma,sigma*papermu);
    519 #endif 
     519#endif
    520520      //printf("paper mu %g\n",(nextGap*nextGap*nextGap)/(complementarityGap_*complementarityGap_*
    521521      //                                            (double) numberComplementarityPairs_));
     
    589589      goodMove=false;
    590590    if (goodMove&&doCorrector) {
    591       memcpy(saveX,deltaX_,numberTotal*sizeof(double));
    592       memcpy(saveY,deltaY_,numberRows_*sizeof(double));
    593       memcpy(saveZ,deltaZ_,numberTotal*sizeof(double));
    594       memcpy(saveW,deltaW_,numberTotal*sizeof(double));
    595       memcpy(saveSL,deltaSL_,numberTotal*sizeof(double));
    596       memcpy(saveSU,deltaSU_,numberTotal*sizeof(double));
     591      CoinMemcpyN(deltaX_,numberTotal,saveX);
     592      CoinMemcpyN(deltaY_,numberRows_,saveY);
     593      CoinMemcpyN(deltaZ_,numberTotal,saveZ);
     594      CoinMemcpyN(deltaW_,numberTotal,saveW);
     595      CoinMemcpyN(deltaSL_,numberTotal,saveSL);
     596      CoinMemcpyN(deltaSU_,numberTotal,saveSU);
    597597#ifdef HALVE
    598598      double savePrimalStep = actualPrimalStep_;
     
    659659          deltaSU_[i] = lambda*deltaSU_[i]+(1.0-lambda)*saveSU[i];
    660660        }
    661         //memcpy(deltaX_,saveX,numberTotal*sizeof(double));
    662         //memcpy(deltaY_,saveY,numberRows_*sizeof(double));
    663         //memcpy(deltaZ_,saveZ,numberTotal*sizeof(double));
    664         //memcpy(deltaW_,saveW,numberTotal*sizeof(double));
    665         //memcpy(deltaSL_,saveSL,numberTotal*sizeof(double));
    666         //memcpy(deltaSU_,saveSU,numberTotal*sizeof(double));
     661   CoinMemcpyN(saveX,numberTotal,deltaX_);
     662   CoinMemcpyN(saveY,numberRows_,deltaY_);
     663   CoinMemcpyN(saveZ,numberTotal,deltaZ_);
     664   CoinMemcpyN(saveW,numberTotal,deltaW_);
     665   CoinMemcpyN(saveSL,numberTotal,deltaSL_);
     666   CoinMemcpyN(saveSU,numberTotal,deltaSU_);
    667667        findStepLength(1);
    668668        nextGap = complementarityGap(nextNumber,nextNumberItems,1);
     
    758758      goodMove=false;
    759759      numberTries++;
    760       memcpy(saveX,deltaX_,numberTotal*sizeof(double));
    761       memcpy(saveY,deltaY_,numberRows_*sizeof(double));
    762       memcpy(saveZ,deltaZ_,numberTotal*sizeof(double));
    763       memcpy(saveW,deltaW_,numberTotal*sizeof(double));
     760      CoinMemcpyN(deltaX_,numberTotal,saveX);
     761      CoinMemcpyN(deltaY_,numberRows_,saveY);
     762      CoinMemcpyN(deltaZ_,numberTotal,saveZ);
     763      CoinMemcpyN(deltaW_,numberTotal,saveW);
    764764      double savePrimalStep = actualPrimalStep_;
    765765      double saveDualStep = actualDualStep_;
     
    791791        actualPrimalStep_ = savePrimalStep;
    792792        actualDualStep_ = saveDualStep;
    793         memcpy(deltaX_,saveX,numberTotal*sizeof(double));
    794         memcpy(deltaY_,saveY,numberRows_*sizeof(double));
    795         memcpy(deltaZ_,saveZ,numberTotal*sizeof(double));
    796         memcpy(deltaW_,saveW,numberTotal*sizeof(double));
     793 CoinMemcpyN(saveX,numberTotal,deltaX_);
     794 CoinMemcpyN(saveY,numberRows_,deltaY_);
     795 CoinMemcpyN(saveZ,numberTotal,deltaZ_);
     796 CoinMemcpyN(saveW,numberTotal,deltaW_);
    797797      } else {
    798798#ifdef SOME_DEBUG
  • trunk/Clp/src/ClpPresolve.cpp

    r1051 r1197  
    192192      rowstat = status + ncols0;
    193193      colstat = status;
    194       memcpy(colstat, presolvedModel_->statusArray(), ncols);
    195       memcpy(rowstat, presolvedModel_->statusArray()+ncols, nrows);
     194      CoinMemcpyN( presolvedModel_->statusArray(), ncols,colstat);
     195      CoinMemcpyN( presolvedModel_->statusArray()+ncols, nrows,rowstat);
    196196    }
    197197#ifndef CLP_NO_STD
     
    206206      rowstat = status + ncols0;
    207207      colstat = status;
    208       memcpy(colstat, presolvedModel_->statusArray(), ncols);
    209       memcpy(rowstat, presolvedModel_->statusArray()+ncols, nrows);
     208      CoinMemcpyN( presolvedModel_->statusArray(), ncols,colstat);
     209      CoinMemcpyN( presolvedModel_->statusArray()+ncols, nrows,rowstat);
    210210    }
    211211  }
     
    235235    originalModel_->restoreModel(saveFile_.c_str());
    236236    remove(saveFile_.c_str());
    237     memcpy(originalModel_->primalRowSolution(),acts,nrows0*sizeof(double));
     237    CoinMemcpyN(acts,nrows0,originalModel_->primalRowSolution());
    238238    // delete [] acts;
    239     memcpy(originalModel_->primalColumnSolution(),sol,ncols0*sizeof(double));
     239    CoinMemcpyN(sol,ncols0,originalModel_->primalColumnSolution());
    240240    // delete [] sol;
    241241    if (updateStatus) {
    242       memcpy(originalModel_->statusArray(),colstat,nrows0+ncols0);
     242      CoinMemcpyN(colstat,nrows0+ncols0,originalModel_->statusArray());
    243243      // delete [] colstat;
    244244    }
     
    252252#endif
    253253  // put back duals
    254   memcpy(originalModel_->dualRowSolution(),prob.rowduals_,
    255          nrows_*sizeof(double));
     254  CoinMemcpyN(prob.rowduals_,   nrows_,originalModel_->dualRowSolution());
    256255  double maxmin = originalModel_->getObjSense();
    257256  if (maxmin<0.0) {
     
    264263  // Now check solution
    265264  double offset;
    266   memcpy(originalModel_->dualColumnSolution(),
    267          originalModel_->objectiveAsObject()->gradient(originalModel_,
    268                                                        originalModel_->primalColumnSolution(),
    269                                                        offset,true),ncols_*sizeof(double));
     265  CoinMemcpyN(originalModel_->objectiveAsObject()->gradient(originalModel_,
     266                                                            originalModel_->primalColumnSolution(),offset,true),
     267              ncols_,originalModel_->dualColumnSolution());
    270268  originalModel_->transposeTimes(-1.0,
    271269                                 originalModel_->dualRowSolution(),
     
    439437  if (!prob->status_) {
    440438    bool slackSingleton = doSingletonColumn();
    441     slackSingleton = false;
     439    slackSingleton = true;
    442440    const bool slackd = doSingleton();
    443441    const bool doubleton = doDoubleton();
     
    689687          if (!hinrow[i])
    690688            numberDropped++;
    691        
     689
    692690        prob->messageHandler()->message(COIN_PRESOLVE_PASS,
    693691                                        messages)
     
    11221120  delete mRow;
    11231121  if (si->integerInformation()) {
    1124     memcpy(integerType_,si->integerInformation(),ncols_*sizeof(char));
     1122    CoinMemcpyN((unsigned char *) si->integerInformation(),ncols_,integerType_);
    11251123  } else {
    11261124    ClpFillN<unsigned char>(integerType_, ncols_, (unsigned char) 0);
     
    11761174    // allow for status and solution
    11771175    sol_ = new double[ncols_];
    1178     memcpy(sol_,si->primalColumnSolution(),ncols_*sizeof(double));;
     1176    CoinMemcpyN(si->primalColumnSolution(),ncols_,sol_);;
    11791177    acts_ = new double [nrows_];
    1180     memcpy(acts_,si->primalRowSolution(),nrows_*sizeof(double));
     1178    CoinMemcpyN(si->primalRowSolution(),nrows_,acts_);
    11811179    if (!si->statusArray())
    11821180      si->createStatus();
    11831181    colstat_ = new unsigned char [nrows_+ncols_];
    1184     memcpy(colstat_,si->statusArray(),
    1185            (nrows_+ncols_)*sizeof(unsigned char));
     1182    CoinMemcpyN(si->statusArray(),      (nrows_+ncols_),colstat_);
    11861183    rowstat_ = colstat_+ncols_;
    11871184  }
     
    15511548      prob.update_model(presolvedModel_, nrows_, ncols_, nelems_);
    15521549      // copy status and solution
    1553       memcpy(presolvedModel_->primalColumnSolution(),
    1554              prob.sol_,prob.ncols_*sizeof(double));
    1555       memcpy(presolvedModel_->primalRowSolution(),
    1556              prob.acts_,prob.nrows_*sizeof(double));
    1557       memcpy(presolvedModel_->statusArray(),
    1558              prob.colstat_,prob.ncols_*sizeof(unsigned char));
    1559       memcpy(presolvedModel_->statusArray()+prob.ncols_,
    1560              prob.rowstat_,prob.nrows_*sizeof(unsigned char));
     1550      CoinMemcpyN(           prob.sol_,prob.ncols_,presolvedModel_->primalColumnSolution());
     1551      CoinMemcpyN(           prob.acts_,prob.nrows_,presolvedModel_->primalRowSolution());
     1552      CoinMemcpyN(           prob.colstat_,prob.ncols_,presolvedModel_->statusArray());
     1553      CoinMemcpyN(           prob.rowstat_,prob.nrows_,presolvedModel_->statusArray()+prob.ncols_);
    15611554      delete [] prob.sol_;
    15621555      delete [] prob.acts_;
     
    15671560     
    15681561      int ncolsNow = presolvedModel_->getNumCols();
    1569       memcpy(originalColumn_,prob.originalColumn_,ncolsNow*sizeof(int));
     1562      CoinMemcpyN(prob.originalColumn_,ncolsNow,originalColumn_);
    15701563#ifndef SLIM_CLP
    15711564#ifndef NO_RTTI
     
    15911584        // and modify linear and check
    15921585        double * linear = newObj->linearObjective();
    1593         memcpy(linear,presolvedModel_->objective(),ncolsNow*sizeof(double));
     1586 CoinMemcpyN(presolvedModel_->objective(),ncolsNow,linear);
    15941587        int iColumn;
    15951588        for ( iColumn=0;iColumn<numberColumns;iColumn++) {
     
    16171610      prob.originalColumn_=NULL;
    16181611      int nrowsNow = presolvedModel_->getNumRows();
    1619       memcpy(originalRow_,prob.originalRow_,nrowsNow*sizeof(int));
     1612      CoinMemcpyN(prob.originalRow_,nrowsNow,originalRow_);
    16201613      delete [] prob.originalRow_;
    16211614      prob.originalRow_=NULL;
  • trunk/Clp/src/ClpPrimalColumnSteepest.cpp

    r1167 r1197  
    584584    if (model_->getStatus(bestSequence)==ClpSimplex::atLowerBound)
    585585      assert(model_->reducedCost(bestSequence)<0.0);
    586     if (model_->getStatus(bestSequence)==ClpSimplex::atUpperBound)
     586    if (model_->getStatus(bestSequence)==ClpSimplex::atUpperBound) {
    587587      assert(model_->reducedCost(bestSequence)>0.0);
     588    }
    588589  }
    589590#endif
     
    644645     
    645646      switch(status) {
    646        
     647
    647648      case ClpSimplex::basic:
    648649        infeasible_->zero(iSequence+addSequence);
     
    12601261     
    12611262      switch(status) {
    1262        
     1263
    12631264      case ClpSimplex::basic:
    12641265        infeasible_->zero(iSequence+addSequence);
     
    14521453     
    14531454      switch(status) {
    1454        
     1455
    14551456      case ClpSimplex::basic:
    14561457        infeasible_->zero(iSequence+addSequence);
     
    15581559        double modification = other[iSequence];
    15591560        double pivotSquared = pivot * pivot;
    1560        
     1561
    15611562        thisWeight += pivotSquared * devex_ + pivot * modification;
    15621563        if (thisWeight<TRY_NORM) {
     
    25372538        double modification = other[iSequence];
    25382539        double pivotSquared = pivot * pivot;
    2539        
     2540
    25402541        thisWeight += pivotSquared * devex_ + pivot * modification;
    25412542        if (thisWeight<TRY_NORM) {
     
    25922593        updateBy2[j]=0.0;
    25932594        double pivotSquared = pivot * pivot;
    2594        
     2595
    25952596        thisWeight += pivotSquared * devex_ + pivot * modification;
    25962597        if (thisWeight<TRY_NORM) {
  • trunk/Clp/src/ClpQuadraticObjective.cpp

    r1034 r1197  
    4545  if (objective) {
    4646    objective_ = new double [numberExtendedColumns_];
    47     memcpy(objective_,objective,numberColumns_*sizeof(double));
     47    CoinMemcpyN(objective,numberColumns_,objective_);
    4848    memset(objective_+numberColumns_,0,(numberExtendedColumns_-numberColumns_)*sizeof(double));
    4949  } else {
     
    7373  if (rhs.objective_) {
    7474    objective_ = new double [numberExtendedColumns_];
    75     memcpy(objective_,rhs.objective_,numberExtendedColumns_*sizeof(double));
     75    CoinMemcpyN(rhs.objective_,numberExtendedColumns_,objective_);
    7676  } else {
    7777    objective_=NULL;
     
    7979  if (rhs.gradient_) {
    8080    gradient_ = new double [numberExtendedColumns_];
    81     memcpy(gradient_,rhs.gradient_,numberExtendedColumns_*sizeof(double));
     81    CoinMemcpyN(rhs.gradient_,numberExtendedColumns_,gradient_);
    8282  } else {
    8383    gradient_=NULL;
     
    217217    for (i=0;i<numberColumns_;i++)
    218218      objective_[i]=rhs.objective_[whichColumn[i]];
    219     memcpy(objective_+numberColumns_,rhs.objective_+rhs.numberColumns_,
    220            (numberExtendedColumns_-numberColumns_)*sizeof(double));
     219    CoinMemcpyN(rhs.objective_+rhs.numberColumns_,      (numberExtendedColumns_-numberColumns_),
     220                 objective_+numberColumns_);
    221221    if (rhs.gradient_) {
    222222      gradient_ = new double[numberExtendedColumns_];
    223223      for (i=0;i<numberColumns_;i++)
    224224        gradient_[i]=rhs.gradient_[whichColumn[i]];
    225       memcpy(gradient_+numberColumns_,rhs.gradient_+rhs.numberColumns_,
    226              (numberExtendedColumns_-numberColumns_)*sizeof(double));
     225      CoinMemcpyN(rhs.gradient_+rhs.numberColumns_,     (numberExtendedColumns_-numberColumns_),
     226                   gradient_+numberColumns_);
    227227    } else {
    228228      gradient_=NULL;
     
    269269    if (rhs.objective_) {
    270270      objective_ = new double [numberExtendedColumns_];
    271       memcpy(objective_,rhs.objective_,numberExtendedColumns_*sizeof(double));
     271      CoinMemcpyN(rhs.objective_,numberExtendedColumns_,objective_);
    272272    } else {
    273273      objective_=NULL;
     
    275275    if (rhs.gradient_) {
    276276      gradient_ = new double [numberExtendedColumns_];
    277       memcpy(gradient_,rhs.gradient_,numberExtendedColumns_*sizeof(double));
     277      CoinMemcpyN(rhs.gradient_,numberExtendedColumns_,gradient_);
    278278    } else {
    279279      gradient_=NULL;
     
    321321        // use current linear cost region
    322322        if (includeLinear==1)
    323           memcpy(gradient_,cost,numberExtendedColumns_*sizeof(double));
     323   CoinMemcpyN(cost,numberExtendedColumns_,gradient_);
    324324        else if (includeLinear==2)
    325           memcpy(gradient_,objective_,numberExtendedColumns_*sizeof(double));
     325   CoinMemcpyN(objective_,numberExtendedColumns_,gradient_);
    326326        else
    327327          memset(gradient_,0,numberExtendedColumns_*sizeof(double));
     
    403403      // use current linear cost region (already scaled)
    404404      if (includeLinear==1) {
    405         memcpy(gradient_,model->costRegion(),numberExtendedColumns_*sizeof(double));
     405 CoinMemcpyN(model->costRegion(),numberExtendedColumns_,gradient_);
    406406      } else if (includeLinear==2) {
    407407        memset(gradient_+numberColumns_,0,(numberExtendedColumns_-numberColumns_)*sizeof(double));
     
    504504    double * newArray = new double[newExtended];
    505505    if (objective_)
    506       memcpy(newArray,objective_,
    507              CoinMin(newExtended,numberExtendedColumns_)*sizeof(double));
     506      CoinMemcpyN(objective_,   CoinMin(newExtended,numberExtendedColumns_),newArray);
    508507    delete [] objective_;
    509508    objective_ = newArray;
     
    513512      newArray = new double[newExtended];
    514513      if (gradient_)
    515         memcpy(newArray,gradient_,
    516                CoinMin(newExtended,numberExtendedColumns_)*sizeof(double));
     514 CoinMemcpyN(gradient_, CoinMin(newExtended,numberExtendedColumns_),newArray);
    517515      delete [] gradient_;
    518516      gradient_ = newArray;
     
    568566    objective_ = newArray;
    569567    delete [] deleted;
    570     memcpy(objective_+newNumberColumns,objective_+numberColumns_,
    571            (numberExtendedColumns_-numberColumns_)*sizeof(double));
     568    CoinMemcpyN(objective_+numberColumns_,      (numberExtendedColumns_-numberColumns_),
     569                 objective_+newNumberColumns);
    572570  }
    573571  if (gradient_) {
     
    595593    gradient_ = newArray;
    596594    delete [] deleted;
    597     memcpy(gradient_+newNumberColumns,gradient_+numberColumns_,
    598            (numberExtendedColumns_-numberColumns_)*sizeof(double));
     595    CoinMemcpyN(gradient_+numberColumns_,       (numberExtendedColumns_-numberColumns_),
     596                 gradient_+newNumberColumns);
    599597  }
    600598  numberColumns_ = newNumberColumns;
     
    620618      // make correct size
    621619      double * newArray = new double[numberExtended];
    622       memcpy(newArray,objective_,numberColumns_*sizeof(double));
     620      CoinMemcpyN(objective_,numberColumns_,newArray);
    623621      delete [] objective_;
    624622      objective_ = newArray;
     
    628626      // make correct size
    629627      double * newArray = new double[numberExtended];
    630       memcpy(newArray,gradient_,numberColumns_*sizeof(double));
     628      CoinMemcpyN(gradient_,numberColumns_,newArray);
    631629      delete [] gradient_;
    632630      gradient_ = newArray;
  • trunk/Clp/src/ClpSimplex.cpp

    r1174 r1197  
    116116  numberExtraRows_(0),
    117117  maximumBasic_(0),
     118  dontFactorizePivots_(0),
    118119  incomingInfeasibility_(1.0),
    119120  allowedInfeasibility_(10.0),
     
    227228  numberExtraRows_(0),
    228229  maximumBasic_(0),
     230  dontFactorizePivots_(0),
    229231  incomingInfeasibility_(1.0),
    230232  allowedInfeasibility_(10.0),
     
    375377  numberExtraRows_(0),
    376378  maximumBasic_(0),
     379  dontFactorizePivots_(0),
    377380  incomingInfeasibility_(1.0),
    378381  allowedInfeasibility_(10.0),
     
    391394  saveStatus_=NULL;
    392395  factorization_ = new ClpFactorization(*rhs->factorization_);
     396#ifdef CLP_MULTIPLE_FACTORIZATIONS   
     397  if (numberRows_<=factorization_->goDenseThreshold()) //&&!factorization_->isDense())
     398    factorization_->goDense();
     399#endif
     400  ClpDualRowDantzig * pivot =
     401    dynamic_cast< ClpDualRowDantzig*>(rhs->dualRowPivot_);
    393402  // say Steepest pricing
    394   dualRowPivot_ = new ClpDualRowSteepest();
     403  if (!pivot)
     404    dualRowPivot_ = new ClpDualRowSteepest();
     405  else
     406    dualRowPivot_ = new ClpDualRowDantzig();
    395407  // say Steepest pricing
    396408  primalColumnPivot_ = new ClpPrimalColumnSteepest();
     
    513525  // If necessary - override results
    514526  if (givenPrimals) {
    515     memcpy(columnActivityWork_,givenPrimals,numberColumns_*sizeof(double));
     527    CoinMemcpyN(givenPrimals,numberColumns_,columnActivityWork_);
    516528    memset(rowActivityWork_,0,numberRows_*sizeof(double));
    517529    times(-1.0,columnActivityWork_,rowActivityWork_);
     
    10631075    if (givenDjs) {
    10641076      // restore accurate duals
    1065       memcpy(givenDjs,dj_,(numberRows_+numberColumns_)*sizeof(double));
     1077      CoinMemcpyN(dj_,(numberRows_+numberColumns_),givenDjs);
    10661078    }
    10671079    arrayVector->clear();
     
    10721084    objective_->reducedGradient(this,dj_,false);
    10731085    // get dual_ by moving from reduced costs for slacks
    1074     memcpy(dual_,dj_+numberColumns_,numberRows_*sizeof(double));
     1086    CoinMemcpyN(dj_+numberColumns_,numberRows_,dual_);
    10751087  }
    10761088#endif
     
    18291841  numberExtraRows_(0),
    18301842  maximumBasic_(0),
     1843  dontFactorizePivots_(0),
    18311844  incomingInfeasibility_(1.0),
    18321845  allowedInfeasibility_(10.0),
     
    19331946  numberExtraRows_(0),
    19341947  maximumBasic_(0),
     1948  dontFactorizePivots_(0),
    19351949  incomingInfeasibility_(1.0),
    19361950  allowedInfeasibility_(10.0),
     
    19771991  numberExtraRows_ = rhs.numberExtraRows_;
    19781992  maximumBasic_ = rhs.maximumBasic_;
     1993  dontFactorizePivots_ = rhs.dontFactorizePivots_;
    19791994  int numberRows2 = numberRows_+numberExtraRows_;
    19801995  auxiliaryModel_ = NULL;
     
    19831998    int numberTotal = numberColumns_+numberRows2;
    19841999    if ((specialOptions_&65536)!=0&&maximumRows_>=0) {
    1985       assert (maximumRows_>=numberRows2);
    1986       assert (maximumColumns_>=numberColumns_);
    1987       numberTotal = 2*(maximumColumns_+ maximumRows_);
     2000      assert (maximumInternalRows_>=numberRows2);
     2001      assert (maximumInternalColumns_>=numberColumns_);
     2002      numberTotal = 2*(maximumInternalColumns_+ maximumInternalRows_);
    19882003    }
    19892004    lower_ = ClpCopyOfArray(rhs.lower_,numberTotal);
     
    20122027      pivotVariable_=NULL;
    20132028    }
    2014     savedSolution_ = ClpCopyOfArray(rhs.savedSolution_,numberColumns_+numberRows_);
     2029    savedSolution_ = ClpCopyOfArray(rhs.savedSolution_,numberTotal);
    20152030    int i;
    20162031    for (i=0;i<6;i++) {
     
    20232038    }
    20242039    if (rhs.saveStatus_) {
    2025       saveStatus_ = ClpCopyOfArray( rhs.saveStatus_,numberColumns_+numberRows_);
     2040      saveStatus_ = ClpCopyOfArray( rhs.saveStatus_,numberTotal);
    20262041    }
    20272042  } else {
     
    21372152{
    21382153  if (!type||(specialOptions_&65536)==0) {
     2154    maximumInternalColumns_ = -1;
     2155    maximumInternalRows_ = -1;
    21392156    delete [] lower_;
    21402157    lower_=NULL;
     
    23122329  matrix_->dualExpanded(this,NULL,NULL,3);
    23132330  numberDualInfeasibilitiesWithoutFree_= numberDualInfeasibilities_;
     2331  objectiveValue_ = 0.0;
    23142332  for (iColumn=0;iColumn<numberColumns_;iColumn++) {
     2333    objectiveValue_ += objectiveWork_[iColumn]*columnActivityWork_[iColumn];
    23152334    if (getColumnStatus(iColumn) != basic&&!flagged(iColumn)) {
    23162335      // not basic
     
    23722391  }
    23732392  for (iRow=0;iRow<numberRows_;iRow++) {
     2393    objectiveValue_ += rowActivityWork_[iRow]*rowObjectiveWork_[iRow];
    23742394    if (getRowStatus(iRow) != basic&&!flagged(iRow+numberColumns_)) {
    23752395      // not basic
     
    24252445    firstFree_=firstFreePrimal;
    24262446  }
     2447  objectiveValue_ += objective_->nonlinearOffset();
     2448  objectiveValue_ /= (objectiveScale_*rhsScale_);
    24272449}
    24282450/* This sets sum and number of infeasibilities (Dual and Primal) */
     
    26882710      unsigned char * newStatus = new unsigned char [numberNew];
    26892711      memset(newStatus+numberOld,0,numberExtraRows_);
    2690       memcpy(newStatus,status_,numberOld);
     2712      CoinMemcpyN(status_,numberOld,newStatus);
    26912713      delete [] status_;
    26922714      status_=newStatus;
     
    26972719  if ((specialOptions_&65536)!=0&&!auxiliaryModel_) {
    26982720    assert (!numberExtraRows_);
    2699     if (!cost_||numberRows2>maximumRows_||numberColumns_>maximumColumns_) {
     2721    if (!cost_||numberRows2>maximumInternalRows_||
     2722        numberColumns_>maximumInternalColumns_) {
    27002723      newArrays=true;
    27012724      keepPivots=false;
     2725      printf("createrim a %d rows, %d maximum rows %d maxinternal\n",
     2726             numberRows_,maximumRows_,maximumInternalRows_);
     2727      int oldMaximumRows=maximumInternalRows_;
     2728      int oldMaximumColumns=maximumInternalColumns_;
    27022729      if (cost_) {
    2703         if (numberRows2>maximumRows_)
    2704           maximumRows_ = numberRows2+10+numberRows2/100;
    2705         if (numberColumns_>maximumColumns_)
    2706           maximumColumns_ = numberColumns_+10+numberColumns_/100;
     2730        if (numberRows2>maximumInternalRows_)
     2731          maximumInternalRows_ = numberRows2;
     2732        if (numberColumns_>maximumInternalColumns_)
     2733          maximumInternalColumns_ = numberColumns_;
    27072734      } else {
    2708         maximumRows_ = numberRows2;
    2709         maximumColumns_ = numberColumns_;
    2710       }
    2711       int numberTotal2 = (maximumRows_+maximumColumns_)*2;
     2735        maximumInternalRows_ = numberRows2;
     2736        maximumInternalColumns_ = numberColumns_;
     2737      }
     2738      assert(maximumInternalRows_ == maximumRows_);
     2739      assert(maximumInternalColumns_ == maximumColumns_);
     2740      printf("createrim b %d rows, %d maximum rows, %d maxinternal\n",
     2741             numberRows_,maximumRows_,maximumInternalRows_);
     2742      int numberTotal2 = (maximumInternalRows_+maximumInternalColumns_)*2;
    27122743      delete [] cost_;
    27132744      cost_ = new double[numberTotal2];
     
    27232754      //printf("resize %d savedRowScale %x\n",maximumRows_,savedRowScale_);
    27242755      if (savedRowScale_) {
     2756        assert (oldMaximumRows>0);
     2757        double * temp;
     2758        temp = new double [4*maximumRows_];
     2759        CoinFillN(temp,4*maximumRows_,1.0);
     2760        CoinMemcpyN(savedRowScale_,numberRows_,temp);
     2761        CoinMemcpyN(savedRowScale_+oldMaximumRows,numberRows_,temp+maximumRows_);
     2762        CoinMemcpyN(savedRowScale_+2*oldMaximumRows,numberRows_,temp+2*maximumRows_);
     2763        CoinMemcpyN(savedRowScale_+3*oldMaximumRows,numberRows_,temp+3*maximumRows_);
    27252764        delete [] savedRowScale_;
    2726         savedRowScale_ = new double [2*maximumRows_];
     2765        savedRowScale_ = temp;
     2766        temp = new double [4*maximumColumns_];
     2767        CoinFillN(temp,4*maximumColumns_,1.0);
     2768        CoinMemcpyN(savedColumnScale_,numberColumns_,temp);
     2769        CoinMemcpyN(savedColumnScale_+oldMaximumColumns,numberColumns_,temp+maximumColumns_);
     2770        CoinMemcpyN(savedColumnScale_+2*oldMaximumColumns,numberColumns_,temp+2*maximumColumns_);
     2771        CoinMemcpyN(savedColumnScale_+3*oldMaximumColumns,numberColumns_,temp+3*maximumColumns_);
    27272772        delete [] savedColumnScale_;
    2728         savedColumnScale_ = new double [2*maximumColumns_];
     2773        savedColumnScale_ = temp;
    27292774      }
    27302775    }
     
    27442789    if (oldMatrix)
    27452790      checkType = 14;
    2746     if ((specialOptions_&0x1000000)!=0)
     2791    if ((specialOptions_&COIN_CBC_USING_CLP)!=0)
    27472792      checkType -= 4; // don't check for duplicates
    27482793    if (!matrix_->allElementsInRange(this,smallElement_,1.0e20,checkType)) {
     
    27812826      columnScale_=NULL;
    27822827    }
     2828    inverseRowScale_ = NULL;
     2829    inverseColumnScale_ = NULL;
    27832830    if (scalingFlag_>0&&!rowScale_) {
     2831      if ((specialOptions_&131072)!=0) {
     2832        inverseRowScale_ = rowScale_+numberRows2;
     2833        inverseColumnScale_ = columnScale_+numberColumns_;
     2834      }
    27842835      if ((specialOptions_&65536)!=0&&!auxiliaryModel_) {
    27852836        assert (!rowScale_);
    27862837        rowScale_ = savedRowScale_;
    27872838        columnScale_ = savedColumnScale_;
     2839        // put back original
     2840        if (savedRowScale_) {
     2841          inverseRowScale_ = savedRowScale_+maximumInternalRows_;
     2842          inverseColumnScale_ = savedColumnScale_+maximumInternalColumns_;
     2843          CoinMemcpyN(savedRowScale_+2*maximumInternalRows_,
     2844                      numberRows2,savedRowScale_);
     2845          CoinMemcpyN(savedRowScale_+3*maximumInternalRows_,
     2846                      numberRows2,inverseRowScale_);
     2847          CoinMemcpyN(savedColumnScale_+2*maximumColumns_,
     2848                      numberColumns_,savedColumnScale_);
     2849          CoinMemcpyN(savedColumnScale_+3*maximumColumns_,
     2850                      numberColumns_,inverseColumnScale_);
     2851        }
    27882852      }
    27892853      if (matrix_->scale(this))
    27902854        scalingFlag_=-scalingFlag_; // not scaled after all
     2855      if ((specialOptions_&131072)!=0&&rowScale_&&!savedRowScale_) {
     2856        inverseRowScale_ = rowScale_+numberRows2;
     2857        inverseColumnScale_ = columnScale_+numberColumns_;
     2858      }
    27912859      if (rowScale_&&automaticScale_) {
    27922860        // try automatic scaling
     
    29883056      if (auxiliaryModel_) {
    29893057        // save costs
    2990         memcpy(auxiliaryModel_->cost_+numberTotal,cost_,numberTotal*sizeof(double));
     3058        CoinMemcpyN(cost_,numberTotal,auxiliaryModel_->cost_+numberTotal);
    29913059      }
    29923060    } else {
    29933061      // just copy
    2994       memcpy(cost_,auxiliaryModel_->cost_+numberTotal,numberTotal*sizeof(double));
     3062      CoinMemcpyN(auxiliaryModel_->cost_+numberTotal,numberTotal,cost_);
    29953063    }
    29963064  }
     
    30053073        // If scaled then do all columns later in one loop
    30063074        if (what!=63) {
    3007           if ((specialOptions_&131072)==0) {
     3075          if (!inverseColumnScale_) {
    30083076            for (i=0;i<numberColumns_;i++) {
    30093077              double multiplier = rhsScale_/columnScale[i];
     
    30373105            }
    30383106          } else {
    3039             const double * inverseScale = columnScale_+numberColumns_;
     3107            assert (inverseColumnScale_);
     3108            const double * inverseScale = inverseColumnScale_;
    30403109            for (i=0;i<numberColumns_;i++) {
    30413110              double multiplier = rhsScale_*inverseScale[i];
     
    32233292      if (what!=63) {
    32243293        // just copy
    3225         memcpy(lower_,auxiliaryModel_->lower_+numberTotal,numberTotal*sizeof(double));
    3226         memcpy(upper_,auxiliaryModel_->upper_+numberTotal,numberTotal*sizeof(double));
     3294        CoinMemcpyN(auxiliaryModel_->lower_+numberTotal,numberTotal,lower_);
     3295        CoinMemcpyN(auxiliaryModel_->upper_+numberTotal,numberTotal,upper_);
    32273296      } else {
    32283297        assert (rhsScale_==1.0);
     
    32513320          }
    32523321          // save
    3253           memcpy(auxiliaryModel_->lower_+numberTotal,lower_,numberColumns_*sizeof(double));
    3254           memcpy(auxiliaryModel_->upper_+numberTotal,upper_,numberColumns_*sizeof(double));
     3322          CoinMemcpyN(lower_,numberColumns_,auxiliaryModel_->lower_+numberTotal);
     3323          CoinMemcpyN(upper_,numberColumns_,auxiliaryModel_->upper_+numberTotal);
    32553324        } else {
    32563325          // just copy
    3257           memcpy(lower_,auxiliaryModel_->lower_+numberTotal,numberColumns_*sizeof(double));
    3258           memcpy(upper_,auxiliaryModel_->upper_+numberTotal,numberColumns_*sizeof(double));
     3326          CoinMemcpyN(auxiliaryModel_->lower_+numberTotal,numberColumns_,lower_);
     3327          CoinMemcpyN(auxiliaryModel_->upper_+numberTotal,numberColumns_,upper_);
    32593328        }
    32603329        if ((auxiliaryModel_->specialOptions_&1)==0) {
     
    32803349          }
    32813350          // save
    3282           memcpy(auxiliaryModel_->lower_+numberTotal+numberColumns_,
    3283                  lower_+numberColumns_,numberRows_*sizeof(double));
    3284           memcpy(auxiliaryModel_->upper_+numberTotal+numberColumns_,
    3285                  upper_+numberColumns_,numberRows_*sizeof(double));
     3351          CoinMemcpyN(                 lower_+numberColumns_,numberRows_,auxiliaryModel_->lower_+numberTotal+numberColumns_);
     3352          CoinMemcpyN(                 upper_+numberColumns_,numberRows_,auxiliaryModel_->upper_+numberTotal+numberColumns_);
    32863353        } else {
    32873354          // just copy
    3288           memcpy(lower_+numberColumns_,
    3289                  auxiliaryModel_->lower_+numberTotal+numberColumns_,numberRows_*sizeof(double));
    3290           memcpy(upper_+numberColumns_,
    3291                  auxiliaryModel_->upper_+numberTotal+numberColumns_,numberRows_*sizeof(double));
     3355          CoinMemcpyN(                 auxiliaryModel_->lower_+numberTotal+numberColumns_,
     3356                       numberRows_,lower_+numberColumns_);
     3357          CoinMemcpyN(                 auxiliaryModel_->upper_+numberTotal+numberColumns_,
     3358                       numberRows_,upper_+numberColumns_);
    32923359        }
    32933360      }
     
    33563423        double primalTolerance=dblParam_[ClpPrimalTolerance];
    33573424        // on entry
    3358         if ((specialOptions_&131072)==0) {
     3425        if (!inverseColumnScale_) {
    33593426          for (i=0;i<numberColumns_;i++) {
    33603427            CoinAssert(fabs(obj[i])<1.0e25);
     
    34253492          }
    34263493        } else {
    3427           const double * inverseScale = columnScale_+numberColumns_;
     3494          assert (inverseColumnScale_);
     3495          const double * inverseScale = inverseColumnScale_;
    34283496          for (i=0;i<numberColumns_;i++) {
    34293497            CoinAssert(fabs(obj[i])<1.0e25);
     
    34743542            columnActivityWork_[i] = value;
    34753543          }
    3476           inverseScale = rowScale_+numberRows_;
     3544          inverseScale = inverseRowScale_;
    34773545          for (i=0;i<numberRows_;i++) {
    34783546            dual_[i] *= inverseScale[i];
     
    37283796  if (goodMatrix&&(specialOptions_&65536)!=0&&!auxiliaryModel_) {
    37293797    int save = maximumColumns_+maximumRows_;
    3730     memcpy(cost_+save,cost_,numberTotal*sizeof(double));
    3731     memcpy(lower_+save,lower_,numberTotal*sizeof(double));
    3732     memcpy(upper_+save,upper_,numberTotal*sizeof(double));
    3733     memcpy(dj_+save,dj_,numberTotal*sizeof(double));
    3734     memcpy(solution_+save,solution_,numberTotal*sizeof(double));
    3735     if (rowScale_&&false) {
    3736       memcpy(savedRowScale_+maximumRows_,rowScale_,numberRows2*sizeof(double));
    3737       memcpy(savedColumnScale_+maximumColumns_,columnScale_,numberColumns_*sizeof(double));
     3798    CoinMemcpyN(cost_,numberTotal,cost_+save);
     3799    CoinMemcpyN(lower_,numberTotal,lower_+save);
     3800    CoinMemcpyN(upper_,numberTotal,upper_+save);
     3801    CoinMemcpyN(dj_,numberTotal,dj_+save);
     3802    CoinMemcpyN(solution_,numberTotal,solution_+save);
     3803    if (rowScale_&&!savedRowScale_) {
     3804      double * temp;
     3805      temp = new double [4*maximumRows_];
     3806      CoinFillN(temp,4*maximumRows_,1.0);
     3807      CoinMemcpyN(rowScale_,numberRows2,temp);
     3808      CoinMemcpyN(rowScale_+numberRows2,numberRows2,temp+maximumRows_);
     3809      CoinMemcpyN(rowScale_,numberRows2,temp+2*maximumRows_);
     3810      CoinMemcpyN(rowScale_+numberRows2,numberRows2,temp+3*maximumRows_);
     3811      delete [] rowScale_;
     3812      savedRowScale_ = temp;
     3813      rowScale_ = savedRowScale_;
     3814      inverseRowScale_ = savedRowScale_+maximumInternalRows_;
     3815      temp = new double [4*maximumColumns_];
     3816      CoinFillN(temp,4*maximumColumns_,1.0);
     3817      CoinMemcpyN(columnScale_,numberColumns_,temp);
     3818      CoinMemcpyN(columnScale_+numberColumns_,numberColumns_,temp+maximumColumns_);
     3819      CoinMemcpyN(columnScale_,numberColumns_,temp+2*maximumColumns_);
     3820      CoinMemcpyN(columnScale_+numberColumns_,numberColumns_,temp+3*maximumColumns_);
     3821      delete [] columnScale_;
     3822      savedColumnScale_ = temp;
     3823      columnScale_ = savedColumnScale_;
     3824      inverseColumnScale_ = savedColumnScale_+maximumInternalColumns_;
    37383825    }
    37393826  }
     
    37523839      assert (!initial);
    37533840      int save = maximumColumns_+maximumRows_;
    3754       memcpy(lower_,lower_+save,numberTotal*sizeof(double));
    3755       memcpy(upper_,upper_+save,numberTotal*sizeof(double));
     3841      CoinMemcpyN(lower_+save,numberTotal,lower_);
     3842      CoinMemcpyN(upper_+save,numberTotal,upper_);
    37563843      return;
    37573844    }
     
    37643851      // If scaled then do all columns later in one loop
    37653852      if (!initial) {
    3766         if ((specialOptions_&131072)==0) {
     3853        if (!inverseColumnScale_) {
    37673854          for (i=0;i<numberColumns_;i++) {
    37683855            double multiplier = rhsScale_/columnScale[i];
     
    37963883          }
    37973884        } else {
    3798           const double * inverseScale = columnScale_+numberColumns_;
     3885          assert (inverseColumnScale_);
     3886          const double * inverseScale = inverseColumnScale_;
    37993887          for (i=0;i<numberColumns_;i++) {
    38003888            double multiplier = rhsScale_*inverseScale[i];
     
    39824070    if (!initial) {
    39834071      // just copy
    3984       memcpy(lower_,auxiliaryModel_->lower_+numberTotal,numberTotal*sizeof(double));
    3985       memcpy(upper_,auxiliaryModel_->upper_+numberTotal,numberTotal*sizeof(double));
     4072      CoinMemcpyN(auxiliaryModel_->lower_+numberTotal,numberTotal,lower_);
     4073      CoinMemcpyN(auxiliaryModel_->upper_+numberTotal,numberTotal,upper_);
    39864074    } else {
    39874075      // clean up any mismatches on infinity
     
    40144102        }
    40154103        // save
    4016         memcpy(auxiliaryModel_->lower_+numberTotal,lower_,numberColumns_*sizeof(double));
    4017         memcpy(auxiliaryModel_->upper_+numberTotal,upper_,numberColumns_*sizeof(double));
     4104 CoinMemcpyN(lower_,numberColumns_,auxiliaryModel_->lower_+numberTotal);
     4105 CoinMemcpyN(upper_,numberColumns_,auxiliaryModel_->upper_+numberTotal);
    40184106      } else {
    40194107        // just copy
    4020         memcpy(lower_,auxiliaryModel_->lower_+numberTotal,numberColumns_*sizeof(double));
    4021         memcpy(upper_,auxiliaryModel_->upper_+numberTotal,numberColumns_*sizeof(double));
     4108 CoinMemcpyN(auxiliaryModel_->lower_+numberTotal,numberColumns_,lower_);
     4109 CoinMemcpyN(auxiliaryModel_->upper_+numberTotal,numberColumns_,upper_);
    40224110      }
    40234111      if ((auxiliaryModel_->specialOptions_&1)==0) {
     
    40434131        }
    40444132        // save
    4045         memcpy(auxiliaryModel_->lower_+numberTotal+numberColumns_,
    4046                lower_+numberColumns_,numberRows_*sizeof(double));
    4047         memcpy(auxiliaryModel_->upper_+numberTotal+numberColumns_,
    4048                upper_+numberColumns_,numberRows_*sizeof(double));
     4133 CoinMemcpyN(          lower_+numberColumns_,numberRows_,auxiliaryModel_->lower_+numberTotal+numberColumns_);
     4134 CoinMemcpyN(          upper_+numberColumns_,numberRows_,auxiliaryModel_->upper_+numberTotal+numberColumns_);
    40494135      } else {
    40504136        // just copy
    4051         memcpy(lower_+numberColumns_,
    4052                auxiliaryModel_->lower_+numberTotal+numberColumns_,numberRows_*sizeof(double));
    4053         memcpy(upper_+numberColumns_,
    4054                auxiliaryModel_->upper_+numberTotal+numberColumns_,numberRows_*sizeof(double));
     4137 CoinMemcpyN(          auxiliaryModel_->lower_+numberTotal+numberColumns_,numberRows_,
     4138              lower_+numberColumns_);
     4139 CoinMemcpyN(          auxiliaryModel_->upper_+numberTotal+numberColumns_,numberRows_,
     4140              upper_+numberColumns_);
    40554141      }
    40564142    }
     
    40944180    }
    40954181  }
     4182#ifndef NDEBUG
    40964183  if ((specialOptions_&65536)!=0&&false) {
    40974184    assert (!initial);
     
    41024189    }
    41034190  }
     4191#endif
    41044192}
    41054193// Does objective
     
    41154203      assert (!initial);
    41164204      int save = maximumColumns_+maximumRows_;
    4117       memcpy(cost_,cost_+save,numberTotal*sizeof(double));
     4205      CoinMemcpyN(cost_+save,numberTotal,cost_);
    41184206      return;
    41194207    }
     
    41514239    if (auxiliaryModel_) {
    41524240      // save costs
    4153       memcpy(auxiliaryModel_->cost_+numberTotal,cost_,numberTotal*sizeof(double));
     4241      CoinMemcpyN(cost_,numberTotal,auxiliaryModel_->cost_+numberTotal);
    41544242    }
    41554243  } else {
    41564244    // just copy
    4157     memcpy(cost_,auxiliaryModel_->cost_+numberTotal,numberTotal*sizeof(double));
     4245    CoinMemcpyN(auxiliaryModel_->cost_+numberTotal,numberTotal,cost_);
    41584246  }
    41594247}
     
    42044292      double scaleC = 1.0/objectiveScale_;
    42054293      double scaleR = 1.0/rhsScale_;
    4206       if ((specialOptions_&131072)==0) {
     4294      if (!inverseColumnScale_) {
    42074295        for (i=0;i<numberColumns;i++) {
    42084296          double scaleFactor = columnScale_[i];
     
    42684356        }
    42694357      } else {
    4270         const double * inverseScale = columnScale_+numberColumns;
     4358        assert (inverseColumnScale_);
     4359        const double * inverseScale = inverseColumnScale_;
    42714360        for (i=0;i<numberColumns;i++) {
    42724361          double scaleFactor = columnScale_[i];
     
    42994388            numberDualUnscaled++;
    43004389        }
    4301         inverseScale = rowScale_+numberRows;
     4390        inverseScale = inverseRowScale_;
    43024391        for (i=0;i<numberRows;i++) {
    43034392          double scaleFactor = rowScale_[i];
     
    44824571      if (rowArray_[iRow]) {
    44834572        rowArray_[iRow]->clear();
    4484         rowArray_[iRow]->checkClear();
     4573        //rowArray_[iRow]->checkClear();
    44854574      }
    44864575      rowArray_[iRow]=NULL;
     
    44894578      if (columnArray_[iColumn]) {
    44904579        columnArray_[iColumn]->clear();
    4491         columnArray_[iColumn]->checkClear();
     4580        //columnArray_[iColumn]->checkClear();
    44924581      }
    44934582      columnArray_[iColumn]=NULL;
     
    46354724  factorization_= new ClpFactorization(factorization);
    46364725}
     4726// Copies in factorization to existing one
     4727void
     4728ClpSimplex::copyFactorization( ClpFactorization & factorization)
     4729{
     4730  *factorization_= factorization;
     4731}
    46374732/* Perturbation:
    46384733   -50 to +50 - perturb by this power of ten (-6 sounds good)
     
    47604855  // Save column bounds
    47614856  double * saveLower = new double [numberColumns_];
    4762   memcpy(saveLower,columnLower_,numberColumns_*sizeof(double));
     4857  CoinMemcpyN(columnLower_,numberColumns_,saveLower);
    47634858  double * saveUpper = new double [numberColumns_];
    4764   memcpy(saveUpper,columnUpper_,numberColumns_*sizeof(double));
     4859  CoinMemcpyN(columnUpper_,numberColumns_,saveUpper);
    47654860
    47664861  int iRow, iColumn;
     
    51715266          <<CoinMessageEol;
    51725267        // restore column bounds
    5173         memcpy(columnLower_,saveLower,numberColumns_*sizeof(double));
    5174         memcpy(columnUpper_,saveUpper,numberColumns_*sizeof(double));
     5268 CoinMemcpyN(saveLower,numberColumns_,columnLower_);
     5269 CoinMemcpyN(saveUpper,numberColumns_,columnUpper_);
    51755270      }
    51765271    }
     
    51805275      <<CoinMessageEol;
    51815276    // restore column bounds
    5182     memcpy(columnLower_,saveLower,numberColumns_*sizeof(double));
    5183     memcpy(columnUpper_,saveUpper,numberColumns_*sizeof(double));
     5277    CoinMemcpyN(saveLower,numberColumns_,columnLower_);
     5278    CoinMemcpyN(saveUpper,numberColumns_,columnUpper_);
    51845279  }
    51855280  delete [] saveLower;
     
    52165311    // Move status and solution back
    52175312    int numberTotal = numberRows_+numberColumns_;
    5218     memcpy(status_,temp.statusArray(),numberTotal);
    5219     memcpy(columnActivity_,temp.primalColumnSolution(),numberColumns_*sizeof(double));
    5220     memcpy(rowActivity_,temp.primalRowSolution(),numberRows_*sizeof(double));
    5221     memcpy(reducedCost_,temp.dualColumnSolution(),numberColumns_*sizeof(double));
    5222     memcpy(dual_,temp.dualRowSolution(),numberRows_*sizeof(double));
     5313    CoinMemcpyN(temp.statusArray(),numberTotal,status_);
     5314    CoinMemcpyN(temp.primalColumnSolution(),numberColumns_,columnActivity_);
     5315    CoinMemcpyN(temp.primalRowSolution(),numberRows_,rowActivity_);
     5316    CoinMemcpyN(temp.dualColumnSolution(),numberColumns_,reducedCost_);
     5317    CoinMemcpyN(temp.dualRowSolution(),numberRows_,dual_);
    52235318    problemStatus_ = temp.problemStatus_;
    52245319    setObjectiveValue(temp.objectiveValue());
     
    52605355  if (problemStatus_==10) {
    52615356    //printf("Cleaning up with primal\n");
     5357#ifdef COIN_DEVELOP
     5358    int saveNumberIterations=numberIterations_;
     5359#endif
    52625360    //lastAlgorithm=1;
    52635361    int savePerturbation = perturbation_;
     
    52925390    }
    52935391    if (problemStatus_==3&&numberIterations_<saveMax) {
     5392#ifndef COIN_DEVELOP
    52945393      if (handler_->logLevel()==63)
     5394#endif
    52955395        printf("looks like trouble - too many iterations in clean up - trying again\n");
    52965396      // flatten solution and try again
     
    53385438      memset(reducedCost_,0,numberColumns_*sizeof(double));
    53395439      if (problemStatus_==3&&numberIterations_<saveMax&&
     5440#ifndef COIN_DEVELOP
    53405441          handler_->logLevel()>0)
     5442#else
     5443          handler_->logLevel()>0-2)
     5444#endif
    53415445        printf("looks like real trouble - too many iterations in second clean up - giving up\n");
    53425446    }
     
    53525456    }
    53535457    handler_->setLogLevel(saveLog);
     5458#ifdef COIN_DEVELOP
     5459    if (numberIterations_>200)
     5460      printf("after primal status %d - %d iterations (save %d)\n",
     5461             problemStatus_,numberIterations_,saveNumberIterations);
     5462#endif
    53545463  }
    53555464  objective_->setActivated(saveQuadraticActivated);
     
    56735782    saveLower = new double [numberTotal];
    56745783    saveUpper = new double [numberTotal];
    5675     memcpy(saveLower,barrier.columnLower(),numberColumns*sizeof(double));
    5676     memcpy(saveLower+numberColumns,barrier.rowLower(),numberRows*sizeof(double));
    5677     memcpy(saveUpper,barrier.columnUpper(),numberColumns*sizeof(double));
    5678     memcpy(saveUpper+numberColumns,barrier.rowUpper(),numberRows*sizeof(double));
     5784    CoinMemcpyN(barrier.columnLower(),numberColumns,saveLower);
     5785    CoinMemcpyN(barrier.rowLower(),numberRows,saveLower+numberColumns);
     5786    CoinMemcpyN(barrier.columnUpper(),numberColumns,saveUpper);
     5787    CoinMemcpyN(barrier.rowUpper(),numberRows,saveUpper+numberColumns);
    56795788    barrier.fixFixed();
    56805789    saveModel2=model2;
     
    57655874        double * cost = model2->objective();
    57665875        double * saveCost = new double[numberColumns];
    5767         memcpy(saveCost,cost,numberColumns*sizeof(double));
     5876 CoinMemcpyN(cost,numberColumns,saveCost);
    57685877        double * saveLower = new double[numberColumns];
    57695878        double * lower = model2->columnLower();
    5770         memcpy(saveLower,lower,numberColumns*sizeof(double));
     5879 CoinMemcpyN(lower,numberColumns,saveLower);
    57715880        double * saveUpper = new double[numberColumns];
    57725881        double * upper = model2->columnUpper();
    5773         memcpy(saveUpper,upper,numberColumns*sizeof(double));
     5882 CoinMemcpyN(upper,numberColumns,saveUpper);
    57745883        int i;
    57755884        double tolerance = 10.0*dualTolerance_;
     
    58055914        //model2->setFactorizationFrequency(1);
    58065915        model2->dual(2);
    5807         memcpy(cost,saveCost,numberColumns*sizeof(double));
     5916 CoinMemcpyN(saveCost,numberColumns,cost);
    58085917        delete [] saveCost;
    5809         memcpy(lower,saveLower,numberColumns*sizeof(double));
     5918 CoinMemcpyN(saveLower,numberColumns,lower);
    58105919        delete [] saveLower;
    5811         memcpy(upper,saveUpper,numberColumns*sizeof(double));
     5920 CoinMemcpyN(saveUpper,numberColumns,upper);
    58125921        delete [] saveUpper;
    58135922      }
     
    58415950    int numberRows = model2->numberRows();
    58425951    int numberColumns = model2->numberColumns();
    5843     memcpy(model2->columnLower(),saveLower,numberColumns*sizeof(double));
    5844     memcpy(model2->rowLower(),saveLower+numberColumns,numberRows*sizeof(double));
     5952    CoinMemcpyN(saveLower,numberColumns,model2->columnLower());
     5953    CoinMemcpyN(saveLower+numberColumns,numberRows,model2->rowLower());
    58455954    delete [] saveLower;
    5846     memcpy(model2->columnUpper(),saveUpper,numberColumns*sizeof(double));
    5847     memcpy(model2->rowUpper(),saveUpper+numberColumns,numberRows*sizeof(double));
     5955    CoinMemcpyN(saveUpper,numberColumns,model2->columnUpper());
     5956    CoinMemcpyN(saveUpper+numberColumns,numberRows,model2->rowUpper());
    58485957    delete [] saveUpper;
    58495958    model2->primal(1);
     
    59606069    // Fill in scalars
    59616070    scalars.optimizationDirection = optimizationDirection_;
    5962     memcpy(scalars.dblParam, dblParam_,ClpLastDblParam * sizeof(double));
     6071    CoinMemcpyN( dblParam_,ClpLastDblParam,scalars.dblParam);
    59636072    scalars.objectiveValue = objectiveValue_;
    59646073    scalars.dualBound = dualBound_;
     
    59706079    scalars.numberRows = numberRows_;
    59716080    scalars.numberColumns = numberColumns_;
    5972     memcpy(scalars.intParam, intParam_,ClpLastIntParam * sizeof(double));
     6081    CoinMemcpyN( intParam_,ClpLastIntParam,scalars.intParam);
    59736082    scalars.numberIterations = numberIterations_;
    59746083    scalars.problemStatus = problemStatus_;