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

formatting

File:
1 edited

Legend:

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

    r1910 r2385  
    2020// Default Constructor
    2121//-------------------------------------------------------------------
    22 AbcNonLinearCost::AbcNonLinearCost () :
    23   changeCost_(0.0),
    24   feasibleCost_(0.0),
    25   infeasibilityWeight_(-1.0),
    26   largestInfeasibility_(0.0),
    27   sumInfeasibilities_(0.0),
    28   averageTheta_(0.0),
    29   numberRows_(0),
    30   numberColumns_(0),
    31   model_(NULL),
    32   numberInfeasibilities_(-1),
    33   status_(NULL),
    34   bound_(NULL),
    35   cost_(NULL)
    36 {
    37  
     22AbcNonLinearCost::AbcNonLinearCost()
     23  : changeCost_(0.0)
     24  , feasibleCost_(0.0)
     25  , infeasibilityWeight_(-1.0)
     26  , largestInfeasibility_(0.0)
     27  , sumInfeasibilities_(0.0)
     28  , averageTheta_(0.0)
     29  , numberRows_(0)
     30  , numberColumns_(0)
     31  , model_(NULL)
     32  , numberInfeasibilities_(-1)
     33  , status_(NULL)
     34  , bound_(NULL)
     35  , cost_(NULL)
     36{
    3837}
    3938//#define VALIDATE
    4039#ifdef VALIDATE
    41 static double * saveLowerV = NULL;
    42 static double * saveUpperV = NULL;
     40static double *saveLowerV = NULL;
     41static double *saveUpperV = NULL;
    4342#ifdef NDEBUG
    4443Validate should not be set if no debug
    4544#endif
    4645#endif
    47                                 /* Constructor from simplex.
     46  /* Constructor from simplex.
    4847                                    This will just set up wasteful arrays for linear, but
    4948                                    later may do dual analysis and even finding duplicate columns
    5049                                 */
    51 AbcNonLinearCost::AbcNonLinearCost ( AbcSimplex * model)
     50  AbcNonLinearCost::AbcNonLinearCost(AbcSimplex * model)
    5251{
    5352  model_ = model;
     
    6059  feasibleCost_ = 0.0;
    6160  infeasibilityWeight_ = -1.0;
    62   double * cost = model_->costRegion();
     61  double *cost = model_->costRegion();
    6362  // check if all 0
    6463  int iSequence;
     
    8584}
    8685// Refresh - assuming regions OK
    87 void
    88 AbcNonLinearCost::refresh()
     86void AbcNonLinearCost::refresh()
    8987{
    9088  int numberTotal = numberRows_ + numberColumns_;
     
    9492  double infeasibilityCost = model_->infeasibilityCost();
    9593  double primalTolerance = model_->currentPrimalTolerance();
    96   double * cost = model_->costRegion();
    97   double * upper = model_->upperRegion();
    98   double * lower = model_->lowerRegion();
    99   double * solution = model_->solutionRegion();
     94  double *cost = model_->costRegion();
     95  double *upper = model_->upperRegion();
     96  double *lower = model_->lowerRegion();
     97  double *solution = model_->solutionRegion();
    10098  for (int iSequence = 0; iSequence < numberTotal; iSequence++) {
    10199    cost_[iSequence] = cost[iSequence];
     
    105103    if (value - upperValue <= primalTolerance) {
    106104      if (value - lowerValue >= -primalTolerance) {
    107         // feasible
    108         status_[iSequence] = static_cast<unsigned char>(CLP_FEASIBLE | (CLP_SAME << 4));
    109         bound_[iSequence] = 0.0;
     105        // feasible
     106        status_[iSequence] = static_cast< unsigned char >(CLP_FEASIBLE | (CLP_SAME << 4));
     107        bound_[iSequence] = 0.0;
    110108      } else {
    111         // below
    112         double infeasibility = lowerValue - value - primalTolerance;
    113         sumInfeasibilities_ += infeasibility;
    114         largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
    115         cost[iSequence] -= infeasibilityCost;
    116         numberInfeasibilities_++;
    117         status_[iSequence] = static_cast<unsigned char>(CLP_BELOW_LOWER | (CLP_SAME << 4));
    118         bound_[iSequence] = upperValue;
    119         upper[iSequence] = lowerValue;
    120         lower[iSequence] = -COIN_DBL_MAX;
     109        // below
     110        double infeasibility = lowerValue - value - primalTolerance;
     111        sumInfeasibilities_ += infeasibility;
     112        largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
     113        cost[iSequence] -= infeasibilityCost;
     114        numberInfeasibilities_++;
     115        status_[iSequence] = static_cast< unsigned char >(CLP_BELOW_LOWER | (CLP_SAME << 4));
     116        bound_[iSequence] = upperValue;
     117        upper[iSequence] = lowerValue;
     118        lower[iSequence] = -COIN_DBL_MAX;
    121119      }
    122120    } else {
     
    127125      cost[iSequence] += infeasibilityCost;
    128126      numberInfeasibilities_++;
    129       status_[iSequence] = static_cast<unsigned char>(CLP_ABOVE_UPPER | (CLP_SAME << 4));
     127      status_[iSequence] = static_cast< unsigned char >(CLP_ABOVE_UPPER | (CLP_SAME << 4));
    130128      bound_[iSequence] = lowerValue;
    131129      lower[iSequence] = upperValue;
     
    134132  }
    135133  //     checkInfeasibilities(model_->primalTolerance());
    136  
    137134}
    138135// Refresh - from original
    139 void
    140 AbcNonLinearCost::refreshFromPerturbed(double tolerance)
     136void AbcNonLinearCost::refreshFromPerturbed(double tolerance)
    141137{
    142138  // original costs and perturbed bounds
    143   model_->copyFromSaved(32+2);
     139  model_->copyFromSaved(32 + 2);
    144140  refresh();
    145141  //checkInfeasibilities(tolerance);
    146142}
    147143// Refreshes costs always makes row costs zero
    148 void
    149 AbcNonLinearCost::refreshCosts(const double * columnCosts)
    150 {
    151   double * cost = model_->costRegion();
     144void AbcNonLinearCost::refreshCosts(const double *columnCosts)
     145{
     146  double *cost = model_->costRegion();
    152147  // zero row costs
    153148  memset(cost + numberColumns_, 0, numberRows_ * sizeof(double));
     
    161156// Copy constructor
    162157//-------------------------------------------------------------------
    163 AbcNonLinearCost::AbcNonLinearCost (const AbcNonLinearCost & rhs) :
    164   changeCost_(0.0),
    165   feasibleCost_(0.0),
    166   infeasibilityWeight_(-1.0),
    167   largestInfeasibility_(0.0),
    168   sumInfeasibilities_(0.0),
    169   averageTheta_(0.0),
    170   numberRows_(rhs.numberRows_),
    171   numberColumns_(rhs.numberColumns_),
    172   model_(NULL),
    173   numberInfeasibilities_(-1),
    174   status_(NULL),
    175   bound_(NULL),
    176   cost_(NULL)
     158AbcNonLinearCost::AbcNonLinearCost(const AbcNonLinearCost &rhs)
     159  : changeCost_(0.0)
     160  , feasibleCost_(0.0)
     161  , infeasibilityWeight_(-1.0)
     162  , largestInfeasibility_(0.0)
     163  , sumInfeasibilities_(0.0)
     164  , averageTheta_(0.0)
     165  , numberRows_(rhs.numberRows_)
     166  , numberColumns_(rhs.numberColumns_)
     167  , model_(NULL)
     168  , numberInfeasibilities_(-1)
     169  , status_(NULL)
     170  , bound_(NULL)
     171  , cost_(NULL)
    177172{
    178173  if (numberRows_) {
     
    195190// Destructor
    196191//-------------------------------------------------------------------
    197 AbcNonLinearCost::~AbcNonLinearCost ()
    198 {
    199   delete [] status_;
    200   delete [] bound_;
    201   delete [] cost_;
     192AbcNonLinearCost::~AbcNonLinearCost()
     193{
     194  delete[] status_;
     195  delete[] bound_;
     196  delete[] cost_;
    202197}
    203198
     
    206201//-------------------------------------------------------------------
    207202AbcNonLinearCost &
    208 AbcNonLinearCost::operator=(const AbcNonLinearCost& rhs)
     203AbcNonLinearCost::operator=(const AbcNonLinearCost &rhs)
    209204{
    210205  if (this != &rhs) {
    211206    numberRows_ = rhs.numberRows_;
    212207    numberColumns_ = rhs.numberColumns_;
    213     delete [] status_;
    214     delete [] bound_;
    215     delete [] cost_;
     208    delete[] status_;
     209    delete[] bound_;
     210    delete[] cost_;
    216211    status_ = NULL;
    217212    bound_ = NULL;
     
    238233// We will also need a 2 bit per variable array for some
    239234// purpose which will come to me later
    240 void
    241 AbcNonLinearCost::checkInfeasibilities(double oldTolerance)
     235void AbcNonLinearCost::checkInfeasibilities(double oldTolerance)
    242236{
    243237  numberInfeasibilities_ = 0;
     
    248242  double primalTolerance = model_->currentPrimalTolerance();
    249243  int iSequence;
    250   double * solution = model_->solutionRegion();
    251   double * upper = model_->upperRegion();
    252   double * lower = model_->lowerRegion();
    253   double * cost = model_->costRegion();
     244  double *solution = model_->solutionRegion();
     245  double *upper = model_->upperRegion();
     246  double *lower = model_->lowerRegion();
     247  double *cost = model_->costRegion();
    254248  bool toNearest = oldTolerance <= 0.0;
    255249  feasibleCost_ = 0.0;
     
    261255    double value = solution[iSequence];
    262256    unsigned char iStatus = status_[iSequence];
    263     assert (currentStatus(iStatus) == CLP_SAME);
     257    assert(currentStatus(iStatus) == CLP_SAME);
    264258    double lowerValue = lower[iSequence];
    265259    double upperValue = upper[iSequence];
     
    281275    if (upperValue == lowerValue && status != AbcSimplex::isFixed) {
    282276      if (status != AbcSimplex::basic) {
    283         model_->setInternalStatus(iSequence, AbcSimplex::isFixed);
    284         status = AbcSimplex::isFixed;
     277        model_->setInternalStatus(iSequence, AbcSimplex::isFixed);
     278        status = AbcSimplex::isFixed;
    285279      }
    286280    }
    287     switch(status) {
    288      
     281    switch (status) {
     282
    289283    case AbcSimplex::basic:
    290284    case AbcSimplex::superBasic:
    291285      if (value - upperValue <= primalTolerance) {
    292         if (value - lowerValue >= -primalTolerance) {
    293           // feasible
    294           //newWhere=CLP_FEASIBLE;
    295         } else {
    296           // below
    297           newWhere = CLP_BELOW_LOWER;
    298           assert (fabs(lowerValue) < 1.0e100);
    299           double infeasibility = lowerValue - value - primalTolerance;
    300           sumInfeasibilities_ += infeasibility;
    301           largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
    302           costValue = trueCost - infeasibilityCost;
    303           changeCost_ -= lowerValue * (costValue - cost[iSequence]);
    304           numberInfeasibilities_++;
    305         }
     286        if (value - lowerValue >= -primalTolerance) {
     287          // feasible
     288          //newWhere=CLP_FEASIBLE;
     289        } else {
     290          // below
     291          newWhere = CLP_BELOW_LOWER;
     292          assert(fabs(lowerValue) < 1.0e100);
     293          double infeasibility = lowerValue - value - primalTolerance;
     294          sumInfeasibilities_ += infeasibility;
     295          largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
     296          costValue = trueCost - infeasibilityCost;
     297          changeCost_ -= lowerValue * (costValue - cost[iSequence]);
     298          numberInfeasibilities_++;
     299        }
    306300      } else {
    307         // above
    308         newWhere = CLP_ABOVE_UPPER;
    309         double infeasibility = value - upperValue - primalTolerance;
    310         sumInfeasibilities_ += infeasibility;
    311         largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
    312         costValue = trueCost + infeasibilityCost;
    313         changeCost_ -= upperValue * (costValue - cost[iSequence]);
    314         numberInfeasibilities_++;
     301        // above
     302        newWhere = CLP_ABOVE_UPPER;
     303        double infeasibility = value - upperValue - primalTolerance;
     304        sumInfeasibilities_ += infeasibility;
     305        largestInfeasibility_ = CoinMax(largestInfeasibility_, infeasibility);
     306        costValue = trueCost + infeasibilityCost;
     307        changeCost_ -= upperValue * (costValue - cost[iSequence]);
     308        numberInfeasibilities_++;
    315309      }
    316310      break;
     
    319313    case AbcSimplex::atUpperBound:
    320314      if (!toNearest) {
    321         // With increasing tolerances - we may be at wrong place
    322         if (fabs(value - upperValue) > oldTolerance * 1.0001) {
    323           if (fabs(value - lowerValue) <= oldTolerance * 1.0001) {
    324             if (fabs(value - lowerValue) > primalTolerance) {
    325               solution[iSequence] = lowerValue;
    326               value = lowerValue;
    327             }
    328             model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
    329           } else {
    330             if (value < upperValue) {
    331               if (value > lowerValue) {
    332                 model_->setInternalStatus(iSequence, AbcSimplex::superBasic);
    333               } else {
    334                 // set to lower bound as infeasible
    335                 solution[iSequence] = lowerValue;
    336                 value = lowerValue;
    337                 model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
    338               }
    339             } else {
    340               // set to upper bound as infeasible
    341               solution[iSequence] = upperValue;
    342               value = upperValue;
    343             }
    344           }
    345         } else if (fabs(value - upperValue) > primalTolerance) {
    346           solution[iSequence] = upperValue;
    347           value = upperValue;
    348         }
     315        // With increasing tolerances - we may be at wrong place
     316        if (fabs(value - upperValue) > oldTolerance * 1.0001) {
     317          if (fabs(value - lowerValue) <= oldTolerance * 1.0001) {
     318            if (fabs(value - lowerValue) > primalTolerance) {
     319              solution[iSequence] = lowerValue;
     320              value = lowerValue;
     321            }
     322            model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
     323          } else {
     324            if (value < upperValue) {
     325              if (value > lowerValue) {
     326                model_->setInternalStatus(iSequence, AbcSimplex::superBasic);
     327              } else {
     328                // set to lower bound as infeasible
     329                solution[iSequence] = lowerValue;
     330                value = lowerValue;
     331                model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
     332              }
     333            } else {
     334              // set to upper bound as infeasible
     335              solution[iSequence] = upperValue;
     336              value = upperValue;
     337            }
     338          }
     339        } else if (fabs(value - upperValue) > primalTolerance) {
     340          solution[iSequence] = upperValue;
     341          value = upperValue;
     342        }
    349343      } else {
    350         // Set to nearest and make at bound
    351         if (fabs(value - lowerValue) < fabs(value - upperValue)) {
    352           solution[iSequence] = lowerValue;
    353           value = lowerValue;
    354           model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
    355         } else {
    356           solution[iSequence] = upperValue;
    357           value = upperValue;
    358         }
     344        // Set to nearest and make at bound
     345        if (fabs(value - lowerValue) < fabs(value - upperValue)) {
     346          solution[iSequence] = lowerValue;
     347          value = lowerValue;
     348          model_->setInternalStatus(iSequence, AbcSimplex::atLowerBound);
     349        } else {
     350          solution[iSequence] = upperValue;
     351          value = upperValue;
     352        }
    359353      }
    360354      break;
    361355    case AbcSimplex::atLowerBound:
    362356      if (!toNearest) {
    363         // With increasing tolerances - we may be at wrong place
    364         if (fabs(value - lowerValue) > oldTolerance * 1.0001) {
    365           if (fabs(value - upperValue) <= oldTolerance * 1.0001) {
    366             if (fabs(value - upperValue) > primalTolerance) {
    367               solution[iSequence] = upperValue;
    368               value = upperValue;
    369             }
    370             model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
    371           } else {
    372             if (value < upperValue) {
    373               if (value > lowerValue) {
    374                 model_->setInternalStatus(iSequence, AbcSimplex::superBasic);
    375               } else {
    376                 // set to lower bound as infeasible
    377                 solution[iSequence] = lowerValue;
    378                 value = lowerValue;
    379               }
    380             } else {
    381               // set to upper bound as infeasible
    382               solution[iSequence] = upperValue;
    383               value = upperValue;
    384               model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
    385             }
    386           }
    387         } else if (fabs(value - lowerValue) > primalTolerance) {
    388           solution[iSequence] = lowerValue;
    389           value = lowerValue;
    390         }
     357        // With increasing tolerances - we may be at wrong place
     358        if (fabs(value - lowerValue) > oldTolerance * 1.0001) {
     359          if (fabs(value - upperValue) <= oldTolerance * 1.0001) {
     360            if (fabs(value - upperValue) > primalTolerance) {
     361              solution[iSequence] = upperValue;
     362              value = upperValue;
     363            }
     364            model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
     365          } else {
     366            if (value < upperValue) {
     367              if (value > lowerValue) {
     368                model_->setInternalStatus(iSequence, AbcSimplex::superBasic);
     369              } else {
     370                // set to lower bound as infeasible
     371                solution[iSequence] = lowerValue;
     372                value = lowerValue;
     373              }
     374            } else {
     375              // set to upper bound as infeasible
     376              solution[iSequence] = upperValue;
     377              value = upperValue;
     378              model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
     379            }
     380          }
     381        } else if (fabs(value - lowerValue) > primalTolerance) {
     382          solution[iSequence] = lowerValue;
     383          value = lowerValue;
     384        }
    391385      } else {
    392         // Set to nearest and make at bound
    393         if (fabs(value - lowerValue) < fabs(value - upperValue)) {
    394           solution[iSequence] = lowerValue;
    395           value = lowerValue;
    396         } else {
    397           solution[iSequence] = upperValue;
    398           value = upperValue;
    399           model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
    400         }
     386        // Set to nearest and make at bound
     387        if (fabs(value - lowerValue) < fabs(value - upperValue)) {
     388          solution[iSequence] = lowerValue;
     389          value = lowerValue;
     390        } else {
     391          solution[iSequence] = upperValue;
     392          value = upperValue;
     393          model_->setInternalStatus(iSequence, AbcSimplex::atUpperBound);
     394        }
    401395      }
    402396      break;
     
    409403      setOriginalStatus(status_[iSequence], newWhere);
    410404      if (newWhere == CLP_BELOW_LOWER) {
    411         bound_[iSequence] = upperValue;
    412         upperValue = lowerValue;
    413         lowerValue = -COIN_DBL_MAX;
    414         costValue = trueCost - infeasibilityCost;
     405        bound_[iSequence] = upperValue;
     406        upperValue = lowerValue;
     407        lowerValue = -COIN_DBL_MAX;
     408        costValue = trueCost - infeasibilityCost;
    415409      } else if (newWhere == CLP_ABOVE_UPPER) {
    416         bound_[iSequence] = lowerValue;
    417         lowerValue = upperValue;
    418         upperValue = COIN_DBL_MAX;
    419         costValue = trueCost + infeasibilityCost;
     410        bound_[iSequence] = lowerValue;
     411        lowerValue = upperValue;
     412        upperValue = COIN_DBL_MAX;
     413        costValue = trueCost + infeasibilityCost;
    420414      } else {
    421         costValue = trueCost;
     415        costValue = trueCost;
    422416      }
    423417      lower[iSequence] = lowerValue;
     
    431425}
    432426// Puts feasible bounds into lower and upper
    433 void
    434 AbcNonLinearCost::feasibleBounds()
     427void AbcNonLinearCost::feasibleBounds()
    435428{
    436429  int iSequence;
    437   double * upper = model_->upperRegion();
    438   double * lower = model_->lowerRegion();
    439   double * cost = model_->costRegion();
     430  double *upper = model_->upperRegion();
     431  double *lower = model_->lowerRegion();
     432  double *cost = model_->costRegion();
    440433  int numberTotal = numberColumns_ + numberRows_;
    441434  for (iSequence = 0; iSequence < numberTotal; iSequence++) {
    442435    unsigned char iStatus = status_[iSequence];
    443     assert (currentStatus(iStatus) == CLP_SAME);
     436    assert(currentStatus(iStatus) == CLP_SAME);
    444437    double lowerValue = lower[iSequence];
    445438    double upperValue = upper[iSequence];
     
    449442      lowerValue = upperValue;
    450443      upperValue = bound_[iSequence];
    451       assert (fabs(lowerValue) < 1.0e100);
     444      assert(fabs(lowerValue) < 1.0e100);
    452445    } else if (iWhere == CLP_ABOVE_UPPER) {
    453446      upperValue = lowerValue;
     
    460453  }
    461454}
    462 void
    463 AbcNonLinearCost::goBackAll(const CoinIndexedVector * update)
    464 {
    465   assert (model_ != NULL);
    466   const int * pivotVariable = model_->pivotVariable();
     455void AbcNonLinearCost::goBackAll(const CoinIndexedVector *update)
     456{
     457  assert(model_ != NULL);
     458  const int *pivotVariable = model_->pivotVariable();
    467459  int number = update->getNumElements();
    468   const int * index = update->getIndices();
     460  const int *index = update->getIndices();
    469461  for (int i = 0; i < number; i++) {
    470462    int iRow = index[i];
     
    473465  }
    474466}
    475 void
    476 AbcNonLinearCost::checkInfeasibilities(int numberInArray, const int * index)
    477 {
    478   assert (model_ != NULL);
     467void AbcNonLinearCost::checkInfeasibilities(int numberInArray, const int *index)
     468{
     469  assert(model_ != NULL);
    479470  double primalTolerance = model_->currentPrimalTolerance();
    480   const int * pivotVariable = model_->pivotVariable();
    481   double * upper = model_->upperRegion();
    482   double * lower = model_->lowerRegion();
    483   double * cost = model_->costRegion();
    484   double * solutionBasic = model_->solutionBasic();
    485   double * upperBasic = model_->upperBasic();
    486   double * lowerBasic = model_->lowerBasic();
    487   double * costBasic = model_->costBasic();
     471  const int *pivotVariable = model_->pivotVariable();
     472  double *upper = model_->upperRegion();
     473  double *lower = model_->lowerRegion();
     474  double *cost = model_->costRegion();
     475  double *solutionBasic = model_->solutionBasic();
     476  double *upperBasic = model_->upperBasic();
     477  double *lowerBasic = model_->lowerBasic();
     478  double *costBasic = model_->costBasic();
    488479  for (int i = 0; i < numberInArray; i++) {
    489480    int iRow = index[i];
     
    491482    double value = solutionBasic[iRow];
    492483    unsigned char iStatus = status_[iSequence];
    493     assert (currentStatus(iStatus) == CLP_SAME);
     484    assert(currentStatus(iStatus) == CLP_SAME);
    494485    double lowerValue = lowerBasic[iRow];
    495486    double upperValue = upperBasic[iRow];
     
    500491      upperValue = bound_[iSequence];
    501492      numberInfeasibilities_--;
    502       assert (fabs(lowerValue) < 1.0e100);
     493      assert(fabs(lowerValue) < 1.0e100);
    503494    } else if (iWhere == CLP_ABOVE_UPPER) {
    504495      upperValue = lowerValue;
     
    510501    if (value - upperValue <= primalTolerance) {
    511502      if (value - lowerValue >= -primalTolerance) {
    512         // feasible
    513         //newWhere=CLP_FEASIBLE;
     503        // feasible
     504        //newWhere=CLP_FEASIBLE;
    514505      } else {
    515         // below
    516         newWhere = CLP_BELOW_LOWER;
    517         assert (fabs(lowerValue) < 1.0e100);
    518         costValue -= infeasibilityWeight_;
    519         numberInfeasibilities_++;
     506        // below
     507        newWhere = CLP_BELOW_LOWER;
     508        assert(fabs(lowerValue) < 1.0e100);
     509        costValue -= infeasibilityWeight_;
     510        numberInfeasibilities_++;
    520511      }
    521512    } else {
     
    528519      setOriginalStatus(status_[iSequence], newWhere);
    529520      if (newWhere == CLP_BELOW_LOWER) {
    530         bound_[iSequence] = upperValue;
    531         upperValue = lowerValue;
    532         lowerValue = -COIN_DBL_MAX;
     521        bound_[iSequence] = upperValue;
     522        upperValue = lowerValue;
     523        lowerValue = -COIN_DBL_MAX;
    533524      } else if (newWhere == CLP_ABOVE_UPPER) {
    534         bound_[iSequence] = lowerValue;
    535         lowerValue = upperValue;
    536         upperValue = COIN_DBL_MAX;
     525        bound_[iSequence] = lowerValue;
     526        lowerValue = upperValue;
     527        upperValue = COIN_DBL_MAX;
    537528      }
    538529      lower[iSequence] = lowerValue;
     
    551542   changed costs will be stored as normal CoinIndexedVector
    552543*/
    553 void
    554 AbcNonLinearCost::checkChanged(int numberInArray, CoinIndexedVector * update)
    555 {
    556   assert (model_ != NULL);
     544void AbcNonLinearCost::checkChanged(int numberInArray, CoinIndexedVector *update)
     545{
     546  assert(model_ != NULL);
    557547  double primalTolerance = model_->currentPrimalTolerance();
    558   const int * pivotVariable = model_->pivotVariable();
     548  const int *pivotVariable = model_->pivotVariable();
    559549  int number = 0;
    560   int * index = update->getIndices();
    561   double * work = update->denseVector();
    562   double * upper = model_->upperRegion();
    563   double * lower = model_->lowerRegion();
    564   double * cost = model_->costRegion();
    565   double * solutionBasic = model_->solutionBasic();
    566   double * upperBasic = model_->upperBasic();
    567   double * lowerBasic = model_->lowerBasic();
    568   double * costBasic = model_->costBasic();
     550  int *index = update->getIndices();
     551  double *work = update->denseVector();
     552  double *upper = model_->upperRegion();
     553  double *lower = model_->lowerRegion();
     554  double *cost = model_->costRegion();
     555  double *solutionBasic = model_->solutionBasic();
     556  double *upperBasic = model_->upperBasic();
     557  double *lowerBasic = model_->lowerBasic();
     558  double *costBasic = model_->costBasic();
    569559  for (int i = 0; i < numberInArray; i++) {
    570560    int iRow = index[i];
     
    572562    double value = solutionBasic[iRow];
    573563    unsigned char iStatus = status_[iSequence];
    574     assert (currentStatus(iStatus) == CLP_SAME);
     564    assert(currentStatus(iStatus) == CLP_SAME);
    575565    double lowerValue = lowerBasic[iRow];
    576566    double upperValue = upperBasic[iRow];
     
    581571      upperValue = bound_[iSequence];
    582572      numberInfeasibilities_--;
    583       assert (fabs(lowerValue) < 1.0e100);
     573      assert(fabs(lowerValue) < 1.0e100);
    584574    } else if (iWhere == CLP_ABOVE_UPPER) {
    585575      upperValue = lowerValue;
     
    591581    if (value - upperValue <= primalTolerance) {
    592582      if (value - lowerValue >= -primalTolerance) {
    593         // feasible
    594         //newWhere=CLP_FEASIBLE;
     583        // feasible
     584        //newWhere=CLP_FEASIBLE;
    595585      } else {
    596         // below
    597         newWhere = CLP_BELOW_LOWER;
    598         costValue -= infeasibilityWeight_;
    599         numberInfeasibilities_++;
    600         assert (fabs(lowerValue) < 1.0e100);
     586        // below
     587        newWhere = CLP_BELOW_LOWER;
     588        costValue -= infeasibilityWeight_;
     589        numberInfeasibilities_++;
     590        assert(fabs(lowerValue) < 1.0e100);
    601591      }
    602592    } else {
     
    611601      setOriginalStatus(status_[iSequence], newWhere);
    612602      if (newWhere == CLP_BELOW_LOWER) {
    613         bound_[iSequence] = upperValue;
    614         upperValue = lowerValue;
    615         lowerValue = -COIN_DBL_MAX;
     603        bound_[iSequence] = upperValue;
     604        upperValue = lowerValue;
     605        lowerValue = -COIN_DBL_MAX;
    616606      } else if (newWhere == CLP_ABOVE_UPPER) {
    617         bound_[iSequence] = lowerValue;
    618         lowerValue = upperValue;
    619         upperValue = COIN_DBL_MAX;
     607        bound_[iSequence] = lowerValue;
     608        lowerValue = upperValue;
     609        upperValue = COIN_DBL_MAX;
    620610      }
    621611      lower[iSequence] = lowerValue;
     
    633623AbcNonLinearCost::setOne(int iSequence, double value)
    634624{
    635   assert (model_ != NULL);
     625  assert(model_ != NULL);
    636626  double primalTolerance = model_->currentPrimalTolerance();
    637627  // difference in cost
    638628  double difference = 0.0;
    639   double * upper = model_->upperRegion();
    640   double * lower = model_->lowerRegion();
    641   double * cost = model_->costRegion();
     629  double *upper = model_->upperRegion();
     630  double *lower = model_->lowerRegion();
     631  double *cost = model_->costRegion();
    642632  unsigned char iStatus = status_[iSequence];
    643   assert (currentStatus(iStatus) == CLP_SAME);
     633  assert(currentStatus(iStatus) == CLP_SAME);
    644634  double lowerValue = lower[iSequence];
    645635  double upperValue = upper[iSequence];
     
    650640    upperValue = bound_[iSequence];
    651641    numberInfeasibilities_--;
    652     assert (fabs(lowerValue) < 1.0e100);
     642    assert(fabs(lowerValue) < 1.0e100);
    653643  } else if (iWhere == CLP_ABOVE_UPPER) {
    654644    upperValue = lowerValue;
     
    667657      costValue -= infeasibilityWeight_;
    668658      numberInfeasibilities_++;
    669       assert (fabs(lowerValue) < 1.0e100);
     659      assert(fabs(lowerValue) < 1.0e100);
    670660    }
    671661  } else {
     
    695685    model_->setInternalStatus(iSequence, AbcSimplex::isFixed);
    696686  }
    697   switch(status) {
    698    
     687  switch (status) {
     688
    699689  case AbcSimplex::basic:
    700690  case AbcSimplex::superBasic:
     
    722712AbcNonLinearCost::setOneBasic(int iRow, double value)
    723713{
    724   assert (model_ != NULL);
    725   int iSequence=model_->pivotVariable()[iRow];
     714  assert(model_ != NULL);
     715  int iSequence = model_->pivotVariable()[iRow];
    726716  double primalTolerance = model_->currentPrimalTolerance();
    727717  // difference in cost
    728718  double difference = 0.0;
    729   double * upper = model_->upperRegion();
    730   double * lower = model_->lowerRegion();
    731   double * cost = model_->costRegion();
    732   double * upperBasic = model_->upperBasic();
    733   double * lowerBasic = model_->lowerBasic();
    734   double * costBasic = model_->costBasic();
     719  double *upper = model_->upperRegion();
     720  double *lower = model_->lowerRegion();
     721  double *cost = model_->costRegion();
     722  double *upperBasic = model_->upperBasic();
     723  double *lowerBasic = model_->lowerBasic();
     724  double *costBasic = model_->costBasic();
    735725  unsigned char iStatus = status_[iSequence];
    736   assert (currentStatus(iStatus) == CLP_SAME);
     726  assert(currentStatus(iStatus) == CLP_SAME);
    737727  double lowerValue = lowerBasic[iRow];
    738728  double upperValue = upperBasic[iRow];
     
    743733    upperValue = bound_[iSequence];
    744734    numberInfeasibilities_--;
    745     assert (fabs(lowerValue) < 1.0e100);
     735    assert(fabs(lowerValue) < 1.0e100);
    746736  } else if (iWhere == CLP_ABOVE_UPPER) {
    747737    upperValue = lowerValue;
     
    760750      costValue -= infeasibilityWeight_;
    761751      numberInfeasibilities_++;
    762       assert (fabs(lowerValue) < 1.0e100);
     752      assert(fabs(lowerValue) < 1.0e100);
    763753    }
    764754  } else {
     
    793783   may change value
    794784   Returns direction */
    795 int
    796 AbcNonLinearCost::setOneOutgoing(int iRow, double & value)
    797 {
    798   assert (model_ != NULL);
    799   int iSequence=model_->pivotVariable()[iRow];
     785int AbcNonLinearCost::setOneOutgoing(int iRow, double &value)
     786{
     787  assert(model_ != NULL);
     788  int iSequence = model_->pivotVariable()[iRow];
    800789  double primalTolerance = model_->currentPrimalTolerance();
    801790  // difference in cost
    802791  double difference = 0.0;
    803792  int direction = 0;
    804   double * upper = model_->upperRegion();
    805   double * lower = model_->lowerRegion();
    806   double * cost = model_->costRegion();
    807   double * upperBasic = model_->upperBasic();
    808   double * lowerBasic = model_->lowerBasic();
     793  double *upper = model_->upperRegion();
     794  double *lower = model_->lowerRegion();
     795  double *cost = model_->costRegion();
     796  double *upperBasic = model_->upperBasic();
     797  double *lowerBasic = model_->lowerBasic();
    809798  unsigned char iStatus = status_[iSequence];
    810   assert (currentStatus(iStatus) == CLP_SAME);
     799  assert(currentStatus(iStatus) == CLP_SAME);
    811800  double lowerValue = lowerBasic[iRow];
    812801  double upperValue = upperBasic[iRow];
     
    826815    upperValue = bound_[iSequence];
    827816    numberInfeasibilities_--;
    828     assert (fabs(lowerValue) < 1.0e100);
     817    assert(fabs(lowerValue) < 1.0e100);
    829818  } else if (iWhere == CLP_ABOVE_UPPER) {
    830819    upperValue = lowerValue;
     
    846835      costValue -= infeasibilityWeight_;
    847836      numberInfeasibilities_++;
    848       assert (fabs(lowerValue) < 1.0e100);
     837      assert(fabs(lowerValue) < 1.0e100);
    849838    }
    850839  } else {
     
    891880AbcNonLinearCost::nearest(int iRow, double solutionValue)
    892881{
    893   assert (model_ != NULL);
    894   int iSequence=model_->pivotVariable()[iRow];
     882  assert(model_ != NULL);
     883  int iSequence = model_->pivotVariable()[iRow];
    895884  double nearest = 0.0;
    896   const double * upperBasic = model_->upperBasic();
    897   const double * lowerBasic = model_->lowerBasic();
     885  const double *upperBasic = model_->upperBasic();
     886  const double *lowerBasic = model_->lowerBasic();
    898887  double lowerValue = lowerBasic[iRow];
    899888  double upperValue = upperBasic[iRow];
     
    902891    lowerValue = upperValue;
    903892    upperValue = bound_[iSequence];
    904     assert (fabs(lowerValue) < 1.0e100);
     893    assert(fabs(lowerValue) < 1.0e100);
    905894  } else if (iWhere == CLP_ABOVE_UPPER) {
    906895    upperValue = lowerValue;
     
    919908  double value;
    920909  model_->getDblParam(ClpObjOffset, value);
    921   return (feasibleCost_ + model_->objectiveAsObject()->nonlinearOffset()) * model_->optimizationDirection() /
    922     (model_->objectiveScale() * model_->rhsScale()) - value;
     910  return (feasibleCost_ + model_->objectiveAsObject()->nonlinearOffset()) * model_->optimizationDirection() / (model_->objectiveScale() * model_->rhsScale()) - value;
    923911}
    924912// Get rid of real costs (just for moment)
    925 void
    926 AbcNonLinearCost::zapCosts()
     913void AbcNonLinearCost::zapCosts()
    927914{
    928915}
    929916#ifdef VALIDATE
    930917// For debug
    931 void
    932 AbcNonLinearCost::validate()
     918void AbcNonLinearCost::validate()
    933919{
    934920  double primalTolerance = model_->currentPrimalTolerance();
    935921  int iSequence;
    936   const double * solution = model_->solutionRegion();
    937   const double * upper = model_->upperRegion();
    938   const double * lower = model_->lowerRegion();
    939   const double * cost = model_->costRegion();
     922  const double *solution = model_->solutionRegion();
     923  const double *upper = model_->upperRegion();
     924  const double *lower = model_->lowerRegion();
     925  const double *cost = model_->costRegion();
    940926  double infeasibilityCost = model_->infeasibilityCost();
    941927  int numberTotal = numberRows_ + numberColumns_;
    942928  int numberInfeasibilities = 0;
    943929  double sumInfeasibilities = 0.0;
    944  
     930
    945931  for (iSequence = 0; iSequence < numberTotal; iSequence++) {
    946932    double value = solution[iSequence];
    947933    int iStatus = status_[iSequence];
    948     assert (currentStatus(iStatus) == CLP_SAME);
     934    assert(currentStatus(iStatus) == CLP_SAME);
    949935    double lowerValue = lower[iSequence];
    950936    double upperValue = upper[iSequence];
    951     double costValue = cost_[iSequence]; 
     937    double costValue = cost_[iSequence];
    952938    int iWhere = originalStatus(iStatus);
    953939    if (iWhere == CLP_BELOW_LOWER) {
    954940      lowerValue = upperValue;
    955941      upperValue = bound_[iSequence];
    956       assert (fabs(lowerValue) < 1.0e100);
     942      assert(fabs(lowerValue) < 1.0e100);
    957943      costValue -= infeasibilityCost;
    958       assert (value <= lowerValue - primalTolerance);
     944      assert(value <= lowerValue - primalTolerance);
    959945      numberInfeasibilities++;
    960946      sumInfeasibilities += lowerValue - value - primalTolerance;
    961       assert (model_->getInternalStatus(iSequence) == AbcSimplex::basic);
     947      assert(model_->getInternalStatus(iSequence) == AbcSimplex::basic);
    962948    } else if (iWhere == CLP_ABOVE_UPPER) {
    963949      upperValue = lowerValue;
    964950      lowerValue = bound_[iSequence];
    965951      costValue += infeasibilityCost;
    966       assert (value >= upperValue + primalTolerance);
     952      assert(value >= upperValue + primalTolerance);
    967953      numberInfeasibilities++;
    968954      sumInfeasibilities += value - upperValue - primalTolerance;
    969       assert (model_->getInternalStatus(iSequence) == AbcSimplex::basic);
     955      assert(model_->getInternalStatus(iSequence) == AbcSimplex::basic);
    970956    } else {
    971       assert (value >= lowerValue - primalTolerance && value <= upperValue + primalTolerance);
    972     }
    973     assert (lowerValue == saveLowerV[iSequence]);
    974     assert (upperValue == saveUpperV[iSequence]);
    975     assert (costValue == cost[iSequence]);
     957      assert(value >= lowerValue - primalTolerance && value <= upperValue + primalTolerance);
     958    }
     959    assert(lowerValue == saveLowerV[iSequence]);
     960    assert(upperValue == saveUpperV[iSequence]);
     961    assert(costValue == cost[iSequence]);
    976962  }
    977963  if (numberInfeasibilities)
    978964    printf("JJ %d infeasibilities summing to %g\n",
    979            numberInfeasibilities, sumInfeasibilities);
     965      numberInfeasibilities, sumInfeasibilities);
    980966}
    981967#endif
     968
     969/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
     970*/
Note: See TracChangeset for help on using the changeset viewer.