def check_duality_gap(a, b, M, G, u, v, cost):
cost_dual = np.vdot(a, u) + np.vdot(b, v)
# Check that dual and primal cost are equal
np.testing.assert_almost_equal(cost_dual, cost)
[ind1, ind2] = np.nonzero(G)
# Check that reduced cost is zero on transport arcs
np.testing.assert_array_almost_equal((M - u.reshape(-1, 1) - v.reshape(1, -1))[ind1, ind2],
np.zeros(ind1.size))
评论列表
文章目录