Skip to content

Commit 4bedda6

Browse files
committed
Just add blank names in addCol/Row and return no warning
1 parent 344481e commit 4bedda6

File tree

5 files changed

+76
-105
lines changed

5 files changed

+76
-105
lines changed

check/TestFilereader.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,11 @@ TEST_CASE("handle-blank-space-names", "[highs_filereader]") {
491491
lp.a_matrix_.index_ = {0, 1, 0, 1};
492492
lp.a_matrix_.value_ = {1, 2, 2, 4};
493493
Highs h;
494-
h.setOptionValue("output_flag", dev_run);
494+
// h.setOptionValue("output_flag", dev_run);
495495
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
496496
h.run();
497-
REQUIRE(h.writeSolution("", 1) == HighsStatus::kOk);
497+
// Names will be created when writing the solution
498+
REQUIRE(h.writeSolution("", 1) == HighsStatus::kWarning);
498499
REQUIRE(h.writeModel("") == HighsStatus::kOk);
499500

500501
lp.col_names_ = {"Column", "Column"};
@@ -505,15 +506,16 @@ TEST_CASE("handle-blank-space-names", "[highs_filereader]") {
505506
lp.col_names_ = {"Column0", ""};
506507
REQUIRE(h.passModel(lp) == HighsStatus::kOk);
507508
h.run();
508-
REQUIRE(h.writeSolution("", -1) == HighsStatus::kOk);
509+
REQUIRE(h.writeSolution("", kSolutionStyleOldRaw) == HighsStatus::kWarning);
509510
REQUIRE(h.writeModel("") == HighsStatus::kOk);
510511

511512
std::vector<HighsInt> index = {0, 1};
512513
std::vector<double> value = {2, 3};
513514
REQUIRE(h.addRow(5, inf, 2, index.data(), value.data()) == HighsStatus::kOk);
514515
h.run();
515-
REQUIRE(h.writeBasis("") == HighsStatus::kOk);
516-
REQUIRE(h.writeSolution("", 1) == HighsStatus::kOk);
516+
printf("h.getLP().row_names_[2] = %s\n", h.getLp().row_names_[2].c_str());
517+
REQUIRE(h.writeBasis("") == HighsStatus::kWarning);
518+
REQUIRE(h.writeSolution("", kSolutionStylePretty) == HighsStatus::kOk);
517519
REQUIRE(h.writeModel("") == HighsStatus::kOk);
518520

519521
lp.row_names_[1] = "Row 1";

highs/lp_data/Highs.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,13 @@ HighsStatus Highs::writeLocalModel(HighsModel& model,
752752
// Dimensions in a_matrix_ may not be set, so take them from lp
753753
lp.setMatrixDimensions();
754754

755-
// Replace any blank names and check for names with spaces
755+
// Replace any blank names and return error if there are duplicates
756+
// or names with spaces
756757
call_status = normaliseNames(this->options_.log_options, lp);
757-
if (call_status == HighsStatus::kError) return call_status;
758+
return_status =
759+
interpretCallStatus(options_.log_options, call_status,
760+
return_status, "normaliseNames");
761+
if (return_status == HighsStatus::kError) return return_status;
758762

759763
// Ensure that the LP is column-wise
760764
lp.ensureColwise();
@@ -820,9 +824,13 @@ HighsStatus Highs::writeBasis(const std::string& filename) {
820824
return_status = interpretCallStatus(options_.log_options, call_status,
821825
return_status, "openWriteFile");
822826
if (return_status == HighsStatus::kError) return return_status;
823-
// Replace any blank names and check for names with spaces
827+
// Replace any blank names and return error if there are duplicates
828+
// or names with spaces
824829
call_status = normaliseNames(this->options_.log_options, this->model_.lp_);
825-
if (call_status == HighsStatus::kError) return call_status;
830+
return_status =
831+
interpretCallStatus(options_.log_options, call_status,
832+
return_status, "normaliseNames");
833+
if (return_status == HighsStatus::kError) return return_status;
826834

827835
// Report to user that basis is being written
828836
if (filename != "")
@@ -3358,9 +3366,13 @@ HighsStatus Highs::writeSolution(const std::string& filename,
33583366
return_status = interpretCallStatus(options_.log_options, call_status,
33593367
return_status, "openWriteFile");
33603368
if (return_status == HighsStatus::kError) return return_status;
3361-
// Replace any blank names and check for names with spaces
3369+
// Replace any blank names and return error if there are duplicates
3370+
// or names with spaces
33623371
call_status = normaliseNames(this->options_.log_options, this->model_.lp_);
3363-
if (call_status == HighsStatus::kError) return call_status;
3372+
return_status =
3373+
interpretCallStatus(options_.log_options, call_status,
3374+
return_status, "normaliseNames");
3375+
if (return_status == HighsStatus::kError) return return_status;
33643376

33653377
// Report to user that solution is being written
33663378
if (filename != "")

highs/lp_data/HighsLpUtils.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ void reportLpColVectors(const HighsLogOptions& log_options, const HighsLp& lp) {
18641864
std::string type;
18651865
HighsInt count;
18661866
bool have_integer_columns = (getNumInt(lp) != 0);
1867-
bool have_col_names = (lp.col_names_.size() != 0);
1867+
bool have_col_names = lp.col_names_.size() == static_cast<size_t>(lp.num_col_);
18681868

18691869
highsLogUser(log_options, HighsLogType::kInfo,
18701870
" Column Lower Upper Cost "
@@ -2515,7 +2515,7 @@ HighsStatus assessLpPrimalSolution(const std::string message,
25152515
row_value.assign(lp.num_row_, 0);
25162516
const bool have_integrality = (lp.integrality_.size() != 0);
25172517
if (!solution.value_valid) return HighsStatus::kError;
2518-
const bool have_col_names = lp.col_names_.size() >= lp.num_col_;
2518+
const bool have_col_names = lp.col_names_.size() == static_cast<size_t>(lp.num_col_);
25192519
for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++) {
25202520
const std::string name_string =
25212521
have_col_names ? (" (" + lp.col_names_[iCol] + ")") : "";
@@ -2628,20 +2628,6 @@ HighsStatus assessLpPrimalSolution(const std::string message,
26282628

26292629
void writeBasisFile(FILE*& file, const HighsOptions& options, const HighsLp& lp,
26302630
const HighsBasis& basis) {
2631-
/*
2632-
fprintf(file, "HiGHS_basis_file %s\n", kHighsBasisFileV2.c_str());
2633-
if (basis.valid == false) {
2634-
fprintf(file, "None\n");
2635-
return;
2636-
}
2637-
fprintf(file, "Valid\n");
2638-
fprintf(file, "# Columns %d\n", (int)basis.col_status.size());
2639-
for (const auto& status : basis.col_status) fprintf(file, "%d ", (int)status);
2640-
fprintf(file, "\n");
2641-
fprintf(file, "# Rows %d\n", (int)basis.row_status.size());
2642-
for (const auto& status : basis.row_status) fprintf(file, "%d ", (int)status);
2643-
fprintf(file, "\n");
2644-
*/
26452631
const HighsLogOptions& log_options = options.log_options;
26462632
std::stringstream ss;
26472633
// Basis version line
@@ -2734,6 +2720,7 @@ HighsStatus readBasisStream(const HighsLogOptions& log_options, HighsLp& lp,
27342720
// Reads a basis as an ifstream, returning an error if what's read is
27352721
// inconsistent with the sizes of the HighsBasis passed in
27362722
HighsStatus return_status = HighsStatus::kOk;
2723+
HighsStatus call_status = HighsStatus::kOk;
27372724
std::string from_method = "readBasisStream";
27382725
std::string string_highs, string_version;
27392726
in_file >> string_highs >> string_version;
@@ -2757,12 +2744,13 @@ HighsStatus readBasisStream(const HighsLogOptions& log_options, HighsLp& lp,
27572744
highsLogUser(log_options, HighsLogType::kWarning,
27582745
"readBasisFile: Basis file format %s is deprecated\n",
27592746
kHighsBasisFileV1.c_str());
2747+
return_status = HighsStatus::kWarning;
27602748
}
27612749
std::string keyword;
27622750
in_file >> keyword;
27632751
if (keyword == "None") {
27642752
basis.valid = false;
2765-
return HighsStatus::kOk;
2753+
return return_status;
27662754
}
27672755
const HighsInt basis_num_col = (HighsInt)basis.col_status.size();
27682756
const HighsInt basis_num_row = (HighsInt)basis.row_status.size();
@@ -2793,10 +2781,10 @@ HighsStatus readBasisStream(const HighsLogOptions& log_options, HighsLp& lp,
27932781
in_file >> name >> int_status;
27942782
if (have_col_names) {
27952783
// Use the column name if possible
2796-
return_status =
2784+
call_status =
27972785
getIndexFromName(log_options, from_method, is_column, name,
27982786
lp.col_hash_.name2index, iCol, lp.col_names_);
2799-
if (return_status != HighsStatus::kOk) return return_status;
2787+
if (call_status != HighsStatus::kOk) return call_status;
28002788
} else {
28012789
// Have to assume column basis status are in the right order
28022790
iCol = iX;
@@ -2827,10 +2815,10 @@ HighsStatus readBasisStream(const HighsLogOptions& log_options, HighsLp& lp,
28272815
in_file >> name >> int_status;
28282816
if (have_row_names) {
28292817
// Use the row name if possible
2830-
return_status =
2818+
call_status =
28312819
getIndexFromName(log_options, from_method, is_column, name,
28322820
lp.row_hash_.name2index, iRow, lp.row_names_);
2833-
if (return_status != HighsStatus::kOk) return return_status;
2821+
if (call_status != HighsStatus::kOk) return call_status;
28342822
} else {
28352823
// Have to assume row solution values are in the right order
28362824
iRow = iX;
@@ -3120,8 +3108,8 @@ HighsLp withoutSemiVariables(const HighsLp& lp_, HighsSolution& solution,
31203108
HighsInt semi_row_num = 0;
31213109
// Insert the new variables and their coefficients
31223110
std::stringstream ss;
3123-
const bool have_col_names = (lp.col_names_.size() != 0);
3124-
const bool have_row_names = (lp.row_names_.size() != 0);
3111+
const bool have_col_names = lp.col_names_.size() == static_cast<size_t>(lp.num_col_);
3112+
const bool have_row_names = lp.row_names_.size() == static_cast<size_t>(lp.num_row_);
31253113
const bool have_solution = solution.value_valid;
31263114
if (have_solution) {
31273115
// Create zeroed row values for the new rows

0 commit comments

Comments
 (0)