import tsp_reader import networkx as nx import matplotlib.pyplot as plt import sys theorem = int(sys.argv[1]) filename = sys.argv[2] city = filename.split('/')[-1].split('.')[0] fn = None if theorem == 1: fn = teo1.teo_1 else: fn = teo2.teo_2 g = tsp_reader.read(open(filename).read()) for k in range(1, len(g.nodes())+1): f = fn(g, k) n = nx.Graph() print(k) for edge in f.edges(): print "%d %d %d" % (edge[0], edge[1], g.edge_weight(edge)) print for node in f.nodes(): n.add_node(node) for edge in f.edges():
import tsp_reader import networkx as nx import matplotlib.pyplot as plt import sys theorem = int(sys.argv[1]) filename = sys.argv[2] city = filename.split('/')[-1].split('.')[0] fn = None if theorem == 1: fn = teo1.teo_1 else: fn = teo2.teo_2 g = tsp_reader.read(open(filename).read()) for k in range(1, len(g.nodes())+1): f = fn(g, k) n = nx.Graph() print k for edge in f.edges(): print "%d %d %d" % (edge[0], edge[1], g.edge_weight(edge)) print for node in f.nodes(): n.add_node(node) for edge in f.edges():
# Uso: # python teo1.py k arq.tsp # k - o parâmetro K do teorema # arq.tsp - arquivo contendo uma tupla (id, x, y) por linha import tsp_reader import sys from time import time EXECS_PER_LOOP = 1 TIME_THRESHOLD = 5 k = int(sys.argv[1]) tsp_file = sys.argv[2] tsp_str = open(tsp_file).read() g = tsp_reader.read(tsp_str) if k == -1: k = len(g.nodes()) if k > len(g.nodes()): raise ValueError('FORBIDDEN: K > |V|') # Executa EXECS_PER_LOOP vezes a cada vez, ate passar de TIME_THRESHOLD segundos start = time() execs = 0 while time() - start < TIME_THRESHOLD: execs += EXECS_PER_LOOP for i in range(EXECS_PER_LOOP): f = teo_1(g, k) end = time()
return inv_map.values() if __name__ == '__main__': import tsp_reader import sys from time import time EXECS_PER_LOOP = 1 TIME_THRESHOLD = 5 k = int(sys.argv[1]) tsp_file = sys.argv[2] tsp_str = open(tsp_file).read() g = tsp_reader.read(tsp_str) if k == -1: k = len(g.nodes()) if k > len(g.nodes()): raise ValueError('FORBIDDEN: K > |V|') start = time() execs = 0 while time() - start < TIME_THRESHOLD: execs += EXECS_PER_LOOP for i in range(EXECS_PER_LOOP): f = teo_2(g, k) end = time() elapsed = end - start