Skip to content

Commit b00605e

Browse files
authored
Merge pull request #2587 from ERGO-Code/solution-print
Added `HighsSolution::print` with prefix for grep, and added prefix to `HighsBasis::print`
2 parents 98ba6c3 + 9f8d6b3 commit b00605e

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

highs/lp_data/HStruct.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct HighsSolution {
3737
bool hasUndefined() const;
3838
void invalidate();
3939
void clear();
40+
void print(const std::string& prefix = "",
41+
const std::string& message = "") const;
4042
};
4143

4244
struct HighsObjectiveSolution {
@@ -82,8 +84,10 @@ struct HighsBasis {
8284
std::string debug_origin_name = "None";
8385
std::vector<HighsBasisStatus> col_status;
8486
std::vector<HighsBasisStatus> row_status;
85-
void print(std::string message = "") const;
86-
void printScalars(std::string message = "") const;
87+
void print(const std::string& prefix = "",
88+
const std::string& message = "") const;
89+
void printScalars(const std::string& prefix = "",
90+
const std::string& message = "") const;
8791
void invalidate();
8892
void clear();
8993
};

highs/lp_data/HighsSolution.cpp

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,28 +1811,60 @@ void HighsSolution::clear() {
18111811
this->row_dual.clear();
18121812
}
18131813

1814+
void HighsSolution::print(const std::string& prefix,
1815+
const std::string& message) const {
1816+
HighsInt num_col = this->col_value.size();
1817+
HighsInt num_row = this->row_value.size();
1818+
printf("%s HighsSolution(num_col = %d, num_row = %d): %s\n", prefix.c_str(),
1819+
int(num_col), int(num_row), message.c_str());
1820+
for (HighsInt iCol = 0; iCol < num_col; iCol++)
1821+
printf("%s col_value[%3d] = %11.4g\n", prefix.c_str(), int(iCol),
1822+
this->col_value[iCol]);
1823+
for (HighsInt iRow = 0; iRow < num_row; iRow++)
1824+
printf("%s row_value[%3d] = %11.4g\n", prefix.c_str(), int(iRow),
1825+
this->row_value[iRow]);
1826+
1827+
num_col = this->col_dual.size();
1828+
num_row = this->row_dual.size();
1829+
printf("%s HighsSolution(num_col = %d, num_row = %d): %s\n", prefix.c_str(),
1830+
int(num_col), int(num_row), message.c_str());
1831+
for (HighsInt iCol = 0; iCol < num_col; iCol++)
1832+
printf("%s col_dual[%3d] = %11.4g\n", prefix.c_str(), int(iCol),
1833+
this->col_dual[iCol]);
1834+
for (HighsInt iRow = 0; iRow < num_row; iRow++)
1835+
printf("%s row_dual[%3d] = %11.4g\n", prefix.c_str(), int(iRow),
1836+
this->row_dual[iRow]);
1837+
}
1838+
18141839
void HighsObjectiveSolution::clear() { this->col_value.clear(); }
18151840

1816-
void HighsBasis::print(std::string message) const {
1817-
this->printScalars(message);
1841+
void HighsBasis::print(const std::string& prefix,
1842+
const std::string& message) const {
1843+
this->printScalars(prefix, message);
18181844
if (!this->useful) return;
18191845
for (HighsInt iCol = 0; iCol < HighsInt(this->col_status.size()); iCol++)
1820-
printf("Basis: col_status[%2d] = %d\n", int(iCol),
1846+
printf("%s HighsBasis: col_status[%2d] = %d\n", prefix.c_str(), int(iCol),
18211847
int(this->col_status[iCol]));
18221848
for (HighsInt iRow = 0; iRow < HighsInt(this->row_status.size()); iRow++)
1823-
printf("Basis: row_status[%2d] = %d\n", int(iRow),
1849+
printf("%s HighsBasis: row_status[%2d] = %d\n", prefix.c_str(), int(iRow),
18241850
int(this->row_status[iRow]));
18251851
}
18261852

1827-
void HighsBasis::printScalars(std::string message) const {
1828-
printf("\nBasis: %s\n", message.c_str());
1829-
printf(" valid = %d\n", this->valid);
1830-
printf(" alien = %d\n", this->alien);
1831-
printf(" useful = %d\n", this->useful);
1832-
printf(" was_alien = %d\n", this->was_alien);
1833-
printf(" debug_id = %d\n", int(this->debug_id));
1834-
printf(" debug_update_count = %d\n", int(this->debug_update_count));
1835-
printf(" debug_origin_name = %s\n", this->debug_origin_name.c_str());
1853+
void HighsBasis::printScalars(const std::string& prefix,
1854+
const std::string& message) const {
1855+
HighsInt num_col = this->col_status.size();
1856+
HighsInt num_row = this->row_status.size();
1857+
printf("\n%s HighsBasis(num_col = %d, num_row = %d): %s\n", prefix.c_str(),
1858+
int(num_col), int(num_row), message.c_str());
1859+
printf("%s valid = %d\n", prefix.c_str(), this->valid);
1860+
printf("%s alien = %d\n", prefix.c_str(), this->alien);
1861+
printf("%s useful = %d\n", prefix.c_str(), this->useful);
1862+
printf("%s was_alien = %d\n", prefix.c_str(), this->was_alien);
1863+
printf("%s debug_id = %d\n", prefix.c_str(), int(this->debug_id));
1864+
printf("%s debug_update_count = %d\n", prefix.c_str(),
1865+
int(this->debug_update_count));
1866+
printf("%s debug_origin_name = %s\n", prefix.c_str(),
1867+
this->debug_origin_name.c_str());
18361868
}
18371869

18381870
void HighsBasis::invalidate() {

0 commit comments

Comments
 (0)