def adjustMHTransFormat(mhDict, iniState): # mhDict: Dictionary of (MHstate, Dictionary of (tuple(Term), # List of MHstate)) mit MHstate: Pair of Tuple of State # iniState: MHstate "Delete unreachable states and simultaneously transfer to \ the format Dictionary of (MHstate, Dictionary of (MHstate, List of Term))" newDict = {} q = Utilities.Queue(iniState) while not q.isEmpty(): state = q.dequeue() if not newDict.has_key(state): newDict[state] = {} for t in mhDict[state].keys(): for nextState in mhDict[state][t]: if newDict[state].has_key(nextState): newDict[state][nextState] += [t] else: newDict[state][nextState] = [t] q.enqueue(nextState) "Simplify the term lists" for p in newDict.keys(): for q in newDict[p].keys(): newDict[p][q] = Utilities.maximalElements(newDict[p][q], \ oneTermImplies) mhDict.clear() mhDict.update(newDict)
def simplifyMHAuto(mhDict, sim=None): # mhDict: Dictionary of (MHstate, Dictionary of (tuple(Term), # List of MHstate)) mit MHstate: Pair of Tuple of State # sim: SimulationRelation "If for (M, N) and t in mhDict[(M, N)][t] there are states (M0, N0), \ (M1, N1) s.t. M0 \subset M1 and N0 \subset N1, then delete (M1, N1) from \ the successor list." for (M, N) in mhDict.keys(): for t in mhDict[(M, N)].keys(): i = 0 while i < (len(mhDict[(M, N)][t]) - 1): j = i + 1 while j < len(mhDict[(M, N)][t]): (M0, N0) = mhDict[(M, N)][t][i] (M1, N1) = mhDict[(M, N)][t][j] if Utilities.isSubList(M0, M1) and \ Utilities.isSubList(N0, N1): del mhDict[(M, N)][t][j] elif Utilities.isSubList(M1, M0) and \ Utilities.isSubList(N1, N0): del mhDict[(M, N)][t][i] else: j += 1 i += 1 "Accepting states only need maximal successors -- at this point, we use \ the preorder defined by sim.isLessMH. Further, you may delete \ non-maximal successors from non-accepting states in favor of greater \ accepting successor states." if not (sim == None): def isLessMHspecial(x, y): # x, y: MHstate return (y[1] == ()) and sim.isLessMH(x, y) ## And not "(x[1] != () and y[1] == ()) and ...", cf. the examples ## FX((a | b) U (a & XGa)) and (a | b | c) U ( a & X((a | b) U (a & XGa))). for p in mhDict.keys(): for t in mhDict[p].keys(): if p[1] == (): # p is accepting mhDict[p][t] = Utilities.maximalElements(mhDict[p][t], \ sim.isLessMH) else: # p is not accepting mhDict[p][t] = Utilities.maximalElements(mhDict[p][t], \ isLessMHspecial)