def run(self, graph):
     edges = graph.edges
     vertices = graph.vertices
     edges = self.__sort_edges(edges)
     self.__intial_joint_lists(vertices)
     tree_edges = list()
     tree_vertices = list()
     for edge in edges:
         if (len(self.__joint_lists) == 1):
             break
         if self.__joint(edge.source, edge.destination):
             tree_edges.append(edge)
     tree_graph = Graph()
     tree_graph.vertices = vertices.copy()
     tree_graph.edges = tree_edges.copy()
     return tree_graph
Exemple #2
0
    def run(self, graph):
        vertices = graph.vertices
        self.__initial_algorithm(vertices)
        for edge in vertices[3].edges:
            self.__queue.append(edge)

        tree_edges = list()
        counter = 0
        while False in self.__is_visited.values():
            self.__queue = sorted(self.__queue, key=lambda edge: edge.weight)
            min_edge = self.__queue.pop(0)
            tree_edges.append(min_edge)
            self.__is_visited[min_edge.source] = True
            self.__is_visited[min_edge.destination] = True
            for edge in min_edge.destination.edges:
                if not self.__is_visited[edge.destination]:
                    self.__queue.append(edge)

        tree_graph = Graph()
        tree_graph.vertices = vertices.copy()
        tree_graph.edges = tree_edges.copy()
        return tree_graph