-
Notifications
You must be signed in to change notification settings - Fork 0
/
hilbertsolver.cpp
64 lines (55 loc) · 2.11 KB
/
hilbertsolver.cpp
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
/*
* Facility matching hilbert solver file.
*
* There could be not more than 1 facility per node, but multiple customers per node are allowed.
*/
#include <iostream>
#include <string>
#include <boost/program_options.hpp>
#include "HilbertSolver.h"
using namespace std;
namespace po = boost::program_options;
int main(int argc, const char** argv) {
string filename;
long facility_number_to_locate;
long facility_capacity;
string out_filename;
string facilityfile;
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("input,i", po::value<string>(&filename)->required(), "Input file, a network")
("facilityfile,f", po::value<string>(&facilityfile)->default_value(""), "File with a list of facilities")
("facilities,n", po::value<long>(&facility_number_to_locate)->required(), "Facilities to locate")
("faccap,c", po::value<long>(&facility_capacity)->default_value(1), "Capacity of facilities")
("output,o", po::value<string>(&out_filename)->required(), "Output file");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
po::notify(vm);
Logger logger;
logger.start("total time");
// if (facilityfile != "") {
//@todo if components > 1 - special case
//@todo change uniform capacities
// throw "Not implemented";
// }
try {
Network net(filename,facilityfile);
HilbertSolver hilbert_solver = HilbertSolver(&net, &logger);
hilbert_solver.run(facility_number_to_locate, facility_capacity);
if (logger.str_dict.count("error") > 0) {
cout << "Error " << logger.str_dict["error"][0] << endl;
} else {
cout << logger.float_dict["objective"][0] << " " << logger.float_dict["runtime"][0] << endl;
}
logger.finish("total time");
hilbert_solver.save_log(out_filename);
} catch (const std::string& e) {
std::cout << e << std::endl;
}
return 0;
}