@@ -21,80 +21,78 @@ void* operator new(size_t size) {
2121*/
2222
2323namespace uno {
24- void run_uno_ampl (const std::string &model_name, const Options &options) {
25- try {
26- const AMPLModel model (model_name);
27- Uno uno{};
28- Result result = uno.solve (model, options);
29- if (result.optimization_status == OptimizationStatus::SUCCESS) {
30- // check result.solution_status
31- } else {
32- // ...
33- }
34- if (options.get_bool (" AMPL_write_solution_to_file" )) {
35- model.write_solution_to_file (result);
36- }
37- // std::cout << "memory_allocation_amount = " << memory_allocation_amount <<
38- // '\n';
39- } catch (std::exception &exception) {
40- DISCRETE << exception.what () << ' \n ' ;
41- }
42- }
43- } // namespace uno
24+ void run_uno_ampl (const std::string& model_name, const Options& options) {
25+ try {
26+ const AMPLModel model (model_name);
27+ Uno uno{};
28+ Result result = uno.solve (model, options);
29+ if (result.optimization_status == OptimizationStatus::SUCCESS) {
30+ // check result.solution_status
31+ }
32+ else {
33+ // ...
34+ }
35+ if (options.get_bool (" AMPL_write_solution_to_file" )) {
36+ model.write_solution_to_file (result);
37+ }
38+ // std::cout << "memory_allocation_amount = " << memory_allocation_amount << '\n';
39+ }
40+ catch (std::exception& exception) {
41+ DISCRETE << exception.what () << ' \n ' ;
42+ }
43+ }
44+ } // namespace
4445
4546int main (int argc, char *argv[]) {
4647 using namespace uno ;
4748
48- try {
49- if (argc == 1 || (argc == 2 && std::string (argv[1 ]) == " --v" )) {
50- std::cout << " Uno " << Uno::current_version () << ' \n ' ;
51- } else if (argc == 2 && std::string (argv[1 ]) == " --dump-options" ) {
52- // Print all available options (type + default value) for automated tools
53- Options::dump_default_options ();
54- } else if (argc == 2 && std::string (argv[1 ]) == " --strategies" ) {
55- Uno::print_available_strategies ();
56- } else {
57- // AMPL expects: ./uno_ampl model.nl [-AMPL] [option_name=option_value,
58- // ...] model name
59- const char *model_name = argv[1 ];
60-
61- // gather the options
62- Options options;
63- DefaultOptions::load (options);
64- // the -AMPL flag indicates that the solution should be written to the
65- // AMPL solution file
66- size_t offset = 2 ;
67- if (argc > 2 && std::string (argv[2 ]) == " -AMPL" ) {
68- options.set_bool (" AMPL_write_solution_to_file" , true );
69- ++offset;
49+ try {
50+ if (argc == 1 || (argc == 2 && std::string (argv[1 ]) == " --v" )) {
51+ std::cout << " Uno " << Uno::current_version () << ' \n ' ;
52+ } else if (argc == 2 && std::string (argv[1 ]) == " --dump-options" ) {
53+ // Print all available options (type + default value) for automated tools
54+ Options::dump_default_options ();
55+ } else if (argc == 2 && std::string (argv[1 ]) == " --strategies" ) {
56+ Uno::print_available_strategies ();
7057 } else {
71- options.set_bool (" AMPL_write_solution_to_file" , false );
72- }
73- // get the command line arguments (options start at index offset)
74- const Options command_line_options =
75- Options::get_command_line_options (argc, argv, offset);
76- // possibly set options from an option file
77- const auto optional_option_file =
78- command_line_options.get_string_optional (" option_file" );
79- if (optional_option_file.has_value ()) {
80- Options file_options = Options::load_option_file (*optional_option_file);
81- options.overwrite_with (file_options);
58+ // AMPL expects: ./uno_ampl model.nl [-AMPL] [option_name=option_value,
59+ // ...] model name
60+ const char *model_name = argv[1 ];
61+
62+ // gather the options
63+ Options options;
64+ DefaultOptions::load (options);
65+ // the -AMPL flag indicates that the solution should be written to the AMPL solution file
66+ size_t offset = 2 ;
67+ if (argc > 2 && std::string (argv[2 ]) == " -AMPL" ) {
68+ options.set_bool (" AMPL_write_solution_to_file" , true );
69+ ++offset;
70+ }
71+ else {
72+ options.set_bool (" AMPL_write_solution_to_file" , false );
73+ }
74+ // get the command line arguments (options start at index offset)
75+ const Options command_line_options = Options::get_command_line_options (argc, argv, offset);
76+ // possibly set options from an option file
77+ const auto optional_option_file = command_line_options.get_string_optional (" option_file" );
78+ if (optional_option_file.has_value ()) {
79+ Options file_options = Options::load_option_file (*optional_option_file);
80+ options.overwrite_with (file_options);
81+ }
82+ // possibly set a preset
83+ const auto optional_preset = command_line_options.get_string_optional (" preset" );
84+ const Options preset_options = Presets::get_preset_options (optional_preset);
85+ options.overwrite_with (preset_options);
86+ // overwrite the options with the command line arguments
87+ options.overwrite_with (command_line_options);
88+
89+ // solve the model
90+ Logger::set_logger (options.get_string (" logger" ));
91+ run_uno_ampl (model_name, options);
8292 }
83- // possibly set a preset
84- const auto optional_preset =
85- command_line_options.get_string_optional (" preset" );
86- const Options preset_options =
87- Presets::get_preset_options (optional_preset);
88- options.overwrite_with (preset_options);
89- // overwrite the options with the command line arguments
90- options.overwrite_with (command_line_options);
91-
92- // solve the model
93- Logger::set_logger (options.get_string (" logger" ));
94- run_uno_ampl (model_name, options);
95- }
96- } catch (std::exception &exception) {
97- DISCRETE << exception.what () << ' \n ' ;
98- }
99- return EXIT_SUCCESS;
93+ }
94+ catch (std::exception& exception) {
95+ DISCRETE << exception.what () << ' \n ' ;
96+ }
97+ return EXIT_SUCCESS;
10098}
0 commit comments