def write_hypergraph(hgr, colored = False):
dotG = pydot.Dot()<EOL>if not '<STR_LIT:name>' in dir(hgr):<EOL><INDENT>dotG.set_name('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>dotG.set_name(hgr.name)<EOL><DEDENT>colortable = {}<EOL>colorcount = <NUM_LIT:0><EOL>for node in hgr.nodes():<EOL><INDENT>newNode = pydot.Node(str(node), hyper_node_type = '<STR_LIT>')<EOL>dotG.add_node(newNode)<EOL><DEDENT>for hyperedge in hgr.hyperedges():<EOL><INDENT>if (colored):<EOL><INDENT>colortable[hyperedge] = colors[colorcount % len(colors)]<EOL>colorcount += <NUM_LIT:1><EOL>newNode = pydot.Node(str(hyperedge), hyper_node_type = '<STR_LIT>',color = str(colortable[hyperedge]),shape = '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>newNode = pydot.Node(str(hyperedge), hyper_node_type = '<STR_LIT>')<EOL><DEDENT>dotG.add_node(newNode)<EOL>for link in hgr.links(hyperedge):<EOL><INDENT>newEdge = pydot.Edge(str(hyperedge), str(link))<EOL>dotG.add_edge(newEdge)<EOL><DEDENT><DEDENT>return dotG.to_string()<EOL>
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.