Graph theory, like matrix games, are fundamental concepts in programming and data structures. Databases rely on mathematical objects for logical connection in their methods of storing and working with data.
def print_tree_by_level(tree): for level in tree: print(level) def print_tree_by_level2(tree): for level in tree: for i in range(len(level)): print(str(level[i]), end = ' ') print() def get_path(edge): path = [] while edge.parent: path.append(edge.tag) edge = edge.parent path.append(edge.tag) return path[::-1]
Separate math methods into functions to encapsulate and call them quickly for each layer, in a loop:
tree = generate_random_game_tree(g_cur_game) solution = reverse_induction(tree, g_cur_game) path = get_path(solution.path_last) print("Game cost array: {}".format(solution.cost_array)) print("Winner is {} player ({})".format(1 + get_max_index(solution.cost_array), max(solution.cost_array))) print("Path is {}".format(path))
We also print output cyclically, layer by layer. Alignment of vertices by constant lengths is mandatory. Without an output format that is understandable to the user, it is impossible to test yourself.
The above is the detailed content of Graphs as methods of implication. For more information, please follow other related articles on the PHP Chinese website!