Skip to content

Commit 7bd0035

Browse files
committed
Moved deleteLpCols/Rows to HighsLp
1 parent b6172a8 commit 7bd0035

File tree

4 files changed

+46
-103
lines changed

4 files changed

+46
-103
lines changed

src/lp_data/HighsInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void Highs::deleteRowsInterface(HighsIndexCollection& index_collection) {
412412
// any rows have been removed, and if there is mask to be updated
413413
HighsInt original_num_row = lp.num_row_;
414414

415-
deleteLpRows(lp, index_collection);
415+
lp.deleteRows(index_collection);
416416
assert(lp.num_row_ <= original_num_row);
417417
if (lp.num_row_ < original_num_row) {
418418
// Nontrivial deletion so reset the model_status and invalidate

src/lp_data/HighsLp.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,45 @@ void HighsLp::deleteColsFromVectors(
438438
}
439439

440440
void HighsLp::deleteRowsFromVectors(
441-
HighsInt& new_num_row, const HighsIndexCollection& index_collection) {}
441+
HighsInt& new_num_row, const HighsIndexCollection& index_collection) {
442+
assert(ok(index_collection));
443+
HighsInt from_k;
444+
HighsInt to_k;
445+
limits(index_collection, from_k, to_k);
446+
// Initialise new_num_row in case none is removed due to from_k > to_k
447+
new_num_row = this->num_row_;
448+
if (from_k > to_k) return;
449+
450+
HighsInt delete_from_row;
451+
HighsInt delete_to_row;
452+
HighsInt keep_from_row;
453+
HighsInt keep_to_row = -1;
454+
HighsInt current_set_entry = 0;
455+
456+
HighsInt row_dim = this->num_row_;
457+
new_num_row = 0;
458+
bool have_names = (HighsInt)this->row_names_.size() > 0;
459+
for (HighsInt k = from_k; k <= to_k; k++) {
460+
updateOutInIndex(index_collection, delete_from_row, delete_to_row,
461+
keep_from_row, keep_to_row, current_set_entry);
462+
if (k == from_k) {
463+
// Account for the initial rows being kept
464+
new_num_row = delete_from_row;
465+
}
466+
if (delete_to_row >= row_dim - 1) break;
467+
assert(delete_to_row < row_dim);
468+
for (HighsInt row = keep_from_row; row <= keep_to_row; row++) {
469+
this->row_lower_[new_num_row] = this->row_lower_[row];
470+
this->row_upper_[new_num_row] = this->row_upper_[row];
471+
if (have_names) this->row_names_[new_num_row] = this->row_names_[row];
472+
new_num_row++;
473+
}
474+
if (keep_to_row >= row_dim - 1) break;
475+
}
476+
this->row_lower_.resize(new_num_row);
477+
this->row_upper_.resize(new_num_row);
478+
if (have_names) this->row_names_.resize(new_num_row);
479+
}
442480

443481
void HighsLp::deleteCols(const HighsIndexCollection& index_collection) {
444482
HighsInt new_num_col;
@@ -447,7 +485,12 @@ void HighsLp::deleteCols(const HighsIndexCollection& index_collection) {
447485
this->num_col_ = new_num_col;
448486
}
449487

450-
void HighsLp::deleteRows(const HighsIndexCollection& index_collection) {}
488+
void HighsLp::deleteRows(const HighsIndexCollection& index_collection) {
489+
HighsInt new_num_row;
490+
this->deleteRowsFromVectors(new_num_row, index_collection);
491+
this->a_matrix_.deleteRows(index_collection);
492+
this->num_row_ = new_num_row;
493+
}
451494

452495
void HighsLp::unapplyMods() {
453496
// Restore any non-semi types

src/lp_data/HighsLpUtils.cpp

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,98 +1495,6 @@ void appendRowsToLpVectors(HighsLp& lp, const HighsInt num_new_row,
14951495
}
14961496
}
14971497

1498-
void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
1499-
const HighsIndexCollection& index_collection) {
1500-
assert(ok(index_collection));
1501-
HighsInt from_k;
1502-
HighsInt to_k;
1503-
limits(index_collection, from_k, to_k);
1504-
;
1505-
// Initialise new_num_col in case none is removed due to from_k > to_k
1506-
new_num_col = lp.num_col_;
1507-
if (from_k > to_k) return;
1508-
1509-
HighsInt delete_from_col;
1510-
HighsInt delete_to_col;
1511-
HighsInt keep_from_col;
1512-
HighsInt keep_to_col = -1;
1513-
HighsInt current_set_entry = 0;
1514-
1515-
HighsInt col_dim = lp.num_col_;
1516-
new_num_col = 0;
1517-
bool have_names = (lp.col_names_.size() != 0);
1518-
bool have_integrality = (lp.integrality_.size() != 0);
1519-
for (HighsInt k = from_k; k <= to_k; k++) {
1520-
updateOutInIndex(index_collection, delete_from_col, delete_to_col,
1521-
keep_from_col, keep_to_col, current_set_entry);
1522-
// Account for the initial columns being kept
1523-
if (k == from_k) new_num_col = delete_from_col;
1524-
if (delete_to_col >= col_dim - 1) break;
1525-
assert(delete_to_col < col_dim);
1526-
for (HighsInt col = keep_from_col; col <= keep_to_col; col++) {
1527-
lp.col_cost_[new_num_col] = lp.col_cost_[col];
1528-
lp.col_lower_[new_num_col] = lp.col_lower_[col];
1529-
lp.col_upper_[new_num_col] = lp.col_upper_[col];
1530-
if (have_names) lp.col_names_[new_num_col] = lp.col_names_[col];
1531-
if (have_integrality) lp.integrality_[new_num_col] = lp.integrality_[col];
1532-
new_num_col++;
1533-
}
1534-
if (keep_to_col >= col_dim - 1) break;
1535-
}
1536-
lp.col_cost_.resize(new_num_col);
1537-
lp.col_lower_.resize(new_num_col);
1538-
lp.col_upper_.resize(new_num_col);
1539-
if (have_names) lp.col_names_.resize(new_num_col);
1540-
}
1541-
1542-
void deleteLpRows(HighsLp& lp, const HighsIndexCollection& index_collection) {
1543-
HighsInt new_num_row;
1544-
deleteRowsFromLpVectors(lp, new_num_row, index_collection);
1545-
lp.a_matrix_.deleteRows(index_collection);
1546-
lp.num_row_ = new_num_row;
1547-
}
1548-
1549-
void deleteRowsFromLpVectors(HighsLp& lp, HighsInt& new_num_row,
1550-
const HighsIndexCollection& index_collection) {
1551-
assert(ok(index_collection));
1552-
HighsInt from_k;
1553-
HighsInt to_k;
1554-
limits(index_collection, from_k, to_k);
1555-
// Initialise new_num_row in case none is removed due to from_k > to_k
1556-
new_num_row = lp.num_row_;
1557-
if (from_k > to_k) return;
1558-
1559-
HighsInt delete_from_row;
1560-
HighsInt delete_to_row;
1561-
HighsInt keep_from_row;
1562-
HighsInt keep_to_row = -1;
1563-
HighsInt current_set_entry = 0;
1564-
1565-
HighsInt row_dim = lp.num_row_;
1566-
new_num_row = 0;
1567-
bool have_names = (HighsInt)lp.row_names_.size() > 0;
1568-
for (HighsInt k = from_k; k <= to_k; k++) {
1569-
updateOutInIndex(index_collection, delete_from_row, delete_to_row,
1570-
keep_from_row, keep_to_row, current_set_entry);
1571-
if (k == from_k) {
1572-
// Account for the initial rows being kept
1573-
new_num_row = delete_from_row;
1574-
}
1575-
if (delete_to_row >= row_dim - 1) break;
1576-
assert(delete_to_row < row_dim);
1577-
for (HighsInt row = keep_from_row; row <= keep_to_row; row++) {
1578-
lp.row_lower_[new_num_row] = lp.row_lower_[row];
1579-
lp.row_upper_[new_num_row] = lp.row_upper_[row];
1580-
if (have_names) lp.row_names_[new_num_row] = lp.row_names_[row];
1581-
new_num_row++;
1582-
}
1583-
if (keep_to_row >= row_dim - 1) break;
1584-
}
1585-
lp.row_lower_.resize(new_num_row);
1586-
lp.row_upper_.resize(new_num_row);
1587-
if (have_names) lp.row_names_.resize(new_num_row);
1588-
}
1589-
15901498
void deleteScale(vector<double>& scale,
15911499
const HighsIndexCollection& index_collection) {
15921500
assert(ok(index_collection));

src/lp_data/HighsLpUtils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ void appendRowsToLpVectors(HighsLp& lp, const HighsInt num_new_row,
9696
const vector<double>& rowLower,
9797
const vector<double>& rowUpper);
9898

99-
void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
100-
const HighsIndexCollection& index_collection);
101-
102-
void deleteLpRows(HighsLp& lp, const HighsIndexCollection& index_collection);
103-
104-
void deleteRowsFromLpVectors(HighsLp& lp, HighsInt& new_num_row,
105-
const HighsIndexCollection& index_collection);
106-
10799
void deleteScale(vector<double>& scale,
108100
const HighsIndexCollection& index_collection);
109101

0 commit comments

Comments
 (0)