MCPcopy Create free account
hub / github.com/Valdecy/pyCombinatorial / decoder

Function decoder

pyCombinatorial/algorithm/hpn.py:40–53  ·  view source on GitHub ↗
(u, distance_matrix)

Source from the content-addressed store, hash-verified

38
39# Function: Decoder
40def 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

Callers 1

hopfield_network_tspFunction · 0.70

Calls 1

distance_calcFunction · 0.70

Tested by

no test coverage detected