test_closure.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:knowledge_linker 作者: glciampaglia 项目源码 文件源码
def run_test(G, expect):
    N = G.shape[0]
    clofunc = partial(clo.epclosuress, G, retpaths=True)
    o, p = zip(*map(clofunc, xrange(N)))
    o = np.round(o, 2)
    # check capacities match
    assert np.allclose(o, expect)
    # check paths match with computed capacities
    for s, t in np.ndindex(G.shape):
        if (s == t) or G[s, t] > 0 or (o[s, t] == 0):
            # path must be empty
            assert len(p[s][t]) == 0
        else:
            # minimum on path must correspond to computed capacity
            path = p[s][t]
            weights = np.ravel(G[path[:-1], path[1:]])[:-1]
            weights = np.round(weights, 2)
            assert o[s, t] == np.min(weights)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号