| 2176 | } |
| 2177 | |
| 2178 | HighsStatus readSolutionFile(const std::string& filename, |
| 2179 | const HighsOptions& options, HighsLp& lp, |
| 2180 | HighsBasis& basis, HighsSolution& solution, |
| 2181 | const HighsInt style) { |
| 2182 | HighsStatus return_status = HighsStatus::kOk; |
| 2183 | const HighsLogOptions& log_options = options.log_options; |
| 2184 | if (style != kSolutionStyleRaw && style != kSolutionStyleSparse) { |
| 2185 | highsLogUser(log_options, HighsLogType::kError, |
| 2186 | "readSolutionFile: Cannot read file of style %d\n", |
| 2187 | (int)style); |
| 2188 | return HighsStatus::kError; |
| 2189 | } |
| 2190 | std::ifstream in_file(filename); |
| 2191 | if (in_file.fail()) { |
| 2192 | highsLogUser(log_options, HighsLogType::kError, |
| 2193 | "readSolutionFile: Cannot open readable file \"%s\"\n", |
| 2194 | filename.c_str()); |
| 2195 | return HighsStatus::kError; |
| 2196 | } |
| 2197 | std::string from_method = "readSolutionFile"; |
| 2198 | std::string hash; |
| 2199 | std::string keyword; |
| 2200 | std::string value_string; |
| 2201 | std::string name; |
| 2202 | double value; |
| 2203 | HighsInt num_col = -1; |
| 2204 | HighsInt num_row = -1; |
| 2205 | const HighsInt lp_num_col = lp.num_col_; |
| 2206 | const HighsInt lp_num_row = lp.num_row_; |
| 2207 | // Define identifiers for reading in |
| 2208 | HighsSolution read_solution = solution; |
| 2209 | HighsBasis read_basis = basis; |
| 2210 | read_solution.clear(); |
| 2211 | read_basis.clear(); |
| 2212 | read_solution.col_value.resize(lp_num_col); |
| 2213 | read_solution.row_value.resize(lp_num_row); |
| 2214 | read_solution.col_dual.resize(lp_num_col); |
| 2215 | read_solution.row_dual.resize(lp_num_row); |
| 2216 | read_basis.col_status.resize(lp_num_col); |
| 2217 | read_basis.row_status.resize(lp_num_row); |
| 2218 | std::string section_name; |
| 2219 | if (!readSolutionFileIdIgnoreLineOk(section_name, in_file)) |
| 2220 | return readSolutionFileErrorReturn( |
| 2221 | in_file); // Model (status) or =obj= (value) |
| 2222 | const bool miplib_sol = section_name == "=obj="; |
| 2223 | const bool have_col_names = |
| 2224 | lp.col_names_.size() == static_cast<size_t>(lp_num_col); |
| 2225 | const bool have_row_names = |
| 2226 | lp.row_names_.size() == static_cast<size_t>(lp_num_row); |
| 2227 | if (miplib_sol) { |
| 2228 | // A MIPLIB solution file has nonzero solution values for a subset |
| 2229 | // of the variables identified by name, so there must be column |
| 2230 | // names, |
| 2231 | if (!have_col_names) { |
| 2232 | highsLogUser(log_options, HighsLogType::kError, |
| 2233 | "readSolutionFile: Cannot read a MIPLIB solution file " |
| 2234 | "without column names in the model\n"); |
| 2235 | return HighsStatus::kError; |
no test coverage detected