-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (69 loc) · 2.9 KB
/
main.cpp
File metadata and controls
85 lines (69 loc) · 2.9 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
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
#include "parser.hpp"
#include "network.hpp"
#include "tree.hpp"
#include "simplex.hpp"
namespace po = boost::program_options;
int main(int argc, char **argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "Produce help message.")
("verbose,v", "Print runtimes of different parts of the program.")
("print-arcs,a", "Print the arcs of the solution with their flow.")
("input-file", po::value<std::string>(), "Input file.")
;
po::positional_options_description p;
p.add("input-file", -1);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
std::string filename = vm["input-file"].as<std::string>();
Network *network = parse_nwk<Network>(filename);
boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration msdiff = mst2 - mst1;
if (vm.count("verbose")) {
std::cout << "Parse time: " << msdiff.total_milliseconds() << std::endl;
}
mst1 = boost::posix_time::microsec_clock::local_time();
NWSimplex *simplex = new NWSimplex(network, 500, 11);
mst2 = boost::posix_time::microsec_clock::local_time();
msdiff = mst2 - mst1;
if (vm.count("verbose")) {
std::cout << "Constructor time: " << msdiff.total_milliseconds() << std::endl;
}
mst1 = boost::posix_time::microsec_clock::local_time();
int solution_state = simplex->compute_solution();
mst2 = boost::posix_time::microsec_clock::local_time();
msdiff = mst2 - mst1;
if (vm.count("verbose")) {
std::cout << "Simplex time: " << msdiff.total_milliseconds() << std::endl;
std::cout << "Iterations: " << simplex->num_iterations << std::endl;
}
if (solution_state == SOLUTION_UNBOUNDED) {
std::cout << "unbounded" << std::endl;
} else if (solution_state == SOLUTION_INFEASIBLE) {
std::cout << "infeasible" << std::endl;
} else {
std::cout << "value: " << simplex->solution_value() << std::endl;
if (vm.count("print-arcs")) {
std::list<Arc*> *arcs = simplex->sorted_solution_arcs();
for (std::list<Arc*>::iterator it = arcs->begin();
it != arcs->end(); ++it) {
Arc *arc = (*it);
std::cout << arc->v << " " << arc->w << " " << arc->flow << std::endl;
}
}
}
return 0;
}