Skip to content

Commit b6172a8

Browse files
committed
Now casting 1 to HighsInt in std::max
1 parent 79666d0 commit b6172a8

File tree

6 files changed

+65
-12
lines changed

6 files changed

+65
-12
lines changed

check/TestQpSolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ TEST_CASE("test-qp-delete-col", "[qpsolver]") {
812812
std::vector<double> hessian_col(dim);
813813
for (HighsInt iCol = 0; iCol < dim; iCol++) {
814814
hessian_col.assign(dim, 0);
815-
HighsInt kmax = std::max(1, (dim - iCol) / 3);
815+
HighsInt kmax = std::max(HighsInt(1), (dim - iCol) / 3);
816816
hessian_col[iCol] = dim * iCol + iCol;
817817
if (iCol < dim - 1) {
818818
for (HighsInt k = 0; k < kmax; k++) {
@@ -842,7 +842,7 @@ TEST_CASE("test-qp-delete-col", "[qpsolver]") {
842842
std::vector<HighsInt> mask;
843843
mask.assign(dim, 0);
844844

845-
HighsInt kmax = std::max(1, dim / 3);
845+
HighsInt kmax = std::max(HighsInt(1), dim / 3);
846846
for (HighsInt k = 0; k < kmax; k++) {
847847
HighsInt iRow = random.integer(dim);
848848
assert(iRow >= 0);

src/lp_data/HighsInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void Highs::deleteColsInterface(HighsIndexCollection& index_collection) {
366366
// any columns have been removed, and if there is mask to be updated
367367
HighsInt original_num_col = lp.num_col_;
368368

369-
deleteLpCols(lp, index_collection);
369+
lp.deleteCols(index_collection);
370370
model_.hessian_.deleteCols(index_collection);
371371
assert(lp.num_col_ <= original_num_col);
372372
if (lp.num_col_ < original_num_col) {

src/lp_data/HighsLp.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,62 @@ void HighsLp::addRowNames(const std::string name, const HighsInt num_new_row) {
393393
}
394394
}
395395

396+
void HighsLp::deleteColsFromVectors(
397+
HighsInt& new_num_col, const HighsIndexCollection& index_collection) {
398+
assert(ok(index_collection));
399+
HighsInt from_k;
400+
HighsInt to_k;
401+
limits(index_collection, from_k, to_k);
402+
// Initialise new_num_col in case none is removed due to from_k > to_k
403+
new_num_col = this->num_col_;
404+
if (from_k > to_k) return;
405+
406+
HighsInt delete_from_col;
407+
HighsInt delete_to_col;
408+
HighsInt keep_from_col;
409+
HighsInt keep_to_col = -1;
410+
HighsInt current_set_entry = 0;
411+
412+
HighsInt col_dim = this->num_col_;
413+
new_num_col = 0;
414+
bool have_names = (this->col_names_.size() != 0);
415+
bool have_integrality = (this->integrality_.size() != 0);
416+
for (HighsInt k = from_k; k <= to_k; k++) {
417+
updateOutInIndex(index_collection, delete_from_col, delete_to_col,
418+
keep_from_col, keep_to_col, current_set_entry);
419+
// Account for the initial columns being kept
420+
if (k == from_k) new_num_col = delete_from_col;
421+
if (delete_to_col >= col_dim - 1) break;
422+
assert(delete_to_col < col_dim);
423+
for (HighsInt col = keep_from_col; col <= keep_to_col; col++) {
424+
this->col_cost_[new_num_col] = this->col_cost_[col];
425+
this->col_lower_[new_num_col] = this->col_lower_[col];
426+
this->col_upper_[new_num_col] = this->col_upper_[col];
427+
if (have_names) this->col_names_[new_num_col] = this->col_names_[col];
428+
if (have_integrality)
429+
this->integrality_[new_num_col] = this->integrality_[col];
430+
new_num_col++;
431+
}
432+
if (keep_to_col >= col_dim - 1) break;
433+
}
434+
this->col_cost_.resize(new_num_col);
435+
this->col_lower_.resize(new_num_col);
436+
this->col_upper_.resize(new_num_col);
437+
if (have_names) this->col_names_.resize(new_num_col);
438+
}
439+
440+
void HighsLp::deleteRowsFromVectors(
441+
HighsInt& new_num_row, const HighsIndexCollection& index_collection) {}
442+
443+
void HighsLp::deleteCols(const HighsIndexCollection& index_collection) {
444+
HighsInt new_num_col;
445+
this->deleteColsFromVectors(new_num_col, index_collection);
446+
this->a_matrix_.deleteCols(index_collection);
447+
this->num_col_ = new_num_col;
448+
}
449+
450+
void HighsLp::deleteRows(const HighsIndexCollection& index_collection) {}
451+
396452
void HighsLp::unapplyMods() {
397453
// Restore any non-semi types
398454
const HighsInt num_non_semi = this->mods_.save_non_semi_variable_index.size();

src/lp_data/HighsLp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class HighsLp {
8888
void exactResize();
8989
void addColNames(const std::string name, const HighsInt num_new_col = 1);
9090
void addRowNames(const std::string name, const HighsInt num_new_row = 1);
91+
void deleteColsFromVectors(HighsInt& new_num_col,
92+
const HighsIndexCollection& index_collection);
93+
void deleteRowsFromVectors(HighsInt& new_num_row,
94+
const HighsIndexCollection& index_collection);
95+
void deleteCols(const HighsIndexCollection& index_collection);
96+
void deleteRows(const HighsIndexCollection& index_collection);
9197
void unapplyMods();
9298
void clear();
9399
};

src/lp_data/HighsLpUtils.cpp

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

1498-
void deleteLpCols(HighsLp& lp, const HighsIndexCollection& index_collection) {
1499-
HighsInt new_num_col;
1500-
deleteColsFromLpVectors(lp, new_num_col, index_collection);
1501-
lp.a_matrix_.deleteCols(index_collection);
1502-
lp.num_col_ = new_num_col;
1503-
}
1504-
15051498
void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
15061499
const HighsIndexCollection& index_collection) {
15071500
assert(ok(index_collection));

src/lp_data/HighsLpUtils.h

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

99-
void deleteLpCols(HighsLp& lp, const HighsIndexCollection& index_collection);
100-
10199
void deleteColsFromLpVectors(HighsLp& lp, HighsInt& new_num_col,
102100
const HighsIndexCollection& index_collection);
103101

0 commit comments

Comments
 (0)