def get_christofides_tours_edges(self, graph, weight="weight"):
        """ Extract the doubletours edges from the graph """

        tours = self.get_christofides_tours(graph)
        edges_a = graph_utils.get_tour_edges(tours[0]).tolist()
        edges_b = graph_utils.get_tour_edges(tours[1]).tolist()
        return edges_a + edges_b
    def extract_doubletours_edges_from_tree(self, tree, weight="weight"):
        """ Extract the doubletours edges from the tree """

        tours = self.get_doubletours_from_tree(tree)
        edges_a = graph_utils.get_tour_edges(tours[0]).tolist()
        edges_b = graph_utils.get_tour_edges(tours[1]).tolist()
        return edges_a + edges_b
    def compute_labels_from_solution(self, solution_fname):
        """ Using the solution file, read the solution in """

        tour = self._object.read_solution_from_file(solution_fname)
        edges = graph_utils.get_tour_edges(tour)
        min_vertex = np.min(self._graph.nodes)
        order = len(self._graph.nodes)
        indices = [graph_utils.compute_vector_index_symmetric(edge, order, min_vertex)
                   for edge in edges]
        vector = np.zeros((len(self._graph.edges)))
        vector[indices] = 1
        return vector
    def get_christofides_tour_edges(self, graph, weight="weight"):
        """ Extract the doubletour edges from the graph """

        tour = self.get_get_christofides_tour(graph)
        return graph_utils.get_tour_edges(tour).tolist()
    def extract_doubletour_edges_from_tree(self, tree, weight="weight"):
        """ Extract the doubletour edges from the tree """

        tour = self.get_doubletour_from_tree(tree)
        return graph_utils.get_tour_edges(tour).tolist()
Exemple #6
0
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
    three = np.sum([edge in features[2] for edge in edges]) + two
    four = np.sum([edge in features[3] for edge in edges]) + three
    five = np.sum([edge in features[4] for edge in edges]) + four
    length = len(solution.tour)

    ones.append(one / length)
Exemple #7
0
    def _compute_christofides_edges(self, graph):
        """ Compute the Christofides edges """

        tour = self._compute_christofides_tour(graph)
        is_symmetric = graph_utils.check_graph(graph)
        return graph_utils.get_tour_edges(tour, is_symmetric)
Exemple #8
0
    def _compute_doubletree_edges(self, graph):
        """ Compute the doubletree edges """

        tour = self._compute_doubletree_tour(graph)
        is_symmetric = graph_utils.check_graph(graph)
        return graph_utils.get_tour_edges(tour, is_symmetric)
 def read_solution_from_file(self, fname, symmetric=True):
     tour = read_solution_from_file(fname)
     edges = graph_utils.get_tour_edges(tour, symmetric=symmetric)
     self._solution = edges
     return tour