1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                       */
3 /*    This file is part of the HiGHS linear optimization suite           */
4 /*                                                                       */
5 /*    Written and engineered 2008-2021 at the University of Edinburgh    */
6 /*                                                                       */
7 /*    Available as open-source under the MIT License                     */
8 /*                                                                       */
9 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10 #include "io/LoadOptions.h"
11 
12 #include <fstream>
13 
14 #include "util/stringutil.h"
15 
16 // For extended options to be parsed from a file. Assuming options file is
17 // specified.
loadOptionsFromFile(HighsOptions & options)18 bool loadOptionsFromFile(HighsOptions& options) {
19   if (options.options_file.size() == 0) return false;
20 
21   string line, option, value;
22   int line_count = 0;
23   std::ifstream file(options.options_file);
24   if (file.is_open()) {
25     while (file.good()) {
26       getline(file, line);
27       line_count++;
28       if (line.size() == 0 || line[0] == '#') continue;
29 
30       int equals = line.find_first_of("=");
31       if (equals < 0 || equals >= (int)line.size() - 1) {
32         HighsLogMessage(options.logfile, HighsMessageType::ERROR,
33                         "Error on line %d of options file.", line_count);
34         return false;
35       }
36       option = line.substr(0, equals);
37       value = line.substr(equals + 1, line.size() - equals);
38       trim(option);
39       trim(value);
40       if (setOptionValue(options.logfile, option, options.records, value) !=
41           OptionStatus::OK)
42         return false;
43     }
44   } else {
45     HighsLogMessage(options.logfile, HighsMessageType::ERROR,
46                     "Options file not found.");
47     return false;
48   }
49 
50   return true;
51 }
52