Exemplo n.º 1
0
def dot_dfa_w_bh(D):
    """In : D (DFA : partially consistent)
       Out: dot representation (string)
       Generate a dot string representing the automaton. 
       Do not suppress "black-hole states". 
    """
    assert (is_partially_consistent_dfa(D))
    D = shrink_dfastates(D)
    hdr = prDotHeader()
    nodeDefs = prNodeDefs(D, lambda x: True)  # Show all nodes
    orientation = prOrientation()
    edges = prEdges(D, lambda x: True)  # Show all edges
    closing = prClosing()
    return hdr + nodeDefs + orientation + edges + closing
Exemplo n.º 2
0
def dot_dfa(D):
    """In : D (DFA : partially consistent)
       Out: dot representation (string)
       Generate a dot string representing the automaton. 
       Suppress "black-hole states". 
    """
    assert (is_partially_consistent_dfa(D))
    D = shrink_dfastates(D)
    hdr = prDotHeader()
    nodeDefs = prNodeDefs(D, isNotBH)  # Show isNotBH states
    orientation = prOrientation()
    # Show edge if src AND trg are isNotBH
    edges = prEdges(D, isNotBH)
    closing = prClosing()
    return hdr + nodeDefs + orientation + edges + closing
Exemplo n.º 3
0
def dotObj_dfa_w_bh(D, FuseEdges=False, dfaName='do_'):
    """In : D (DFA : partially consistent, states shrunk)
            dfaName (string)
       Out: A dot object. 
       Generate a dot object representing the automaton. 
       Do not suppress "black-hole states".       
    """
    assert (is_partially_consistent_dfa(D))
    D = shrink_dfastates(D)
    if dfaName == 'do_':
        dfaName = dfaName + NxtStateStr()
    dotObj1 = Digraph(comment=dfaName)
    dotObj1.graph_attr['rankdir'] = 'LR'
    dotObj2 = addNodeDefs(D, dotObj1, lambda x: True)  # Show all nodes
    dotObj3 = addEdges(D, dotObj2, FuseEdges, lambda x: True)  # Show all edges
    return dotObj3
Exemplo n.º 4
0
def dotObj_dfa(D, FuseEdges=False, dfaName='do_'):
    """In : D1 (DFA : partially consistent)
            dfaName (string)
       Out: A dot object. 
       Generate a dot object representing the automaton. 
       Suppress "black-hole states".       
    """
    assert (is_partially_consistent_dfa(D))
    D = shrink_dfastates(D)
    if dfaName == 'do_':
        dfaName = dfaName + NxtStateStr()
    dotObj1 = Digraph(comment=dfaName)
    dotObj1.graph_attr['rankdir'] = 'LR'
    # Show isNotBH states
    dotObj2 = addNodeDefs(D, dotObj1, isNotBH)
    # Show edge if src AND trg are isNotBH
    dotObj3 = addEdges(D, dotObj2, FuseEdges, isNotBH)
    return dotObj3
Exemplo n.º 5
0
def n2d(Frontier, Visited, Delta, Nfa):
    """In : Frontier (list of state sets; initially Eclosed Q0)
            Visited  (list of visited state sets; initially Eclosed Q0)
            Delta    (the DFA transition function being formed)
            Nfa      (the NFA being converted)
       Helper to nfa2dfa. Given a (BFS) frontier, a Visited
       set of states, the Delta being formed, and NFA Nfa, see
       if all new moves are in Visited: 
         do last gasp of Delta update; make and return a DFA;
       else: extend Frontier, Visited, Delta; recurse.
    """
    All_c_Moves = [ ((Q,c),ec_step_nfa(Nfa,Q,c)) 
                   for Q in Frontier 
                   for c in Nfa["Sigma"] ]
    New_c_Moves = list(filter(lambda QcQ: trTrg(QcQ) not in Visited, 
                              All_c_Moves))  
    if New_c_Moves == []:
        # Add last-gasp c-moves that curl back!
        last_gasp_c_moves = dict([ ((mkSSnam(Qfrom),c),mkSSnam(Qto)) 
                                  for ((Qfrom, c), Qto) in All_c_Moves ])
        Delta.update(last_gasp_c_moves)
                  
        # DFA states are visited states
        DFA_Q = { mkSSnam(Q) for Q in Visited }
                  
        # Retain alphabet
        DFA_Sigma = Nfa["Sigma"]
                  
        # Delta is ready to go
        DFA_Delta = Delta
                  
        # DFA starts at Eclosure of Nfa's Q0 set of states
        DFA_q0 = mkSSnam(Eclosure(Nfa, Nfa["Q0"]))
                  
        # DFA's final states are those in visited that contain an NFA 
        # F-state but don't retain any empty sets, in case the NFA given 
        # has no F-states!
        # This is another corner-case (i.e. don't shove-in black hole 
        # states!)
        DFA_F = set(map(lambda Q: mkSSnam(Q), 
                        filter(lambda Q: (Nfa["F"]&Q) != set({}), 
                               Visited)))
                  
        # Make the DFA; send it to the DFA-shrink to bask ugly long 
        # state names...
        return shrink_dfastates(mk_dfa(DFA_Q, 
                                       DFA_Sigma, 
                                       DFA_Delta, 
                                       DFA_q0, 
                                       DFA_F))
    else:
        newFrontier = list(map(lambda QcQ: trTrg(QcQ), New_c_Moves)) 
        newVisited = Visited + newFrontier
                  
        # Even though the NFA has not closed back on itself, we MUST 
        # accommodate for the "curl-backs" along the way !!  Thus, run it
        # over All_c_Moves which may include "partial revisits along the 
        # way". We MUST pick up those curl-backs!
        NewMovesDelta = dict([ ((mkSSnam(Qfrom),c),mkSSnam(Qto)) 
                              for ((Qfrom, c), Qto) in All_c_Moves ]) 
        Delta.update(NewMovesDelta)
        return n2d(newFrontier, newVisited, Delta, Nfa)