Mealy v/s. Moore

后端 未结 6 746
滥情空心
滥情空心 2020-12-14 08:24

What is the difference between Mealy & Moore type of finite state machines?

6条回答
  •  無奈伤痛
    2020-12-14 09:01

    Explanation by Example / Anecdote.

    This is perhaps best illustrated with an example and an anecdote.

    I hate airports, and getting to them, but I love being on the plane. There are three distinct states that I have to enter into before getting on the plane:

    1. State: In Taxi (event: then I pay the fare, and transition to the next state:)
    2. State: In Lounge (event: wait 2 hours, and transition to the next state: )
    3. State: In Plane

    But what is the outcome?

    In a Mealy machine, the preceding state from which you come from makes a difference - how you get somewhere is very important. In a Moore machine, how you get to a state makes no difference.

    Let's add in an outcome to the above to create a Moore representation of a state machine:

    Example of a Moore Representation of a State Machine:

    1. State: In Taxi (event: pay fare and then transition to the next state). (Outcome: unhappy).
    2. State: In Lounge (event: wait 2 hours, and then transition to the next state) (outcome: unhappy)
    3. State: In Plane (outcome: happy).

    With a Moore representation the outcome is attached directly to the state. With a Mealy representation - the particular outcome/output depends on where you have come from. For example, if I can get to the plane without having to catch a taxi and wait in the lounge, then I would be happy. Inputs make a difference. The where you come from is important. A Mealy representation state machine allows for this to be shown in the diagram. In other words, the output/outcome is shown OUTSIDE the state, during the transition.

提交回复
热议问题