python类Node()的实例源码

dot.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def write_hypergraph(hgr, colored = False):
    """
    Return a string specifying the given hypergraph in DOT Language.

    @type  hgr: hypergraph
    @param hgr: Hypergraph.

    @type  colored: boolean
    @param colored: Whether hyperedges should be colored.

    @rtype:  string
    @return: String specifying the hypergraph in DOT Language.
    """ 
    dotG = pydot.Dot()

    if not 'name' in dir(hgr):
        dotG.set_name('hypergraph')
    else:
        dotG.set_name(hgr.name)

    colortable = {}
    colorcount = 0

    # Add all of the nodes first
    for node in hgr.nodes():
        newNode = pydot.Node(str(node), hyper_node_type = 'hypernode')

        dotG.add_node(newNode)

    for hyperedge in hgr.hyperedges():

        if (colored):
            colortable[hyperedge] = colors[colorcount % len(colors)]
            colorcount += 1

            newNode = pydot.Node(str(hyperedge), hyper_node_type = 'hyperedge', \
                                                 color = str(colortable[hyperedge]), \
                                                 shape = 'point')
        else:
            newNode = pydot.Node(str(hyperedge), hyper_node_type = 'hyperedge')

        dotG.add_node(newNode)

        for link in hgr.links(hyperedge):
            newEdge = pydot.Edge(str(hyperedge), str(link))
            dotG.add_edge(newEdge)

    return dotG.to_string()
render.py 文件源码 项目:smtdos 作者: joelwanner 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_graph(self):
        g = pydot.Dot(graph_type='digraph')
        node_map = {}

        for h in self.network.topology.hosts:
            label = "<<B>%s</B><br/>%d  %d<br/>%d>" % (h.name, h.receiving_cap, h.sending_cap, h.amp_factor)

            n = pydot.Node(h.name, label=label, style='filled', margin=-0.8, width=0.5, height=0.5,
                           fontname=self.font_name, fontsize=self.node_fontsize)

            if type(h) is Server:
                if self.network.victims and h in self.network.victims:
                    n.set_shape('doublecircle')
                else:
                    n.set_shape('Mcircle')

                n.set_fillcolor(self.server_color)
            elif type(h) is Router:
                if self.network.victims and h in self.network.victims:
                    n.set_shape('doubleoctagon')
                else:
                    n.set_shape('octagon')

                n.set_fillcolor(self.server_color)
            else:
                if self.network.victims and h in self.network.victims:
                    n.set_shape('doublecircle')
                else:
                    n.set_shape('circle')

                if self.network.attackers and h in self.network.attackers:
                    n.set_fillcolor(self.attacker_color)
                else:
                    n.set_fillcolor(self.host_color)

            g.add_node(n)
            node_map[h] = n

        for l in self.network.topology.links:
            v1 = node_map[l.h1]
            v2 = node_map[l.h2]

            e = pydot.Edge(v1, v2, dir='none', label=str(l.capacity), color=self.link_color, fontcolor=self.link_color,
                           fontname=self.font_name, fontsize=self.label_size)
            g.add_edge(e)

            if self.network.flows:
                f1 = sum([f.get(l.h1, l.h2) for f in self.network.flows])
                f2 = sum([f.get(l.h2, l.h1) for f in self.network.flows])

                if f1 > 0:
                    g.add_edge(self.__create_link_flow(v1, v2, f1))

                if f2 > 0:
                    g.add_edge(self.__create_link_flow(v2, v1, f2))

        return g
visualize_util.py 文件源码 项目:keras-customized 作者: ambrite 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def model_to_dot(model, show_shapes=False, show_layer_names=True):
    dot = pydot.Dot()
    dot.set('rankdir', 'TB')
    dot.set('concentrate', True)
    dot.set_node_defaults(shape='record')

    if isinstance(model, Sequential):
        if not model.built:
            model.build()
        model = model.model
    layers = model.layers

    # Create graph nodes.
    for layer in layers:
        layer_id = str(id(layer))

        # Append a wrapped layer's label to node's label, if it exists.
        layer_name = layer.name
        class_name = layer.__class__.__name__
        if isinstance(layer, Wrapper):
            layer_name = '{}({})'.format(layer_name, layer.layer.name)
            child_class_name = layer.layer.__class__.__name__
            class_name = '{}({})'.format(class_name, child_class_name)

        # Create node's label.
        if show_layer_names:
            label = '{}: {}'.format(layer_name, class_name)
        else:
            label = class_name

        # Rebuild the label as a table including input/output shapes.
        if show_shapes:
            try:
                outputlabels = str(layer.output_shape)
            except:
                outputlabels = 'multiple'
            if hasattr(layer, 'input_shape'):
                inputlabels = str(layer.input_shape)
            elif hasattr(layer, 'input_shapes'):
                inputlabels = ', '.join(
                    [str(ishape) for ishape in layer.input_shapes])
            else:
                inputlabels = 'multiple'
            label = '%s\n|{input:|output:}|{{%s}|{%s}}' % (label, inputlabels, outputlabels)

        node = pydot.Node(layer_id, label=label)
        dot.add_node(node)

    # Connect nodes with edges.
    for layer in layers:
        layer_id = str(id(layer))
        for i, node in enumerate(layer.inbound_nodes):
            node_key = layer.name + '_ib-' + str(i)
            if node_key in model.container_nodes:
                for inbound_layer in node.inbound_layers:
                    inbound_layer_id = str(id(inbound_layer))
                    layer_id = str(id(layer))
                    dot.add_edge(pydot.Edge(inbound_layer_id, layer_id))
    return dot
class_diagrams.py 文件源码 项目:mappyfile 作者: geographika 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def main(gviz_path, layer_only=False):

    graphviz_setup(gviz_path)
    graph = pydot.Dot(graph_type='digraph', rankdir="TB")

    layer_children = {'CLASS': {'LABEL': {'STYLE': {}},
               'LEADER': {'STYLE': {}},
               'STYLE': {},
               'VALIDATION': {}},
     'CLUSTER': {},
     'COMPOSITE': {},
     'FEATURE': {'POINTS': {}},
     'GRID': {},
     'JOIN': {},
     'METADATA': {},
     'PROJECTION': {},
     'SCALETOKEN': {'VALUES': {}},
     'VALIDATION': {}}

    #pprint.pprint(layer_children)

    classes = {
        "MAP": {"LAYER": layer_children, 
         'LEGEND': {'LABEL': {}},
         'PROJECTION': {},
         'QUERYMAP': {},
         'REFERENCE': {},
         'SCALEBAR': {'LABEL': {}},
         'SYMBOL': {},
         'WEB': {'METADATA': {}, 'VALIDATION': {}}}}        

    if layer_only:
        root = "LAYER"
        classes = classes["MAP"]
        fn = "layer_classes"
    else:
        fn = "map_classes"
        root,  = classes.keys()

    node = pydot.Node(root, style="filled", fillcolor="#33a333", label=root, fontname=FONT, shape="polygon")
    graph.add_node(node)
    add_children(graph, root, classes[root])
    save_file(graph, fn)
manager.py 文件源码 项目:frontera-docs-zh_CN 作者: xsren 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def render(self, filename, label='', labelloc='t', labeljust='c',
               rankdir="TB", ranksep=0.7,
               fontname='Arial', fontsize=24,
               use_urls=False,
               node_fixedsize='true', nodesep=0.1, node_width=0.85, node_height=0.85, node_fontsize=15,
               include_ids=False):
        import pydot

        # Graph
        graph_args = {
            "rankdir": rankdir,
            "ranksep": ranksep,
            "nodesep": nodesep,
            "fontname": fontname,
            "fontsize": fontsize,
        }
        if label:
            graph_args.update({
                "labelloc": labelloc,
                "labeljust": labeljust,
                "label": label
            })
        graph = pydot.Dot(**graph_args)

        # Node
        node_args = {
            "fontsize": node_fontsize,
        }
        if use_urls:
            node_seed_shape = 'rectangle'
            node_shape = 'oval'
        else:
            node_seed_shape = 'square'
            node_shape = 'circle'
            node_args.update({
                "fixedsize": node_fixedsize,
                "width": node_width,
                "height": node_height,
            })

        graph.set_node_defaults(**node_args)
        for page in self.pages:
            graph.add_node(pydot.Node(name=self._clean_page_name(page, include_id=include_ids),
                                      fontname=fontname,
                                      fontsize=node_fontsize,
                                      shape=node_seed_shape if page.is_seed else node_shape))
            for link in page.links:
                graph.add_edge(pydot.Edge(self._clean_page_name(page, include_id=include_ids),
                                          self._clean_page_name(link, include_id=include_ids)))
        graph.write_png(filename)
mcconf.py 文件源码 项目:mcconf 作者: ManyThreads 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def createConfigurationGraph(modules, selectedmods, moddb, filename):
    graph = pydot.Dot(graph_name="G", graph_type='digraph')
    nodes = dict()

    # add modules as nodes
    for mod in modules:
        tt = ", ".join(mod.provides) + " "
        if mod.name in selectedmods:
            fc = "#BEF781"
        else:
            fc = "white"
        if moddb.getConflictingModules(mod):
            nc = "#DF0101"
        else:
            nc = "black"

        node = pydot.Node(mod.name, tooltip=tt,
                          style='filled', fillcolor=fc, color=nc, fontcolor=nc)
        # node = pydot.Node(mod.name)
        nodes[mod.name] = node
        graph.add_node(node)

    # add directed edges from modules to modules that satisfy at least one dependency
    for src in modules:
        dstmods = moddb.getSolutionCandidates(src)
        #print(str(src) + ' --> ' + str(dstmods))
        # don't show modules that are not in 'modules'
        for dst in dstmods:
            if dst not in modules: continue
            tt = ", ".join(dstmods[dst]) + " "
            edge = pydot.Edge(src.name, dst.name, tooltip=tt)
            # edge = pydot.Edge(src.name, dst.name)
            graph.add_edge(edge)

    # add special directed edges for "modules" inclusion
    for src in modules:
        for dstname in src.modules:
            dst = moddb[dstname]
            edge = pydot.Edge(src.name, dst.name, color="green")
            graph.add_edge(edge)

    graph.write(filename)
