(u, distance_matrix)
| 38 | |
| 39 | # Function: Decoder |
| 40 | def decoder(u, distance_matrix): |
| 41 | route = np.where(u == 1)[1].tolist() |
| 42 | if (len(route) == 0): |
| 43 | route = np.argmax(u, axis = 1).tolist() |
| 44 | route = [item for item in route if route.count(item) == 1] |
| 45 | route = [route.index(item) for item in range(0, len(route)) if item in route] |
| 46 | if (len(route) < distance_matrix.shape[0]): |
| 47 | complete = list(range(0, distance_matrix.shape[0])) |
| 48 | complete = [item for item in complete if item not in route] |
| 49 | route = route + complete |
| 50 | route = route + [route[0]] |
| 51 | route = [item+1 for item in route] |
| 52 | distance = distance_calc(distance_matrix, [route, 1]) |
| 53 | return route, distance |
| 54 | |
| 55 | ############################################################################### |
| 56 |
no test coverage detected