Professional Documents
Culture Documents
Finitestatevendingmachine PDF
Finitestatevendingmachine PDF
net/publication/285599126
CITATIONS READS
0 1,741
1 author:
Nasreen Ahmad
De Montfort University
17 PUBLICATIONS 0 CITATIONS
SEE PROFILE
All content following this page was uploaded by Nasreen Ahmad on 09 December 2015.
Reset
Clock
Fig1: Vending Machine Block Diagram
Vending Machine
Button Pressed Insert Door/ Output Milk/Sugar
FMS
Reset
Clock
Fig1.2: Vending Machine Block Diagram
The combine sweet-drink machine, which dispense two or more portions of sugar.
The combine milk-drink-sugar machine, which dispense milky and sweet drink
2. THE MODEL DESIGN SPECIFICATION FOR MACHINE 1:
Definition: A mathematical description that has a syntax and rules for computation of the behavior described by
the syntax (semantics). Used to specify the semantics of computation and concurrency.
D0 CLOCK
D1 INIT
D2 5p
D3 10p
D4 20p
D5 50p
(Coffee)
C (Coffee)
Disp1
Disp2 (Tea) T (Tea)
Disp3 (Milk)
(Suger)
Disp4
Fig2: Vending Machine Model
D0 CLOCK D0 CLOCK
D1 INIT D1 INIT
Button Button
D2
Therefore:
I {5p,10p,20p,50p,C,T} 5 Coffee
O Coffee, Tea, Milk’s, Suger’s 10 Tea
S Start, 5p,10p,20p,50p, S1,S2,S3, S4, S5, S6, S7, S8, 20 Milk Cartoni
S9, S10, Disp, Sugi, Cartoni, 50 Sugari
Deterministic description:
Now we are going to define the model based on the above study.
EXERCISE 1:
EX: 2. I. I DRINK, MILK AND SUGAR MACHINES THAT DISPENSES A DRINK, A MAXIMUM OF
ONE CARTON OF MILK AND A MAXIMUM OF ONE PORTION OF SUGAR.
The Algorithm of first state machine prepared for the two Start
products Tea or Coffee, where algorithm starts with request of
input using either slot depending on your coins. The machine INIT
will examine, if the coin is appropriate else it will ask to put Input
penny again. There are two selection input tea or coffee, if the penny
product is available will dispense otherwise the machine will
demand to choose another product. Finally algorithm indicate Slot1 Slot2
Coffee
Y
N
If Product N
Available
N
Y
If the right Drink
Wait
amount inserted Dispensed
N
Y
Coins Drop in
Money Box
End
Fig. 3 Flow Diagram for the First Vending Machine for Tea and Coffee
The relationship ├ M between configurations is defined as (q,w) ├ M (q’, w’), if there is a u {e}.
Therefore, L (M), the language accepted by M, is the set of all strings accepted by M. Let's say, M is given, he
string 10p10p5pT as input, several different sequences of moves may follow. In above FSM M may wind up in
the nonfinal state start in case, the only transition used is (start):
Then,
(Start, 10p10p5pT) ├ M (start, 10p10p5pT)
├ M (S2, 10p5pT)
├ M (S4, 5pT)
├ M (S5, T)
├ M (start)
Therefore (Start,10p10p5pT) ├ *M (Start) and so statement is acceptable by D.
The 50pC input may derive from start to state reset, and indeed may do so in the given below way.
Then,
The flow charts for the milk-drink and sweet-drinks has start point. The flow will wait or request for the press
button for the customer. The machine will dispense only one a milk-carton or a portion-sugar for each
transaction and finally end the flow by initializing the machine.
Int Cnt=0;
Cnst stock=10; Start Start
Machine_off_on=true;
If (button_press) then Press Press
{ Button for Button for
Milk Sugar
Dispense_Carton;
Cnt=1; stock=stock-1; 1 Milk A portion of
}else if (stock==0) then Carton Suger
Dispensed Dispensed
{
Machine_off_on=false;
Cnt=0; End End
}else
{
Cnt=0;
Wait;
}
Fig. 8: Milk-Carton, Sugar-PortionVending Machine Flow Chart
check if user press twice, then the machine will count initially. Unit changes its state to sag when machine
received 1 that means button press for single carton. However, the user press twice, then the machine will move
to carton state once and then the second 1 (press) will be ignored and remain
Formally, these machines are NFSM transition M= (K, , ∆, s, F), M, where: K an element of being a finite set
of states, (is an alphabet, s (K is the initial state, F K is the set of final states and ∆ the transition relation, is a
subset of K x ( {e}) x K:
K= {Init,1},
= {1},
S K = {Init},
F = {Sug}
And
∆ = {(Init,0, Init), (Init,1,Carton),
(Carton,1,Init)}
init 1
e
car
tt
dis e
p
According to definition w inputs* being accepted by the NFSM M, if at least one computation path M on w
that terminates in a state q accept.
W q transaction*(q,u) transaction (q,a) Transaction* (initial,w)
0 Transaction(Init,0) {init}
1 Transaction(Init,1) {carton}
1 Transaction(Carton,1) {init}
Transaction*(init,1)={Carton,init}
Accept ={init}
Accept (transaction* (init,1)={init} = 0
So, 1 inputs are accepted by the NFSM M in both the cases (Milk,Sug)
Fig. 12: The Simulation for the Milk and Sugar Machine
EX: 2. II. A COMBIND DRINK, MILK MACHINES THAT DISPENSES A MILK CARTON AFTER
THE DRINK DISPENSE.
desired drink and also push the button the milk carton. Suppose the
customer inserted 50p using slot 2, the machine will check the right
Slot1 Slot2
amount inserted through the slot and the total amount. Once the total
amount counted the machine will check the required product
availability, if not, then the machine will ask to choose another product
If the penny is 5p or
within 30 seconds. Once the product availability, the machine will 10p or 20p or 50p
dispense first the drink and then drop a milk carton for free in the N
Y
dispenser box. Finally machine will drop all the coins in the money
box and the initialize machine for the next customer. Select Product
If you noticed, this algorithm has no cancel button because once the Tea
customer insert amount then the there is no other option to return it Y N
back. Here only option, that the machine will wait for more money to
Coffee
insert if money is less than the required or machine will wait for the
Y N
next selection, if the product is not available.
Main….. If Product
Available
N
cnt=cnt+pence Y
N
If the right Y Drink
If amount=>cent) Wait
amount inserted Dispensed
{ A Milk Carton
Dispensed
Drink_disp;
Disp_milk; Coins Drop in
Money Box
}else
{ End
Wait;
}
The relationship ├ M between configurations is defined as (q,w) ├ M (q’, w’), if there is a u {e}.
Therefore, L (M), the language accepted by M, is the set of all strings accepted by M. Let's say, M is given, he
string a10105T1 as input, several different sequences of moves may follow. In above FSM M may wind up in
the nonfinal state START in case, the only transitions used is (Start):
(Start, 20p10p10p10pC) ├ M (Start, 20p10p10p10pC)
├ M (S4, 10p10p10pC)
├ M (S6, 10p10pC)
├ M (S8, 10pC)
├ M (10, C)
├ M (Disp, λ)
├ M (Carton)
├ M (Start, λ)
Since a string is accepted by a nondeterministic finite automaton if and only if there is at least one sequence of
moves leading to a final, it follows that a10p10p5pT1 L(M)◊
State table
Presen Inputs Next Output Open
t State State
5p 10p 20p 50p e T C Tea Coffee Carton-Milk
Start S1 S2 S4 S10 - Start Start S1 0 0 0
S1 S2 S3 S5 0 - S1 S1 S2 0 0 0
S2 S3 S4 S6 0 - S2 S2 S3 0 0 0
S3 S4 S5 S7 0 - S3 S3 S4 0 0 0
S4 S5 S6 S8 0 - S4 S4 S5 0 0 0
S5 S6 S7 S9 0 - Disp S5 S6 0 0 0
S6 S7 S8 S10 0 - Disp S6 S7 0 0 0
S7 S8 S9 S10 0 - Disp S7 S8 0 0 0
S8 S9 S10 S10 0 - Disp S8 S9 0 0 0
S9 S10 S10 S10 0 - Disp S9 S10 0 0 0
S10 S10 S10 S10 S10 - Disp Disp Carton 0 0 0
Disp 0 0 0 0 λ - - Carton T C 0
Carton 0 0 0 0 λ - - Start 0 0 Carton
Design Decision
The design methodology follows the non-deterministic state where merged two machines together, a drink
machine with a milk machine. The process will dispatch Tea/ Coffee according to choice and then machine will
dispatch a milk carton for free of charge. This machine will take care of mistreat of the facility, such as it will
take care of product delivery which will deliver product once only and then machine will initialize for the next
customer..
The combined FSM concatenation recognition is: L(M1) ˆ L(M2), where the concatenation of M1 and M2
Simulation / Tests
The machine has been tested with various strings, some are purposely inserted for the abnormal testing, in order
to make sure that the machine responding correctly and bug free. The first rejection is for incorrect coin in the
slot, second is for twice Milk button pressed but one carton dispensed, third rejection due to missing entries, and
the last one against the wrong request where the machine will go to the waiting state and wait for the next input.
Fig. 15: Test-Results for a Combined Vendint Machine for Tea-Coffee and A Milk-Carton
Fig. 16:Ssimulation-Results for a Combined Vendint Machine for Tea-Coffee and A Milk-Carton
EX: 2. III. A COMBIND DRINK, SUGAR MACHINES THAT DISPENSES A PORTION OF SUGAR
AFTER THE DRINK DISPENSE.
The flow diagram exploits the functionality of the machine, this flow Start
diagram almost same as previous, where two slots are the source to
INIT
insert the desired amount and product, if the product available, then
Input
the machine will dispense the drink and then the portion of sugar penny
after the drink, which is free machine, if the product is unavailable
then the machine will wait to re-select the product, even though the
product is unavailable then the, machine will alert for the service. Slot1 Slot2
…
Main()
If the penny is 5p or
… 10p or 20p or 50p
N
If (amount>=cnt) Y
{ Select Product
Dip_drink;
Tea
Wait; Y N
Dips_sug; Coffee
}else Y N
{ If Product
Available
N
Wait;
Y
} N
Y
If the right Drink
Wait Dispensed
amount inserted
Call Start;
A Portion-
Sugar
Dispensed
Coins Drop in
Money Box
End
Fig. 17:Flow Chart for a Combined Vendint Machine for Tea-Coffee and A portion of Sugar
The relationship ├ M between configurations is defined as (q,w) ├ M (q’, w’), if there is a u {e}.
Therefore, L (M), the language accepted by M, is the set of all strings accepted by M. Let's say, M is given, the
string 20p10pT as input, several different sequences of moves may follow. In above FSM M may wind up in the
non final state START in case, the only transitions used is (Start):
(START, 20p10pT1) ├ M (Start, 20p10pT)
├ M (S4, 10pT)
├ M (S5, T)
├ M (Disp, λ)
├ M (Sug, λ)
├ M (S7, λ)
├ M (Sug, λ )
├ M (Start)
Since a string is accepted by a nondeterministic finite automaton if and only if there is at least one sequence of
moves leading to a final, it follows that 20p10pT L(M).◊
State table
Presen Inputs Next Output Open
t State State
5p 10p 20p 50p λ T C Tea Coffee Carton-Milk
Start S1 S2 S4 S10 - Start Start S1 0 0 0
S1 S2 S3 S5 0 - S1 S1 S2 0 0 0
S2 S3 S4 S6 0 - S2 S2 S3 0 0 0
S3 S4 S5 S7 0 - S3 S3 S4 0 0 0
S4 S5 S6 S8 0 - S4 S4 S5 0 0 0
S5 S6 S7 S9 0 - Disp S5 S6 0 0 0
S6 S7 S8 S10 0 - Disp S6 S7 0 0 0
S7 S8 S9 S10 0 - Disp S7 S8 0 0 0
S8 S9 S10 S10 0 - Disp S8 S9 0 0 0
S9 S10 S10 S10 0 - Disp S9 S10 0 0 0
S10 S10 S10 S10 S10 - Disp Disp Dip 0 0 0
Disp 0 0 0 0 λ - - Sug T C 0
Sug 0 0 0 0 λ - - Start 0 0 A Portion-
Sugar
Design Decision
The design methodology follows the deterministic state where I merged two machines together, a drink machine
with a milk machine. The process will dispatch Tea/ Coffee according to choice and then machine will dispatch
a milk carton free of charge. This machine will take care of miss use of the facility, such as it will take care of
product delivery which will deliver one carton per customer.
The combined FSM concatenation recognition is: L(M1) ˆ L(M2), where the concatenation of M1 and M2
Simulation / Tests
We have tested this machine and confirmed that the machine is bug free and responding absolutely as per
requirement.
Fig. 19: Test-Results for a combined Vending Machine for Tea-Coffee and A portion-Sug
10p=SS2
20p=S6
5p=S7
5p=S8
10p=S10
C=Disp
e=Sug
Sug=Start/Init
Fig. 20: Simulation-Results for a combined Vending Machine for Tea-Coffee and A portion-Sug
EX: 2. IV. A COMBIND MILKY DRINK MACHINES THAT DISPENSES TWO OR MORE MILK
CARTON AFTER THE DRINK DISPENSE.
The flow diagram initialized to the start state and wait for the inputs Start
from the customer. Specific two slots are designed for the various coin
INIT
inputs. The program will check the inputs in the initial stage and action
Input
accordingly. If the inputs are accepted by the machine, then the penny
machine will request to select the product, the right selection or
availability of product will move the machine to its next flow and
Slot1 Slot2
count the total amount. The required amount will allow to dispense
drinks and two milk cartons one after the other for free of charge.
Finally the machine will drop all the coins into the money box and
drive to the initialize state. If the penny is 5p or
10p or 20p or 50p
… N
Y
Main()
… Select Product
If (amount>=cnt)
{ Tea
Dip_drink; Y N
Wait;
Dips_Caron1; Coffee
Dips_Caron2; Y N
Another Milk-
Carton
Dispensed
Coins Drop in
Money Box
End
Fig. 21: Flow Chart for a combined Vending Machine for Milk-Drink with 2 Milk-Carton
.
State table
Present Inputs Next Output Open
State State
Design Decision
The combined methodology used for this machine is determination + non determination for two merged models.
The first drink is one machine which is DFA and the other is milk machine that convey NFA methodology
where two empty transactions reading from the input string derived from Disp state to the end state. The
cartons will dispatch two packs. I declared as a maximum two, but depends on the requirement. Once the drink
‘Tea and Coffee’ dispatch then the cartons will deliver all together. The start state is the initial state and the init
is the final stage, which required empty transaction string to initialize and derived machine to beginning state
for the next state. Between these two state the transaction derived to its right direction reading ne states as per
input strings, finally machine reached to this beginning state.
Simulation / Tests
The following results are positive results except one rejection.this is because the slot can accept less than 50
pence and coffee cannot deliver in less the 50 pence. Therefore, the rejection occurred due to the Coffee
request. The other results are tested in the abnormal conditions where more than 25 pence accepted without
return policy. The cartons dispatched more than 2, the dispatch items can deliver once and then the machine
would initialize for the next customer.
Fig. 23: Test-Results for a combined Vending Machine for Milk-Drink with 2 Milk-Carton0
20p=S4
5p=S5
10p=S7
5p=S8
20p=S10
C=Disp
Disp=Cart1
Disp=Cart2
Cart1=Init
Cart2=Init
Init=Start
Fig. 24: simulation-Results for a combined Vending Machine for Milk-Drink with 2 Milk-Carton
EX: 2. V. A COMBIND SWEET DRINK MACHINES THAT DISPENSES TWO PORTION OF SUGAR.
The flow diagram initialized to the start state and wait for the inputs Start
from the customer. Specific two slots are designed for the various
INIT
coin inputs. The program will check the inputs in the initial stage
Input
and act accordingly. If the inputs are accepted by the machine, then penny
the machine will request to select the product, the right selection or
availability of product will move the machine to its next flow and
Slot1 Slot2
count the total amount. The required amount will allow to dispense
drinks and two portions of sugar one after the other for free of
charge. Finally the machine will drop all the coins into the money
box and drive to the initialize state. If the penny is 5p or
10p or 20p or 50p
… N
Y
Main()
… Select Product
If (amount>=cnt)
{ Tea
Dip_drink; Y N
Wait;
Coffee
Dips_sug1;
Y N
Dips_sug2;
Dips_Caron1; If Product
Dips_Caron2; Available
N
Call collect_money; Y
}else N
Y
If the right Drink
{ Wait
amount inserted Dispensed
Wait;
A Portion-
} Sugar
Call Start; Dispensed
Another
Portion-Sugar
Dispensed
Coins Drop in
Money Box
End
Fig. 25: Flow Chart for a combined Vending Machine for Sweet-Drink with 2 Portion-Sugar
And
State table
Present Inputs Next Output Open
State State
5p 10p 20p 50p λ T C Tea Coffee Sugar-1 Sugar-2
Design Decision
The combined methodology used for this machine is determination + non determination. The cartons will
dispatch 2 portions of sugar. The machine will dispatch drink and subsequently, the sweet-drink with two sugar
portions will dispatch.
Simulation / Tests
The test rejected the third lane of below test-result screen shortly, due to insufficient amount entered for the Tea
request, where tea can be purchase by the >=25p. However, the other various possible tests were successfully
completed by this machine.
Fig. 27: Test-Results for a combined Vending Machine for Sweet-Drink with 2 Portion-Sugar
The following below simulation is representing the├ M (Start, 50pC), where the machine begins with the state
start, then moved to the s10 state by reading a string of 50p as input. The other input C which is for Coffee
product moved from s10 state to the Disp state and dispatch a coffee. The nondeterministic automation began
from this merged machine that read the empty input strings for the sweet-drink, i.e. two portion of sugar which
dispatched after the drink.. Finally the machine reached to its initial state, confirming that no more reputation
for this transaction.
Let V = ({50p,C}, {n, d, q}, {Start, S10, Start}, δ, ω, s}
10p5p5p10pT
Fig. 28: Simulation for a combined Vending Machine for Sweet-Drink with 2 Portion-Sugar
The flow diagram begins with the start and wait for the inputs Start
from the customer for any of the slots. The program will
INIT
check the inputs in the initial stage and action consequently.
Input
The machine will request to select the product if the inputs are penny
accepted, the right selection or availability of product will
move the machine to its next flow and count the total amount.
Slot1 Slot2
The required amount will allow to dispense drink-milk-sugar.
Finally the machine will drop all the coins into the money box
and move to the initialize state.
If the penny is 5p or
… 10p or 20p or 50p
N
Main()
Y
…
If (amount>=cnt) Select Product
{
Dip_drink; Tea
Wait; Y N
Dips_sug1;
Coffee
Dips_sug2;
Y N
Dips_Caron1;
Dips_Caron2; If Product
Available
Call collect_money; N
}else Y
N
{ If the right Y Drink
Wait
Wait; amount inserted Dispensed
}
Call Start; 1 Portion A Milk-Carton
Sugar Dispensed
Dispensed
2 Portion A Milk-Carton
Sugar Dispensed
Dispensed
Coins Drop in
Money Box
End
State table
Present Inputs Next Output Open
State State
5p 10p 20p 50p λ T C Tea Coffee Sugar-1 Sugar-2
Design Decision
The design methodology continued for the Milky-Sweet-Drink, where I used B input, which dispense Milky
and Sweet Drink at once. The machine look at instruction B and move transactions towards three sugar portion
along with the milk cartons, all the product dispense through S7.
Simulation / Tests
Solution:
No, the combined drink-milk machine produced combined milky-drink machine produced
Where,
L(M1) = drink-milk machine <> L(M2) = Milky-drink machine
So, L(M1) L(M2)
Because if we say, two languages are behaving same even if they are using different methods, then these two
machines producing not equal products but using the same method.
Where,
L(M1) =1+1 = 2
L(M2) = 1+2 =3
Therefore,
L(M1) L(M2)