-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in distance calculation from flattened matrix #40
Comments
Hi @leonlan, |
The problem here is mainly with the way that the matrix in E-n13-k4 is given.
This array of numbers corresponds to the lower triangle of the distances matrix. Since it's not formatted like that, I assumed that this should be first put in an 1-D array, and then each element of the array corresponds to some index of the lower triangle matrix. The TSPLIB specification describes the
This reads as if the matrix should be parsed per row, so the entries are supposed to be parsed in order (1, 0), (2, 0), (2, 1), (3, 0), etc. But, as shown in the paper, the E-n13-k4 instance is parsed in order of columns instead. Fortunately, I'm pretty sure this is the only edge case that needs to be parsed like this. But I need to double check this. I'll think a bit about what I'll do here to fix this edge case! |
Alright, thank you. The E-n13-k4 was indeed the only instance I encountered this bug. |
@wgfiis Thanks for reporting this. I'll close this issue because it's a problem with the CVRPLIB and the instance they have provided. But I'll send them a message about it and ask if they can change it. |
Just found a bug in the distance calculation from flattened distance matrices.
The function 'from_flattened' (line 141 in cvrp.py) assumes that
" The numbers in a flattened list correspond the matrix element indices
(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2), (4, 0), ..."
However, for the instance E-n13-k4 the flattened list correponds to indices
(0, 1), (0, 2), (0, 3), (0, 4), ... (11,12).
Changing line 150
indices = sorted([(i, j) for (j, i) in combinations(range(n), r=2)])
to
indices = sorted([(i, j) for (i, j) in combinations(range(n), r=2)])
resolves this issue.
However, I do not know whether the original sorting might be correct for some other instances.
The text was updated successfully, but these errors were encountered: