当前位置: 首页>>代码示例>>Python>>正文


Python Graph.print_graph方法代码示例

本文整理汇总了Python中Graph.print_graph方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.print_graph方法的具体用法?Python Graph.print_graph怎么用?Python Graph.print_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.print_graph方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connectivity

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import print_graph [as 别名]
def test_connectivity():
    conn_dict = {}
    conn_lst = []
    for i in range(1000):
        graph, laplacian = random_graph(4)
        con = get_connectivity(laplacian)
        conn_lst.append(nx.average_node_connectivity(graph))
        conn_lst.sort()
        print con
        # if con < 0.74 and con>0.73:
        #     Graph.print_graph(graph)
        if 1.43 < con < 2.45:
            Graph.print_graph(graph)
        con = abs(con)
        con = round(con, 3)
        if con not in conn_dict:
            conn_dict[con] = 0
        conn_dict[con] += 1
开发者ID:tzaga,项目名称:test,代码行数:20,代码来源:Main.py

示例2: generate_cfg

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import print_graph [as 别名]

#.........这里部分代码省略.........

        for i in range(start_clnum, end_clnum + 1):
            pc = self.get_pc(i)
            asm = self.get_disasm(pc)
            if enter_call == 0:
                if pc == start_addr:
                    if ret_addr is None:
                        end_addr = self.get_ret_addr(i - 1)
                        print hex(end_addr)
                    else:
                        end_addr = ret_addr
                    enter_call = 1
                    trace = [(i, pc, asm)]
            else:
                if end_addr == pc:
                    print 'exit call'
                    enter_call = 0
                    traces.append(trace)
                    trace = []
                if enter_sub_call == 0:
                    trace.append((i, pc, asm))
                    if asm.startswith('call'):
                        enter_sub_call = 1
                        sub_call_ret = self.get_ret_addr(i)
                else:
                    if pc == sub_call_ret:
                        trace.append((i, pc, asm))
                        enter_sub_call = 0

        graph = Graph()

        pcs = []
        for trace in traces:
            print trace

        for trace in traces:
            exist_node = None
            exist_index = 1
            new_node = None
            for ins in trace:
                if ins[1] not in pcs:
                    pcs.append(ins[1])
                    if exist_node is None:
                        if new_node is None:
                            new_node = Node([Assemble(ins[1], ins[2])])
                            graph.add_node(new_node)
                        else:
                            new_node.add_asm(Assemble(ins[1], ins[2]))
                    else:
                        new_node = Node([Assemble(ins[1], ins[2])])
                        graph.add_node(new_node)
                        if len(exist_node.asm_seqs) == exist_index:
                            graph.add_edge(exist_node, new_node)
                        else:
                            node1, node2 = graph.split_node(exist_node, exist_index, count=exist_node.count - 1)
                            graph.add_edge(node1, new_node)
                        exist_node = None
                        exist_index = 0
                else:
                    if exist_node is None:
                        if new_node is None:
                            exist_node = graph.search_and_split(ins[1])
                            exist_node.add_count()
                            exist_index = 1
                        else:
                            node, index = graph.search_node(ins[1])
                            if index == 0:
                                graph.add_edge(new_node, node)
                                node2 = node
                            else:
                                node1, node2 = graph.split_node(node, index)
                                if node == new_node:
                                    graph.add_edge(node2, node2)
                                else:
                                    graph.add_edge(new_node, node2)
                            new_node = None
                            exist_node = node2
                            node2.add_count()
                            exist_index = 1
                    else:
                        if new_node is None:
                            if len(exist_node.asm_seqs) == exist_index:
                                node3 = graph.search_and_split(ins[1])
                                graph.add_edge(exist_node, node3)
                                exist_node = node3
                                node3.add_count()
                                exist_index = 1
                            else:
                                if exist_node.asm_seqs[exist_index].addr == ins[1]:
                                    exist_index += 1
                                else:
                                    node1, node2 = graph.split_node(exist_node, exist_index, count=exist_node.count-1)
                                    node3 = graph.search_and_split(ins[1])
                                    graph.add_edge(node1, node3)
                                    exist_node = node3
                                    node3.add_count()
                                    exist_index = 1
                        else:
                            print 'impossible2', ins
        graph.print_graph('tracer.png')
开发者ID:MatrixLing,项目名称:stuff,代码行数:104,代码来源:Tracer.py

示例3: Interpreter

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import print_graph [as 别名]

#.........这里部分代码省略.........
        --- Display graph ---
        Display a bar or pie graph that visually represents the data
        type "display_graph <chart-type> <data-type>"

        ARGUMENTS:
            chart-type: type of graph. Can be either 'pie' or 'bar'
            data-type: the data you want to show. For 'pie' chart can be 'gender, bmi or age'.
            For 'bar' graph can be 'salary by gender'

        """
        try:
            argss = []
            args = getopt.getopt(args, "t:o:", ["graph-type=", "option="])
            # if new graph is none then create argss as regular else append args from create_graph
            if my_graph is None:
                argss = args[1].split()
            else:
                argss.append(args[1][0])
                argss.append(args[1][1])
            if len(argss) > 2 or len(argss) < 2:
                raise TypeError
            if argss[0] == 'pie' and argss[1] != 'gender' and argss[1] != 'bmi' and argss[1] != 'age' \
                    or argss[0] == 'bar' and argss[1] != 'salary-by-gender' and argss[1] != 'salary-by-age':
                raise ValueError
        except TypeError:
            print('This functions takes exactly one parameters')
            return
        except ValueError:
            print('Ensure Graph Value Option Parameter is correctly spelt')
            return

        if my_graph is None:
            my_graph = self.graph.build_graph(argss)
            self.graph.print_graph(my_graph)
            del my_graph
        else:
            self.graph.print_graph(my_graph)

    # Brendan Holt
    # Used to create a graph by calling collecting user defined arguments -
    # and passing them to build_graph in the graph class
    def do_create_graph(self, args):
        """

        --- Create Graph ---
        Create a bar or pie graph that visually represent the chosen data
        type "create_graph <chart-type> <data-type>"

        ARGUMENTS:
            chart-type: type of graph. Can be either 'pie' or 'bar'
            data-type: the data you want to show. For 'pie' chart can be 'gender, bmi or age'.
            For 'bar' graph can be 'salary by gender'
        """
        try:
            args = getopt.getopt(args, "t:o:", ["graph-type=", "option="])
            argss = args[1].split()
            # Raises exception if the incorrect amount of args have been entered
            if len(argss) != 2:
                raise TypeError
            # Raises exception if the args have been incorrectly typed
            if argss[0] == 'pie' and argss[1] != 'gender' and argss[1] != 'bmi' and argss[1] != 'age' \
                    or argss[0] == 'bar' and argss[1] != 'salary-by-gender' and argss[1] != 'salary-by-age':
                raise ValueError
        except TypeError:
            print('This functions takes exactly two parameters')
            return
开发者ID:strakofski,项目名称:Refactoring-Assignment,代码行数:70,代码来源:Interpreter.py


注:本文中的Graph.print_graph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。