 Timestamp:
 Jul 8, 2011 6:41:36 AM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/src/ClpSimplexOther.cpp
r1761 r1762 5433 5433 } 5434 5434 } else { 5435 #if 0 5436 // when in stable 5435 5437 CoinPackedMatrix * matrix = clpMatrix>getPackedMatrix(); 5436 5438 matrix>modifyCoefficients(number,which,start, 5437 5439 row,newCoefficient); 5440 #else 5441 // Copy and sort which 5442 int * which2 = new int [2*number+2]; 5443 int * sort = which2+number+1; 5444 int n=0; 5445 for (int i=0;i<number;i++) { 5446 int iSequence=which[i]; 5447 if (iSequence<numberColumns_) { 5448 which2[n]=iSequence; 5449 sort[n++]=i; 5450 } else { 5451 assert (start[i]==start[i+1]); 5452 } 5453 } 5454 if (n) { 5455 CoinIndexedVector * rowVector=NULL; 5456 for (int i=0;i<4;i++) { 5457 if (rowArray_[i]&&!rowArray_[i]>getNumElements()) { 5458 rowVector = rowArray_[i]; 5459 break; 5460 } 5461 } 5462 bool tempVector=false; 5463 if (!rowVector) { 5464 tempVector=true; 5465 rowVector=new CoinIndexedVector(numberRows_); 5466 } 5467 CoinSort_2(which2,which2+n,sort); 5468 // Stop at end 5469 which2[n]=numberColumns_; 5470 sort[n]=n; 5471 CoinPackedMatrix * matrix = clpMatrix>getPackedMatrix(); 5472 int * rowNow = matrix>getMutableIndices(); 5473 CoinBigIndex * columnStart = matrix>getMutableVectorStarts(); 5474 int * columnLength = matrix>getMutableVectorLengths(); 5475 double * elementByColumn = matrix>getMutableElements(); 5476 double * array = rowVector>denseVector(); 5477 //int * index = rowVector>getIndices(); 5478 int needed=0; 5479 bool moveUp=false; 5480 for (int i=0;i<n;i++) { 5481 int inWhich=sort[i]; 5482 int iSequence=which2[inWhich]; 5483 int nZeroNew=0; 5484 int nZeroOld=0; 5485 for (CoinBigIndex j=start[inWhich];j<start[inWhich+1];j++) { 5486 int iRow=row[j]; 5487 double newValue=newCoefficient[j]; 5488 if (!newValue) { 5489 newValue = COIN_INDEXED_REALLY_TINY_ELEMENT; 5490 nZeroNew++; 5491 } 5492 array[iRow]=newValue; 5493 } 5494 for (CoinBigIndex j=columnStart[iSequence]; 5495 j<columnStart[iSequence]+columnLength[iSequence];j++) { 5496 int iRow=rowNow[j]; 5497 double oldValue=elementByColumn[j]; 5498 if (fabs(oldValue)>COIN_INDEXED_REALLY_TINY_ELEMENT) { 5499 double newValue=array[iRow]; 5500 if (oldValue!=newValue) { 5501 if (newValue) { 5502 array[iRow]=0.0; 5503 if (newValue==COIN_INDEXED_REALLY_TINY_ELEMENT) { 5504 needed; 5505 } 5506 } 5507 } 5508 } else { 5509 nZeroOld++; 5510 } 5511 } 5512 assert (!nZeroOld); 5513 for (CoinBigIndex j=start[inWhich];j<start[inWhich+1];j++) { 5514 int iRow=row[j]; 5515 double newValue=array[iRow]; 5516 if (newValue) { 5517 array[iRow]=0.0; 5518 needed++; 5519 if (needed>0) 5520 moveUp=true; 5521 } 5522 } 5523 } 5524 int numberElements = matrix>getNumElements(); 5525 assert (numberElements==columnStart[numberColumns_]); 5526 if (needed>0) { 5527 // need more space 5528 matrix>reserve(numberColumns_, numberElements+needed); 5529 rowNow = matrix>getMutableIndices(); 5530 elementByColumn = matrix>getMutableElements(); 5531 } 5532 if (moveUp) { 5533 // move up from top 5534 CoinBigIndex top = numberElements+needed; 5535 for (int iColumn=numberColumns_1;iColumn>=0;iColumn) { 5536 CoinBigIndex end = columnStart[iColumn+1]; 5537 columnStart[iColumn+1]=top; 5538 CoinBigIndex startThis = columnStart[iColumn]; 5539 for (CoinBigIndex j=end1;j>=startThis;j) { 5540 if (elementByColumn[j]) { 5541 top; 5542 elementByColumn[top]=elementByColumn[j]; 5543 rowNow[top]=rowNow[j]; 5544 } 5545 } 5546 } 5547 columnStart[0]=top; 5548 } 5549 // now move down and insert 5550 CoinBigIndex put=0; 5551 int iColumn=0; 5552 for (int i=0;i<n+1;i++) { 5553 int inWhich=sort[i]; 5554 int nextMod=which2[inWhich]; 5555 for (;iColumn<nextMod;iColumn++) { 5556 CoinBigIndex startThis = columnStart[iColumn]; 5557 columnStart[iColumn]=put; 5558 for (CoinBigIndex j=startThis; 5559 j<columnStart[iColumn+1];j++) { 5560 int iRow=rowNow[j]; 5561 double oldValue=elementByColumn[j]; 5562 if (oldValue) { 5563 rowNow[put]=iRow; 5564 elementByColumn[put++]=oldValue; 5565 } 5566 } 5567 } 5568 if (i==n) { 5569 columnStart[iColumn]=put; 5570 break; 5571 } 5572 // Now 5573 for (CoinBigIndex j=start[inWhich];j<start[inWhich+1];j++) { 5574 int iRow=row[j]; 5575 double newValue=newCoefficient[j]; 5576 if (!newValue) { 5577 newValue = COIN_INDEXED_REALLY_TINY_ELEMENT; 5578 } 5579 array[iRow]=newValue; 5580 } 5581 CoinBigIndex startThis = columnStart[iColumn]; 5582 columnStart[iColumn]=put; 5583 for (CoinBigIndex j=startThis; 5584 j<columnStart[iColumn+1];j++) { 5585 int iRow=rowNow[j]; 5586 double oldValue=elementByColumn[j]; 5587 if (array[iRow]) { 5588 oldValue=array[iRow]; 5589 if (oldValue==COIN_INDEXED_REALLY_TINY_ELEMENT) 5590 oldValue=0.0; 5591 array[iRow]=0.0; 5592 } 5593 if (fabs(oldValue)>COIN_INDEXED_REALLY_TINY_ELEMENT) { 5594 rowNow[put]=iRow; 5595 elementByColumn[put++]=oldValue; 5596 } 5597 } 5598 for (CoinBigIndex j=start[inWhich];j<start[inWhich+1];j++) { 5599 int iRow=row[j]; 5600 double newValue=array[iRow]; 5601 if (newValue) { 5602 array[iRow]=0.0; 5603 rowNow[put]=iRow; 5604 elementByColumn[put++]=newValue; 5605 } 5606 } 5607 iColumn++; 5608 } 5609 matrix>setNumElements(put); 5610 if (tempVector) 5611 delete rowVector; 5612 for (int i=0;i<numberColumns_;i++) { 5613 columnLength[i]=columnStart[i+1]columnStart[i]; 5614 } 5615 } 5616 #endif 5438 5617 if (canPivot) { 5439 5618 // ? faster to modify row copy??
Note: See TracChangeset
for help on using the changeset viewer.