Skip to content

Commit

Permalink
Moved deleteLpCols/Rows to HighsLp
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed May 25, 2024
1 parent b6172a8 commit 7bd0035
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/lp_data/HighsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void Highs::deleteRowsInterface(HighsIndexCollection& index_collection) {
// any rows have been removed, and if there is mask to be updated
HighsInt original_num_row = lp.num_row_;

deleteLpRows(lp, index_collection);
lp.deleteRows(index_collection);
assert(lp.num_row_ <= original_num_row);
if (lp.num_row_ < original_num_row) {
// Nontrivial deletion so reset the model_status and invalidate
Expand Down
47 changes: 45 additions & 2 deletions src/lp_data/HighsLp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,45 @@ void HighsLp::deleteColsFromVectors(
}

void HighsLp::deleteRowsFromVectors(
HighsInt& new_num_row, const HighsIndexCollection& index_collection) {}
HighsInt& new_num_row, const HighsIndexCollection& index_collection) {
assert(ok(index_collection));
HighsInt from_k;
HighsInt to_k;
limits(index_collection, from_k, to_k);
// Initialise new_num_row in case none is removed due to from_k > to_k
new_num_row = this->num_row_;
if (from_k > to_k) return;

HighsInt delete_from_row;
HighsInt delete_to_row;
HighsInt keep_from_row;
HighsInt keep_to_row = -1;
HighsInt current_set_entry = 0;

HighsInt row_dim = this->num_row_;
new_num_row = 0;
bool have_names = (HighsInt)this->row_names_.size() > 0;
for (HighsInt k = from_k; k <= to_k; k++) {
updateOutInIndex(index_collection, delete_from_row, delete_to_row,
keep_from_row, keep_to_row, current_set_entry);
if (k == from_k) {
// Account for the initial rows being kept
new_num_row = delete_from_row;
}
if (delete_to_row >= row_dim - 1) break;
assert(delete_to_row < row_dim);
for (HighsInt row = keep_from_row; row <= keep_to_row; row++) {
this->row_lower_[new_num_row] = this->row_lower_[row];
this->row_upper_[new_num_row] = this->row_upper_[row];
if (have_names) this->row_names_[new_num_row] = this->row_names_[row];
new_num_row++;
}
if (keep_to_row >= row_dim - 1) break;
}
this->row_lower_.resize(new_num_row);
this->row_upper_.resize(new_num_row);
if (have_names) this->row_names_.resize(new_num_row);
}

void HighsLp::deleteCols(const HighsIndexCollection& index_collection) {
HighsInt new_num_col;
Expand All @@ -447,7 +485,12 @@ void HighsLp::deleteCols(const HighsIndexCollection& index_collection) {
this->num_col_ = new_num_col;
}

void HighsLp::deleteRows(const HighsIndexCollection& index_collection) {}
void HighsLp::deleteRows(const HighsIndexCollection& index_collection) {
HighsInt new_num_row;
this->deleteRowsFromVectors(new_num_row, index_collection);
this->a_matrix_.deleteRows(index_collection);
this->num_row_ = new_num_row;
}

void HighsLp::unapplyMods() {
// Restore any non-semi types
Expand Down
92 changes: 0 additions & 92 deletions src/lp_data/HighsLpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,98 +1495,6 @@ void appendRowsToLpVectors(HighsLp& lp, const HighsInt num_new_row,
}
}

void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
const HighsIndexCollection& index_collection) {
assert(ok(index_collection));
HighsInt from_k;
HighsInt to_k;
limits(index_collection, from_k, to_k);
;
// Initialise new_num_col in case none is removed due to from_k > to_k
new_num_col = lp.num_col_;
if (from_k > to_k) return;

HighsInt delete_from_col;
HighsInt delete_to_col;
HighsInt keep_from_col;
HighsInt keep_to_col = -1;
HighsInt current_set_entry = 0;

HighsInt col_dim = lp.num_col_;
new_num_col = 0;
bool have_names = (lp.col_names_.size() != 0);
bool have_integrality = (lp.integrality_.size() != 0);
for (HighsInt k = from_k; k <= to_k; k++) {
updateOutInIndex(index_collection, delete_from_col, delete_to_col,
keep_from_col, keep_to_col, current_set_entry);
// Account for the initial columns being kept
if (k == from_k) new_num_col = delete_from_col;
if (delete_to_col >= col_dim - 1) break;
assert(delete_to_col < col_dim);
for (HighsInt col = keep_from_col; col <= keep_to_col; col++) {
lp.col_cost_[new_num_col] = lp.col_cost_[col];
lp.col_lower_[new_num_col] = lp.col_lower_[col];
lp.col_upper_[new_num_col] = lp.col_upper_[col];
if (have_names) lp.col_names_[new_num_col] = lp.col_names_[col];
if (have_integrality) lp.integrality_[new_num_col] = lp.integrality_[col];
new_num_col++;
}
if (keep_to_col >= col_dim - 1) break;
}
lp.col_cost_.resize(new_num_col);
lp.col_lower_.resize(new_num_col);
lp.col_upper_.resize(new_num_col);
if (have_names) lp.col_names_.resize(new_num_col);
}

void deleteLpRows(HighsLp& lp, const HighsIndexCollection& index_collection) {
HighsInt new_num_row;
deleteRowsFromLpVectors(lp, new_num_row, index_collection);
lp.a_matrix_.deleteRows(index_collection);
lp.num_row_ = new_num_row;
}

void deleteRowsFromLpVectors(HighsLp& lp, HighsInt& new_num_row,
const HighsIndexCollection& index_collection) {
assert(ok(index_collection));
HighsInt from_k;
HighsInt to_k;
limits(index_collection, from_k, to_k);
// Initialise new_num_row in case none is removed due to from_k > to_k
new_num_row = lp.num_row_;
if (from_k > to_k) return;

HighsInt delete_from_row;
HighsInt delete_to_row;
HighsInt keep_from_row;
HighsInt keep_to_row = -1;
HighsInt current_set_entry = 0;

HighsInt row_dim = lp.num_row_;
new_num_row = 0;
bool have_names = (HighsInt)lp.row_names_.size() > 0;
for (HighsInt k = from_k; k <= to_k; k++) {
updateOutInIndex(index_collection, delete_from_row, delete_to_row,
keep_from_row, keep_to_row, current_set_entry);
if (k == from_k) {
// Account for the initial rows being kept
new_num_row = delete_from_row;
}
if (delete_to_row >= row_dim - 1) break;
assert(delete_to_row < row_dim);
for (HighsInt row = keep_from_row; row <= keep_to_row; row++) {
lp.row_lower_[new_num_row] = lp.row_lower_[row];
lp.row_upper_[new_num_row] = lp.row_upper_[row];
if (have_names) lp.row_names_[new_num_row] = lp.row_names_[row];
new_num_row++;
}
if (keep_to_row >= row_dim - 1) break;
}
lp.row_lower_.resize(new_num_row);
lp.row_upper_.resize(new_num_row);
if (have_names) lp.row_names_.resize(new_num_row);
}

void deleteScale(vector<double>& scale,
const HighsIndexCollection& index_collection) {
assert(ok(index_collection));
Expand Down
8 changes: 0 additions & 8 deletions src/lp_data/HighsLpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ void appendRowsToLpVectors(HighsLp& lp, const HighsInt num_new_row,
const vector<double>& rowLower,
const vector<double>& rowUpper);

void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
const HighsIndexCollection& index_collection);

void deleteLpRows(HighsLp& lp, const HighsIndexCollection& index_collection);

void deleteRowsFromLpVectors(HighsLp& lp, HighsInt& new_num_row,
const HighsIndexCollection& index_collection);

void deleteScale(vector<double>& scale,
const HighsIndexCollection& index_collection);

Expand Down

0 comments on commit 7bd0035

Please sign in to comment.