MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / deleteCols

Method deleteCols

highs/util/HighsSparseMatrix.cpp:594–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

592}
593
594void HighsSparseMatrix::deleteCols(
595 const HighsIndexCollection& index_collection) {
596 assert(this->formatOk());
597 // Can't handle rowwise matrices yet
598 assert(!this->isRowwise());
599 assert(ok(index_collection));
600 HighsInt from_k;
601 HighsInt to_k;
602 limits(index_collection, from_k, to_k);
603 if (from_k > to_k) return;
604
605 HighsInt delete_from_col;
606 HighsInt delete_to_col;
607 HighsInt keep_from_col;
608 HighsInt keep_to_col = -1;
609 HighsInt current_set_entry = 0;
610
611 HighsInt col_dim = this->num_col_;
612 HighsInt new_num_col = 0;
613 HighsInt new_num_nz = 0;
614 for (HighsInt k = from_k; k <= to_k; k++) {
615 updateOutInIndex(index_collection, delete_from_col, delete_to_col,
616 keep_from_col, keep_to_col, current_set_entry);
617 if (k == from_k) {
618 // Account for the initial columns being kept
619 new_num_col = delete_from_col;
620 new_num_nz = this->start_[delete_from_col];
621 }
622 // Ensure that the starts of the deleted columns are zeroed to
623 // avoid redundant start information for columns whose indices
624 // aren't used after the deletion takes place. In particular, if
625 // all columns are deleted then something must be done to ensure
626 // that the matrix isn't magically recreated by increasing the
627 // number of columns from zero when there are no rows in the
628 // matrix.
629 for (HighsInt col = delete_from_col; col <= delete_to_col; col++)
630 this->start_[col] = 0;
631 // Shift the starts - both in place and value - to account for the
632 // columns and nonzeros removed
633 const HighsInt keep_from_el = this->start_[keep_from_col];
634 for (HighsInt col = keep_from_col; col <= keep_to_col; col++) {
635 this->start_[new_num_col] = new_num_nz + this->start_[col] - keep_from_el;
636 new_num_col++;
637 }
638 for (HighsInt el = keep_from_el; el < this->start_[keep_to_col + 1]; el++) {
639 this->index_[new_num_nz] = this->index_[el];
640 this->value_[new_num_nz] = this->value_[el];
641 new_num_nz++;
642 }
643 if (keep_to_col >= col_dim - 1) break;
644 }
645 // Ensure that the start of the spurious last column is zeroed so
646 // that it doesn't give a positive number of matrix entries if the
647 // number of columns in the matrix is increased when there are no
648 // rows in the matrix.
649 this->start_[this->num_col_] = 0;
650 this->start_[new_num_col] = new_num_nz;
651 this->start_.resize(new_num_col + 1);

Callers

nothing calls this directly

Calls 6

formatOkMethod · 0.95
isRowwiseMethod · 0.95
okFunction · 0.85
limitsFunction · 0.85
updateOutInIndexFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected