From fdbf1ff6d8ecee01b2c2c199e467f96efd0ba412 Mon Sep 17 00:00:00 2001 From: JAJHall Date: Thu, 9 Jan 2025 16:24:57 +0000 Subject: [PATCH] Formatted --- check/Avgas.cpp | 3 +- check/TestLpModification.cpp | 65 ++++---- src/Highs.h | 22 +-- src/lp_data/HighsInterface.cpp | 262 +++------------------------------ src/lp_data/HighsLpUtils.cpp | 127 ++++++++-------- src/lp_data/HighsLpUtils.h | 47 +++--- 6 files changed, 144 insertions(+), 382 deletions(-) diff --git a/check/Avgas.cpp b/check/Avgas.cpp index 0ea8234de0..9e7d21d5f4 100644 --- a/check/Avgas.cpp +++ b/check/Avgas.cpp @@ -11,11 +11,12 @@ * @brief Utilities for tests with AVGAS */ #include "Avgas.h" -#include "lp_data/HConst.h" #include #include // For printf +#include "lp_data/HConst.h" + const bool dev_run = false; void Avgas::row(HighsInt row, HighsInt& num_row, HighsInt& num_row_nz, diff --git a/check/TestLpModification.cpp b/check/TestLpModification.cpp index 67e6a563e5..eb358633ab 100644 --- a/check/TestLpModification.cpp +++ b/check/TestLpModification.cpp @@ -5,8 +5,8 @@ #include "catch.hpp" #include "lp_data/HighsLpUtils.h" #include "util/HighsRandom.h" -#include "util/HighsUtils.h" #include "util/HighsTimer.h" +#include "util/HighsUtils.h" const bool dev_run = false; // const double inf = kHighsInf; @@ -1982,71 +1982,73 @@ TEST_CASE("row-wise-get-row-time", "[highs_data]") { return_status = h.addRow(0.0, kHighsInf, 2, index, value); } std::vector lower; - std::vector upper; + std::vector upper; HighsInt num_row = 0; HighsInt num_nz = 0; std::vector matrix_start; std::vector matrix_index; std::vector matrix_value; - assert(h.getNumRow() == 2*dim-2); + assert(h.getNumRow() == 2 * dim - 2); for (HighsInt i = 0; i < dim - 1; i++) { return_status = h.getRows(i, i, num_row, lower.data(), upper.data(), - num_nz, nullptr, nullptr, nullptr); + num_nz, nullptr, nullptr, nullptr); REQUIRE(num_row == 1); REQUIRE(num_nz == 2); matrix_start.resize(num_row); matrix_index.resize(num_nz); matrix_value.resize(num_nz); return_status = h.getRows(i, i, num_row, lower.data(), upper.data(), - num_nz, matrix_start.data(), matrix_index.data(), - matrix_value.data()); + num_nz, matrix_start.data(), + matrix_index.data(), matrix_value.data()); REQUIRE(matrix_start[0] == 0); - REQUIRE(matrix_index[0] == i+1); + REQUIRE(matrix_index[0] == i + 1); REQUIRE(matrix_index[1] == i); REQUIRE(matrix_value[0] == 1); REQUIRE(matrix_value[1] == 2); - std::vector set = {i, 2*dim-3}; - return_status = h.getRows(2, set.data(), num_row, lower.data(), upper.data(), - num_nz, nullptr, nullptr, nullptr); + std::vector set = {i, 2 * dim - 3}; + return_status = + h.getRows(2, set.data(), num_row, lower.data(), upper.data(), num_nz, + nullptr, nullptr, nullptr); REQUIRE(num_row == 2); REQUIRE(num_nz == 4); matrix_start.resize(num_row); matrix_index.resize(num_nz); matrix_value.resize(num_nz); - return_status = h.getRows(2, set.data(), num_row, lower.data(), upper.data(), - num_nz, matrix_start.data(), matrix_index.data(), - matrix_value.data()); + return_status = h.getRows(2, set.data(), num_row, lower.data(), + upper.data(), num_nz, matrix_start.data(), + matrix_index.data(), matrix_value.data()); REQUIRE(matrix_start[0] == 0); REQUIRE(matrix_start[1] == 2); - REQUIRE(matrix_index[0] == i+1); + REQUIRE(matrix_index[0] == i + 1); REQUIRE(matrix_index[1] == i); - REQUIRE(matrix_index[2] == dim-1); - REQUIRE(matrix_index[3] == dim-2); + REQUIRE(matrix_index[2] == dim - 1); + REQUIRE(matrix_index[3] == dim - 2); REQUIRE(matrix_value[0] == 1); REQUIRE(matrix_value[1] == 2); REQUIRE(matrix_value[2] == 1); REQUIRE(matrix_value[3] == 2); std::vector mask; - mask.assign(2*(dim-1), 0); + mask.assign(2 * (dim - 1), 0); mask[0] = 1; - mask[dim-1+i] = 1; - return_status = h.getRows(mask.data(), num_row, lower.data(), upper.data(), - num_nz, nullptr, nullptr, nullptr); + mask[dim - 1 + i] = 1; + return_status = + h.getRows(mask.data(), num_row, lower.data(), upper.data(), num_nz, + nullptr, nullptr, nullptr); REQUIRE(num_row == 2); REQUIRE(num_nz == 4); matrix_start.resize(num_row); matrix_index.resize(num_nz); matrix_value.resize(num_nz); - return_status = h.getRows(mask.data(), num_row, lower.data(), upper.data(), - num_nz, matrix_start.data(), matrix_index.data(), - matrix_value.data()); + return_status = h.getRows(mask.data(), num_row, lower.data(), + upper.data(), num_nz, matrix_start.data(), + matrix_index.data(), matrix_value.data()); REQUIRE(matrix_start[0] == 0); REQUIRE(matrix_start[1] == 2); REQUIRE(matrix_index[0] == 1); REQUIRE(matrix_index[1] == 0); - REQUIRE(matrix_index[2] == i+1); + REQUIRE(matrix_index[2] == i + 1); REQUIRE(matrix_index[3] == i); REQUIRE(matrix_value[0] == 1); REQUIRE(matrix_value[1] == 2); @@ -2058,7 +2060,6 @@ TEST_CASE("row-wise-get-row-time", "[highs_data]") { h.clear(); dim *= 2; } - } TEST_CASE("row-wise-get-row-avgas", "[highs_data]") { @@ -2070,15 +2071,16 @@ TEST_CASE("row-wise-get-row-avgas", "[highs_data]") { std::vector colCost; std::vector colLower; std::vector colUpper; - std::vector Astart; - std::vector Aindex; - std::vector Avalue; + std::vector Astart; + std::vector Aindex; + std::vector Avalue; for (HighsInt col = 0; col < avgas_num_col; col++) { HighsInt num_col = 0; HighsInt num_col_nz = 0; avgas.col(col, num_col, num_col_nz, colCost, colLower, colUpper, Astart, Aindex, Avalue); - REQUIRE(h.addCol(colCost[0], colLower[0], colUpper[0], 0, nullptr, nullptr) == HighsStatus::kOk); + REQUIRE(h.addCol(colCost[0], colLower[0], colUpper[0], 0, nullptr, + nullptr) == HighsStatus::kOk); } std::vector rowLower; @@ -2092,8 +2094,7 @@ TEST_CASE("row-wise-get-row-avgas", "[highs_data]") { HighsInt num_row_nz = 0; avgas.row(row, num_row, num_row_nz, rowLower, rowUpper, ARstart, ARindex, ARvalue); - REQUIRE(h.addRow(rowLower[0], rowUpper[0], num_row_nz, ARindex.data(), - ARvalue.data()) == HighsStatus::kOk); + REQUIRE(h.addRow(rowLower[0], rowUpper[0], num_row_nz, ARindex.data(), + ARvalue.data()) == HighsStatus::kOk); } - } diff --git a/src/Highs.h b/src/Highs.h index 5901c2916d..c42203f761 100644 --- a/src/Highs.h +++ b/src/Highs.h @@ -1556,25 +1556,13 @@ class Highs { void getColsInterface(const HighsIndexCollection& index_collection, HighsInt& num_col, double* cost, double* lower, - double* upper, HighsInt& num_nz, - HighsInt* start, HighsInt* index, - double* value); - - void getColsInterfaceArch(const HighsIndexCollection& index_collection, - HighsInt& num_col, double* cost, double* lower, - double* upper, HighsInt& num_nz, - HighsInt* start, HighsInt* index, - double* value); + double* upper, HighsInt& num_nz, HighsInt* start, + HighsInt* index, double* value); void getRowsInterface(const HighsIndexCollection& index_collection, - HighsInt& num_row, double* lower, - double* upper, HighsInt& num_nz, - HighsInt* start, HighsInt* index, double* value); - - void getRowsInterfaceArch(const HighsIndexCollection& index_collection, - HighsInt& num_row, double* row_lower, double* row_upper, - HighsInt& num_nz, HighsInt* row_matrix_start, - HighsInt* row_matrix_index, double* row_matrix_value); + HighsInt& num_row, double* lower, double* upper, + HighsInt& num_nz, HighsInt* start, HighsInt* index, + double* value); void getCoefficientInterface(const HighsInt ext_row, const HighsInt ext_col, double& value); diff --git a/src/lp_data/HighsInterface.cpp b/src/lp_data/HighsInterface.cpp index f1f6067690..e522e46db9 100644 --- a/src/lp_data/HighsInterface.cpp +++ b/src/lp_data/HighsInterface.cpp @@ -667,259 +667,35 @@ void Highs::deleteRowsInterface(HighsIndexCollection& index_collection) { void Highs::getColsInterface(const HighsIndexCollection& index_collection, HighsInt& num_col, double* cost, double* lower, - double* upper, HighsInt& num_nz, - HighsInt* start, HighsInt* index, double* value) { + double* upper, HighsInt& num_nz, HighsInt* start, + HighsInt* index, double* value) { const HighsLp& lp = model_.lp_; if (lp.a_matrix_.isColwise()) { - printf("Calling getSubVectors from getColsInterface (Interval = %d; Set = %d; Mask = %d)\n", - index_collection.is_interval_, index_collection.is_set_, index_collection.is_mask_); - getSubVectors(index_collection, - lp.num_col_, - lp.col_cost_.data(), lp.col_lower_.data(), lp.col_upper_.data(), - lp.a_matrix_, - num_col, - cost, lower, upper, - num_nz, start, index, value); + getSubVectors(index_collection, lp.num_col_, lp.col_cost_.data(), + lp.col_lower_.data(), lp.col_upper_.data(), lp.a_matrix_, + num_col, cost, lower, upper, num_nz, start, index, value); } else { - printf("Calling getSubVectorsTranspose from getColsInterface (Interval = %d; Set = %d; Mask = %d)\n", - index_collection.is_interval_, index_collection.is_set_, index_collection.is_mask_); - getSubVectorsTranspose(index_collection, - lp.num_col_, - lp.col_cost_.data(), lp.col_lower_.data(), lp.col_upper_.data(), - lp.a_matrix_, - num_col, - cost, lower, upper, - num_nz, start, index, value); - } -} - -void Highs::getColsInterfaceArch(const HighsIndexCollection& index_collection, - HighsInt& get_num_col, double* col_cost, - double* col_lower, double* col_upper, - HighsInt& get_num_nz, HighsInt* col_matrix_start, - HighsInt* col_matrix_index, - double* col_matrix_value) { - HighsLp& lp = model_.lp_; - assert(ok(index_collection)); - lp.ensureColwise(); - HighsInt from_k; - HighsInt to_k; - limits(index_collection, from_k, to_k); - // Surely this is checked elsewhere - assert(0 <= from_k && to_k < lp.num_col_); - assert(from_k <= to_k); - HighsInt out_from_col; - HighsInt out_to_col; - HighsInt in_from_col; - HighsInt in_to_col = -1; - HighsInt current_set_entry = 0; - HighsInt col_dim = lp.num_col_; - get_num_col = 0; - get_num_nz = 0; - if (lp.a_matrix_.isColwise()) { - for (HighsInt k = from_k; k <= to_k; k++) { - updateOutInIndex(index_collection, out_from_col, out_to_col, in_from_col, - in_to_col, current_set_entry); - assert(out_to_col < col_dim); - assert(in_to_col < col_dim); - for (HighsInt iCol = out_from_col; iCol <= out_to_col; iCol++) { - if (col_cost != NULL) col_cost[get_num_col] = lp.col_cost_[iCol]; - if (col_lower != NULL) col_lower[get_num_col] = lp.col_lower_[iCol]; - if (col_upper != NULL) col_upper[get_num_col] = lp.col_upper_[iCol]; - if (col_matrix_start != NULL) - col_matrix_start[get_num_col] = get_num_nz + lp.a_matrix_.start_[iCol] - - lp.a_matrix_.start_[out_from_col]; - get_num_col++; - } - for (HighsInt iEl = lp.a_matrix_.start_[out_from_col]; - iEl < lp.a_matrix_.start_[out_to_col + 1]; iEl++) { - if (col_matrix_index != NULL) - col_matrix_index[get_num_nz] = lp.a_matrix_.index_[iEl]; - if (col_matrix_value != NULL) - col_matrix_value[get_num_nz] = lp.a_matrix_.value_[iEl]; - get_num_nz++; - } - if (out_to_col == col_dim - 1 || in_to_col == col_dim - 1) break; - } - } else { - assert(111==222); + getSubVectorsTranspose(index_collection, lp.num_col_, lp.col_cost_.data(), + lp.col_lower_.data(), lp.col_upper_.data(), + lp.a_matrix_, num_col, cost, lower, upper, num_nz, + start, index, value); } } void Highs::getRowsInterface(const HighsIndexCollection& index_collection, - HighsInt& num_row, double* lower, - double* upper, HighsInt& num_nz, - HighsInt* start, HighsInt* index, double* value) { + HighsInt& num_row, double* lower, double* upper, + HighsInt& num_nz, HighsInt* start, HighsInt* index, + double* value) { const HighsLp& lp = model_.lp_; if (lp.a_matrix_.isColwise()) { - printf("Calling getSubVectorsTranspose from getRowsInterface (Interval = %d; Set = %d; Mask = %d)\n", - index_collection.is_interval_, index_collection.is_set_, index_collection.is_mask_); - getSubVectorsTranspose(index_collection, - lp.num_row_, - nullptr, lp.row_lower_.data(), lp.row_upper_.data(), - lp.a_matrix_, - num_row, - nullptr, lower, upper, - num_nz, start, index, value); + getSubVectorsTranspose(index_collection, lp.num_row_, nullptr, + lp.row_lower_.data(), lp.row_upper_.data(), + lp.a_matrix_, num_row, nullptr, lower, upper, num_nz, + start, index, value); } else { - getSubVectors(index_collection, - lp.num_row_, - nullptr, lp.row_lower_.data(), lp.row_upper_.data(), - lp.a_matrix_, - num_row, - nullptr, lower, upper, - num_nz, start, index, value); - } -} - -void Highs::getRowsInterfaceArch(const HighsIndexCollection& index_collection, - HighsInt& get_num_row, double* row_lower, - double* row_upper, HighsInt& get_num_nz, - HighsInt* row_matrix_start, - HighsInt* row_matrix_index, - double* row_matrix_value) { - HighsLp& lp = model_.lp_; - assert(ok(index_collection)); - HighsInt from_k; - HighsInt to_k; - limits(index_collection, from_k, to_k); - // Surely this is checked elsewhere - assert(0 <= from_k && to_k < lp.num_row_); - assert(from_k <= to_k); - // "Out" means not in the set to be extracted - // "In" means in the set to be extracted - HighsInt out_from_row; - HighsInt out_to_row; - HighsInt in_from_row; - HighsInt in_to_row = -1; - HighsInt current_set_entry = 0; - HighsInt row_dim = lp.num_row_; - // Set up a row mask so that entries to be got from the column-wise - // matrix can be identified and have their correct row index. - vector new_index; - new_index.resize(lp.num_row_); - - get_num_row = 0; - get_num_nz = 0; - if (lp.a_matrix_.isColwise()) { - if (!index_collection.is_mask_) { - out_to_row = -1; - current_set_entry = 0; - for (HighsInt k = from_k; k <= to_k; k++) { - updateOutInIndex(index_collection, in_from_row, in_to_row, out_from_row, - out_to_row, current_set_entry); - if (k == from_k) { - // Account for any initial rows not being extracted - for (HighsInt iRow = 0; iRow < in_from_row; iRow++) { - new_index[iRow] = -1; - } - } - for (HighsInt iRow = in_from_row; iRow <= in_to_row; iRow++) { - new_index[iRow] = get_num_row; - get_num_row++; - } - for (HighsInt iRow = out_from_row; iRow <= out_to_row; iRow++) { - new_index[iRow] = -1; - } - if (out_to_row >= row_dim - 1) break; - } - } else { - for (HighsInt iRow = 0; iRow < lp.num_row_; iRow++) { - if (index_collection.mask_[iRow]) { - new_index[iRow] = get_num_row; - get_num_row++; - } else { - new_index[iRow] = -1; - } - } - } - - // Bail out if no rows are to be extracted - if (get_num_row == 0) return; - - for (HighsInt iRow = 0; iRow < lp.num_row_; iRow++) { - HighsInt new_iRow = new_index[iRow]; - if (new_iRow >= 0) { - assert(new_iRow < get_num_row); - if (row_lower != NULL) row_lower[new_iRow] = lp.row_lower_[iRow]; - if (row_upper != NULL) row_upper[new_iRow] = lp.row_upper_[iRow]; - } - } - const bool extract_start = row_matrix_start != NULL; - const bool extract_index = row_matrix_index != NULL; - const bool extract_value = row_matrix_value != NULL; - const bool extract_matrix = extract_index || extract_value; - // Allocate an array of lengths for the row-wise matrix to be - // extracted: necessary even if just the number of nonzeros is - // required - vector row_matrix_length; - row_matrix_length.assign(get_num_row, 0); - // Identify the lengths of the rows in the row-wise matrix to be extracted - for (HighsInt col = 0; col < lp.num_col_; col++) { - for (HighsInt iEl = lp.a_matrix_.start_[col]; - iEl < lp.a_matrix_.start_[col + 1]; iEl++) { - HighsInt iRow = lp.a_matrix_.index_[iEl]; - HighsInt new_iRow = new_index[iRow]; - if (new_iRow >= 0) row_matrix_length[new_iRow]++; - } - } - if (!extract_start) { - // bail out if no matrix starts are to be extracted, but only after - // computing the number of nonzeros - for (HighsInt iRow = 0; iRow < get_num_row; iRow++) - get_num_nz += row_matrix_length[iRow]; - return; - } - // Allocate an array of lengths for the row-wise matrix to be extracted - row_matrix_start[0] = 0; - for (HighsInt iRow = 0; iRow < get_num_row - 1; iRow++) { - row_matrix_start[iRow + 1] = - row_matrix_start[iRow] + row_matrix_length[iRow]; - row_matrix_length[iRow] = row_matrix_start[iRow]; - } - HighsInt iRow = get_num_row - 1; - get_num_nz = row_matrix_start[iRow] + row_matrix_length[iRow]; - // Bail out if matrix indices and values are not required - if (!extract_matrix) return; - row_matrix_length[iRow] = row_matrix_start[iRow]; - // Fill the row-wise matrix with indices and values - for (HighsInt col = 0; col < lp.num_col_; col++) { - for (HighsInt iEl = lp.a_matrix_.start_[col]; - iEl < lp.a_matrix_.start_[col + 1]; iEl++) { - HighsInt iRow = lp.a_matrix_.index_[iEl]; - HighsInt new_iRow = new_index[iRow]; - if (new_iRow >= 0) { - HighsInt row_iEl = row_matrix_length[new_iRow]; - if (extract_index) row_matrix_index[row_iEl] = col; - if (extract_value) row_matrix_value[row_iEl] = lp.a_matrix_.value_[iEl]; - row_matrix_length[new_iRow]++; - } - } - } - } else { - for (HighsInt k = from_k; k <= to_k; k++) { - updateOutInIndex(index_collection, out_from_row, out_to_row, in_from_row, - in_to_row, current_set_entry); - assert(out_to_row < row_dim); - assert(in_to_row < row_dim); - for (HighsInt iRow = out_from_row; iRow <= out_to_row; iRow++) { - if (row_lower != NULL) row_lower[get_num_row] = lp.row_lower_[iRow]; - if (row_upper != NULL) row_upper[get_num_row] = lp.row_upper_[iRow]; - if (row_matrix_start != NULL) - row_matrix_start[get_num_row] = get_num_nz + lp.a_matrix_.start_[iRow] - - lp.a_matrix_.start_[out_from_row]; - get_num_row++; - } - for (HighsInt iEl = lp.a_matrix_.start_[out_from_row]; - iEl < lp.a_matrix_.start_[out_to_row + 1]; iEl++) { - if (row_matrix_index != NULL) - row_matrix_index[get_num_nz] = lp.a_matrix_.index_[iEl]; - if (row_matrix_value != NULL) - row_matrix_value[get_num_nz] = lp.a_matrix_.value_[iEl]; - get_num_nz++; - } - if (out_to_row == row_dim - 1 || in_to_row == row_dim - 1) break; - } + getSubVectors(index_collection, lp.num_row_, nullptr, lp.row_lower_.data(), + lp.row_upper_.data(), lp.a_matrix_, num_row, nullptr, lower, + upper, num_nz, start, index, value); } } diff --git a/src/lp_data/HighsLpUtils.cpp b/src/lp_data/HighsLpUtils.cpp index ac2f647f13..266938f467 100644 --- a/src/lp_data/HighsLpUtils.cpp +++ b/src/lp_data/HighsLpUtils.cpp @@ -3079,15 +3079,13 @@ void removeRowsOfCountOne(const HighsLogOptions& log_options, HighsLp& lp) { } void getSubVectors(const HighsIndexCollection& index_collection, - const HighsInt data_dim, - const double* data0, - const double* data1, - const double* data2, - const HighsSparseMatrix matrix, - HighsInt& num_sub_vector, double* sub_vector_data0, double* sub_vector_data1, - double* sub_vector_data2, HighsInt& sub_matrix_num_nz, - HighsInt* sub_matrix_start, HighsInt* sub_matrix_index, - double* sub_matrix_value) { + const HighsInt data_dim, const double* data0, + const double* data1, const double* data2, + const HighsSparseMatrix matrix, HighsInt& num_sub_vector, + double* sub_vector_data0, double* sub_vector_data1, + double* sub_vector_data2, HighsInt& sub_matrix_num_nz, + HighsInt* sub_matrix_start, HighsInt* sub_matrix_index, + double* sub_matrix_value) { // Ensure that if there's no data0 then it's not required in the // sub-vector if (data0 == nullptr) assert(sub_vector_data0 == nullptr); @@ -3106,25 +3104,30 @@ void getSubVectors(const HighsIndexCollection& index_collection, num_sub_vector = 0; sub_matrix_num_nz = 0; for (HighsInt k = from_k; k <= to_k; k++) { - updateOutInIndex(index_collection, out_from_vector, out_to_vector, in_from_vector, - in_to_vector, current_set_entry); + updateOutInIndex(index_collection, out_from_vector, out_to_vector, + in_from_vector, in_to_vector, current_set_entry); assert(out_to_vector < data_dim); assert(in_to_vector < data_dim); - for (HighsInt iVector = out_from_vector; iVector <= out_to_vector; iVector++) { - if (sub_vector_data0 != nullptr) sub_vector_data0[num_sub_vector] = data0[iVector]; - if (sub_vector_data1 != nullptr) sub_vector_data1[num_sub_vector] = data1[iVector]; - if (sub_vector_data2 != nullptr) sub_vector_data2[num_sub_vector] = data2[iVector]; + for (HighsInt iVector = out_from_vector; iVector <= out_to_vector; + iVector++) { + if (sub_vector_data0 != nullptr) + sub_vector_data0[num_sub_vector] = data0[iVector]; + if (sub_vector_data1 != nullptr) + sub_vector_data1[num_sub_vector] = data1[iVector]; + if (sub_vector_data2 != nullptr) + sub_vector_data2[num_sub_vector] = data2[iVector]; if (sub_matrix_start != nullptr) - sub_matrix_start[num_sub_vector] = sub_matrix_num_nz + matrix.start_[iVector] - - matrix.start_[out_from_vector]; + sub_matrix_start[num_sub_vector] = sub_matrix_num_nz + + matrix.start_[iVector] - + matrix.start_[out_from_vector]; num_sub_vector++; } for (HighsInt iEl = matrix.start_[out_from_vector]; - iEl < matrix.start_[out_to_vector + 1]; iEl++) { + iEl < matrix.start_[out_to_vector + 1]; iEl++) { if (sub_matrix_index != nullptr) - sub_matrix_index[sub_matrix_num_nz] = matrix.index_[iEl]; + sub_matrix_index[sub_matrix_num_nz] = matrix.index_[iEl]; if (sub_matrix_value != nullptr) - sub_matrix_value[sub_matrix_num_nz] = matrix.value_[iEl]; + sub_matrix_value[sub_matrix_num_nz] = matrix.value_[iEl]; sub_matrix_num_nz++; } if (out_to_vector == data_dim - 1 || in_to_vector == data_dim - 1) break; @@ -3132,19 +3135,15 @@ void getSubVectors(const HighsIndexCollection& index_collection, } void getSubVectorsTranspose(const HighsIndexCollection& index_collection, - const HighsInt data_dim, - const double* data0, - const double* data1, - const double* data2, - const HighsSparseMatrix matrix, - HighsInt& num_sub_vector, - double* sub_vector_data0, - double* sub_vector_data1, - double* sub_vector_data2, - HighsInt& sub_matrix_num_nz, - HighsInt* sub_matrix_start, - HighsInt* sub_matrix_index, - double* sub_matrix_value) { + const HighsInt data_dim, const double* data0, + const double* data1, const double* data2, + const HighsSparseMatrix matrix, + HighsInt& num_sub_vector, double* sub_vector_data0, + double* sub_vector_data1, double* sub_vector_data2, + HighsInt& sub_matrix_num_nz, + HighsInt* sub_matrix_start, + HighsInt* sub_matrix_index, + double* sub_matrix_value) { // Ensure that if there's no data0 then it's not required in the // sub-vector if (data0 == nullptr) assert(sub_vector_data0 == nullptr); @@ -3173,44 +3172,49 @@ void getSubVectorsTranspose(const HighsIndexCollection& index_collection, out_to_vector = -1; current_set_entry = 0; for (HighsInt k = from_k; k <= to_k; k++) { - updateOutInIndex(index_collection, in_from_vector, in_to_vector, out_from_vector, - out_to_vector, current_set_entry); + updateOutInIndex(index_collection, in_from_vector, in_to_vector, + out_from_vector, out_to_vector, current_set_entry); if (k == from_k) { - // Account for any initial vectors not being extracted - for (HighsInt iVector = 0; iVector < in_from_vector; iVector++) { - new_index[iVector] = -1; - } + // Account for any initial vectors not being extracted + for (HighsInt iVector = 0; iVector < in_from_vector; iVector++) { + new_index[iVector] = -1; + } } - for (HighsInt iVector = in_from_vector; iVector <= in_to_vector; iVector++) { - new_index[iVector] = num_sub_vector; - num_sub_vector++; + for (HighsInt iVector = in_from_vector; iVector <= in_to_vector; + iVector++) { + new_index[iVector] = num_sub_vector; + num_sub_vector++; } - for (HighsInt iVector = out_from_vector; iVector <= out_to_vector; iVector++) { - new_index[iVector] = -1; + for (HighsInt iVector = out_from_vector; iVector <= out_to_vector; + iVector++) { + new_index[iVector] = -1; } if (out_to_vector >= data_dim - 1) break; } } else { for (HighsInt iVector = 0; iVector < data_dim; iVector++) { if (index_collection.mask_[iVector]) { - new_index[iVector] = num_sub_vector; - num_sub_vector++; + new_index[iVector] = num_sub_vector; + num_sub_vector++; } else { - new_index[iVector] = -1; + new_index[iVector] = -1; } } } - + // Bail out if no vectors are to be extracted if (num_sub_vector == 0) return; - + for (HighsInt iVector = 0; iVector < data_dim; iVector++) { HighsInt new_iVector = new_index[iVector]; if (new_iVector >= 0) { assert(new_iVector < num_sub_vector); - if (sub_vector_data0 != NULL) sub_vector_data0[new_iVector] = data0[iVector]; - if (sub_vector_data1 != NULL) sub_vector_data1[new_iVector] = data1[iVector]; - if (sub_vector_data2 != NULL) sub_vector_data2[new_iVector] = data2[iVector]; + if (sub_vector_data0 != NULL) + sub_vector_data0[new_iVector] = data0[iVector]; + if (sub_vector_data1 != NULL) + sub_vector_data1[new_iVector] = data1[iVector]; + if (sub_vector_data2 != NULL) + sub_vector_data2[new_iVector] = data2[iVector]; } } const bool extract_start = sub_matrix_start != NULL; @@ -3223,9 +3227,10 @@ void getSubVectorsTranspose(const HighsIndexCollection& index_collection, vector sub_matrix_length; sub_matrix_length.assign(num_sub_vector, 0); // Identify the lengths of the vectors in the sub-matrix to be extracted - HighsInt num_vector = matrix.start_.size()-1; + HighsInt num_vector = matrix.start_.size() - 1; for (HighsInt vector = 0; vector < num_vector; vector++) { - for (HighsInt iEl = matrix.start_[vector]; iEl < matrix.start_[vector + 1]; iEl++) { + for (HighsInt iEl = matrix.start_[vector]; iEl < matrix.start_[vector + 1]; + iEl++) { HighsInt iVector = matrix.index_[iEl]; HighsInt new_iVector = new_index[iVector]; if (new_iVector >= 0) sub_matrix_length[new_iVector]++; @@ -3242,7 +3247,7 @@ void getSubVectorsTranspose(const HighsIndexCollection& index_collection, sub_matrix_start[0] = 0; for (HighsInt iVector = 0; iVector < num_sub_vector - 1; iVector++) { sub_matrix_start[iVector + 1] = - sub_matrix_start[iVector] + sub_matrix_length[iVector]; + sub_matrix_start[iVector] + sub_matrix_length[iVector]; sub_matrix_length[iVector] = sub_matrix_start[iVector]; } HighsInt iVector = num_sub_vector - 1; @@ -3252,15 +3257,15 @@ void getSubVectorsTranspose(const HighsIndexCollection& index_collection, sub_matrix_length[iVector] = sub_matrix_start[iVector]; // Fill the row-wise matrix with indices and values for (HighsInt vector = 0; vector < num_vector; vector++) { - for (HighsInt iEl = matrix.start_[vector]; - iEl < matrix.start_[vector + 1]; iEl++) { + for (HighsInt iEl = matrix.start_[vector]; iEl < matrix.start_[vector + 1]; + iEl++) { HighsInt iVector = matrix.index_[iEl]; HighsInt new_iVector = new_index[iVector]; if (new_iVector >= 0) { - HighsInt row_iEl = sub_matrix_length[new_iVector]; - if (extract_index) sub_matrix_index[row_iEl] = vector; - if (extract_value) sub_matrix_value[row_iEl] = matrix.value_[iEl]; - sub_matrix_length[new_iVector]++; + HighsInt row_iEl = sub_matrix_length[new_iVector]; + if (extract_index) sub_matrix_index[row_iEl] = vector; + if (extract_value) sub_matrix_value[row_iEl] = matrix.value_[iEl]; + sub_matrix_length[new_iVector]++; } } } diff --git a/src/lp_data/HighsLpUtils.h b/src/lp_data/HighsLpUtils.h index 6c414f68d8..318999ed1f 100644 --- a/src/lp_data/HighsLpUtils.h +++ b/src/lp_data/HighsLpUtils.h @@ -269,39 +269,30 @@ void removeRowsOfCountOne(const HighsLogOptions& log_options, HighsLp& lp); // // Data to be extracted is given by sub_* being nullpointer // -// * cost, lower and upper bounds for columns, and column-wise LP constraint matrix +// * cost, lower and upper bounds for columns, and column-wise LP constraint +// matrix // // * lower and upper bounds for rows, and row-wise LP constraint // * matrix. "cost" is nullptr, and so must be sub_vector_data0 -// +// void getSubVectors(const HighsIndexCollection& index_collection, - const HighsInt data_dim, - const double* data0, - const double* data1, - const double* data2, - const HighsSparseMatrix matrix, - HighsInt& num_sub_vector, - double* sub_vector_data0, - double* sub_vector_data1, - double* sub_vector_data2, - HighsInt& sub_matrix_num_nz, - HighsInt* sub_matrix_start, - HighsInt* sub_matrix_index, - double* sub_matrix_value); + const HighsInt data_dim, const double* data0, + const double* data1, const double* data2, + const HighsSparseMatrix matrix, HighsInt& num_sub_vector, + double* sub_vector_data0, double* sub_vector_data1, + double* sub_vector_data2, HighsInt& sub_matrix_num_nz, + HighsInt* sub_matrix_start, HighsInt* sub_matrix_index, + double* sub_matrix_value); void getSubVectorsTranspose(const HighsIndexCollection& index_collection, - const HighsInt data_dim, - const double* data0, - const double* data1, - const double* data2, - const HighsSparseMatrix matrix, - HighsInt& num_sub_vector, - double* sub_vector_data0, - double* sub_vector_data1, - double* sub_vector_data2, - HighsInt& sub_matrix_num_nz, - HighsInt* sub_matrix_start, - HighsInt* sub_matrix_index, - double* sub_matrix_value); + const HighsInt data_dim, const double* data0, + const double* data1, const double* data2, + const HighsSparseMatrix matrix, + HighsInt& num_sub_vector, double* sub_vector_data0, + double* sub_vector_data1, double* sub_vector_data2, + HighsInt& sub_matrix_num_nz, + HighsInt* sub_matrix_start, + HighsInt* sub_matrix_index, + double* sub_matrix_value); #endif // LP_DATA_HIGHSLPUTILS_H_