MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / loadOptionsFromFile

Function loadOptionsFromFile

highs/io/LoadOptions.cpp:16–62  ·  view source on GitHub ↗

For extended options to be parsed from a file. Assuming options file is specified.

Source from the content-addressed store, hash-verified

14// For extended options to be parsed from a file. Assuming options file is
15// specified.
16HighsLoadOptionsStatus loadOptionsFromFile(
17 const HighsLogOptions& report_log_options, HighsOptions& options,
18 const std::string& filename) {
19 if (filename.size() == 0) return HighsLoadOptionsStatus::kEmpty;
20
21 string line, option, value;
22 HighsInt line_count = 0;
23 // loadOptionsFromFile needs its own non-chars string since the
24 // default setting in io/stringutil.h excludes \" and \' that can
25 // appear in an MPS name - the only other place where trim() is used
26 const std::string non_chars = "\t\n\v\f\r\"\' ";
27 std::ifstream file(filename);
28 if (file.is_open()) {
29 while (file.good()) {
30 getline(file, line);
31 line_count++;
32 size_t non_space = line.find_first_not_of(" ");
33 if (line.size() == 0 || line[0] == '#' || non_space == std::string::npos)
34 continue;
35 size_t equals = line.find_first_of("=");
36 if (equals == std::string::npos || equals + 1 >= line.size()) {
37 highsLogUser(report_log_options, HighsLogType::kError,
38 "Error on line %" HIGHSINT_FORMAT
39 " (\"%s\") of options file\n",
40 line_count, line.c_str());
41 return HighsLoadOptionsStatus::kError;
42 }
43 option = line.substr(0, equals);
44 value = line.substr(equals + 1, line.size() - equals);
45 trim(option, non_chars);
46 trim(value, non_chars);
47 if (setLocalOptionValue(report_log_options, option, options.log_options,
48 options.records, value) != OptionStatus::kOk) {
49 highsLogUser(report_log_options, HighsLogType::kError,
50 "Cannot read value \"%s\" for option \"%s\"\n",
51 value.c_str(), option.c_str());
52 return HighsLoadOptionsStatus::kError;
53 }
54 }
55 } else {
56 highsLogUser(report_log_options, HighsLogType::kError,
57 "Options file not found\n");
58 return HighsLoadOptionsStatus::kError;
59 }
60
61 return HighsLoadOptionsStatus::kOk;
62}

Callers 3

readOptionsMethod · 0.85
loadOptionsFunction · 0.85
TestOptions.cppFile · 0.85

Calls 7

highsLogUserFunction · 0.85
trimFunction · 0.85
c_strMethod · 0.80
substrMethod · 0.80
setLocalOptionValueFunction · 0.50
sizeMethod · 0.45
is_openMethod · 0.45

Tested by

no test coverage detected