コード例 #1
0
    def testFSA(self):
        '''
        Used to generate an fsa and display transition graph
        '''
        fsaStates = self.gameStates.keys()
        #print fsaStates
        fsaAlphabet = list(self.gameAlphabet)

        fsaInitialState = fsaStates[0]
        fsaFinalStates = fsaStates[-1]

        if not (fsaInitialState in fsaStates) or not (fsaFinalStates
                                                      in fsaStates):
            sys.stderr.write("Initial of final state not in state space")
            sys.stderr.write("Exiting function")
            sys.exit()

        #fsaInitialState = self.gameStates.keys()[4]
        #fsaFinalStates = self.gameStates.keys()[7]

        fsaTransitions = self.transitionTableGenerator()
        myFsa = FSA(fsaStates, fsaAlphabet, fsaTransitions, fsaInitialState,
                    [fsaFinalStates])
        myFsa.view()
        return fsaStates, fsaAlphabet, fsaTransitions
コード例 #2
0
    def testFSA(self):
        '''
        Generate inputs required for Fsa
        '''
        fsaStates = list(self.states.keys())
        fsaAlphabet = self.alphabetList
        fsaInitialStates = self.initialStates
        fsaFinalStates = self.goalStates
        fsaTransitions = self.transitionTableGenerator()

        self.fsa = FSA(fsaStates, fsaAlphabet, fsaTransitions,
                       fsaInitialStates[0], fsaFinalStates)  #FSA processing
        self.fsa.view()
        return
コード例 #3
0
from FSA import FSA

# Define the dataset that makes up the sheeptalk input table
sheeptalk_data = np.array((["q1", None,
                            None], [None, "q2",
                                    None], [None, "q3",
                                            None], [None, "q3",
                                                    "q4"], [None, None, None]))

# Put data into a pandas df with row and column labels
sheeptalk_table = pd.DataFrame(data=sheeptalk_data,
                               index=["q0", "q1", "q2", "q3", "q4"],
                               columns=["b", "a", "!"])

# Initialize the sheeptalk FSA and define states
sheeptalk_FSA = FSA()
sheeptalk_FSA.add_state("q0")
sheeptalk_FSA.add_state("q1")
sheeptalk_FSA.add_state("q2")
sheeptalk_FSA.add_state("q3")
sheeptalk_FSA.add_state("q4", final_state=1)
sheeptalk_FSA.start_state = "q0"


def main():
    '''
    Prompt the user for a string and then determine
    whether or not it is an example of sheeptalk.
    '''
    print("Is it sheeptalk?")
コード例 #4
0
# You also need to specify an initial and final state for this.
# To see how to specify the states see the comments on how to generate
# state labels mentioned above. To avoid accidentally trying to
# draw a transition graph visualization with too many states, this
# section gets disabled if the number of states is greater than 50.
###################################################################

# Checking if number of states is less than 50
    if len(gameStates) <= 50:
        # Setting initial and final states
        gameInitialState = 'R00E11TR'
        gameFinalStates = 'R11E00TR'

        # Verifying if the initial state and final state of the transition system
        # is included in the statespace
        if not (gameInitialState in gameStates) or not (gameFinalStates
                                                        in gameStates):
            sys.stderr.write("Initial of final state not in state space\n")
            sys.stderr.write("Exiting function")
            sys.exit()

        #Drawing transition graph
        myFsa = FSA(gameStates, gameAlphabet, gameTransitions,
                    gameInitialState, [gameFinalStates])
        myFsa.view()
    else:
        print "Number of states: ", len(gameStates)
        print "Too many states, visualization of transition graph disabled"

###### End of draw transition graph code #####################