diff --git a/src/main.cc b/src/main.cc index c2a9e0b..8799b56 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,7 +18,7 @@ //int main(int argc, char *argv[]) { int main() { -// BasicRanges::build(); + BasicRanges::build(); // AllCases::build(); @@ -59,73 +59,36 @@ int main() { // } + auto start_time = clock(); + // auto a = Analyse(RawCode::from_common_code("1a9bf0c")); // auto a = Analyse(RawCode::from_common_code("4fea134")); -// auto a = Analyse(RawCode::from_common_code("A5D3AF")); -// auto a = Analyse(RawCode::from_common_code("1FA6F80")); -// auto a = Analyse(RawCode::from_common_code("0F5747")); - -// if (argc < 2) { -// std::cout << "without input code" << std::endl; -// } -// auto a = Analyse(RawCode::from_common_code(argv[1])); - - - std::string input; - std::cout << "Please give a common code: "; - std::cin >> input; + auto a = Analyse(RawCode::from_common_code("A5D3AF")); - auto common_code = CommonCode::from_string(input); - - std::cout << ShortCode::from_common_code(common_code).to_string() << " -> "; - - auto start_time = clock(); - - auto a = Analyse(RawCode::from_common_code(common_code)); // a.build(); auto ret = a.build_until([](uint64_t code) { return ((code >> (3 * 0xD)) & 0b111) == B_2x2; }); - std::cout << ret.size() << std::endl; - - std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; - -// std::cout << "analyse complete" << std::endl; // for (const auto &r : ret) { // std::cout << r << std::endl; // } +// std::cout << ret.size() << std::endl; -// auto ret = a.backtrack({ -// 0x7F87E0E5BFFF492, 0x1FB1E36F9FFF492, RawCode::from_common_code("2CEA8DC").unwrap() -// }); - auto svg_ret = a.backtrack(ret); + std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; -// std::cout << "backtrack complete" << std::endl; auto g = Graph(); + auto svg_ret = a.backtrack(ret); auto svg_data = g.svg_demo(svg_ret); + std::cout << svg_data << std::endl; - std::ofstream output; - output.open(common_code.to_string(true) + ".svg"); - output << svg_data << std::endl; - output.close(); - -// std::cout << svg_data << std::endl; - -// auto start_time = clock(); // std::cout << a.layer_export(81).size() << std::endl; // std::cout << a.layer_export()[81].size() << std::endl; -// auto raw_code = CommonCode("A5D3AF0").to_raw_code().unwrap(); - -// auto a = Analyse(); -// a.start_analyse(raw_code); - -// a.backtrack(0x07F87E0E5BFFF492); // std::vector raw_codes = { // CommonCode(0xDAAF4CC00).to_raw_code().unwrap(), @@ -159,12 +122,11 @@ int main() { // std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl; // std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; -// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; + std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; // std::cout << "complete benchmark" << std::endl; - std::cerr << "Press CTRL-C for exit..."; - pause(); +// pause(); return 0; } diff --git a/svg-demo/svg_dump.py b/svg-demo/svg_dump.py deleted file mode 100755 index 10ae08f..0000000 --- a/svg-demo/svg_dump.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import yaml - -BLOCK_LENGTH = 12 -BLOCK_DISTANCE = 4 - -CASE_WIDTH = BLOCK_LENGTH * 4 + BLOCK_DISTANCE * 5 -CASE_HEIGHT = BLOCK_LENGTH * 5 + BLOCK_DISTANCE * 6 - -CASE_DISTANCE_X = 80 -CASE_DISTANCE_Y = 40 - -MAIN_MARGIN_X = 10 -MAIN_MARGIN_Y = 8 - -LINK_OFFSET = 1 - -raw_data = yaml.load(open('demo.yml').read(), Loader = yaml.FullLoader) -layer = raw_data['layer'] -link = raw_data['next'] - -# print(layer) -# print(link) - -MAX_CASE_X = max([len(x)for x in layer]) -MAX_CASE_Y = len(layer) - -# def cal_length(num: int, single_length: int, distance: int): -# return num * single_length + (num - 1) * distance - - -MAX_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X - - -def case_address(layer_num: int, layer_index: int) -> (int, int): - - case_number_x = len(layer[layer_num]) - - MY_WIDTH = case_number_x * CASE_WIDTH + (case_number_x - 1) * CASE_DISTANCE_X - - MY_WIDTH_OFFSET = int((MAX_WIDTH - MY_WIDTH) / 2) - - return ( - layer_index * (CASE_WIDTH + CASE_DISTANCE_X) + MY_WIDTH_OFFSET + MAIN_MARGIN_X, - layer_num * (CASE_HEIGHT + CASE_DISTANCE_Y) + MAIN_MARGIN_Y, - ) - - -def link_address(start_layer_num: int, start_layer_index: int, end_layer_num: int, end_layer_index: int) -> (int, int, int, int): - - x1, y1 = case_address(start_layer_num, start_layer_index) - x2, y2 = case_address(end_layer_num, end_layer_index) - - return ( - x1 + int(CASE_WIDTH / 2), - y1 + CASE_HEIGHT + LINK_OFFSET, - x2 + int(CASE_WIDTH / 2), - y2 - LINK_OFFSET, - ) - - -def svg_rect(left: int, top: int, width: int, height: int, line_width: int): - return '' % ( - left, top, width, height, line_width - ) - - -def svg_line(start_x: int, start_y: int, end_x: int, end_y: int): - return '' % ( - start_x, start_y, end_x, end_y - ) - - -def case_output(info: list, x_offset: int, y_offset: int): - print(' ', svg_rect(x_offset, y_offset, CASE_WIDTH, CASE_HEIGHT, 2)) - for (x, y, h, w) in info: - - left = BLOCK_LENGTH * x + BLOCK_DISTANCE * (x + 1) + x_offset - top = BLOCK_LENGTH * y + BLOCK_DISTANCE * (y + 1) + y_offset - width = BLOCK_LENGTH * w + BLOCK_DISTANCE * (w - 1) - height = BLOCK_LENGTH * h + BLOCK_DISTANCE * (h - 1) - - print(' ', svg_rect(left, top, width, height, 1)) - - -MAIN_WIDTH = MAX_CASE_X * CASE_WIDTH + (MAX_CASE_X - 1) * CASE_DISTANCE_X + MAIN_MARGIN_X * 2 -MAIN_HEIGHT = MAX_CASE_Y * CASE_HEIGHT + (MAX_CASE_Y - 1) * CASE_DISTANCE_Y + MAIN_MARGIN_Y * 2 - -print('' % (MAIN_WIDTH, MAIN_HEIGHT)) - -for layer_num in range(0, len(layer)): - for layer_index in range(0, len(layer[layer_num])): - x, y = case_address(layer_num, layer_index) - case_output(layer[layer_num][layer_index], x, y) - -for layer_num in range(0, len(link)): - for layer_index in range(0, len(link[layer_num])): - for next_index in link[layer_num][layer_index]: - x1, y1, x2, y2 = link_address(layer_num, layer_index, layer_num + 1, next_index) - # print('(%d, %d) -> (%d, %d)' % (layer_num, layer_index, layer_num + 1, next_index)) - print(' ', svg_line(x1, y1, x2, y2)) - - -print('')