def find_matches(D_s, print_assignment=False):
matches=[]
costs=[]
t_start=time.time()
for ii,D in enumerate(D_s):
DD=D.copy()
if np.sum(np.where(np.isnan(DD)))>0:
raise Exception('Distance Matrix contains NaN, not allowed!')
# indexes = m.compute(DD)
# indexes = linear_assignment(DD)
indexes = linear_sum_assignment(DD)
indexes2=[(ind1,ind2) for ind1,ind2 in zip(indexes[0],indexes[1])]
matches.append(indexes)
DD=D.copy()
total = []
for row, column in indexes2:
value = DD[row,column]
if print_assignment:
print '(%d, %d) -> %f' % (row, column, value)
total.append(value)
print 'FOV: %d, shape: %d,%d total cost: %f' % (ii, DD.shape[0],DD.shape[1], np.sum(total))
print time.time()-t_start
costs.append(total)
return matches,costs
#%%
评论列表
文章目录