예제 #1
0
def read(filename):
    """Returns Vertexes using the data from the file with the given filename"""
    with open(filename) as fp:
        lines = fp.readlines()
    first_line_to_read = [i for i, line in enumerate(lines) if 'NODE_COORD_SECTION' in line][0] + 1
    last_line_to_read = [i for i, line in enumerate(lines) if 'EOF' in line][0]
    cities = list()
    for city_data in lines[first_line_to_read:last_line_to_read]:
        city_data = city_data.split(' ')
        label = city_data[0]
        c = Vertex(label)
        c.x = int(city_data[1])
        c.y = int(city_data[2])
        cities.append(c)

    return cities