principle
当我们拥有good basis时,我们可以求解CVP问题
实现
"""
Babai's algorithm
"""
def Babai(v, w):
t = np.linalg.solve(v, w)
n = np.shape(t)
n = n[0]
aa = np.zeros((1, n))
for i in range(n):
aa[0][i] = round(t[i])
res = np.dot(aa,v.T)
print('res.shape:'+str(np.shape(res)))
print('||v-w||:'+str(np.linalg.norm(res-w)))
return res
v1 = np.array([137, 312])
v2 = np.array([215, -187])
v = np.array([v1, v2])
w = np.array([53172, 81743])
print('Babai:'+str(Babai(v.T, w)))