-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunHighs.cpp
More file actions
128 lines (106 loc) · 3.97 KB
/
Copy pathRunHighs.cpp
File metadata and controls
128 lines (106 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "Highs.h"
#include "io/Filereader.h"
#include "util/HighsTimer.h"
bool runHighs(std::string model_file, std::string solver,
std::string hipo_system, std::stringstream &summary_stream,
std::stringstream &data_stream, double &solve_time) {
HighsTimer timer;
// create highs instance and choose options
Highs highs;
HighsOptions highs_options;
highs_options.solver = solver;
highs_options.hipo_system = hipo_system;
highs_options.run_crossover = "off";
highs_options.time_limit = 5000;
highs.passOptions(highs_options);
HighsStatus status = highs.readModel(model_file);
timer.start();
status = highs.run();
solve_time = timer.read();
// log information for output
HighsInfo info = highs.getInfo();
std::string problem_name = extractModelName(model_file);
summary_stream << std::setw(40) << problem_name << ' ' << std::setw(20)
<< highsStatusToString(status) << ' ' << std::setw(20)
<< info.ipm_iteration_count << ' ' << std::setw(20)
<< solve_time << '\n';
data_stream << std::setw(40) << problem_name << std::setw(20)
<< std::scientific << highs.getLp().num_col_ << ' ';
data_stream << std::setw(20) << solve_time << ' ';
data_stream << std::setw(20) << info.ipm_iteration_count << ' ';
data_stream << std::setw(20) << (status == HighsStatus::kOk) << '\n';
return status == HighsStatus::kOk;
}
int main(int argc, char **argv) {
if (argc < 3) {
std::cerr << "First input must indicate the collection of problems: "
"netlib, pypsa, mittelmann\n";
std::cerr << "Second input must indicate the solver to use: hipo, ipx, "
"simplex\n";
std::cerr << "Third input may select the linear system to use for HiPO: "
"AS, NE\n";
return 1;
}
std::string collection = argv[1];
std::string solver = argv[2];
std::string nla_approach;
if (argc < 4 || solver != "hipo")
nla_approach = "choose";
else {
if (strcmp(argv[3], "AS") == 0)
nla_approach = "augmented";
else if (strcmp(argv[3], "NE") == 0)
nla_approach = "normaleq";
else {
std::cerr << "Invalid linear system option\n";
std::cerr << "Must be AS or NE\n";
return 1;
}
}
std::string data_path = collection + "_pb/data/";
std::string names_path = collection + "_pb/names.txt";
std::stringstream summary_stream;
summary_stream << std::scientific;
summary_stream << "\n\n";
summary_stream << std::setw(40) << "Problem" << ' ' << std::setw(20)
<< "Status" << ' ' << std::setw(20) << "Iterations" << ' '
<< std::setw(20) << "Time (s)" << '\n';
char filename[100];
if (nla_approach == "choose")
snprintf(filename, 100, "results_%s_%s.txt", collection.c_str(),
solver.c_str());
else
snprintf(filename, 100, "results_%s_%s_%s.txt", collection.c_str(),
solver.c_str(), argv[3]);
std::ofstream output_file(filename);
output_file << std::setw(40) << "problem" << std::setw(20) << " vars "
<< std::setw(20) << "time" << std::setw(20) << "iter"
<< std::setw(20) << "solved" << '\n';
double total_time = 0.0;
int pb_solved = 0;
int pb_count = 0;
std::ifstream pb_names(names_path);
std::string current_pb;
while (pb_names >> current_pb) {
++pb_count;
double solve_time;
std::stringstream data_stream;
bool solved = runHighs(data_path + current_pb, solver, nla_approach,
summary_stream, data_stream, solve_time);
if (solved)
++pb_solved;
total_time += solve_time;
output_file << data_stream.str() << std::flush;
}
summary_stream << "Total solve time: " << total_time << '\n';
summary_stream << "Problems solved: " << pb_solved << " / " << pb_count
<< '\n';
std::cout << summary_stream.str();
output_file.close();
return 0;
}