Example #1
0
// For long double versions
CoinWorkDouble
maximumAbsElement(const CoinWorkDouble * region, int size)
{
     int i;
     CoinWorkDouble maxValue = 0.0;
     for (i = 0; i < size; i++)
          maxValue = CoinMax(maxValue, CoinAbs(region[i]));
     return maxValue;
}
Example #2
0
//-----------------------------------------------------------------------------
void
BCP_lp_user::select_zeros(const double * first, const double * last,
			  const double etol,
			  BCP_vec<int>& zeros) const {
    zeros.reserve(last - first);
    BCP_vec<double>::const_iterator current = first;
    for ( ; current != last; ++current)
	if (CoinAbs(*current) <= etol)
	    zeros.unchecked_push_back(current - first);
}
Example #3
0
void
getNorms(const CoinWorkDouble * region, int size, CoinWorkDouble & norm1, CoinWorkDouble & norm2)
{
     norm1 = 0.0;
     norm2 = 0.0;
     int i;
     for (i = 0; i < size; i++) {
          norm2 += region[i] * region[i];
          norm1 = CoinMax(norm1, CoinAbs(region[i]));
     }
}
Example #4
0
// Sanity check on input data - returns true if okay
bool
ClpInterior::sanityCheck()
{
     // bad if empty
     if (!numberColumns_ || ((!numberRows_ || !matrix_->getNumElements()) && objective_->type() < 2)) {
          problemStatus_ = emptyProblem();
          return false;
     }
     int numberBad ;
     CoinWorkDouble largestBound, smallestBound, minimumGap;
     CoinWorkDouble smallestObj, largestObj;
     int firstBad;
     int modifiedBounds = 0;
     int i;
     numberBad = 0;
     firstBad = -1;
     minimumGap = 1.0e100;
     smallestBound = 1.0e100;
     largestBound = 0.0;
     smallestObj = 1.0e100;
     largestObj = 0.0;
     // If bounds are too close - fix
     CoinWorkDouble fixTolerance = 1.1 * primalTolerance();
     for (i = numberColumns_; i < numberColumns_ + numberRows_; i++) {
          CoinWorkDouble value;
          value = CoinAbs(cost_[i]);
          if (value > 1.0e50) {
               numberBad++;
               if (firstBad < 0)
                    firstBad = i;
          } else if (value) {
               if (value > largestObj)
                    largestObj = value;
               if (value < smallestObj)
                    smallestObj = value;
          }
          value = upper_[i] - lower_[i];
          if (value < -primalTolerance()) {
               numberBad++;
               if (firstBad < 0)
                    firstBad = i;
          } else if (value <= fixTolerance) {
               if (value) {
                    // modify
                    upper_[i] = lower_[i];
                    modifiedBounds++;
               }
          } else {
               if (value < minimumGap)
                    minimumGap = value;
          }
          if (lower_[i] > -1.0e100 && lower_[i]) {
               value = CoinAbs(lower_[i]);
               if (value > largestBound)
                    largestBound = value;
               if (value < smallestBound)
                    smallestBound = value;
          }
          if (upper_[i] < 1.0e100 && upper_[i]) {
               value = CoinAbs(upper_[i]);
               if (value > largestBound)
                    largestBound = value;
               if (value < smallestBound)
                    smallestBound = value;
          }
     }
     if (largestBound)
          handler_->message(CLP_RIMSTATISTICS3, messages_)
                    << static_cast<double>(smallestBound)
                    << static_cast<double>(largestBound)
                    << static_cast<double>(minimumGap)
                    << CoinMessageEol;
     minimumGap = 1.0e100;
     smallestBound = 1.0e100;
     largestBound = 0.0;
     for (i = 0; i < numberColumns_; i++) {
          CoinWorkDouble value;
          value = CoinAbs(cost_[i]);
          if (value > 1.0e50) {
               numberBad++;
               if (firstBad < 0)
                    firstBad = i;
          } else if (value) {
               if (value > largestObj)
                    largestObj = value;
               if (value < smallestObj)
                    smallestObj = value;
          }
          value = upper_[i] - lower_[i];
          if (value < -primalTolerance()) {
               numberBad++;
               if (firstBad < 0)
                    firstBad = i;
          } else if (value <= fixTolerance) {
               if (value) {
                    // modify
                    upper_[i] = lower_[i];
                    modifiedBounds++;
               }
          } else {
               if (value < minimumGap)
                    minimumGap = value;
          }
          if (lower_[i] > -1.0e100 && lower_[i]) {
               value = CoinAbs(lower_[i]);
               if (value > largestBound)
                    largestBound = value;
               if (value < smallestBound)
                    smallestBound = value;
          }
          if (upper_[i] < 1.0e100 && upper_[i]) {
               value = CoinAbs(upper_[i]);
               if (value > largestBound)
                    largestBound = value;
               if (value < smallestBound)
                    smallestBound = value;
          }
     }
     char rowcol[] = {'R', 'C'};
     if (numberBad) {
          handler_->message(CLP_BAD_BOUNDS, messages_)
                    << numberBad
                    << rowcol[isColumn(firstBad)] << sequenceWithin(firstBad)
                    << CoinMessageEol;
          problemStatus_ = 4;
          return false;
     }
     if (modifiedBounds)
          handler_->message(CLP_MODIFIEDBOUNDS, messages_)
                    << modifiedBounds
                    << CoinMessageEol;
     handler_->message(CLP_RIMSTATISTICS1, messages_)
               << static_cast<double>(smallestObj)
               << static_cast<double>(largestObj)
               << CoinMessageEol;
     if (largestBound)
          handler_->message(CLP_RIMSTATISTICS2, messages_)
                    << static_cast<double>(smallestBound)
                    << static_cast<double>(largestBound)
                    << static_cast<double>(minimumGap)
                    << CoinMessageEol;
     return true;
}
Example #5
0
// fix variables interior says should be
void
ClpInterior::fixFixed(bool reallyFix)
{
     // Arrays for change in columns and rhs
     CoinWorkDouble * columnChange = new CoinWorkDouble[numberColumns_];
     CoinWorkDouble * rowChange = new CoinWorkDouble[numberRows_];
     CoinZeroN(columnChange, numberColumns_);
     CoinZeroN(rowChange, numberRows_);
     matrix_->times(1.0, columnChange, rowChange);
     int i;
     CoinWorkDouble tolerance = primalTolerance();
     for (i = 0; i < numberColumns_; i++) {
          if (columnUpper_[i] < 1.0e20 || columnLower_[i] > -1.0e20) {
               if (columnUpper_[i] > columnLower_[i]) {
                    if (fixedOrFree(i)) {
                         if (columnActivity_[i] - columnLower_[i] < columnUpper_[i] - columnActivity_[i]) {
                              CoinWorkDouble change = columnLower_[i] - columnActivity_[i];
                              if (CoinAbs(change) < tolerance) {
                                   if (reallyFix)
                                        columnUpper_[i] = columnLower_[i];
                                   columnChange[i] = change;
                                   columnActivity_[i] = columnLower_[i];
                              }
                         } else {
                              CoinWorkDouble change = columnUpper_[i] - columnActivity_[i];
                              if (CoinAbs(change) < tolerance) {
                                   if (reallyFix)
                                        columnLower_[i] = columnUpper_[i];
                                   columnChange[i] = change;
                                   columnActivity_[i] = columnUpper_[i];
                              }
                         }
                    }
               }
          }
     }
     CoinZeroN(rowChange, numberRows_);
     matrix_->times(1.0, columnChange, rowChange);
     // If makes mess of things then don't do
     CoinWorkDouble newSum = 0.0;
     for (i = 0; i < numberRows_; i++) {
          CoinWorkDouble value = rowActivity_[i] + rowChange[i];
          if (value > rowUpper_[i] + tolerance)
               newSum += value - rowUpper_[i] - tolerance;
          else if (value < rowLower_[i] - tolerance)
               newSum -= value - rowLower_[i] + tolerance;
     }
     if (newSum > 1.0e-5 + 1.5 * sumPrimalInfeasibilities_) {
          // put back and skip changes
          for (i = 0; i < numberColumns_; i++)
               columnActivity_[i] -= columnChange[i];
     } else {
          CoinZeroN(rowActivity_, numberRows_);
          matrix_->times(1.0, columnActivity_, rowActivity_);
          if (reallyFix) {
               for (i = 0; i < numberRows_; i++) {
                    if (rowUpper_[i] < 1.0e20 || rowLower_[i] > -1.0e20) {
                         if (rowUpper_[i] > rowLower_[i]) {
                              if (fixedOrFree(i + numberColumns_)) {
                                   if (rowActivity_[i] - rowLower_[i] < rowUpper_[i] - rowActivity_[i]) {
                                        CoinWorkDouble change = rowLower_[i] - rowActivity_[i];
                                        if (CoinAbs(change) < tolerance) {
                                             if (reallyFix)
                                                  rowUpper_[i] = rowLower_[i];
                                             rowActivity_[i] = rowLower_[i];
                                        }
                                   } else {
                                        CoinWorkDouble change = rowLower_[i] - rowActivity_[i];
                                        if (CoinAbs(change) < tolerance) {
                                             if (reallyFix)
                                                  rowLower_[i] = rowUpper_[i];
                                             rowActivity_[i] = rowUpper_[i];
                                        }
                                   }
                              }
                         }
                    }
               }
          }
     }
     delete [] rowChange;
     delete [] columnChange;
}