コード例 #1
0
if __name__ == "__main__":
    # load file containing data
    filename = 'input.txt'
    lines = get_input(filename)

    # Retrieve data
    coordinates, num_nodes = get_input(filename)

    # initialise Graph object for constructing minimum spanning tree
    mst = Logic(num_nodes)

    # load edges to graph. Assume fully connected
    # node 0 is earth, node 1 is zearth
    for i, coord1 in enumerate(coordinates):
        for j, coord2 in enumerate(coordinates):
            if (i != j) & (i < j):
                weight = get_distance(coord1, coord2)
                mst.add_edge(i, j, weight)

    result = mst.find_MST()

    # Get best route from mst
    route = mst.find_shortest_path(0, 1, result)
    # Get max weight path in route
    max_weight = mst.get_max_weight(route)

    # print results
    print("Best route is: {}".format(route))
    print("Output: %.2f" % max_weight)