Changeset 1141


Ignore:
Timestamp:
Dec 13, 2007 9:55:08 AM (12 years ago)
Author:
forrest
Message:

for threaded random numbers

Location:
trunk/Clp/src
Files:
13 edited

Legend:

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

    r1034 r1141  
    247247  start[1]=number;
    248248  start[2]=0;
    249   double dstart = ((double) number) * CoinDrand48();
     249  double dstart = ((double) number) * model_->randomNumberGenerator()->randomDouble();
    250250  start[0]=(int) dstart;
    251251  start[3]=start[0];
  • trunk/Clp/src/ClpModel.cpp

    r1128 r1141  
    107107    coinMessages_ = CoinMessage();
    108108  }
    109   CoinSeedRandom(1234567);
     109  randomNumberGenerator_.setSeed(1234567);
    110110}
    111111
     
    620620    }
    621621  }
    622   CoinSeedRandom(1234567);
     622  randomNumberGenerator_.setSeed(1234567);
    623623}
    624624// Assignment operator. This copies the data
     
    649649    handler_ = rhs.handler_;
    650650  eventHandler_ = rhs.eventHandler_->clone();
     651  randomNumberGenerator_ = rhs.randomNumberGenerator_;
    651652  messages_ = rhs.messages_;
    652653  coinMessages_ = rhs.coinMessages_;
     
    27972798    handler_ = rhs->handler_;
    27982799  eventHandler_ = rhs->eventHandler_->clone();
     2800  randomNumberGenerator_ = rhs->randomNumberGenerator_;
    27992801  messages_ = rhs->messages_;
    28002802  coinMessages_ = rhs->coinMessages_;
     
    29162918                                        numberColumns,whichColumn);
    29172919  }
    2918   CoinSeedRandom(1234567);
     2920  randomNumberGenerator_.setSeed(1234567);
    29192921}
    29202922#ifndef CLP_NO_STD
  • trunk/Clp/src/ClpModel.hpp

    r1137 r1141  
    1616#include "ClpPackedMatrix.hpp"
    1717#include "CoinMessageHandler.hpp"
     18#include "CoinHelperFunctions.hpp"
    1819#include "ClpParameters.hpp"
    1920#include "ClpObjective.hpp"
     
    690691   inline ClpEventHandler * eventHandler() const
    691692  { return eventHandler_;}
     693  /// Thread specific random number generator
     694  inline CoinThreadRandom * randomNumberGenerator()
     695  { return &randomNumberGenerator_;}
     696  /// Thread specific random number generator
     697  inline CoinThreadRandom & mutableRandomNumberGenerator()
     698  { return randomNumberGenerator_;}
     699  /// Set seed for thread specific random number generator
     700  inline void setRandomSeed(int value)
     701  { randomNumberGenerator_.setSeed(value);}
    692702   /// length of names (0 means no names0
    693703   inline int lengthNames() const { return lengthNames_; }
     
    972982  /// Flag to say if default handler (so delete)
    973983  bool defaultHandler_;
     984  /// Thread specific random number generator
     985  CoinThreadRandom randomNumberGenerator_;
    974986  /// Event handler
    975987  ClpEventHandler * eventHandler_;
  • trunk/Clp/src/ClpPackedMatrix.cpp

    r1128 r1141  
    23912391    // randomize by up to 10%
    23922392    for (iRow=0;iRow<numberRows;iRow++) {
    2393       double value = 0.5-CoinDrand48();//between -0.5 to + 0.5
     2393      double value = 0.5-randomNumberGenerator_.randomDouble();//between -0.5 to + 0.5
    23942394      rowScale[iRow] *= (1.0+0.1*value);
    23952395    }
     
    24202420        columnScale[iColumn]=CoinMax(1.0e-10,CoinMin(1.0e10,columnScale[iColumn]));
    24212421#ifdef RANDOMIZE
    2422         double value = 0.5-CoinDrand48();//between -0.5 to + 0.5
     2422        double value = 0.5-randomNumberGenerator_.randomDouble();//between -0.5 to + 0.5
    24232423        columnScale[iColumn] *= (1.0+0.1*value);
    24242424#endif
  • trunk/Clp/src/ClpPrimalColumnSteepest.cpp

    r1034 r1141  
    517517  start[1]=number;
    518518  start[2]=0;
    519   double dstart = ((double) number) * CoinDrand48();
     519  double dstart = ((double) number) * model_->randomNumberGenerator()->randomDouble();
    520520  start[0]=(int) dstart;
    521521  start[3]=start[0];
     
    26822682  start[1]=number;
    26832683  start[2]=0;
    2684   double dstart = ((double) number) * CoinDrand48();
     2684  double dstart = ((double) number) * model_->randomNumberGenerator()->randomDouble();
    26852685  start[0]=(int) dstart;
    26862686  start[3]=start[0];
     
    36013601  startR[1]=nSlacks;
    36023602  startR[2]=0;
    3603   double randomR = CoinDrand48();
     3603  double randomR = model_->randomNumberGenerator()->randomDouble();
    36043604  double dstart = ((double) nSlacks) * randomR;
    36053605  startR[0]=(int) dstart;
     
    36083608  startC[1]=1.0;
    36093609  startC[2]=0;
    3610   double randomC = CoinDrand48();
     3610  double randomC = model_->randomNumberGenerator()->randomDouble();
    36113611  startC[0]=randomC;
    36123612  startC[3]=randomC;
  • trunk/Clp/src/ClpSimplex.cpp

    r1137 r1141  
    15331533    // reset
    15341534    progress_->startCheck();
    1535     double random = CoinDrand48();
     1535    double random = randomNumberGenerator_.randomDouble();
    15361536    int extra = (int) (9.999*random);
    15371537    int off[]={1,1,1,1,2,2,2,3,3,4};
     
    15901590    return 1;
    15911591  } else if (numberIterations_>1000+10*(numberRows_+(numberColumns_>>2))) {
    1592     double random = CoinDrand48();
     1592    double random = randomNumberGenerator_.randomDouble();
    15931593    int maxNumber = (forceFactorization_<0) ? maximumPivots : CoinMin(forceFactorization_,maximumPivots);
    15941594    if (factorization_->pivots()>=random*maxNumber) {
  • trunk/Clp/src/ClpSimplexDual.cpp

    r1124 r1141  
    29162916              else
    29172917                weight=1.0;
    2918               weight += CoinDrand48()*1.0e-2;
     2918              weight += randomNumberGenerator_.randomDouble()*1.0e-2;
    29192919              if (absAlpha>2.0*bestPivot) {
    29202920                take=true;
     
    45594559        if (rowLowerWork_[iRow]>-largeValue_) {
    45604560          if (fabs(rowLowerWork_[iRow])<fabs(rowUpperWork_[iRow]))
    4561             value *= CoinDrand48();
     4561            value *= randomNumberGenerator_.randomDouble();
    45624562          else
    4563             value *= -CoinDrand48();
     4563            value *= -randomNumberGenerator_.randomDouble();
    45644564        } else if (rowUpperWork_[iRow]<largeValue_) {
    4565           value *= -CoinDrand48();
     4565          value *= -randomNumberGenerator_.randomDouble();
    45664566        } else {
    45674567          value=0.0;
     
    46164616        if (fabs(columnLowerWork_[iColumn])<
    46174617            fabs(columnUpperWork_[iColumn])) {
    4618           value *= (1.0-m1 +m1*CoinDrand48());
    4619           value2 *= (1.0-m1 +m1*CoinDrand48());
     4618          value *= (1.0-m1 +m1*randomNumberGenerator_.randomDouble());
     4619          value2 *= (1.0-m1 +m1*randomNumberGenerator_.randomDouble());
    46204620        } else {
    4621           value *= -(1.0-m1+m1*CoinDrand48());
    4622           value2 *= -(1.0-m1+m1*CoinDrand48());
     4621          value *= -(1.0-m1+m1*randomNumberGenerator_.randomDouble());
     4622          value2 *= -(1.0-m1+m1*randomNumberGenerator_.randomDouble());
    46234623        }
    46244624      } else if (columnUpperWork_[iColumn]<largeValue_) {
    4625         value *= -(1.0-m1+m1*CoinDrand48());
    4626         value2 *= -(1.0-m1+m1*CoinDrand48());
     4625        value *= -(1.0-m1+m1*randomNumberGenerator_.randomDouble());
     4626        value2 *= -(1.0-m1+m1*randomNumberGenerator_.randomDouble());
    46274627      } else {
    46284628        value=0.0;
  • trunk/Clp/src/ClpSimplexNonlinear.cpp

    r1124 r1141  
    24422442        double alpha = work[iIndex];
    24432443        if (fabs(alpha)>1.0e-6) {
    2444           double distance = CoinDrand48();
     2444          double distance = randomNumberGenerator_.randomDouble();
    24452445          if (distance<smallest) {
    24462446            pivotRow_=iRow;
  • trunk/Clp/src/ClpSimplexPrimal.cpp

    r1137 r1141  
    774774                setFlagged(sequenceOut_);
    775775              }
    776               double newTolerance = CoinMax(0.5 + 0.499*CoinDrand48(),factorization_->pivotTolerance());
     776              double newTolerance = CoinMax(0.5 + 0.499*randomNumberGenerator_.randomDouble(),factorization_->pivotTolerance());
    777777              factorization_->pivotTolerance(newTolerance);
    778778            } else {
     
    22462246          double value = maximumFraction*(difference+1.0);
    22472247          value = CoinMin(value,0.1);
    2248           value *= CoinDrand48();
     2248          value *= randomNumberGenerator_.randomDouble();
    22492249          if (solutionValue-lowerValue<=primalTolerance_) {
    22502250            lower_[iSequence] -= value;
     
    22882288        double value = perturbation*maximumFraction;
    22892289        value = CoinMin(value,0.1);
    2290         value *= CoinDrand48();
     2290        value *= randomNumberGenerator_.randomDouble();
    22912291        if (savePerturbation!=50) {
    22922292          if (fabs(value)<=primalTolerance_)
     
    23472347      double value = perturbation*maximumFraction;
    23482348      value = CoinMin(value,0.1);
    2349       value *= CoinDrand48();
     2349      value *= randomNumberGenerator_.randomDouble();
    23502350      if (upperValue>lowerValue+tolerance) {
    23512351        if (savePerturbation!=50) {
  • trunk/Clp/src/ClpSolve.cpp

    r1111 r1141  
    400400      if (CoinMin(l,u)<1.0e20) {
    401401        if (l<u)
    402           obj[i]=1.0+CoinDrand48()*1.0e-2;
     402          obj[i]=1.0+randomNumberGenerator_.randomDouble()*1.0e-2;
    403403        else
    404           obj[i]=-1.0-CoinDrand48()*1.0e-2;
     404          obj[i]=-1.0-randomNumberGenerator_.randomDouble()*1.0e-2;
    405405      }
    406406    }
     
    15081508      for (iRow=0;iRow<numberRows;iRow++) {
    15091509        double lowerValue=lower[iRow], upperValue=upper[iRow];
    1510         double value = CoinDrand48();
     1510        double value = randomNumberGenerator_.randomDouble();
    15111511        if (upperValue>lowerValue+primalTolerance_) {
    15121512          if (lowerValue>-1.0e20&&lowerValue)
  • trunk/Clp/src/IdiSolve.cpp

    r754 r1141  
    127127IdiotResult
    128128Idiot::IdiSolve(
    129                     int nrows, int ncols, double * rowsol , double * colsol,
    130               double * pi, double * djs, const double * origcost , double * rowlower,
    131               double * rowupper, const double * lower,
    132               const double * upper, const double * elemnt,
    133                     const int * row, const CoinBigIndex * columnStart,
    134                     const int * length, double * lambda,
    135                     int maxIts,double mu,double drop,
    136                     double maxmin, double offset,
    137                     int strategy,double djTol,double djExit,double djFlag)
     129                int nrows, int ncols, double * rowsol , double * colsol,
     130                double * pi, double * djs, const double * origcost , double * rowlower,
     131                double * rowupper, const double * lower,
     132                const double * upper, const double * elemnt,
     133                const int * row, const CoinBigIndex * columnStart,
     134                const int * length, double * lambda,
     135                int maxIts,double mu,double drop,
     136                double maxmin, double offset,
     137                int strategy,double djTol,double djExit,double djFlag,
     138                CoinThreadRandom * randomNumberGenerator)
    138139{
    139140  IdiotResult result;
     
    361362      // randomize.
    362363      // The cast is to avoid gcc compiler warning
    363       int kcol = (int)(ncols*CoinDrand48());
     364      int kcol = (int)(ncols*randomNumberGenerator->randomDouble());
    364365      if (kcol==ncols)
    365366        kcol=ncols-1;
  • trunk/Clp/src/Idiot.cpp

    r1115 r1141  
    455455  double * rowlower= new double[nrows]; // not const as modified
    456456  memcpy(rowlower,model_->getRowLower(),nrows*sizeof(double));
     457  CoinThreadRandom * randomNumberGenerator=model_->randomNumberGenerator();
    457458  int * whenUsed;
    458459  double * lambda;
     
    729730                       lower,upper,elemXX,row,columnStart,columnLength,lambda,
    730731                       0,mu,drop,
    731                        maxmin,offset,strategy,djTol,djExit,djFlag);
     732                      maxmin,offset,strategy,djTol,djExit,djFlag,randomNumberGenerator);
    732733  // update whenUsed_
    733734  n = cleanIteration(iteration, ordStart,ordEnd,
     
    794795                     lower,upper,elemXX,row,columnStart,columnLength,lambda,
    795796                     maxIts,mu,drop,
    796                      maxmin,offset,strategy,djTol,djExit,djFlag);
     797                     maxmin,offset,strategy,djTol,djExit,djFlag,randomNumberGenerator);
    797798    n = cleanIteration(iteration, ordStart,ordEnd,
    798799                       colsol,  lower,  upper,
  • trunk/Clp/src/Idiot.hpp

    r1055 r1141  
    194194                     int maxIts,double mu,double drop,
    195195                     double maxmin, double offset,
    196                      int strategy,double djTol,double djExit,double djFlag);
     196                     int strategy,double djTol,double djExit,double djFlag,
     197                     CoinThreadRandom * randomNumberGenerator);
    197198int dropping(IdiotResult result,
    198199             double tolerance,
Note: See TracChangeset for help on using the changeset viewer.