pretty printing graphs

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Jul 29 11:31:51 EDT 2003


>>>>> "Bengt" == Bengt Richter <bokr at oz.net> writes:

    Bengt> should be -- def showInPage(self, pageHeight=6*11,
    Bengt> pageWidth=78): return '\n'.join(self.boxlines(pageHeight,
    Bengt> pageWidth)) -- [...]

I think I may have discovered another bug.  In the longish example below,
the children of n2 are n20 and n21

   n2.children.extend([n20, n21])

These children are the branch:

     |------------------+        
 +-------+          +-------+    
 |3 4 5 6|          |6 4 5 6|    
 |3 4 5 6|          |-------|    
 |-------|          |1 1 1 1|    
 |1 1 1 1|          +-------+    
 +-------+                       

However, if you run your pprint on this example, they appear below the
n4 branch.

Haven't had a chance to grok the code yet -- I just came across this
bug when using your code on a test case for a projective clustering
neural network algorithm I'm implementing.  The example is from Cao
and Wu, Neural Networks 15(2002) 105-120.

   http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B6T08-43T2MC4-1&_user=5745&_handle=W-WA-A-A-AD-MsSAYZA-UUW-AUCEZCZEBD-AZZEEDDUV-AD-U&_fmt=full&_coverDate=01%2F31%2F2002&_rdoc=10&_orig=browse&_srch=%23toc%234856%232002%23999849998%23290257!&_cdi=4856&view=c&_acct=C000001358&_version=1&_urlVersion=0&_userid=5745&md5=61f59ff40e082d56154538b436b0010e


def test3():
    n = Node(TextBox("""1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
6 7 8 9
1 2 3 4
3 4 5 6
2 3 4 5
6 4 5 6
4 2 3 1
6 7 1 2
4 5 6 7
-------
0 0 0 0
"""))

    n0 = Node(TextBox("""1 2 3 4
1 2 3 4
4 2 3 1
-------
0 1 1 0
"""))

    n1 = Node(TextBox("""2 3 4 5
2 3 4 5
-------
1 1 1 1
"""))

    n2 = Node(TextBox("""3 4 5 6
3 4 5 6
6 4 5 6
-------
0 1 1 1
"""))

    n3 = Node(TextBox("""4 5 6 7
4 5 6 7
-------
1 1 1 1
"""))

    n4 = Node(TextBox("""6 7 8 9
6 7 1 2
-------
1 1 0 0
"""))

    n.children.extend([n0, n1, n2, n3, n4])

    n00 = Node(TextBox("""1 2 3 4
1 2 3 4
-------
1 1 1 1
"""))

    n01 = Node(TextBox("""4 2 3 1
-------
1 1 1 1
"""))

    n0.children.extend([n00, n01])

    n20 = Node(TextBox("""3 4 5 6
3 4 5 6
-------
1 1 1 1
"""))

    n21 = Node(TextBox("""6 4 5 6
-------
1 1 1 1
"""))

    n2.children.extend([n20, n21])

    n40 = Node(TextBox("""6 7 8 9
-------
1 1 1 1
"""))

    n41 = Node(TextBox("""6 7 1 2
-------
1 1 1 1
"""))

    n4.children.extend([n40, n41])

    print n





More information about the Python-list mailing list