def load_graph(self, path):
     graph = open(path, "r")
     text = ""
     for line in graph:
         formated_input = self.__format_string(line)
         no = No(formated_input[0])
         no.neighbors = formated_input[1]
         text += GRAU.format(formated_input[0], len(formated_input[1]))
         self.graph.append(no)
         self.label2.configure(text=text)
Ejemplo n.º 2
0
def main():
    inputs = []
    graph = []
    length = int(input("Write the graph's length: "))
    for count in range(length):
        line = str(input("Write graph with 'id' + 'list of neighbors': "))
        formated_input = format_string(line)
        inputs.append(formated_input)

    for id, neighbors in inputs:
        no = No(id)
        no.neighbors = neighbors
        graph.append(no)

    BFS(graph)
    results = [verify_no(no) for no in graph]
    if all(results):
        print("All connected")
    else:
        print("Not connected")

    draw_graph(graph)