Skip to content

Commit 9af599a

Browse files
committed
Added HighsSolution::print with prefix for grep, and added prefix to HighsBasis::print
1 parent f86ce19 commit 9af599a

File tree

3 files changed

+72
-26
lines changed

3 files changed

+72
-26
lines changed

highs/interfaces/highs_c_api.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,32 @@ static const char* const kHighsCallbackDataOutPdlpIterationCountName =
117117
"pdlp_iteration_count";
118118
static const char* const kHighsCallbackDataOutObjectiveFunctionValueName =
119119
"objective_function_value";
120-
static const char* const kHighsCallbackDataOutMipNodeCountName = "mip_node_count";
120+
static const char* const kHighsCallbackDataOutMipNodeCountName =
121+
"mip_node_count";
121122
static const char* const kHighsCallbackDataOutMipTotalLpIterationsName =
122123
"mip_total_lp_iterations";
123-
static const char* const kHighsCallbackDataOutMipPrimalBoundName = "mip_primal_bound";
124-
static const char* const kHighsCallbackDataOutMipDualBoundName = "mip_dual_bound";
124+
static const char* const kHighsCallbackDataOutMipPrimalBoundName =
125+
"mip_primal_bound";
126+
static const char* const kHighsCallbackDataOutMipDualBoundName =
127+
"mip_dual_bound";
125128
static const char* const kHighsCallbackDataOutMipGapName = "mip_gap";
126129
static const char* const kHighsCallbackDataOutMipSolutionName = "mip_solution";
127-
static const char* const kHighsCallbackDataOutCutpoolNumColName = "cutpool_num_col";
128-
static const char* const kHighsCallbackDataOutCutpoolNumCutName = "cutpool_num_cut";
129-
static const char* const kHighsCallbackDataOutCutpoolNumNzName = "cutpool_num_nz";
130-
static const char* const kHighsCallbackDataOutCutpoolStartName = "cutpool_start";
131-
static const char* const kHighsCallbackDataOutCutpoolIndexName = "cutpool_index";
132-
static const char* const kHighsCallbackDataOutCutpoolValueName = "cutpool_value";
133-
static const char* const kHighsCallbackDataOutCutpoolLowerName = "cutpool_lower";
134-
static const char* const kHighsCallbackDataOutCutpoolUpperName = "cutpool_upper";
130+
static const char* const kHighsCallbackDataOutCutpoolNumColName =
131+
"cutpool_num_col";
132+
static const char* const kHighsCallbackDataOutCutpoolNumCutName =
133+
"cutpool_num_cut";
134+
static const char* const kHighsCallbackDataOutCutpoolNumNzName =
135+
"cutpool_num_nz";
136+
static const char* const kHighsCallbackDataOutCutpoolStartName =
137+
"cutpool_start";
138+
static const char* const kHighsCallbackDataOutCutpoolIndexName =
139+
"cutpool_index";
140+
static const char* const kHighsCallbackDataOutCutpoolValueName =
141+
"cutpool_value";
142+
static const char* const kHighsCallbackDataOutCutpoolLowerName =
143+
"cutpool_lower";
144+
static const char* const kHighsCallbackDataOutCutpoolUpperName =
145+
"cutpool_upper";
135146

136147
const HighsInt kHighsIisStrategyLight = 0;
137148
const HighsInt kHighsIisStrategyFromLpRowPriority = 1; // WIP

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: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,28 +1811,59 @@ 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 {
1841+
void HighsBasis::print(const std::string& prefix,
1842+
const std::string& message) const {
18171843
if (!this->useful) return;
1818-
this->printScalars(message);
1844+
this->printScalars(prefix, message);
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(), int(num_col), int(num_row), message.c_str());
1858+
printf("%s valid = %d\n", prefix.c_str(), this->valid);
1859+
printf("%s alien = %d\n", prefix.c_str(), this->alien);
1860+
printf("%s useful = %d\n", prefix.c_str(), this->useful);
1861+
printf("%s was_alien = %d\n", prefix.c_str(), this->was_alien);
1862+
printf("%s debug_id = %d\n", prefix.c_str(), int(this->debug_id));
1863+
printf("%s debug_update_count = %d\n", prefix.c_str(),
1864+
int(this->debug_update_count));
1865+
printf("%s debug_origin_name = %s\n", prefix.c_str(),
1866+
this->debug_origin_name.c_str());
18361867
}
18371868

18381869
void HighsBasis::invalidate() {

0 commit comments

Comments
 (0)