Cover

Preface

Contents

Index

Glossary

Models

Rogues

An Example: A Candy Bar Dispenser

It might help to diagram the actions of one of these automatic machines we deal with all the time.  To make it simple, let's assume that we are talking about a machine that dispenses only one product, say, a fifty cent candy bar.  Suppose further that this machine accepts only nickels, dimes, and quarters.  When fifty cents have been inserted, it dispenses the candy bar automatically, along with any necessary change.

This candy bar dispenser first starts in the state of remembering that it has accumulated $0.00 so far.  We will draw a circle with $0.00 in it to represent this state---the information that the dispenser remembers at this point. We will also mark this state with a > symbol to indicate that this is the state in which the dispenser always starts. 

 

From the start state, we can show which next state the dispenser must be in after certain coins have been inserted.  To do this, we draw one arrow from the start state for each coin that is recognized by the Coke machine to another state, which we again denote with a circle.  On the arrow, we put the value of the coin inserted.  In the circle corresponding to the new state, we put the amount of money the Coke machine has accumulated so far.

As shown in the above illustration, the candy bar dispenser always starts in the state of remembering that it has accumulated no money for a transaction. If someone puts in a nickel, the dispenser advances to a state in which it remembers that it has accumulated $0.05 so far.  If instead, the first coin inserted is a dime, the dispenser changes its internal state to remember that it has accumulated $0.10 so far.  A similar event occurs if the first coin inserted is a quarter.

We can continue on with this diagram.  From each of the new states we have included, we have to decide what happens if we insert a second coin---a nickel, a dime, or a quarter.  For example, if the first coin inserted was a nickel, that leaves us in the state corresponding to $0.05.  Now if the second coin we insert is also a nickel, the dispensing machine must change to the state of remembering that it has now accumulated $0.10.  We can update our diagram to account for this fact, which gives:

You probably see the process now.  To show what needs to occur in this candy bar dispensing machine if a dime is inserted when the machine is in the state of remembering that it has accumulated $0.05 so far, we need to have a new state for remembering an accumulation of $0.15.  We then need an arrow from the $0.05 state to this new $0.15 state labeled with 10 cents.  Following this tack given the diagram above, we get

This process continues until all of the states reached finally represent an accumulation of $0.50 or more.  The next phase of the diagram would thus look like

Finally, we would get

In order to more easily see the states in this diagram that represent an accumulation of $0.50 or more, we highlight them as shown below.  The highlighted states represent "final" or "accept" state.  These are states in which the machine actually dispenses the candy bar and any necessary change

You might be wondering how such a dispensing machine can be built from this diagram.  Fortunately for us, we don't care!  We have provided a diagram of the necessary states of the machine. It is now up to the electrical and mechanical engineers to use this design to build a candy bar dispensing machine that works.