def is_mlst(edge_set): """ Get number of leaves if graph is mlst else return False """ import graph graph = graph.make_graph(edge_set) graph.search() return graph.num_leaves if (graph.edges_in_one_component() and len(graph.get_edge_set()) == (graph.num_nodes - 1) and not graph.has_cycle) else False
def search_tweets(update, ctx): text = update.message.text text = cutcmd(text) graf = graph.search(text, title=text) log(graf, text, 'search', text + ':search') ctx.bot.send_message(chat_id=update.effective_chat.id, text="*" + text + "*\n" + graf["url"], parse_mode=telegram.ParseMode.MARKDOWN)
def find_path_to_end(self, g, start): ''' Find the start and end points in order for the solution route to be the longest possible with no backtracking. Uses dynamic programming(???). Arg: reached is a dictionary whose keys are the vertices that can be reached the maze start and reached[u] is the vertex that discovered u in the search Returns the route as a list with the first entry as the start and the last entry as the end. ''' paths = [] # store all possible paths from the start vertices = list(g.vertices()) reached = graph.search(g, start) for v in vertices: # find the path from start to v paths.append(graph.find_path(g, start, v, reached)) # return the longest path # the last entry is the end of the maze return max(paths, key=len)