-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
66 lines (55 loc) · 1.9 KB
/
Main.cpp
File metadata and controls
66 lines (55 loc) · 1.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
#include <iostream>
#include <string>
#include <chrono>
#include <fstream>
#include <cstring>
#include "LatinSquare.h"
using namespace std;
using namespace std::chrono;
using namespace szx;
void loadInput(istream& is, LatinSquare& lsc) {
is >> lsc.n;
lsc.fixedNums.reserve(lsc.n * lsc.n);
for (Assignment a; is >> a.row >> a.col >> a.num; lsc.fixedNums.push_back(a)) {}
}
void saveOutput(ostream& os, Table& assignments) {
for (auto i = assignments.begin(); i != assignments.end(); ++i) {
for (auto j = i->begin(); j != i->end(); ++j) { os << *j << '\t'; }
os << endl;
}
}
void test(istream& inputStream, ostream& outputStream, long long secTimeout, int randSeed) {
cerr << "load input." << endl;
LatinSquare lsc;
loadInput(inputStream, lsc);
cerr << "solve." << endl;
steady_clock::time_point endTime = steady_clock::now() + seconds(secTimeout);
solveLatinSquare(outputStream, lsc, [&]() { return duration_cast<milliseconds>(endTime - steady_clock::now()).count(); }, randSeed);
}
void test(istream& inputStream, ostream& outputStream, long long secTimeout) {
return test(inputStream, outputStream, secTimeout, static_cast<int>(time(nullptr) + clock()));
}
int main(int argc, char* argv[]) {
cerr << "load environment." << endl;
if (argc > 2) {
long long secTimeout = atoll(argv[1]);
int randSeed = atoi(argv[2]);
test(cin, cout, secTimeout, randSeed);
} else {
//string filename = "./Instance/LSC.n70f3920.00.txt";
//for (int i = 0; i < 100; ++i) {
// int h = i / 10, l = i % 10;
// filename[24] = h + '0';
// filename[25] = l + '0';
// cerr << "Current file: " << filename << endl;
// ifstream ifs(filename);
// ofstream ofs("./Instance/solution.txt");
// test(ifs, ofs, 5); // for self-test.
// cerr << "*****************" << endl;
//}
ifstream ifs("./Instance/LSC.n70f3920.00.txt");
ofstream ofs("./Instance/solution.txt");
test(ifs, ofs, 1500); // for self-test
}
return 0;
}