Changeset 5c3d542


Ignore:
Timestamp:
Dec 1, 2010 5:07:50 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
d894c21
Parents:
1f356d3
Message:

Multiple attributes and recursive subgraphs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_image.py

    r1f356d3 r5c3d542  
    3939        self.add_option("--file", dest="file",
    4040                help="experiment description file")
    41         self.add_option("--group", dest="group", default=None,
     41        self.add_option("--group", dest="group", action="append", default=[],
    4242                help="Group nodes by this attribute")
    4343
    44 def make_subgraph(topelems, attr):
     44def make_subgraph(topelems, attrs):
    4545    """
    4646    Take a list of topdl elements (Computers and Substrates ) and partition
     
    5858        else: m[a] = [ v]
    5959
     60    if not attrs: return { }
     61
    6062    sg = { }
     63    attr, rest = attrs[0], attrs[1:]
    6164    for e in topelems:
    6265        if isinstance(e, topdl.Computer):
     
    7376            else: add_to_map(sg, 'default', e)
    7477
     78    if rest:
     79        for k in sg.keys():
     80            sg[k] = make_subgraph(sg[k], rest)
     81
    7582    return sg
    7683
    77 def gen_dot_topo(t, labels, dotfile, sg_attr=None):
    78     """
    79     Write a dot description of the topology in t, a topdl.Topology to the open
    80     file dotfile.  the gen_image function below has already put some of that
    81     file together. This function only generates the nodes and connections.  If
    82     labels is true, label the nodes.
    83     """
    84 
    85 
    86     # The routine draws a circle for substrates with more than 2 interfaces
    87     # connected to it, so this makes lists of each of those.
    88     lans = [ s for s in t.substrates if len(s.interfaces) != 2]
    89     links = [ s for s in t.substrates if len(s.interfaces) == 2]
    90 
    91     # Break into subgraphs by the attribute of one's given
    92     if sg_attr: sg = make_subgraph(t.elements + lans, sg_attr)
    93     else: sg = { 'default': t.elements + lans }
    94 
     84def output_subgraphs(sg, dotfile):
    9585
    9686    # Construct subgraphs featurning nodes from those graphs
     
    10393            print >>dotfile, 'label="%s"' % sn
    10494        else:
    105             print >>dotfile, 'subgraph "%s" {' % sn
     95            print >>dotfile, 'subgraph {'
    10696        print >>dotfile, 'color="#08c0f8"'
    10797        print >>dotfile, 'clusterrank="local"'
    10898
    109         # For each node in the subgraph, output its representation
    110         for i, n in enumerate(nodes):
    111             if isinstance(n, topdl.Computer):
    112                 if n.name:
    113                     print >>dotfile, '\t"%s" [shape=box,style=filled,\\' % \
    114                             n.name
    115                 else:
     99        if isinstance(nodes, dict): output_subgraphs(nodes, dotfile)
     100        elif isinstance(nodes, list):
     101            # For each node in the subgraph, output its representation
     102            for i, n in enumerate(nodes):
     103                if isinstance(n, topdl.Computer):
     104                    if n.name:
     105                        print >>dotfile, \
     106                                '\t"%s" [shape=box,style=filled,\\' % n.name
     107                    else:
     108                        print >>dotfile, \
     109                                '\t"unnamed_node%d" [shape=box,style=filled,\\'\
     110                                % i
    116111                    print >>dotfile, \
    117                             '\t"unnamed_node%d" [shape=box,style=filled,\\' % i
    118                 print >>dotfile, \
    119                         '\t\tcolor=black,fillcolor="#60f8c0",regular=1]'
    120             elif isinstance(n, topdl.Substrate):
    121                 print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' % \
    122                         n.name
    123                 print >>dotfile,'\t\tcolor=black,fillcolor="#80c0f8",regular=1]'
     112                            '\t\tcolor=black,fillcolor="#60f8c0",regular=1]'
     113                elif isinstance(n, topdl.Substrate):
     114                    print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' \
     115                            % n.name
     116                    print >>dotfile,\
     117                            '\t\tcolor=black,fillcolor="#80c0f8",regular=1]'
    124118        print >>dotfile, '}'
     119
     120def gen_dot_topo(t, labels, dotfile, sg_attr):
     121    """
     122    Write a dot description of the topology in t, a topdl.Topology to the open
     123    file dotfile.  the gen_image function below has already put some of that
     124    file together. This function only generates the nodes and connections.  If
     125    labels is true, label the nodes.
     126    """
     127
     128
     129    # The routine draws a circle for substrates with more than 2 interfaces
     130    # connected to it, so this makes lists of each of those.
     131    lans = [ s for s in t.substrates if len(s.interfaces) != 2]
     132    links = [ s for s in t.substrates if len(s.interfaces) == 2]
     133
     134    # Break into subgraphs by the attribute of one's given
     135    if sg_attr: sg = make_subgraph(t.elements + lans, sg_attr)
     136    else: sg = { 'default': t.elements + lans }
     137
     138
     139    output_subgraphs(sg, dotfile)
    125140
    126141    # Pull the edges out ot the lans and links
     
    205220    print >>dotfile, "graph G {"
    206221    if dpi:
    207         print >>dotfile, '\tgraph [size="%i,%i", dpi="%i", ratio=fill];' \
    208                 % (size, size, dpi)
     222        print >>dotfile, \
     223            '\tgraph [size="%i,%i", dpi="%i", ratio=fill, compound="true"];' \
     224            % (size, size, dpi)
    209225    else:
    210         print >>dotfile, '\tgraph [size="%i,%i", ratio=fill, clusterrank="local"compound="true"];' \
    211                 % (size, size)
     226        print >>dotfile, \
     227            '\tgraph [size="%i,%i", ratio=fill, compound="true"];' \
     228            % (size, size)
    212229
    213230    if labels:
Note: See TracChangeset for help on using the changeset viewer.