Rudy’s OBTF Rudolf Adamkovič

Home / Computer science / Traveling salesman problem (TSP) / Computation in Python / Implement


traveling_salesman.read_instance

def read_instance(file_name):

    # Count the cities.
    count = None
    with open(file_name) as file:
        count = int(file.readline())

    # Load the city identifiers and coordinates.
    instance = np.loadtxt(
        file_name, dtype=int, comments=None, skiprows=1, max_rows=count
    )

    # TODO Validate the result.

    return instance
None

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.