-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsp.py
30 lines (21 loc) · 912 Bytes
/
tsp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
class TSP:
def __init__(self, n_nodes, xmax=100, ymax=100, **kwargs):
xs = np.random.uniform(0, xmax, n_nodes).reshape(-1, 1)
ys = np.random.uniform(0, ymax, n_nodes).reshape(-1, 1)
self._n_nodes = n_nodes
self._coords = np.concatenate([xs, ys], axis=1)
self._dist_matrix = np.zeros((self._n_nodes, self._n_nodes))
for i in range(self._n_nodes):
for j in range(self._n_nodes):
self._dist_matrix[i][j] = np.sqrt((self._coords[i, 0] - self._coords[j, 0]) ** 2 + (self._coords[i, 1] - self._coords[j, 1]) ** 2)
def compute_greedy_solution(self):
pass
def get_distances(self, i):
return self._dist_matrix[i, :]
def get_dist_matrix(self):
return self._dist_matrix
def get_nodes(self):
return self._coords
def get_n_nodes(self):
return self._n_nodes