-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (44 loc) · 1.42 KB
/
main.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
#include <iostream>
#include <fstream>
#include <iomanip>
#include "linear_algebra.h"
#include "typedef.h"
#include "LinearProgram.h"
int main(int argc, char **argv) {
std::cout << std::setprecision(2);
if (argc < 2) {
std::cerr << "Error: specify source." << std::endl;
return 1;
}
auto file = std::ifstream(argv[1]);
if (not file) {
std::cerr << "Error: cannot open file." << std::endl;
return 1;
}
LinearProgram linear_program(file);
std::cout << "Solving linear program with "
<< linear_program.num_variables()
<< " variables and "
<< linear_program.num_equations()
<< " constraints."
<< std::endl;
linear_program.maximize();
switch (linear_program.state()) {
case UNBOUNDED:
std::cout << "The LP is unbounded. A solution is ";
print(linear_program.get_solution());
std::cout << std::endl;
break;
case OPTIMAL:
std::cout << "An optimal solution is ";
print(linear_program.get_solution());
std::cout << " with value " << linear_program.get_solution_value() << std::endl;
break;
case INFEASIBLE:
std::cout << "The LP is infeasible." << std::endl;
break;
default:
std::cerr << "Something went wrong." << std::endl;
}
return 0;
}