;(=Xc@s/ddlZddlZdddYZdS(iNtGraphcBseZdZdZd dZd dZd dZd d d dZdZ dZ dZ d Z d Z d Zd ZRS(s docstring for graph cCs1g|_i|_i|_i|_i|_dS(sR use 0,1, 2, 3 as vertices and label the vertices using their variable name N(tverticestedgestparentstedge_labellingtvertice_labelling(tself((s myGraph.pyt__init__ s     cCst|tr9|g}|g}|r0|gnd}n|dkrxt||D]4\}}|j|j||j|j|qUWnax^t|||D]J\}}}|j|j||j|j|||j||ft ts([0-9]+)\[label="(.+)"\];s\2s\1s([0-9]+)->([0-9]+);N( tostgetcwdtjointopentrstriptreplacetretsubR RR( RtdottdtftlineRRRtpatternRRRR((s myGraph.pyt dot_to_graph<s"44  c Cs`|stj}n|d|d}t|d}|jd|sa|jd|dn|s|jd|dnx@t|j|jD])\}}|jd|d |d qW|jd g|jD]%\} }|D]} | | f^qq} x1| D])\} } |jd| d | d q W|jd |jd|j dS(s save a corresponding dot txt file in the specific directory (define in d, and the default location is current working directory) the dot txt file name is given by name, it is a string Rs.txttwsdigraph abstract { s label = "s"; s labeljust = "s s [label="s"]; s s->s; s} N( RRRtwriteR RRtwirteRtclose( RtnameRt labeljustR#R$ttmpRRRRtall_edge((s myGraph.pyt graph_to_dot^s(  " 5!  cCsdS(N((RR((s myGraph.pytdelete_verrticescCsdS(N((RR R((s myGraph.pyt delete_edgescCsi}t|j}x;|jD]0}||j|krEd||t||D]-\}}x|D]}|j||qWWqDWdS(s- add edges whose parents have been given N(RRRR R(RtvertstparsRtpartp((s myGraph.pyt fromParentss    cCsttt|jjS(N(R<tmapR3RR=(R((s myGraph.pyt num_edgessN(t__name__t __module__t__doc__RR RRR'R0R1R2R;R>R?RDRF(((s myGraph.pyRs   ",     ((RR R(((s myGraph.pyts