def compute_labels_from_problem(self, problem_fname):
        """ Using the problem file, compute the labels """
        
        object = io_utils.optObject().read_problem_from_file(problem_fname)
        graph = object.get_graph()

        return compute_solutions.get_all_optimal_tsp_solutions(graph)
Beispiel #2
0
from optlearn import experiment_utils
from optlearn import graph_utils
from optlearn import io_utils
from optlearn import cc_solve

from optlearn.mst import mst_model

files = experiment_utils.list_files_recursive("/home/james/Data/MATHILDA/tsp/")

model = mst_model.mstSparsifier()

ones, twos, threes, fours, fives = [], [], [], [], []

for num, file in enumerate(files):
    object = io_utils.optObject().read_from_file(file)
    graph = object.get_graph()
    graph = graph_utils.delete_self_weights(graph)
    graph = graph.to_undirected()

    solution = cc_solve.solution_from_path(file)
    edges = graph_utils.get_tour_edges(solution.tour)
    if np.min(solution.tour) < 1 and np.min(graph.nodes) > 0:
        edges += 1
    edges = model.tuples_to_strings(edges)

    features = model.run_sparsify(graph, 15)
    features = [model.tuples_to_strings(item) for item in features]

    one = np.sum([edge in features[0] for edge in edges])
    two = np.sum([edge in features[1] for edge in edges]) + one
    def load_object(self, problem_fname):
        """ Load the problem file and store it as a hidden attribute """

        self._object = io_utils.optObject()
        self._object.read_problem_from_file(problem_fname)
        self._graph = self._object.get_graph()
def load_problem(problem_path):
    """ Given the path to a tsp problem, load it as a networkx complete graph """

    object = io_utils.optObject().read_problem_from_file(problem_path)
    return object.get_graph()