median: vertices selected for the solution """ N = len(dist) median = random.sample(range(N), p) d1 = [-1 for i in range(N)] d2 = [-1 for i in range(N)] r = update_assignment(dist, median, d1, d2, p , N) if verbose: print(r) while True: result = next(dist, median, d1, d2, p, N) if result[0]: r = result[1] if verbose: print(r) else: break return r, median if __name__ == "__main__": import sys sys.path.append('../networks') from network2listmatrix import network2distancematrix from allpairdist import allpairs print('Problem: simple network') a = network2distancematrix('../data/network-links', True) allpairs(a) teitz_bart(a, 2, True) print('Problem: pmed1 in OR-lib') a = network2distancematrix('../data/orlib/pmed1.orlib', False) allpairs(a) teitz_bart(a, 5, True)
""" N = len(dist) median = random.sample(range(N), p) d1 = [-1 for i in range(N)] d2 = [-1 for i in range(N)] r = update_assignment(dist, median, d1, d2, p, N) if verbose: print(r) while True: result = next(dist, median, d1, d2, p, N) if result[0]: r = result[1] if verbose: print(r) else: break return r, median if __name__ == "__main__": import sys sys.path.append('../networks') from network2listmatrix import network2distancematrix from allpairdist import allpairs print('Problem: simple network') a = network2distancematrix('../data/network-links', True) allpairs(a) teitz_bart(a, 2, True) print('Problem: pmed1 in OR-lib') a = network2distancematrix('../data/orlib/pmed1.orlib', False) allpairs(a) teitz_bart(a, 5, True)
__author__ = "Ningchuan Xiao <*****@*****.**>" def allpairs(a): """ Returns the weight/distance matrix for all pair shortest path using the Floyd-Warshall algorithm. Input a: initial distance matrix where weights for non-adjacent pairs are infinity Output The function directly changes the values in the input """ n = len(a) for k in range(n): for i in range(n): for j in range(n): if a[i][j] > a[i][k] + a[k][j]: a[i][j] = a[i][k] + a[k][j] if __name__ == "__main__": from network2listmatrix import network2distancematrix fname = '../data/network-links' a = network2distancematrix(fname, True) allpairs(a) print(a[1][6]) print(a[0][7])