finstance = sys.argv[1] kruskal_activated = False if len(sys.argv) > 2: kruskal_activated = (sys.argv[2] == "0") with open(finstance, "r") as fd: header = read_stsp.read_header(fd) print 'Header: ', header dim = header['DIMENSION'] edge_weight_format = header['EDGE_WEIGHT_FORMAT'] print "Reading nodes" nodes = read_stsp.read_nodes(header, fd) print "Reading edges" edges = read_stsp.read_edges(header, fd) edge_list = [] for k in range(dim): edge_list.append([]) for e in edges: if edge_weight_format in ['UPPER_ROW', 'LOWER_COL', \ 'UPPER_DIAG_ROW', 'LOWER_DIAG_COL']: edge_list[e[0]].append((e[1], int(e[2]))) else: edge_list[e[1]].append((e[0], int(e[2]))) for k in range(dim): edge_list[k].sort()
from read_stsp import read_edges from read_stsp import read_header from read_stsp import read_nodes from graph import Graph if __name__ == "__main__": import sys finstance = sys.argv[1] G = Graph() with open(finstance, "r") as fd: header = read_header(fd) print 'Header: ', header dim = header['DIMENSION'] edge_weight_format = header['EDGE_WEIGHT_FORMAT'] print "Reading nodes" nodes = read_nodes(header, fd, G) print "Reading edges" edges = read_edges(header, fd, G) # G.plot_graph() # print (G)
from edge import Edge from graph import Graph import read_stsp as rs logging.basicConfig(filename='logfile.log', level=logging.DEBUG) logging.info('Debut') finstance = sys.argv[1] with open(finstance, 'r') as fd: header = rs.read_header(fd) dim = header['DIMENSION'] edge_weight_format = header['EDGE_WEIGHT_FORMAT'] nodes = rs.read_nodes(header, fd) edges = rs.read_edges(header, fd) # create Graph G = Graph(name='Graphe') # convert dim dim = int(dim) # add nodes to graph if len(nodes) == 0: nodes = {k: None for k in xrange(dim)} for node in nodes.items(): # node id n = node[0] # node data