Coder Social home page Coder Social logo

cpo-lab2's Introduction

cpo-lab2

Computational Process Organization lab2

Title: StateMachine

eDSL for finite state machine (mealy).

List of group members

Laboratory work number: 2

Variant description

eDSL for finite state machine (mealy).

  • Visualization as a state diagram (GraphViz DOT) or table (ASCII).
  • Provide complex an example like a controller for an elevator, crossroad with a traffific light, etc.

To work together:

Complete the disevent class together,Zhao Ji finished disevent.py code module writing. Duan Shoujian completed the disevent_test modules and Visualization.

Code Introduction:

src/disevent.py:

class StateMachineis a class of finite state machine .

member variables:

self.handlers = {}  # State transfer function dictionary
self.startState = None  # initial state
self.endStates = []  # Final state list
self.runResult = 0  # The result of function run
self.state = []  # To collect all state
self.trans = {}  # Transfer process information
self.trans_to = {} # "Key" state can be transferred to "value" state

member methods:

def add_state(self, name, handler, trans_to, end_state=0):
    '''
    Function introduction:Add state
    :param name:Name of the added state
    :param handler:State transition function of the state
    :param trans_to:The next state that this state allows to move to
    :param end_state:Is the state final state or not.
    :return:
    '''
def add_trans_status(self, state, move):
    '''
    Function introduction:Add state transition information
    :param state:State name.
    :param move:Actions performed in this state/
    :return:
    '''
def set_start(self, name):
    '''
    Function introduction:Set start state.
    :param name:State name.
    :return:
    '''
def run(self, cargo):
    '''
    Function introduction:Running FSM.
    :param cargo:Input action list.
    :return:
    '''
def visualize(self):
    '''
    Function introduction:Create dot code for graphviz.
    :return:
    '''

conclusion:

1.The application of decorator pattern is necessary to effectively limit the format of input data and enhance the robustness of the code

2.Graphviz is a handy tool for data visualization, turning obscure lines of code into readable ones

3.According to the elevator example, different actions are performed by entering different values through the state machine.Understand the basic purpose of a finite state machine: to "run" in response to a series of events

cpo-lab2's People

Contributors

duanshoujian avatar 1986081114 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.