Esempio n. 1
0
input_answer = args.input
n_dims = 3
n_dims_half = n_dims / 2

# 配線を表示する
def show_board(_board, show_float=False):
    shstr = ['   ', ' │ ', '─┘ ', ' └─', '─┐ ', ' ┌─', '───']
    idx = 0
    for y in range(n_dims_half, board_y + n_dims_half):
        for x in range(n_dims_half, board_x + n_dims_half):
            if _board[y][x]['type'] == 1:
                sys.stdout.write('\033[1;30;47m {} \033[0m'.format(nl.int2str(_board[y][x]['data'], 36)))
            else:
                # 正しい配線形状
                fr_color = '30'

                # 途切れてないセル / 途切れてるセル
                bg_color = '47'
                if show_float:
                    if _board[y][x]['float'] != None:
                        bg_color = '43'

                sys.stdout.write('\033[1;{};{}m{}\033[0m'.format(fr_color, bg_color, shstr[_board[y][x]['shape']]))

                idx = idx + 1
        print ''

board_x, board_y, board = nl.read_ansfile(input_answer, n_dims)
show_board(board)
Esempio n. 2
0

# Learning loop
x_train_raw, y_train_raw = [], []
x_test_raw,  y_test_raw  = [], []

# トレーニング/テスト ファイルを読み込む
datafiles = glob.glob(DIR_DATA + '/*.txt')
for datafile in datafiles:
    path_datafile = datafile.replace('\\', '/').split('/')
    datafilename = path_datafile[-1]
    datafilename_woext = datafilename[0:-4]
    # Training data
    if datafilename != testfilename and datafilename_woext != testfilename:
        print 'Reading train file: {}/{} ...'.format(DIR_DATA, datafilename)
        _board_x, _board_y, _board = nl.read_ansfile(datafile, n_dims)

        x_data, y_data = nl.gen_dataset_shape(_board_x, _board_y, _board, n_dims, args.dataset) # 配線形状の分類
        #x_data, y_data = nl.gen_dataset_dirsrc(board_x, board_y, board, n_dims) # 配線接続位置の分類 (ソースから)
        #x_data, y_data = nl.gen_dataset_dirsnk(board_x, board_y, board, n_dims) # 配線接続位置の分類 (シンクから)

        x_train_raw = x_train_raw + x_data
        y_train_raw = y_train_raw + y_data
    # Test data
    else:
        print 'Reading test file: {}/{} ...'.format(DIR_DATA, datafilename)
        board_x, board_y, board = nl.read_ansfile(datafile, n_dims)

        x_data, y_data = nl.gen_dataset_shape(board_x, board_y, board, n_dims, args.dataset) # 配線形状の分類
        #x_data, y_data = nl.gen_dataset_dirsrc(board_x, board_y, board, n_dims) # 配線接続位置の分類 (ソースから)
        #x_data, y_data = nl.gen_dataset_dirsnk(board_x, board_y, board, n_dims) # 配線接続位置の分類 (シンクから)
Esempio n. 3
0
            if _from == 'east':
                return _find_path(_board, x - 1, y, 'east', depth) + cur
            elif _from == 'west':
                return _find_path(_board, x + 1, y, 'west', depth) + cur
            else:
                return []
        else:
            #raise Exception('Never reachable here')
            return []


# Testing phase
if (not args.answer):
    board_x, board_y, board = nl.read_probfile(input_problem, n_dims)
else:
    board_x, board_y, board = nl.read_ansfile(input_problem, n_dims)
x_data, _ = nl.gen_dataset_shape(board_x, board_y, board, n_dims, dataset)

x_test = np.array(x_data, dtype=np.float32)

result = evaluate(x_test)

# board_pr: 予想される配線のボード
# `wrong` に間違った配線形状かどうか記録する
board_pr = copy.deepcopy(board)
idx = 0
for y in range(n_dims_half, board_y + n_dims_half):
    for x in range(n_dims_half, board_x + n_dims_half):
        if board_pr[y][x]['type'] != 1:
            board_pr[y][x]['shape'] = np.argmax(result.data[idx])
            if board[y][x]['type'] != board_pr[y][x]['type'] or board[y][x]['shape'] != board_pr[y][x]['shape']: