-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
63 lines (53 loc) · 1.36 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
56
57
58
59
60
61
62
63
#include "solver.h"
#include <iostream>
#include <fstream>
using namespace ratio;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: oRatio <input-file> [<input-file> ...] <output-file>\n";
return -1;
}
// the problem files..
std::vector<std::string> prob_names;
for (int i = 1; i < argc - 1; i++)
prob_names.push_back(argv[i]);
// the solution file..
std::string sol_name = argv[argc - 1];
#ifdef NDEBUG
if (std::ifstream(sol_name).good())
{
std::cout << "The solution file '" << sol_name << "' already exists! Please, specify a different solution file..";
return -1;
}
#endif
std::cout << "starting oRatio";
#ifndef NDEBUG
std::cout << " in debug mode";
#endif
std::cout << "..\n";
solver s;
try
{
std::cout << "parsing input files..\n";
s.read(prob_names);
std::cout << "solving the problem..\n";
if (s.solve())
std::cout << "hurray!! we have found a solution..\n";
else
{
std::cout << "the problem is unsolvable..\n";
return 1;
}
std::ofstream sol_file;
sol_file.open(sol_name);
sol_file << s;
sol_file.close();
}
catch (const std::exception &ex)
{
std::cout << ex.what() << '\n';
return 1;
}
}