コード例 #1
0
ファイル: pydot_unittest.py プロジェクト: ziggi0703/pydotplus
    def test_subgraphs(self):

        g = pydotplus.Graph()
        s = pydotplus.Subgraph("foo")

        self.assertEqual(g.get_subgraphs(), [])
        self.assertEqual(g.get_subgraph_list(), [])

        g.add_subgraph(s)

        self.assertEqual(g.get_subgraphs()[0].get_name(), s.get_name())
        self.assertEqual(g.get_subgraph_list()[0].get_name(), s.get_name())
コード例 #2
0
ファイル: pydot_unittest.py プロジェクト: ziggi0703/pydotplus
    def test_graph_pickling(self):

        import pickle

        g = pydotplus.Graph()
        s = pydotplus.Subgraph("foo")
        g.add_subgraph(s)
        g.add_edge(pydotplus.Edge('A', 'B'))
        g.add_edge(pydotplus.Edge('A', 'C'))
        g.add_edge(pydotplus.Edge(('D', 'E')))
        g.add_node(pydotplus.Node('node!'))

        self.assertEqual(type(pickle.dumps(g)), bytes)
コード例 #3
0
ファイル: pydot_unittest.py プロジェクト: ziggi0703/pydotplus
    def _reset_graphs(self):

        self.graph_directed = pydotplus.Graph('testgraph',
                                              graph_type='digraph')
コード例 #4
0
 def _reset_graphs(self):
     # 重置图像,定义图像类,名称是testGraph,图像类型是digraph
     self.graph_directed = pydotplus.Graph(
         'testgraph', graph_type='digraph'
     )
コード例 #5
0
def constroi_ramo(est,k, grafo, visitados_hips, w,descarte_counter):
# Build and return the derivation of the absurdity (q) that a partial cycle having the (k-1)th visited node as w and descarte_counter and
# is the label that discharges the next step assumption, namely, in the k-th visited node in the whole derivation yet to be constructed
  global seqnode
  hg=(visitados_hips, grafo)
#  print "\rNIVEL"+" = "+str(k),
#  sys.stdout.write("\rNIVEL= %i" % str(k))
#  sys.stdout.flush()
  vw=vertex_name(w)
  novo_est={}
  this_context_descarte_counter=descarte_counter-1
#  descarte_counter=label_descarte
  if k < (Max+1):
#     print "visitados_hips"
#     print visitados_hips
     visitados=set([])
     for ((i,v),n) in visitados_hips:
        visitados.add(v)
#     visitados={ v for v in nos for j in range(1,k) if (j,v) in visitados_hips}
##     print "VISITADOS"
##     print visitados
     proibidos={v for v in nos if not linked(g,vw,v) and not linked(g,v,vw)}
##     print "PROIBIDOS"
##     print proibidos
     for v in nos:
#         print "atuando em v= "+v
         if v in visitados:
            i=get_k(v,visitados_hips)
            n_descarte=get_descarte(v,visitados_hips)
            hg=gera_grafo_ja_visitado(hg,w,i,v,k,n_descarte)
#            print "DENTRO DO CONSTROI RAMO:visitados"
            # print hg[0]
            # print hg[1].to_string()
            # print "ROOT"
            # print hg[1].root.to_string()
#            print type(est[(k-1,vw)])
            est[(k,v)]=hg[1].root
#            est=update_ref(est, (k-1,vw), ((k,v), hg[1].root))
            # print "ESTRUTURA"
            # print est
         elif v in proibidos:
              hg=gera_grafo_proibido(hg,w,v,k,this_context_descarte_counter)
#              label_descarte=label_descarte+1
#              print "DENTRO DO CONSTROI RAMO:proibidos"
              # print hg[0]
              # print hg[1].to_string()
              # print "ROOT"
              # print hg[1].root.to_string()
              est[(k,v)]=hg[1].root
#              est=update_ref(est, (k-1,vw), ((k,v), hg[1].root))
              # print "ESTRUTURA"
              # print est
         else:
#              print "CHAMANDO CONSTROI_RAMO DE DENTRO DELE MESMO:Sem Restricoes"
              # print "Visitando "+v+" no passo k= "+str(k)
              # print hg[0]
              hg[0].add(((k,v),descarte_counter))
              # print "ESTADOS"
              # print est
              novo_est={}
              (hg,novo_est,descarte_counter)=constroi_ramo(novo_est,k+1,hg[1],hg[0] ,v,descarte_counter+1)
#              print "descarte_counter="+str(descarte_counter)
#              label_descarte=label_descarte+1
              # print "depois de constroi ramo novo_est= em k="+str(k)+"v="+v
              # print novo_est
#              print novo_est.get((k,v))
              est[(k,v)]=novo_est[(k,v)]
#              print "est antes do grafo disjuntivo"
#              print "k="+str(k)+" v="+ v
#              print est
#              z=raw_input("est depois de atualizado com novo_est")
#     print "construindo grafo disjuntivo"
#     print "a partir do par ="+str(k-1)+" "+vw+"aqui"
#     print est
     hg=constroi_grafo_disjuntivo(hg,k-1,vw,est)
     imply_intro_conclusion_com_descarte=node_id_hid(str(seqnode)+"=(X"+str(k-1)+vw+" imp q)"+" "+str(this_context_descarte_counter))
     seqnode=seqnode+1
     hg[1].add_node(imply_intro_conclusion_com_descarte)
     hg[1].add_edge(Deduction_Edge(hg[1].root,imply_intro_conclusion_com_descarte))
     hg[1].root=imply_intro_conclusion_com_descarte
     hg=destroi_visitados_ref_nivel(hg,k-1,vw,this_context_descarte_counter)
     est[(k-1,vw)]=hg[1].root
