示例#1
0
            else:
                return []
        else:
            #raise Exception('Never reachable here')
            return []


# Testing phase
if (not args.answer):
    board_x, board_y, board_z, boards = nl3d.read_probfile(input_problem, n_dims)
else:
    board_x, board_y, board_z, boards = nl3d.read_ansfile(input_problem, n_dims)

x_data = [[] for z in range(board_z)]
for z in range(board_z):
    x_data[z], _ = nl.gen_dataset_shape(board_x, board_y, boards[z], n_dims, method)

x_test = [[] for z in range(board_z)]
for z in range(board_z):
    x_test[z] = np.array(x_data[z], dtype=np.float32)

result = [[] for z in range(board_z)]
for z in range(board_z):
    result[z] = evaluate(x_test[z])

# boards_pr: 予想される配線のボード
# `wrong` に間違った配線形状かどうか記録する
boards_pr = copy.deepcopy(boards)
for z in range(board_z):
    idx = 0
    for y in range(n_dims_half, board_y + n_dims_half):
示例#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) # 配線接続位置の分類 (シンクから)

        x_test_raw = x_test_raw + x_data
示例#3
0
                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']:
                board_pr[y][x]['wrong'] = True