@@ -2057,7 +2057,9 @@ HighsStatus readSolutionFile(const std::string filename,
20572057 return HighsStatus::kError ;
20582058 }
20592059 std::string from_method = " readSolutionFile" ;
2060+ std::string hash;
20602061 std::string keyword;
2062+ std::string value_string;
20612063 std::string name;
20622064 double value;
20632065 HighsInt num_col = -1 ;
@@ -2101,9 +2103,10 @@ HighsStatus readSolutionFile(const std::string filename,
21012103 if (!readSolutionFileIgnoreLineOk (in_file))
21022104 return readSolutionFileErrorReturn (in_file); // Objective
21032105 // Next line should be "Columns" and correct number
2104- if (!readSolutionFileHashKeywordIntLineOk (keyword, num_col, in_file)) {
2106+ if (!readSolutionFileHashKeywordIntLineOk (hash, keyword, value_string , num_col, in_file)) {
21052107 highsLogUser (log_options, HighsLogType::kError ,
2106- " readSolutionFile: Error reading line \" # %s %d\" " , keyword.c_str (), int (num_col));
2108+ " readSolutionFile: Error reading line \" %s %s %s\" " ,
2109+ hash.c_str (), keyword.c_str (), value_string.c_str ());
21072110 return readSolutionFileErrorReturn (in_file);
21082111 }
21092112 assert (keyword == " Columns" );
@@ -2189,7 +2192,7 @@ HighsStatus readSolutionFile(const std::string filename,
21892192 }
21902193 // Read in the col values: OK to have none, otherwise next line
21912194 // should be "Rows" and correct number
2192- if (!readSolutionFileHashKeywordIntLineOk (keyword, num_row , in_file)) {
2195+ if (!readSolutionFileHashKeywordIntLineOk (hash, keyword, value_string, num_col , in_file)) {
21932196 // Compute the row values since there are none to read
21942197 if (calculateRowValuesQuad (lp, read_solution.col_value ,
21952198 read_solution.row_value ) != HighsStatus::kOk )
@@ -2262,9 +2265,13 @@ HighsStatus readSolutionFile(const std::string filename,
22622265 if (!readSolutionFileIgnoreLineOk (in_file))
22632266 return readSolutionFileErrorReturn (in_file); // EOL
22642267 // Next line should be "Columns" and correct number
2265- if (!readSolutionFileHashKeywordIntLineOk (keyword, num_col, in_file))
2268+ if (!readSolutionFileHashKeywordIntLineOk (hash, keyword, value_string, num_col, in_file)) {
2269+ highsLogUser (log_options, HighsLogType::kError ,
2270+ " readSolutionFile: Error reading line \" %s %s %s\" " ,
2271+ hash.c_str (), keyword.c_str (), value_string.c_str ());
22662272 return readSolutionFileReturn (HighsStatus::kOk , solution, basis,
22672273 read_solution, read_basis, in_file);
2274+ }
22682275 assert (keyword == " Columns" );
22692276 double dual;
22702277 is_column = true ;
@@ -2280,9 +2287,13 @@ HighsStatus readSolutionFile(const std::string filename,
22802287 }
22812288 // Read in the col values: next line should be "Rows" and correct
22822289 // number
2283- if (!readSolutionFileHashKeywordIntLineOk (keyword, num_row, in_file))
2290+ if (!readSolutionFileHashKeywordIntLineOk (hash, keyword, value_string, num_col, in_file)) {
2291+ highsLogUser (log_options, HighsLogType::kError ,
2292+ " readSolutionFile: Error reading line \" %s %s %s\" " ,
2293+ hash.c_str (), keyword.c_str (), value_string.c_str ());
22842294 return readSolutionFileReturn (HighsStatus::kOk , solution, basis,
22852295 read_solution, read_basis, in_file);
2296+ }
22862297 assert (keyword == " Rows" );
22872298 is_column = false ;
22882299 assert (!is_column);
@@ -2350,14 +2361,29 @@ bool readSolutionFileKeywordLineOk(std::string& keyword,
23502361 return true ;
23512362}
23522363
2353- bool readSolutionFileHashKeywordIntLineOk (std::string& keyword, HighsInt& value,
2364+ bool readSolutionFileHashKeywordIntLineOk (std::string& hash,
2365+ std::string& keyword,
2366+ std::string& value_string,
2367+ HighsInt& value,
23542368 std::ifstream& in_file) {
2369+ hash = " " ;
2370+ keyword = " " ;
2371+ value_string = " " ;
2372+ // Read the hash symbol
23552373 if (in_file.eof ()) return false ;
2356- in_file >> keyword; // #
2374+ in_file >> hash; // #
2375+ if (hash != " #" ) return false ;
2376+
2377+ // Read the keyword
23572378 if (in_file.eof ()) return false ;
23582379 in_file >> keyword; // keyword
2380+
2381+ // Read the value
23592382 if (in_file.eof ()) return false ;
2360- in_file >> value; // integer value
2383+ // Read as a string, and then check it only contains digits
2384+ in_file >> value_string;
2385+ if (value_string[std::strspn (value_string.c_str (), " -0123456789" )]) return false ;
2386+ value = std::stoi (value_string); // integer value
23612387 return true ;
23622388}
23632389
0 commit comments