Changeset 910 for branches


Ignore:
Timestamp:
Jan 16, 2007 3:51:55 PM (13 years ago)
Author:
forrest
Message:

extend ranging

Location:
branches/devel/Clp/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Clp/src/ClpSimplex.cpp

    r908 r910  
    45674567int ClpSimplex::dualRanging(int numberCheck,const int * which,
    45684568                            double * costIncrease, int * sequenceIncrease,
    4569                             double * costDecrease, int * sequenceDecrease)
     4569                            double * costDecrease, int * sequenceDecrease,
     4570                            double * valueIncrease, double * valueDecrease)
    45704571{
    45714572  int savePerturbation = perturbation_;
     
    46004601  ((ClpSimplexOther *) this)->dualRanging(numberCheck,which,
    46014602                                          costIncrease,sequenceIncrease,
    4602                                           costDecrease,sequenceDecrease);
     4603                                          costDecrease,sequenceDecrease,
     4604                                          valueIncrease, valueDecrease);
    46034605  finish(); // get rid of arrays
    46044606  return 0;
  • branches/devel/Clp/src/ClpSimplex.hpp

    r908 r910  
    274274      which contains list of variables for which information is desired.  All other
    275275      arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
    276       will information for variable 7.
     276      will be information for variable 7.
     277
     278      If valueIncrease/Decrease not NULL (both must be NULL or both non NULL) then these are filled with
     279      the value of variable if such a change in cost were made (the existing bounds are ignored)
    277280
    278281      Returns non-zero if infeasible unbounded etc
     
    280283  int dualRanging(int numberCheck,const int * which,
    281284                  double * costIncrease, int * sequenceIncrease,
    282                   double * costDecrease, int * sequenceDecrease);
     285                  double * costDecrease, int * sequenceDecrease,
     286                  double * valueIncrease=NULL, double * valueDecrease=NULL);
    283287  /** Primal ranging.
    284288      This computes increase/decrease in value for each given variable and corresponding
     
    290294      which contains list of variables for which information is desired.  All other
    291295      arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
    292       will information for variable 7.
     296      will be information for variable 7.
    293297
    294298      Returns non-zero if infeasible unbounded etc
  • branches/devel/Clp/src/ClpSimplexOther.cpp

    r888 r910  
    3535void ClpSimplexOther::dualRanging(int numberCheck,const int * which,
    3636                            double * costIncreased, int * sequenceIncreased,
    37                             double * costDecreased, int * sequenceDecreased)
     37                                  double * costDecreased, int * sequenceDecreased,
     38                                  double * valueIncrease, double * valueDecrease)
    3839{
    3940  rowArray_[1]->clear();
     
    6869    int sequenceIncrease=-1;
    6970    int sequenceDecrease=-1;
     71    if (valueIncrease) {
     72      assert (valueDecrease);
     73      valueIncrease[i]=iSequence<numberColumns_ ? columnActivity_[iSequence] : rowActivity_[iSequence-numberColumns_];
     74      valueDecrease[i]=valueIncrease[i];
     75    }
    7076   
    7177    switch(getStatus(iSequence)) {
     
    8894        checkDualRatios(rowArray_[0],columnArray_[0],costIncrease,sequenceIncrease,alphaIncrease,
    8995                    costDecrease,sequenceDecrease,alphaDecrease);
     96        if (valueIncrease) {
     97          if (sequenceIncrease>=0)
     98            valueIncrease[i] = primalRanging1(sequenceIncrease,iSequence);
     99            valueDecrease[i] = primalRanging1(sequenceDecrease,iSequence);
     100        }
    90101        if (inCBC) {
    91102          if (sequenceIncrease>=0) {
     
    136147      costIncrease = CoinMax(0.0,-dj_[iSequence]);
    137148      sequenceIncrease = iSequence;
     149      if (valueIncrease)
     150        valueIncrease[i] = primalRanging1(iSequence,iSequence);
    138151      break;
    139152    case atLowerBound:
    140153      costDecrease = CoinMax(0.0,dj_[iSequence]);
    141154      sequenceDecrease = iSequence;
     155      if (valueIncrease)
     156        valueDecrease[i] = primalRanging1(iSequence,iSequence);
    142157      break;
    143158    }
     
    176191      costDecreased[i] = costIncrease;
    177192      sequenceDecreased[i] = sequenceIncrease;
     193      if (valueIncrease) {
     194        double temp = valueIncrease[i];
     195        valueIncrease[i]=valueDecrease[i];
     196        valueDecrease[i]=temp;
     197      }
    178198    } else if (optimizationDirection_==0.0) {
    179199      // !!!!!! ???
     
    391411    sequenceDecreased[i] = sequenceDecrease;
    392412  }
     413}
     414// Returns new value of whichOther when whichIn enters basis
     415double
     416ClpSimplexOther::primalRanging1(int whichIn, int whichOther)
     417{
     418  rowArray_[0]->clear();
     419  rowArray_[1]->clear();
     420  int iSequence = whichIn;
     421  double newValue=solution_[whichOther];
     422  double alphaOther=0.0;
     423  Status status = getStatus(iSequence);
     424  assert (status==atLowerBound||status==atUpperBound);
     425  int wayIn = (status==atLowerBound) ? 1 : -1;
     426 
     427  switch(getStatus(iSequence)) {
     428   
     429  case basic:
     430  case isFree:
     431  case superBasic:
     432    assert (whichIn==whichOther);
     433    // Easy
     434    newValue = wayIn>0 ? upper_[iSequence] : lower_[iSequence];
     435    break;
     436  case isFixed:
     437  case atUpperBound:
     438  case atLowerBound:
     439    // Non trivial
     440    {
     441      // Other bound is ignored
     442      unpackPacked(rowArray_[1],iSequence);
     443      factorization_->updateColumn(rowArray_[2],rowArray_[1]);
     444      // Get extra rows
     445      matrix_->extendUpdated(this,rowArray_[1],0);
     446      // do ratio test
     447      double acceptablePivot=1.0e-7;
     448      double * work=rowArray_[1]->denseVector();
     449      int number=rowArray_[1]->getNumElements();
     450      int * which=rowArray_[1]->getIndices();
     451     
     452      // we may need to swap sign
     453      double way = wayIn;
     454      double theta = 1.0e30;
     455      for (int iIndex=0;iIndex<number;iIndex++) {
     456       
     457        int iRow = which[iIndex];
     458        double alpha = work[iIndex]*way;
     459        int iPivot=pivotVariable_[iRow];
     460        if (iPivot==whichOther) {
     461          alphaOther=alpha;
     462          continue;
     463        }
     464        double oldValue = solution_[iPivot];
     465        if (fabs(alpha)>acceptablePivot) {
     466          if (alpha>0.0) {
     467            // basic variable going towards lower bound
     468            double bound = lower_[iPivot];
     469            oldValue -= bound;
     470            if (oldValue-theta*alpha<0.0) {
     471              theta = CoinMax(0.0,oldValue/alpha);
     472            }
     473          } else {
     474            // basic variable going towards upper bound
     475            double bound = upper_[iPivot];
     476            oldValue = oldValue-bound;
     477            if (oldValue-theta*alpha>0.0) {
     478              theta = CoinMax(0.0,oldValue/alpha);
     479            }
     480          }
     481        }
     482      }
     483      if (theta<1.0e30)
     484        newValue -= theta*alphaOther;
     485      else
     486        newValue = alphaOther>0.0 ? -1.0e30 : 1.0e30;
     487    }
     488    rowArray_[1]->clear();
     489    break;
     490  }
     491  double scaleFactor;
     492  if (rowScale_) {
     493    if (whichOther<numberColumns_)
     494      scaleFactor = columnScale_[whichOther]/rhsScale_;
     495    else
     496      scaleFactor = 1.0/(rowScale_[whichOther-numberColumns_]*rhsScale_);
     497  } else {
     498    scaleFactor = 1.0/rhsScale_;
     499  }
     500  if (newValue<1.0e30)
     501    if (newValue>-1.0e30)
     502      newValue *= scaleFactor;
     503    else
     504      newValue = -COIN_DBL_MAX;
     505  else
     506    newValue = COIN_DBL_MAX;
     507  return newValue;
    393508}
    394509/*
  • branches/devel/Clp/src/ClpSimplexOther.hpp

    r861 r910  
    3939      which contains list of variables for which information is desired.  All other
    4040      arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
    41       will information for variable 7.
     41      will be information for variable 7.
     42
     43      If valueIncrease/Decrease not NULL (both must be NULL or both non NULL) then these are filled with
     44      the value of variable if such a change in cost were made (the existing bounds are ignored)
    4245
    4346      When here - guaranteed optimal
    4447  */
    4548  void dualRanging(int numberCheck,const int * which,
    46                   double * costIncrease, int * sequenceIncrease,
    47                   double * costDecrease, int * sequenceDecrease);
     49                   double * costIncrease, int * sequenceIncrease,
     50                   double * costDecrease, int * sequenceDecrease,
     51                   double * valueIncrease=NULL, double * valueDecrease=NULL);
    4852  /** Primal ranging.
    4953      This computes increase/decrease in value for each given variable and corresponding
     
    5559      which contains list of variables for which information is desired.  All other
    5660      arrays will be filled in by function.  If fifth entry in which is variable 7 then fifth entry in output arrays
    57       will information for variable 7.
     61      will be information for variable 7.
    5862
    5963      When here - guaranteed optimal
     
    7983                  const double * changeLowerRhs, const double * changeUpperRhs,
    8084                  const double * changeObjective);
     85private:
    8186  /** Parametrics - inner loop
    8287      This first attempt is when reportIncrement non zero and may
     
    134139  void checkPrimalRatios(CoinIndexedVector * rowArray,
    135140                         int direction);
     141  /// Returns new value of whichOther when whichIn enters basis
     142  double primalRanging1(int whichIn, int whichOther);
     143
     144public:
    136145    /** Write the basis in MPS format to the specified file.
    137146        If writeValues true writes values of structurals
Note: See TracChangeset for help on using the changeset viewer.