#     print "ESTRUTURA APOS GRAFO DISJUNTIVO"
#     print est
#     print "hg[0] apos construir grafo disjuntivo"
#     print hg[0]
#     print "hg[1] apos construir grafo disjuntivo"
#     print hg[1].to_string()
#     z=raw_input("vai retornar depois de vir de destroi_visitados")
#     print hg[0]
     return (hg,est,descarte_counter)
  else:
#    Verifica se e vw no passo 3 alcanca ini (primeiro) no passo Max+1
#     print "chegou no passo Max+1"
#     print "k="+str(k)+" vw="+vw
#     print "visitados"
#     print hg[0]
#     z=raw_input("pausa ")
     ini=str(0)
     for v in nos:
##         print "par de="+str(type(1))+str(type(v))
         for j in range(0,descarte_counter+1):
          if ((1,v),j) in hg[0]:
            ini=v
            label=j
#     print "ini="+ini
     if not linked(g,vw, ini):
        no_prova_pleft=node_id_hid(str(seqnode)+"=[X"+str(1)+ini+"]"+str(label))
        label_descarte_local=str(descarte_counter)+"a"
        hg[1].add_node(no_prova_pleft)
        seqnode=seqnode+1
        no_prova_pright=node_id_hid(str(seqnode)+"=(X"+str(1)+ini+" imp (X"+str(Max+1)+ini+"))")
        hg[1].add_node(no_prova_pright)
        seqnode=seqnode+1
        no_prova_l=node_id_hid(str(seqnode)+"=X"+str(Max+1)+ini)
        hg[1].add_node(no_prova_l)
        hg[1].add_edge(Deduction_Edge(no_prova_pleft,no_prova_l))
        hg[1].add_edge(Deduction_Edge(no_prova_pright,no_prova_l))
        seqnode=seqnode+1
        no_provaright_pleft=node_id_hid(str(seqnode)+"=[X"+str(Max)+vw+"]"+label_descarte_local)
        seqnode=seqnode+1
        no_provaright_pright=node_id_hid(str(seqnode)+"=(X"+str(Max)+vw+" imp (X"+str(Max+1)+ini+" imp q))")
        seqnode=seqnode+1
        no_provaright=node_id_hid(str(seqnode)+"=(X"+str(Max+1)+ini+" imp q)")
        seqnode=seqnode+1
        no_absurdity=node_id_hid(str(seqnode)+"=q")
        seqnode=seqnode+1
        no_conclusao=node_id_hid(str(seqnode)+"=(X"+str(Max)+vw+" imp q)"+label_descarte_local)
        seqnode=seqnode+1
        hg[1].add_node(no_absurdity)
        hg[1].add_node(no_conclusao)
        hg[1].add_node(no_provaright)
        hg[1].add_node(no_provaright_pleft)
        hg[1].add_node(no_provaright_pright)
        hg[1].add_edge(Deduction_Edge(no_provaright_pleft,no_provaright))
        hg[1].add_edge(Deduction_Edge(no_provaright_pright,no_provaright))
        hg[1].add_edge(Deduction_Edge(no_prova_l,no_absurdity))
        hg[1].add_edge(Deduction_Edge(no_provaright,no_absurdity))
        hg[1].add_edge(Deduction_Edge(no_absurdity,no_conclusao))
        hg[1].root=no_conclusao
        hg=destroi_visitados_ref_nivel(hg,k-1,vw,descarte_counter)
        est[(Max,vw)]=hg[1].root
##        print "gerou o X1v1  X1v1 --> (X4v_vw --> q) / X4v_vw --> q"
##        print hg[0]
        # text_file = open("img/testestring", "w")
        # text_file.write(hg[1].to_string())
        # text_file.close()
        return (hg,est,descarte_counter)
     else:
#        print "Achou um ciclo Hamiltoniano"
        return pd.Graph()
コード例 #6
0
# g=add_edges(g, [('v1', 'v2'), ('v1','v5'),('v1','v7')])
# g=add_edges(g, [('v2', 'v8'), ('v2', 'v3')])
# g=add_edges(g, [('v3','v9'),('v3', 'v4')])
# g=add_edges(g, [('v4', 'v10'), ('v4', 'v5')])
# g=add_edges(g, [('v5', 'v6')])
# g=add_edges(g, [('v6', 'v8'), ('v6','v9')])
# g=add_edges(g, [('v7', 'v10'), ('v7','v9')])
# g=add_edges(g, [('v8', 'v10')])

# # Grafo G3
# g=pd.Graph()
# g=add_nodes(g,list_nodes)
# g=add_edges(g, [('v1', 'v2'), ('v1','v3')])

# Grafo G5
g=pd.Graph()
g=add_nodes(g, list_nodes)
g=add_edges(g,[('v1','v2'),('v2','v3'),('v3','v1'),('v1','v4'), ('v2','v4'), ('v3','v4'), ('v4''v5')])




# MAIN ###############

# GrafoPetersenDescartes=pd.Graph()
# GrafoPetersenDescartes.set_name("GrafoPetersenDescartes")
# inicia(GrafoPetersenDescartes)
# GrafoPetersenDescartes=draw_discharging_edges(GrafoPetersenDescartes)
GrafoProva=pd.Graph()
GrafoProva.set_name("EntreNiveisVersion3Compressing33G3")
inicia(GrafoProva)