In class, we are asked to draw a finite state machine with the following instructions:

Design a finite state machine to model a vending machine that accepts only quarters and gives a container of juice when 75 cents have been deposited, followed by a button being pushed. If a fourth quarter is deposited before the button has been pushed, this quarter is immediately returned. If the button is pushed before three quarters are deposited, nothing will happen. The machine is in state Si (i = 0; 1; 2; 3) when it has been given i quarters towards the next purchase. Inputs to the machine are Q (inserting a quarter) and B (pushing a button). After one request is processed, it is ready for another request.

I'm not entirely sure what I'm doing is even remotely correct. For instance, I'm not sure how to represent the "return" or "dispense" actions, right now, the are represented as states, but I don't know if that is legally correct or not. I also don't know if my return Q4 is correct. There are no inputs on the lines connecting S4 to Return to S3, and I was hoping that that would mean that those happen automatically without input, is this correct?

Original: Original

Improved: Improved


Returning a quarter is not a state. It's an action. S4 should be removed. Also dispense is not a state. Those are your outputs. You can put them in states but that means ANY transition to that state causes that output. The real error here is that you can't leave a state for free just because there is only one choice. Transitions only happen because of input, unless you go non-deterministic.

An important distinction to make here is which type of finite state machine you're building. There are two types:

enter image description here

In Moore the states determine the output (S1, S2).
In Mealy the transitions determine the output (/0, /1).

Your 2nd diagram looks like it wants to be a hybrid. I advise you pick one kind and stick with it. A word of caution: if you choose Moore and move Dispense into the S0 state you're going to have a problem because people will be able to get juice without paying just by pushing the button.

  • Ok, I simply don't understand how to display the action of dispensing the item without it being a state or making my petri net a "hybrid." I haven't been able to find good resources on this subject through my classes or online searches. I feel like this small detail shouldn't be difficult to grasp, but I'm not seeing how to do it. I want to accept your answer, but I have not been able to fully bridge to the correct answer, although I am trying. – joe_04_04 Oct 20 '17 at 1:18
  • 1
    When you wrote Dispense <- B you were doing it Mealy style. You just used a <- rather than a / and have input and output trasposed. If you do it Mealy style then every transition should have a slash separating input / output. You could make the output be the cost of the juice or how much credit you have: Q2 / 0.50 etc. But once you have enough money (S3) ---B / Dispense ---> (S0) says that now a button push will dispense the juice. – candied_orange Oct 20 '17 at 2:37
  • @joe_04_04 Petri nets are a completely different kind of automaton than DFAs or NFAs. Which kind are you actually trying to build? – amon Oct 20 '17 at 5:37
  • “Transitions only happen because of input.” In NFAs we can have epsilon transitions that may trigger implicitly. But the N stands for non-deterministic, a generally undesirable property. – amon Oct 20 '17 at 5:42
  • @amon, you're correct. I made a mistake because the same assignment works with both and I accidentally mixed up my diagram names. – joe_04_04 Oct 20 '17 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.