dot_parser.py 文件源码 项目:pydot3 作者: log0 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def push_edge_stmt(str, loc, toks):

    tok_attrs = [a for a in toks if isinstance(a, P_AttrList)]
    attrs = {}
    for a in tok_attrs:
        attrs.update(a.attrs)

    e = []

    if isinstance(toks[0][0], pydot.Graph):

        n_prev = pydot.frozendict(toks[0][0].obj_dict)
    else:        
        n_prev = toks[0][0] + do_node_ports( toks[0] )

    if isinstance(toks[2][0], ParseResults):

        n_next_list = [[n.get_name(),] for n in toks[2][0] ]
        for n_next in [n for n in n_next_list]:
            n_next_port = do_node_ports(n_next)
            e.append(pydot.Edge(n_prev, n_next[0]+n_next_port, **attrs))

    elif isinstance(toks[2][0], pydot.Graph):

        e.append(pydot.Edge(n_prev, pydot.frozendict(toks[2][0].obj_dict), **attrs))

    elif isinstance(toks[2][0], pydot.Node):

        node = toks[2][0]

        if node.get_port() is not None:
            name_port = node.get_name() + ":" + node.get_port()
        else:
            name_port = node.get_name()

        e.append(pydot.Edge(n_prev, name_port, **attrs))

    elif isinstance(toks[2][0], type('')):

        for n_next in [n for n in tuple(toks)[2::2]]:

            if isinstance(n_next, P_AttrList) or not isinstance(n_next[0], type('')):
                continue

            n_next_port = do_node_ports( n_next )
            e.append(pydot.Edge(n_prev, n_next[0]+n_next_port, **attrs))

            n_prev = n_next[0]+n_next_port

    else:
        # UNEXPECTED EDGE TYPE
        pass

    return e
visualize_util.py 文件源码 项目:InnerOuterRNN 作者: Chemoinformatics 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def model_to_dot(model, show_shapes=False, show_layer_names=True):
    dot = pydot.Dot()
    dot.set('rankdir', 'TB')
    dot.set('concentrate', True)
    dot.set_node_defaults(shape='record')

    if model.__class__.__name__ == 'Sequential':
        if not model.built:
            model.build()
        model = model.model
    layers = model.layers

    # first, populate the nodes of the graph
    for layer in layers:
        layer_id = str(id(layer))
        if show_layer_names:
            label = str(layer.name) + ' (' + layer.__class__.__name__ + ')'
        else:
            label = layer.__class__.__name__

        if show_shapes:
            # Build the label that will actually contain a table with the
            # input/output
            try:
                outputlabels = str(layer.output_shape)
            except:
                outputlabels = 'multiple'
            if hasattr(layer, 'input_shape'):
                inputlabels = str(layer.input_shape)
            elif hasattr(layer, 'input_shapes'):
                inputlabels = ', '.join(
                    [str(ishape) for ishape in layer.input_shapes])
            else:
                inputlabels = 'multiple'
            label = '%s\n|{input:|output:}|{{%s}|{%s}}' % (label, inputlabels, outputlabels)

        node = pydot.Node(layer_id, label=label)
        dot.add_node(node)

    # second, add the edges
    for layer in layers:
        layer_id = str(id(layer))
        for i, node in enumerate(layer.inbound_nodes):
            node_key = layer.name + '_ib-' + str(i)
            if node_key in model.container_nodes:
                # add edges
                for inbound_layer in node.inbound_layers:
                    inbound_layer_id = str(id(inbound_layer))
                    layer_id = str(id(layer))
                    dot.add_edge(pydot.Edge(inbound_layer_id, layer_id))
    return dot
graphs.py 文件源码 项目:documentr 作者: hive-tools 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def generate(self):
        if not self.__schema:
            return None

        for database in self.__schema:
            for table in self.__schema[database]:
                graph = pydot.Dot(graph_type='digraph')
                main_node_name = "{}.{}".format(database, table['table'])
                graph.add_node(
                    pydot.Node(main_node_name, style="filled",
                               fillcolor="#CCCCCC")
                )

                for field in table['fields']:
                    if not field['metadata']:
                        continue

                    if 'reference' not in field['metadata']:
                        continue

                    related_table = "{}.{}".format(
                        field['metadata']['reference']['database'],
                        field['metadata']['reference']['table']
                    )

                    graph.add_node(
                        pydot.Node(related_table, style="filled",
                                   fillcolor="#FFFFFF")
                    )

                    # add relationship
                    relationship = "{} -> {}".format(
                        field['name'],
                        field['metadata']['reference']['field']
                    )

                    graph.add_edge(
                        pydot.Edge(
                            main_node_name, related_table, label=relationship
                        )
                    )

                    full_path = os.path.join(
                        self.__output_path, 'graph_img'
                    )

                    if not os.path.exists(full_path):
                        os.makedirs(full_path)

                    final_path = os.path.join(
                        full_path, '{}.png'.format(main_node_name)
                    )

                    graph.write_png(final_path)

                graph = None


问题


面经


文章

微信
公众号

扫码关注公众号