This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (64 loc) · 2.1 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
64
65
66
67
68
69
#include <iostream>
#include <fstream>
#include <sstream>
#include <csignal>
#ifdef USE_FILE_DUMP
#include <boost/filesystem.hpp>
#endif
#include "procon26.hpp"
#include "beam_search.hpp"
using namespace std;
void export_to_file(output_t const & a) {
#ifdef USE_FILE_DUMP
string path; {
int i = 0;
do {
ostringstream oss;
oss << ".log-" << (i++) << ".txt";
path = oss.str();
} while (boost::filesystem::exists(path));
}
ofstream fp(path, ios::out);
fp << a;
#endif
}
output_t g_provisional_result; // externed
int g_best_score = 1000000007;;
int g_best_stone = 1000000007;;
void signal_handler(int param) {
cerr << "*** signal " << param << " caught ***" << endl;
cout << g_provisional_result;
cerr << "***" << endl;
export_to_file(g_provisional_result);
cerr << g_best_score << " " << g_best_stone << endl;
exit(param);
}
int main(int argc, char **argv) {
ios_base::sync_with_stdio(false);
input_t a; cin >> a;
int n = a.blocks.size();
board brd = board(a.board);
vector<block> blks(n); repeat (i,n) blks[i] = block(a.blocks[i]);
assert (argc == 3 or argc == 4);
int BEAM_WIDTH = atoi(argv[1]);
double BEAM_SEARCH_TIME = atof(argv[2]);
bool IS_CHOKUDAI = 3 < argc ? atoi(argv[3]) : false;
if (BEAM_SEARCH_TIME > 0.01) { // 幅の自動調整
clock_t start = clock();
beam_search(brd, blks, BEAM_WIDTH, false);
clock_t clock_per_width = (clock() - start) / BEAM_WIDTH;
double sec_per_width = clock_per_width /(double) CLOCKS_PER_SEC;
BEAM_WIDTH = min<int>(16384, (BEAM_SEARCH_TIME * 60 / sec_per_width - BEAM_WIDTH) * 0.95);
cerr << "measured: " << sec_per_width << " sec/width" << endl;
}
cerr << "start with width: " << BEAM_WIDTH << endl;
signal(SIGINT, &signal_handler);
output_t b = { beam_search(brd, blks, BEAM_WIDTH, IS_CHOKUDAI) };
signal(SIGINT, SIG_DFL);
cerr << "*** done ***" << endl;
cout << b;
cerr << "***" << endl;
export_to_file(b);
cerr << g_best_score << " " << g_best_stone << endl;
return 0;
}