def _load(filename, sort=True): f = open(filename) clusters = [] for line in f: if line.startswith('cluster'): a = line.split() a = map(int, a[5:]) clusters.append(a) f.close() if sort: clusters.sort(key=lambda x:average_step(get_agents(x))) return clusters
def sort(self): pair = zip(self.centroids, self.clusters) pair.sort(key=lambda x: average_step(x[1])) self.centroids, self.clusters = zip(*pair)