Ignore:
Timestamp:
Jan 6, 2019 2:43:06 PM (3 months ago)
Author:
unxusr
Message:

formatting

File:
1 edited

Legend:

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

    r1910 r2385  
    33// Corporation and others, Copyright (C) 2012, FasterCoin.  All Rights Reserved.
    44// This code is licensed under the terms of the Eclipse Public License (EPL).
    5 
    65
    76#include "CoinPragma.hpp"
     
    2221// Default Constructor
    2322//-------------------------------------------------------------------
    24 AbcDualRowDantzig::AbcDualRowDantzig ()
    25   : AbcDualRowPivot(),
    26     infeasible_(NULL)
     23AbcDualRowDantzig::AbcDualRowDantzig()
     24  : AbcDualRowPivot()
     25  , infeasible_(NULL)
    2726{
    2827  type_ = 1;
     
    3231// Copy constructor
    3332//-------------------------------------------------------------------
    34 AbcDualRowDantzig::AbcDualRowDantzig (const AbcDualRowDantzig & rhs)
    35   : AbcDualRowPivot(rhs),
    36     infeasible_(NULL)
     33AbcDualRowDantzig::AbcDualRowDantzig(const AbcDualRowDantzig &rhs)
     34  : AbcDualRowPivot(rhs)
     35  , infeasible_(NULL)
    3736{
    3837  model_ = rhs.model_;
     
    4342      infeasible_ = NULL;
    4443    }
    45   } 
     44  }
    4645}
    4746
     
    4948// Destructor
    5049//-------------------------------------------------------------------
    51 AbcDualRowDantzig::~AbcDualRowDantzig ()
     50AbcDualRowDantzig::~AbcDualRowDantzig()
    5251{
    5352  delete infeasible_;
     
    5857//-------------------------------------------------------------------
    5958AbcDualRowDantzig &
    60 AbcDualRowDantzig::operator=(const AbcDualRowDantzig& rhs)
     59AbcDualRowDantzig::operator=(const AbcDualRowDantzig &rhs)
    6160{
    6261  if (this != &rhs) {
     
    7877   4) restore weights
    7978*/
    80 void
    81 AbcDualRowDantzig::saveWeights(AbcSimplex * model, int mode)
     79void AbcDualRowDantzig::saveWeights(AbcSimplex *model, int mode)
    8280{
    8381  model_ = model;
     
    8583  if (mode == 1) {
    8684    // Check if size has changed
    87     if (infeasible_&&infeasible_->capacity() != numberRows) {
     85    if (infeasible_ && infeasible_->capacity() != numberRows) {
    8886      // size has changed - clear everything
    8987      delete infeasible_;
    9088      infeasible_ = NULL;
    9189    }
    92   } else if (mode !=3 && !infeasible_) {
    93       infeasible_ = new CoinIndexedVector();
    94       infeasible_->reserve(numberRows);
     90  } else if (mode != 3 && !infeasible_) {
     91    infeasible_ = new CoinIndexedVector();
     92    infeasible_->reserve(numberRows);
    9593  }
    9694  if (mode >= 2) {
     
    9997}
    10098// Recompute infeasibilities
    101 void
    102 AbcDualRowDantzig::recomputeInfeasibilities()
     99void AbcDualRowDantzig::recomputeInfeasibilities()
    103100{
    104101  int numberRows = model_->numberRows();
    105102  infeasible_->clear();
    106103  double tolerance = model_->currentPrimalTolerance();
    107   const double *  COIN_RESTRICT solutionBasic = model_->solutionBasic();
    108   const double *  COIN_RESTRICT lowerBasic = model_->lowerBasic();
    109   const double *  COIN_RESTRICT upperBasic = model_->upperBasic();
     104  const double *COIN_RESTRICT solutionBasic = model_->solutionBasic();
     105  const double *COIN_RESTRICT lowerBasic = model_->lowerBasic();
     106  const double *COIN_RESTRICT upperBasic = model_->upperBasic();
    110107  for (int iRow = 0; iRow < numberRows; iRow++) {
    111108    double value = solutionBasic[iRow];
     
    116113#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    117114      if (lower == upper)
    118         value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     115        value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    119116#endif
    120117      // store in list
     
    124121#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    125122      if (lower == upper)
    126         value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     123        value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    127124#endif
    128125      // store in list
     
    131128  }
    132129}
    133 #if ABC_PARALLEL==2
    134 static void choose(CoinIndexedVector * infeasible,
    135                    int & chosenRowSave,double & largestSave, int first, int last,
    136                    double tolerance)
    137 {
    138   if (last-first>256) {
    139     int mid=(last+first)>>1;
    140     int chosenRow2=chosenRowSave;
    141     double largest2=largestSave;
    142     cilk_spawn choose(infeasible,chosenRow2,largest2, first, mid,
    143                       tolerance);
    144     choose(infeasible,chosenRowSave,largestSave, mid, last,
    145            tolerance);
     130#if ABC_PARALLEL == 2
     131static void choose(CoinIndexedVector *infeasible,
     132  int &chosenRowSave, double &largestSave, int first, int last,
     133  double tolerance)
     134{
     135  if (last - first > 256) {
     136    int mid = (last + first) >> 1;
     137    int chosenRow2 = chosenRowSave;
     138    double largest2 = largestSave;
     139    cilk_spawn choose(infeasible, chosenRow2, largest2, first, mid,
     140      tolerance);
     141    choose(infeasible, chosenRowSave, largestSave, mid, last,
     142      tolerance);
    146143    cilk_sync;
    147     if (largest2>largestSave) {
    148       largestSave=largest2;
    149       chosenRowSave=chosenRow2;
     144    if (largest2 > largestSave) {
     145      largestSave = largest2;
     146      chosenRowSave = chosenRow2;
    150147    }
    151148  } else {
    152     const int * index=infeasible->getIndices();
    153     const double * infeas=infeasible->denseVector();
    154     double largest=largestSave;
    155     int chosenRow=chosenRowSave;
     149    const int *index = infeasible->getIndices();
     150    const double *infeas = infeasible->denseVector();
     151    double largest = largestSave;
     152    int chosenRow = chosenRowSave;
    156153    for (int i = first; i < last; i++) {
    157154      int iRow = index[i];
    158155      double value = infeas[iRow];
    159156      if (value > largest) {
    160         largest=value;
    161         chosenRow=iRow;
     157        largest = value;
     158        chosenRow = iRow;
    162159      }
    163160    }
    164     chosenRowSave=chosenRow;
    165     largestSave=largest;
     161    chosenRowSave = chosenRow;
     162    largestSave = largest;
    166163  }
    167164}
    168165#endif
    169166// Returns pivot row, -1 if none
    170 int
    171 AbcDualRowDantzig::pivotRow()
     167int AbcDualRowDantzig::pivotRow()
    172168{
    173169  assert(model_);
    174   double *  COIN_RESTRICT infeas = infeasible_->denseVector();
    175   int *  COIN_RESTRICT index = infeasible_->getIndices();
     170  double *COIN_RESTRICT infeas = infeasible_->denseVector();
     171  int *COIN_RESTRICT index = infeasible_->getIndices();
    176172  int number = infeasible_->getNumElements();
    177173  double tolerance = model_->currentPrimalTolerance();
     
    180176    tolerance *= model_->largestPrimalError() / 1.0e-8;
    181177  int numberRows = model_->numberRows();
    182   const double *  COIN_RESTRICT solutionBasic=model_->solutionBasic();
    183   const double *  COIN_RESTRICT lowerBasic=model_->lowerBasic();
    184   const double *  COIN_RESTRICT upperBasic=model_->upperBasic();
    185   const int * pivotVariable = model_->pivotVariable();
     178  const double *COIN_RESTRICT solutionBasic = model_->solutionBasic();
     179  const double *COIN_RESTRICT lowerBasic = model_->lowerBasic();
     180  const double *COIN_RESTRICT upperBasic = model_->upperBasic();
     181  const int *pivotVariable = model_->pivotVariable();
    186182  // code so has list of infeasibilities (like steepest)
    187   int numberWanted=CoinMax(2000,numberRows>>4);
    188   numberWanted=CoinMax(numberWanted,number>>2);
     183  int numberWanted = CoinMax(2000, numberRows >> 4);
     184  numberWanted = CoinMax(numberWanted, number >> 2);
    189185  if (model_->largestPrimalError() > 1.0e-3)
    190186    numberWanted = number + 1; // be safe
     
    193189  start[1] = number;
    194190  start[2] = 0;
    195   double dstart = static_cast<double> (number) * model_->randomNumberGenerator()->randomDouble();
    196   start[0] = static_cast<int> (dstart);
     191  double dstart = static_cast< double >(number) * model_->randomNumberGenerator()->randomDouble();
     192  start[0] = static_cast< int >(dstart);
    197193  start[3] = start[0];
    198194  double largest = tolerance;
    199195  int chosenRow = -1;
    200   int saveNumberWanted=numberWanted;
     196  int saveNumberWanted = numberWanted;
    201197#ifdef DO_REDUCE
    202   bool doReduce=true;
    203   int lastChosen=-1;
    204   double lastLargest=0.0;
     198  bool doReduce = true;
     199  int lastChosen = -1;
     200  double lastLargest = 0.0;
    205201#endif
    206202  for (int iPass = 0; iPass < 2; iPass++) {
    207     int endThis = start[2*iPass+1];
    208     int startThis=start[2*iPass];
    209     while (startThis<endThis) {
    210       int end = CoinMin(endThis,startThis+numberWanted);
    211 #ifdef DO_REDUCE 
     203    int endThis = start[2 * iPass + 1];
     204    int startThis = start[2 * iPass];
     205    while (startThis < endThis) {
     206      int end = CoinMin(endThis, startThis + numberWanted);
     207#ifdef DO_REDUCE
    212208      if (doReduce) {
    213         choose(infeasible,chosenRow,largest,startThis,end,tolerance);
    214         if (chosenRow!=lastChosen) {
    215           assert (chosenRow>=0);
    216           if (model_->flagged(pivotVariable[chosenRow])||
    217               (solutionBasic[chosenRow] <= upperBasic[chosenRow] + tolerance &&
    218                solutionBasic[chosenRow] >= lowerBasic[chosenRow] - tolerance)) {
    219             doReduce=false;
    220             chosenRow=lastChosen;
    221             largest=lastLargest;
    222           } else {
    223             lastChosen=chosenRow;
    224             lastLargest=largest;
    225           }
    226         }
     209        choose(infeasible, chosenRow, largest, startThis, end, tolerance);
     210        if (chosenRow != lastChosen) {
     211          assert(chosenRow >= 0);
     212          if (model_->flagged(pivotVariable[chosenRow]) || (solutionBasic[chosenRow] <= upperBasic[chosenRow] + tolerance && solutionBasic[chosenRow] >= lowerBasic[chosenRow] - tolerance)) {
     213            doReduce = false;
     214            chosenRow = lastChosen;
     215            largest = lastLargest;
     216          } else {
     217            lastChosen = chosenRow;
     218            lastLargest = largest;
     219          }
     220        }
    227221      }
    228222      if (!doReduce) {
    229223#endif
    230       for (int i = startThis; i < end; i++) {
    231         int iRow = index[i];
    232         double value = infeas[iRow];
    233         if (value > largest) {
    234           if (!model_->flagged(pivotVariable[iRow])) {
    235             if (solutionBasic[iRow] > upperBasic[iRow] + tolerance ||
    236                 solutionBasic[iRow] < lowerBasic[iRow] - tolerance) {
    237               chosenRow = iRow;
    238               largest = value;
    239             }
    240           }
    241         }
    242       }
     224        for (int i = startThis; i < end; i++) {
     225          int iRow = index[i];
     226          double value = infeas[iRow];
     227          if (value > largest) {
     228            if (!model_->flagged(pivotVariable[iRow])) {
     229              if (solutionBasic[iRow] > upperBasic[iRow] + tolerance || solutionBasic[iRow] < lowerBasic[iRow] - tolerance) {
     230                chosenRow = iRow;
     231                largest = value;
     232              }
     233            }
     234          }
     235        }
    243236#ifdef DO_REDUCE
    244237      }
    245238#endif
    246       numberWanted-=(end-startThis);
     239      numberWanted -= (end - startThis);
    247240      if (!numberWanted) {
    248         if(chosenRow>=0)
    249           break;
    250         else
    251           numberWanted=(saveNumberWanted+1)>>1;
     241        if (chosenRow >= 0)
     242          break;
     243        else
     244          numberWanted = (saveNumberWanted + 1) >> 1;
    252245      }
    253       startThis=end;
     246      startThis = end;
    254247    }
    255248    if (!numberWanted) {
    256       if(chosenRow>=0)
    257         break;
     249      if (chosenRow >= 0)
     250        break;
    258251      else
    259         numberWanted=(saveNumberWanted+1)>>1;
     252        numberWanted = (saveNumberWanted + 1) >> 1;
    260253    }
    261254  }
     
    264257// FT update and returns pivot alpha
    265258double
    266 AbcDualRowDantzig::updateWeights(CoinIndexedVector & input,CoinIndexedVector & updatedColumn)
     259AbcDualRowDantzig::updateWeights(CoinIndexedVector &input, CoinIndexedVector &updatedColumn)
    267260{
    268261  // Do FT update
     
    271264  double alpha = 0.0;
    272265  // look at updated column
    273   double * work = updatedColumn.denseVector();
     266  double *work = updatedColumn.denseVector();
    274267  int pivotRow = model_->lastPivotRow();
    275   assert (pivotRow == model_->pivotRow());
    276  
    277   assert (!updatedColumn.packedMode());
     268  assert(pivotRow == model_->pivotRow());
     269
     270  assert(!updatedColumn.packedMode());
    278271  alpha = work[pivotRow];
    279272  return alpha;
    280273}
    281 double 
    282 AbcDualRowDantzig::updateWeights1(CoinIndexedVector & input,CoinIndexedVector & updateColumn)
    283 {
    284   return updateWeights(input,updateColumn);
    285 }
    286 #if ABC_PARALLEL==2
     274double
     275AbcDualRowDantzig::updateWeights1(CoinIndexedVector &input, CoinIndexedVector &updateColumn)
     276{
     277  return updateWeights(input, updateColumn);
     278}
     279#if ABC_PARALLEL == 2
    287280static void update(int first, int last,
    288                    const int * COIN_RESTRICT which, double * COIN_RESTRICT work,
    289                    const double * COIN_RESTRICT lowerBasic,double * COIN_RESTRICT solutionBasic,
    290                    const double * COIN_RESTRICT upperBasic,double theta,double tolerance)
    291 {
    292   if (last-first>256) {
    293     int mid=(last+first)>>1;
    294     cilk_spawn update(first,mid,which,work,lowerBasic,solutionBasic,
    295                       upperBasic,theta,tolerance);
    296     update(mid,last,which,work,lowerBasic,solutionBasic,
    297            upperBasic,theta,tolerance);
     281  const int *COIN_RESTRICT which, double *COIN_RESTRICT work,
     282  const double *COIN_RESTRICT lowerBasic, double *COIN_RESTRICT solutionBasic,
     283  const double *COIN_RESTRICT upperBasic, double theta, double tolerance)
     284{
     285  if (last - first > 256) {
     286    int mid = (last + first) >> 1;
     287    cilk_spawn update(first, mid, which, work, lowerBasic, solutionBasic,
     288      upperBasic, theta, tolerance);
     289    update(mid, last, which, work, lowerBasic, solutionBasic,
     290      upperBasic, theta, tolerance);
    298291    cilk_sync;
    299292  } else {
     
    308301      solutionBasic[iRow] = value;
    309302      if (value < lower - tolerance) {
    310         value -= lower;
    311 #ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    312         if (lower == upper)
    313           value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     303        value -= lower;
     304#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
     305        if (lower == upper)
     306          value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    314307#endif
    315308      } else if (value > upper + tolerance) {
    316         value -= upper;
    317 #ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    318         if (lower == upper)
    319           value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     309        value -= upper;
     310#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
     311        if (lower == upper)
     312          value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    320313#endif
    321314      } else {
    322         // feasible
    323         value=0.0;
     315        // feasible
     316        value = 0.0;
    324317      }
    325318      // store
    326       work[iRow]=fabs(value);
     319      work[iRow] = fabs(value);
    327320    }
    328321  }
     
    333326   Computes change in objective function
    334327*/
    335 void
    336 AbcDualRowDantzig::updatePrimalSolution(CoinIndexedVector & primalUpdate,
    337                                         double theta)
    338 {
    339   double *  COIN_RESTRICT work = primalUpdate.denseVector();
     328void AbcDualRowDantzig::updatePrimalSolution(CoinIndexedVector &primalUpdate,
     329  double theta)
     330{
     331  double *COIN_RESTRICT work = primalUpdate.denseVector();
    340332  int numberNonZero = primalUpdate.getNumElements();
    341   int * which = primalUpdate.getIndices();
     333  int *which = primalUpdate.getIndices();
    342334  double tolerance = model_->currentPrimalTolerance();
    343   double * COIN_RESTRICT infeas = infeasible_->denseVector();
    344   double * COIN_RESTRICT solutionBasic = model_->solutionBasic();
    345   const double * COIN_RESTRICT lowerBasic = model_->lowerBasic();
    346   const double * COIN_RESTRICT upperBasic = model_->upperBasic();
    347   assert (!primalUpdate.packedMode());
     335  double *COIN_RESTRICT infeas = infeasible_->denseVector();
     336  double *COIN_RESTRICT solutionBasic = model_->solutionBasic();
     337  const double *COIN_RESTRICT lowerBasic = model_->lowerBasic();
     338  const double *COIN_RESTRICT upperBasic = model_->upperBasic();
     339  assert(!primalUpdate.packedMode());
    348340#if 0 //ABC_PARALLEL==2
    349341  update(0,numberNonZero,which,work,
     
    369361    int iRow = which[i];
    370362    double updateValue = work[iRow];
    371     work[iRow]=0.0;
     363    work[iRow] = 0.0;
    372364    double value = solutionBasic[iRow];
    373365    double change = theta * updateValue;
     
    380372#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    381373      if (lower == upper)
    382         value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     374        value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    383375#endif
    384376      // store in list
    385377      if (infeas[iRow])
    386         infeas[iRow] = fabs(value); // already there
     378        infeas[iRow] = fabs(value); // already there
    387379      else
    388         infeasible_->quickAdd(iRow, fabs(value));
     380        infeasible_->quickAdd(iRow, fabs(value));
    389381    } else if (value > upper + tolerance) {
    390382      value -= upper;
    391383#ifdef CLP_DUAL_FIXED_COLUMN_MULTIPLIER
    392384      if (lower == upper)
    393         value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
     385        value *= CLP_DUAL_FIXED_COLUMN_MULTIPLIER; // bias towards taking out fixed variables
    394386#endif
    395387      // store in list
    396388      if (infeas[iRow])
    397         infeas[iRow] = fabs(value); // already there
     389        infeas[iRow] = fabs(value); // already there
    398390      else
    399         infeasible_->quickAdd(iRow, fabs(value));
     391        infeasible_->quickAdd(iRow, fabs(value));
    400392    } else {
    401393      // feasible - was it infeasible - if so set tiny
    402394      if (infeas[iRow])
    403         infeas[iRow] = COIN_INDEXED_REALLY_TINY_ELEMENT;
     395        infeas[iRow] = COIN_INDEXED_REALLY_TINY_ELEMENT;
    404396    }
    405397  }
     
    410402// Clone
    411403//-------------------------------------------------------------------
    412 AbcDualRowPivot * AbcDualRowDantzig::clone(bool CopyData) const
     404AbcDualRowPivot *AbcDualRowDantzig::clone(bool CopyData) const
    413405{
    414406  if (CopyData) {
     
    418410  }
    419411}
     412
     413/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
     414*/
Note: See TracChangeset for help on using the changeset viewer.