| 26 | } |
| 27 | |
| 28 | void HFactor::addRows(const HighsSparseMatrix* ar_matrix) { |
| 29 | invalidAMatrixAction(); |
| 30 | assert(kExtendInvertWhenAddingRows); |
| 31 | HighsInt num_new_row = ar_matrix->num_row_; |
| 32 | HighsInt new_num_row = num_row + num_new_row; |
| 33 | printf("Adding %" HIGHSINT_FORMAT |
| 34 | " new rows to HFactor instance: increasing dimension from " |
| 35 | "%" HIGHSINT_FORMAT " to %" HIGHSINT_FORMAT " \n", |
| 36 | num_new_row, num_row, new_num_row); |
| 37 | |
| 38 | // Need to know where (if) a column is basic |
| 39 | vector<HighsInt> in_basis; |
| 40 | in_basis.assign(num_col, -1); |
| 41 | for (HighsInt iRow = 0; iRow < num_row; iRow++) { |
| 42 | HighsInt iVar = basic_index[iRow]; |
| 43 | if (iVar < num_col) in_basis[iVar] = iRow; |
| 44 | } |
| 45 | for (HighsInt iRow = num_row; iRow < new_num_row; iRow++) { |
| 46 | HighsInt iVar = basic_index[iRow]; |
| 47 | assert(iVar >= num_col); |
| 48 | } |
| 49 | // reportLu(kReportLuBoth, true); |
| 50 | // reportLu(kReportLuJustL); |
| 51 | |
| 52 | // Create a row-wise sparse matrix containing the new rows of the L |
| 53 | // matrix - so that a column-wise version can be created (after |
| 54 | // inserting the rows into the LR matrix) allowing the cew column |
| 55 | // entries to be inserted efficiently into the L matrix |
| 56 | HighsSparseMatrix new_lr_rows; |
| 57 | new_lr_rows.format_ = MatrixFormat::kRowwise; |
| 58 | new_lr_rows.num_col_ = num_row; |
| 59 | double expected_density = 0.0; |
| 60 | HVector rhs; |
| 61 | rhs.setup(num_row); |
| 62 | this->lr_start.reserve(new_num_row + 1); |
| 63 | for (HighsInt inewRow = 0; inewRow < num_new_row; inewRow++) { |
| 64 | // printf("\nFor new row %" HIGHSINT_FORMAT "\n", inewRow); |
| 65 | // Prepare RHS for system U^T.v = r |
| 66 | rhs.clear(); |
| 67 | rhs.packFlag = true; |
| 68 | for (HighsInt iEl = ar_matrix->start_[inewRow]; |
| 69 | iEl < ar_matrix->start_[inewRow + 1]; iEl++) { |
| 70 | HighsInt iCol = ar_matrix->index_[iEl]; |
| 71 | HighsInt basis_index = in_basis[iCol]; |
| 72 | if (basis_index >= 0) { |
| 73 | rhs.array[basis_index] = ar_matrix->value_[iEl]; |
| 74 | rhs.index[rhs.count++] = basis_index; |
| 75 | } |
| 76 | } |
| 77 | // Solve U^T.v = r |
| 78 | btranU(rhs, expected_density); |
| 79 | double local_density = (1.0 * rhs.count) / num_row; |
| 80 | expected_density = kRunningAverageMultiplier * local_density + |
| 81 | (1 - kRunningAverageMultiplier) * expected_density; |
| 82 | // printf("New row btranU density: local = %11.4g; expected = %11.4g\n", |
| 83 | // local_density, expected_density); |
| 84 | rhs.tight(); |
| 85 | // |