def parse_transitions(root: ET.Element) -> Dict[Transition, List[int]]: """Parses the JFLAP xml to get a dict of transitions Args: root (ET.Element): The root of the JFLAP xml document Returns: Dict[Transition, List[int]]: The dict of transitions """ transitions_ = dict() for trans in root.findall("automaton")[0].findall("transition"): orig = trans.find("from").text dests = trans.find("to").text string = trans.find("read").text if orig is None or dests is None: print("Wtf") exit(1) if string is None: string = "" k = Transition(int(orig), str(string)) if k in transitions_: transitions_[k].append(int(dests)) else: transitions_[k] = [int(dests)] return transitions_
def check_string_in_language(self, string: str) -> bool: """Check if a string is inside the language of a DFA/NFA Args: string (str): The string to check Returns: bool: True if the string is inside the language """ steps = self._get_symbols(string) current_states = {self.initial_state} new_current_states = set() # print(f"========= string is {string} ============") # print("steps is", steps) # Calculate for all steps for symbols in steps: # Calculate for each symbol in the symbols for symbol in symbols: # Get the e closure of the current state new_states = self.calculate_e_closure( [state.id for state in current_states]) for state in new_states: # Get transitions from state "state.id" on symbol "symbol" new_states = self.transitions.get( Transition(state.id, symbol)) if not new_states is None: new_current_states = new_current_states | new_states current_states = new_current_states new_current_states = set() current_states = [ state for state in self.calculate_e_closure( [state.id for state in current_states]) ] return any(state.final for state in current_states)
def __init__(self, app): Transition.__init__(self, app) self.revolutions = 3 self.angle = 0.0 self.radius = 0.0
def __init__(self, app): Transition.__init__(self, app)
def __init__(self, app): Transition.__init__(self, app) self._buffer = None
def get_transition(self, state_id: int, symbol: str) -> Optional[Set[State]]: return self.transitions.get(Transition(state_id, symbol))
def __init__(self, app): Transition.__init__(self, app) self._strobing = [] self._time = {} self._on = {} self._duration = 0.1