Skip to content

Commit

Permalink
allow alternative matrix storage in Cbc
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Nov 1, 2024
1 parent 15d36e7 commit adc06ad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
55 changes: 34 additions & 21 deletions src/ClpPackedMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5801,12 +5801,29 @@ void ClpPackedMatrix::specialColumnCopy(ClpSimplex *model)
if (pricing && pricing->mode() > 1)
pricing->setMode(0);
}
if ((flags_ & 16) != 0 && model->numberRows() > 100 && model->numberColumns() > 500) {
#if 0 // seems better to decide using number elements
#define COPY_ROWS 100
#define COPY_COLS 500
if ((flags_ & 16) != 0 && model->numberRows() > COPY_ROWS && model->numberColumns() > COPY_COLS) {
columnCopy_ = new ClpPackedMatrix3(model, matrix_);
flags_ |= 8;
} else {
columnCopy_ = NULL;
}
if ((flags_ & 16) != 0) {
inFlags++;
if(model->numberRows() > COPY_ROWS && model->numberColumns() > COPY_COLS)
inDone++;
}
#else
#define PACK_COPY_ELEMENTS 10000
if ((flags_ & 16) != 0 && getNumElements()>PACK_COPY_ELEMENTS) {
columnCopy_ = new ClpPackedMatrix3(model, matrix_);
flags_ |= 8;
} else {
columnCopy_ = NULL;
}
#endif
}
// Say we don't want special column copy
void ClpPackedMatrix::releaseSpecialColumnCopy()
Expand Down Expand Up @@ -7289,7 +7306,11 @@ ClpPackedMatrix3::ClpPackedMatrix3(const ClpPackedMatrix3 &rhs)
, plusOnes_(rhs.plusOnes_)
{
if (rhs.numberBlocks_) {
#ifndef OUT_BLOCK_ROWS
block_ = CoinCopyOfArray(rhs.block_, numberBlocks_+1);
#else
block_ = CoinCopyOfArray(rhs.block_, numberBlocks_);
#endif
column_ = CoinCopyOfArray(rhs.column_, 2 * numberColumnsWithGaps_);
int numberOdd = block_->startIndices_;
start_ = CoinCopyOfArray(rhs.start_, numberOdd + 1);
Expand Down Expand Up @@ -8815,17 +8836,13 @@ void ClpPackedMatrix3::transposeTimes(const ClpSimplex *model,
double value2 = newValues[j];
if (fabs(value2) > zeroTolerance) {
int iSequence = column[j];
double alpha;
double oldValue;
double value;
alpha = value2;
if (alpha > 0.0) {
oldValue = reducedCost[iSequence];
value = oldValue - tentativeTheta * alpha;
if (value2 > 0.0) {
double oldValue = reducedCost[iSequence];
double value = oldValue - tentativeTheta * value2;
if (value < dualT) {
value = oldValue - upperTheta * alpha;
if (value < dualT && alpha >= acceptablePivot) {
upperTheta = (oldValue - dualT) / alpha;
value = oldValue - upperTheta * value2;
if (value < dualT && value2 >= acceptablePivot) {
upperTheta = (oldValue - dualT) / value2;
}
// add to list
spareArray[numberRemaining] = value2;
Expand All @@ -8840,17 +8857,13 @@ void ClpPackedMatrix3::transposeTimes(const ClpSimplex *model,
double value2 = newValues[j];
if (fabs(value2) > zeroTolerance) {
int iSequence = column[j];
double alpha;
double oldValue;
double value;
alpha = -value2;
if (alpha > 0.0) {
oldValue = -reducedCost[iSequence];
value = oldValue - tentativeTheta * alpha;
if (value2 < 0.0) {
double oldValue = -reducedCost[iSequence];
double value = oldValue + tentativeTheta * value2;
if (value < dualT) {
value = oldValue - upperTheta * alpha;
if (value < dualT && alpha >= acceptablePivot) {
upperTheta = (oldValue - dualT) / alpha;
value = oldValue + upperTheta * value2;
if (value < dualT && -value2 >= acceptablePivot) {
upperTheta = (dualT - oldValue) / value2;
}
// add to list
spareArray[numberRemaining] = value2;
Expand Down
4 changes: 2 additions & 2 deletions src/ClpSimplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ClpSimplex::ClpSimplex(const ClpSimplex *rhs,
, bestObjectiveValue_(-COIN_DBL_MAX)
, moreSpecialOptions_(2)
, baseIteration_(0)
, vectorMode_(0)
, vectorMode_(rhs->vectorMode_)
, primalToleranceToGetOptimal_(-1.0)
, largeValue_(1.0e15)
, largestPrimalError_(0.0)
Expand Down Expand Up @@ -2403,7 +2403,7 @@ ClpSimplex::ClpSimplex(const ClpSimplex &rhs, int scalingMode)
, bestObjectiveValue_(rhs.bestObjectiveValue_)
, moreSpecialOptions_(2)
, baseIteration_(0)
, vectorMode_(0)
, vectorMode_(rhs.vectorMode_)
, primalToleranceToGetOptimal_(-1.0)
, largeValue_(1.0e15)
, largestPrimalError_(0.0)
Expand Down
4 changes: 4 additions & 0 deletions src/ClpSimplexOther.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,10 @@ ClpSimplexOther::crunch(double *rhs, int *whichRow, int *whichColumn,
assert(n == small->numberRows());
}
#endif
if (small) {
ClpPackedMatrix * matrix = static_cast<ClpPackedMatrix *>(small->clpMatrix());
matrix->specialColumnCopy(small); // vector copy?
}
return small;
}
/* After very cursory presolve.
Expand Down

0 comments on commit adc06ad

Please sign in to comment.