Changeset 1825 for trunk/Clp/src/ClpModel.cpp
 Timestamp:
 Nov 20, 2011 11:02:57 AM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/src/ClpModel.cpp
r1792 r1825 1583 1583 setRowScale(NULL); 1584 1584 setColumnScale(NULL); 1585 } 1586 // Deletes rows AND columns (does not reallocate) 1587 void 1588 ClpModel::deleteRowsAndColumns(int numberRows, const int * whichRows, 1589 int numberColumns, const int * whichColumns) 1590 { 1591 if (!numberColumns) { 1592 deleteRows(numberRows,whichRows); 1593 } else if (!numberRows) { 1594 deleteColumns(numberColumns,whichColumns); 1595 } else { 1596 whatsChanged_ &= ~511; // all changed 1597 bool doStatus = status_!=NULL; 1598 int numberTotal=numberRows_+numberColumns_; 1599 int * backRows = new int [numberTotal]; 1600 int * backColumns = backRows+numberRows_; 1601 memset(backRows,0,numberTotal*sizeof(int)); 1602 int newNumberColumns=0; 1603 for (int i=0;i<numberColumns;i++) { 1604 int iColumn=whichColumns[i]; 1605 if (iColumn>=0&&iColumn<numberColumns_) 1606 backColumns[iColumn]=1; 1607 } 1608 assert (objective_>type()==1); 1609 double * obj = objective(); 1610 for (int i=0;i<numberColumns_;i++) { 1611 if (!backColumns[i]) { 1612 columnActivity_[newNumberColumns] = columnActivity_[i]; 1613 reducedCost_[newNumberColumns] = reducedCost_[i]; 1614 obj[newNumberColumns] = obj[i]; 1615 columnLower_[newNumberColumns] = columnLower_[i]; 1616 columnUpper_[newNumberColumns] = columnUpper_[i]; 1617 if (doStatus) 1618 status_[newNumberColumns] = status_[i]; 1619 backColumns[i]=newNumberColumns++; 1620 } 1621 } 1622 integerType_ = deleteChar(integerType_, numberColumns_, 1623 numberColumns, whichColumns, newNumberColumns, true); 1624 #ifndef CLP_NO_STD 1625 // Now works if which out of order 1626 if (lengthNames_) { 1627 for (int i=0;i<numberColumns_;i++) { 1628 int iColumn=backColumns[i]; 1629 if (iColumn) 1630 columnNames_[iColumn] = columnNames_[i]; 1631 } 1632 columnNames_.erase(columnNames_.begin() + newNumberColumns, columnNames_.end()); 1633 } 1634 #endif 1635 int newNumberRows=0; 1636 assert (!rowObjective_); 1637 unsigned char * status2 = status_ + numberColumns_; 1638 for (int i=0;i<numberRows;i++) { 1639 int iRow=whichRows[i]; 1640 if (iRow>=0&&iRow<numberRows_) 1641 backRows[iRow]=1; 1642 } 1643 for (int i=0;i<numberRows_;i++) { 1644 if (!backRows[i]) { 1645 rowActivity_[newNumberRows] = rowActivity_[i]; 1646 dual_[newNumberRows] = dual_[i]; 1647 rowLower_[newNumberRows] = rowLower_[i]; 1648 rowUpper_[newNumberRows] = rowUpper_[i]; 1649 if (doStatus) 1650 status2[newNumberRows] = status2[i]; 1651 backRows[i]=newNumberRows++; 1652 } 1653 } 1654 #ifndef CLP_NO_STD 1655 // Now works if which out of order 1656 if (lengthNames_) { 1657 for (int i=0;i<numberRows_;i++) { 1658 int iRow=backRows[i]; 1659 if (iRow) 1660 rowNames_[iRow] = rowNames_[i]; 1661 } 1662 rowNames_.erase(rowNames_.begin() + newNumberRows, rowNames_.end()); 1663 } 1664 #endif 1665 // possible matrix is not full 1666 ClpPackedMatrix * clpMatrix = dynamic_cast<ClpPackedMatrix *>(matrix_); 1667 CoinPackedMatrix * matrix = clpMatrix ? clpMatrix>matrix() : NULL; 1668 if (matrix_>getNumCols() < numberColumns_) { 1669 assert (matrix); 1670 CoinBigIndex nel=matrix>getNumElements(); 1671 int n=matrix>getNumCols(); 1672 matrix>reserve(numberColumns_,nel); 1673 CoinBigIndex * columnStart = matrix>getMutableVectorStarts(); 1674 int * columnLength = matrix>getMutableVectorLengths(); 1675 for (int i=n;i<numberColumns_;i++) { 1676 columnStart[i]=nel; 1677 columnLength[i]=0; 1678 } 1679 } 1680 if (matrix) { 1681 matrix>setExtraMajor(0.1); 1682 //CoinPackedMatrix temp(*matrix); 1683 matrix>setExtraGap(0.0); 1684 matrix>setExtraMajor(0.0); 1685 int * row = matrix>getMutableIndices(); 1686 CoinBigIndex * columnStart = matrix>getMutableVectorStarts(); 1687 int * columnLength = matrix>getMutableVectorLengths(); 1688 double * element = matrix>getMutableElements(); 1689 newNumberColumns=0; 1690 CoinBigIndex n=0; 1691 for (int iColumn=0;iColumn<numberColumns_;iColumn++) { 1692 if (backColumns[iColumn]>=0) { 1693 CoinBigIndex start = columnStart[iColumn]; 1694 int nSave=n; 1695 columnStart[newNumberColumns]=n; 1696 for (CoinBigIndex j=start;j<start+columnLength[iColumn];j++) { 1697 int iRow=row[j]; 1698 iRow = backRows[iRow]; 1699 if (iRow>=0) { 1700 row[n]=iRow; 1701 element[n++]=element[j]; 1702 } 1703 } 1704 columnLength[newNumberColumns++]=nnSave; 1705 } 1706 } 1707 columnStart[newNumberColumns]=n; 1708 matrix>setNumElements(n); 1709 matrix>setMajorDim(newNumberColumns); 1710 matrix>setMinorDim(newNumberRows); 1711 clpMatrix>setNumberActiveColumns(newNumberColumns); 1712 //temp.deleteRows(numberRows, whichRows); 1713 //temp.deleteCols(numberColumns, whichColumns); 1714 //assert(matrix>isEquivalent2(temp)); 1715 //*matrix=temp; 1716 } else { 1717 matrix_>deleteRows(numberRows, whichRows); 1718 matrix_>deleteCols(numberColumns, whichColumns); 1719 } 1720 numberColumns_ = newNumberColumns; 1721 numberRows_ = newNumberRows; 1722 delete [] backRows; 1723 // set state back to unknown 1724 problemStatus_ = 1; 1725 secondaryStatus_ = 0; 1726 delete [] ray_; 1727 ray_ = NULL; 1728 if (savedRowScale_ != rowScale_) { 1729 delete [] rowScale_; 1730 delete [] columnScale_; 1731 } 1732 rowScale_ = NULL; 1733 columnScale_ = NULL; 1734 delete scaledMatrix_; 1735 scaledMatrix_ = NULL; 1736 delete rowCopy_; 1737 rowCopy_ = NULL; 1738 } 1585 1739 } 1586 1740 // Add one row
Note: See TracChangeset
for help on using the changeset viewer.