Skip to content

Commit

Permalink
implement floyd on tmat_class atsp generation
Browse files Browse the repository at this point in the history
  • Loading branch information
abcdhhhh committed Oct 17, 2024
1 parent f979492 commit b0e4aa0
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions rl4co/envs/routing/atsp/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ def _generate(self, batch_size) -> TensorDict:
dms[..., torch.arange(self.num_loc), torch.arange(self.num_loc)] = 0
log.info("Using TMAT class (triangle inequality): {}".format(self.tmat_class))
if self.tmat_class:
while True:
old_dms = dms.clone()
dms, _ = (
dms[..., :, None, :] + dms[..., None, :, :].transpose(-2, -1)
).min(dim=-1)
if (dms == old_dms).all():
break
for i in range(self.num_loc):
dms = torch.minimum(dms, dms[..., :, [i]] + dms[..., [i], :])
return TensorDict({"cost_matrix": dms}, batch_size=batch_size)

0 comments on commit b0e4aa0

Please sign in to comment.