Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/285599126

Finite State Vending Machine

Technical Report · April 2015

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.

The user has requested enhancement of the downloaded file.


Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Formal Methods Engineering


Nasreen Iqbal
P13194231@myemail.dmu.ac.uk
De Montfort University

1. GENERAL MACHINE CONCEPT


Conceptually a finite state vending machine model that displays inputs and decide whether a bit string contained
specific pattern. Here the Vending machine model that accepts 5p, 10p, and 20p from the customer, when a
sufficient amount entered by the customer the machine dispenses Coffee, Tea and free Milo or sugar, depending
on the choice and input of the customer, where a cup coffee cost 50p, a cup of tea is 25p. We will describe that
how the machine will work by specifying its states, how states changing when input received and finally the
output produced for every combination of inputs and current status.
The specification exploits the vendor machine containing two coin slot and two buttons for the user.
 Slot 1 will accept 5-10-20-50p
 Slot 2 will accept 50p only
 The machine will not return change
 The machine will wait if money for a specific time, less than sets.
 The machine dispenses complementary a portion of sugar and a milk container on user’s choice
 After the drink dispensed all inserted coins are dropped in the MONEY BOX
 Finally, The machine will set to START state and wait for the next customer

1.1. UNDERSTAND THE PROBLEM:

Vending Machine Coffee / Tea Release


Coin Sensor Insert Door/ Output
FMS Mechanism

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 FMS vending machine exploits the black box process.


The vending machine has to provide the solution for the following requirements.
 The machine dispenses a drink, a maximum of a milk carton and a maximum of a one portion of sugar.
 The combine drink-milk machine, which dispense a carton of milk.
 The combine drink-sugar machine, which dispense a portion of sugar.
 The combine milky-drink machine, which dispense two or more cartons of milk.

Copyright © 2014, De Montfort University. All Rights Reserved


1
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

 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

Disp (Suger) S (Suger) M (Milk)


(Milk)

Fig2.2: Milk and Sugar Machine

The machine should behave in accordance with the following specifications:


1. A customer needs to deposit a sufficient amount of money before he or she is selecting an item for
purchase. If the item costs less or equal than the deposited amount, the item is dispensed with no return
policy. If the item costs more than the deposited amount, the machine waits for more coins to be
inserted.
2. The machine will wait for 30 seconds and then will cancel the transaction. After that the machine will
go to START and wait for another customer or input.
3. A sufficient amount calculated by the machine, resulting requested dispense item.
4. A portion of Sugar and Milk container dispense on customer selection, a free of cost.
5. The coin slot in the machine will only accept a single coin. Attempts to jam two or more coins cannot
affect the state of the machine and are ignored. Similarly, attempts to make multiple selections are
ignored.
6. The drink dispenser can store at most one drink. If it contains a drink, this drink should be removed
before the next one can be dispensed.
7. A Tea costs 25p. A cup of coffee costs 50p.
8. From time to time the drink storage can be recharged. After the recharge both Tea, coffee, Milk and
Suger become available.
2.1. MAP SUITABLE ABSTRACT REPRESENTATION:
Tabulate typical input sequences:

Copyright © 2014, De Montfort University. All Rights Reserved


2
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Our inputs are: List the valid coin input

 Start Sequences:  20p,5p,T


Four pee’s  5p,10p,20p,T  20p,10p,T
(5p,10p,20,
50p)  10p,20p,p5,T  10p,10p,10p,T

Our output is:  20p,5p,10p,T  20p50p,C

• Dispense or Open  5p,5p,5p,5p,5p,T  10p,10p,10p,20pC


 10p,10p,5p,T  50p,C
 20p,50p,C  T or C ( Coffee / Tea)
 5p,5p,5p,20p,T  ( Free choices, a portion of sugar/ milk cartons.)

2.2. DESCRIPTION OF STATES


The selection of products and all the states.
 When initialize=>
money_count=0;
Product=0;
 When select1=>
Tea&!Coffee&!Milk&!Sugar&!Milky&!Sweet
When product_available=1 => nx1<= waiting;
When product_available=0 => nxt1<= service;
 When waiting=>
When 5p&!10p&!20p&!50p => nx_state<=state;
product=0;
When money_count>=25 nx_st1<= Tea;
When money_count>=50 nx_st1<= Coffee;
 When S1=>
5p=1 & 10=0 & 20=0 ;
Product=0;
Money_count=money_count+5;
2.3. STATE TRANSACTION
These transactions change states from one state to another. For example a transaction caused by pressing a
button to dispense a drink. The execution of the transaction may change depending on coin type. The way to
view transaction by defining states as pare (s, s’) here s is the before the transaction and s’ is the after
transaction. The selection effect where, if the price p of the drink <= to the value, then the money decreases by
p. Otherwise, the value remains the same. This transition is applicable to many different states of the system.
certainly, the only requirement is that the value of money is >= to p, so there may be quite a range of acceptable
values for amount. In addition, there are no restrictions on the content of the storage or drink dispenser. It
follows that this transition is not a pair of states, but rather a function of the states. If we identify a state with the
value m of money, then the function is defined as follows:

Copyright © 2014, De Montfort University. All Rights Reserved


3
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Drink dispensing (m) = m-p, if m>p;


{ m, if m<p;
For example, the amount accepting
transition can be represented by the set of pairs
{(m,m′) | m > 0, 0 ≤ m′ < m}.
This implies that for a state s, there may be more than one state s′ such that s can be changed into s′ by the
transition. In this case we will say that the transition is non-deterministic.

Our formalization will use the following state variables.


1. Boolean state variables st Coffee and st Tea signaling whether the corresponding drink is
currently being stored in the drink storage.
2. A state variable disp with the domain none, tea , coffee whose value is the current content of
the drink dispenser.
3. A state variable coins denoting the current number of coins in the slot. Its possible values are
5,10,20,50.
In every such state, the drink should be available, the drink dispenser empty, and the coin slot contains
enough coins. This can be expressed by the following formula
(coffee ∨ Tea) ∧ disp = none ∧ coins ̸= 0 ∧ (coins = 50 → coffee).
Description:
 Alphabet

{5p, 10p, 20p, 50p, C, T }

5 pee 10 pee 20 pee 50 pee Coffee Tea

 Vending Machine Process


VM=(Tea l Coffee); VM
Behaves as (choice) until successful completion and then like VM
o Recursive definition form x=f(x)

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:

Copyright © 2014, De Montfort University. All Rights Reserved


4
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

I x S -> S State transaction function


∆ I x S -> O Output function
Example: `if waiting and 5 pee is inserted change state
( 5p, wait)= 5 -> to 5credit
If 50p and Coffee is requested, then change
(C,50)= wait state to wait and dispatch the coffee
∆ (C,50)= dispatch

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.

 Specification Of the Model


Draw a state diagram for Coffee and Tea Machine:
The state diagram consists of four states, waiting for coin insertion, user's selection, product delivery and
services when product not available=1. Initially the machine is ready to serve by initializing the process which
makes zero to all variables =0 and machine is ready for input in separate two specific slots, such as slot1 can
accept 5p,10p,20p and slot2 can accept only 50p. Subsequently, the amount deposit >25 and the customer push
the button to choose the product, i.e. T for Tea or C for Coffee, in response the machine exerts on changing
states and produce the desired results.
Consequential the machine will ignore the return policy if the amount is less than <25 or <50. In addition, this
machine will check the product availability, if the specific product is out of stock, then the machine will wait for
another product to choose else the machine will blink a light under the product for service.
The waiting state is common to all the states which has been set for 30 seconds. If within 30 seconds the entire
input not received, then the machine will reach to the initial state and ready for the next customer. I know this
machine is cheating because in any case money will not return money and provide excuses to the customer, i.e.
why you didn’t choose within 30 second, why you took so long time to insert a pee and why you are so slow.
Similarly, the machine is not responsible if the machine has no product available. The following flow diagrams
are clearly exploiting the requirements.

Copyright © 2014, De Montfort University. All Rights Reserved


5
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

that the machine will check the amount as per product,


accordingly product will dispense else it will wait for the next
If the penny is 5p or
amount input. Additionally, at the end the machine will drop 10p or 20p or 50p
all the amount in the money box and the machine will N
initialize for the other customer.
Y
This machine has no cancel and money back policy, therefore, Select Product
this requirement is missing, but a machine will have a
automatic service check system.
Tea
Y
N

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

Finite State Machine Model


These machines are deterministic finite automata which has the aptitude to be in current states moving to the
next state on its right side, this process repeated many times until the reading head reaches the end of the input
string. This is the stage where automation indicates its approval or disapproval of what has read by the state at
the end, if it winds up in one of a set of final states the input string is considered to be accepted.
The state machine below designed to capture the desired amount. The FSM begins with the start state, which
will initialize each time, once the machine completes its process with the customer or product dispensed or
appropriate amount not inserted on time or waiting time is expired. The machine can be in any of 10 states Si,
where i=0 to 10 mainly. Where the Si is the state where the machine has collected 5i pees. The machine starts in
state S0, with 0 pee received. The possible inputs are nothing(n), 5p, 10p, 20p, 50p, T (Tea), C (Coffee), at the
same time the possible outputs are nothing (nil), Tea, Coffee, Milk-Carton’s, sugar-portion’s.
Formally, this deterministic FSM automation is M= (K, , , s, F), where: M an element of Kx *.:
K= {start, s1,s2,s3,s4,s5,s6,s7,s8,s9,s10},
= {si}, “an alphabate”
s  K = {Start} “initial state”,
F  K= {Start} ”set of final state”,
M accept the language L(M = {w {Start…..Disp}*

Copyright © 2014, De Montfort University. All Rights Reserved


6
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

And  is the transaction function of x  to K}

 = {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),


(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10),(S1,T,S1),(S1,C,S1),
(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10),(S2,T,S1),(S2,C,S2),
(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), ),(S3,T,S3),(S3,C,S3),
(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), ),(S4,T,S4),(S4,C,S4),
(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10), ),(S5,T,Disp),(S5,C,S5),
(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10), ),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10), ),(S7,T, Disp),(S7,C,S7),
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10), ),(S8,T, Disp),(S8,C,S8),
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10), (S9,T, Disp),(S9,C,S9),
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10), (S10,T,Disp),(S10,C,S1)}

Fig. 4: Tea, Coffee Vending Machine

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,

Copyright © 2014, De Montfort University. All Rights Reserved


7
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

(Start, 50C) ├ M (start, 50pC)


├ M (S10, C)
├ M (start)
Therefore (Start,50pC) ├ *M (Start) and so statement is acceptable by M D

Symbolic state table for Coffee and Tea


Make the function of F: S x I -> S and g: S x I->0 explicit

Present State Inputs Next State Output Open


5p 10p 20p 50p T C Tea Coffee
Start S1 S2 S4 S10 Start Start S1 0 0
S1 S2 S3 S5 0 S1 S1 S2 0 0
S2 S3 S4 S6 0 S2 S2 S3 0 0
S3 S4 S5 S7 0 S3 S3 S4 0 0
S4 S5 S6 S8 0 S4 S4 S5 0 0
S5 S6 S7 S9 0 Start S5 S6 0 0
S6 S7 S8 S10 0 Start S6 S7 0 0
S7 S8 S9 S10 0 Start S7 S8 0 0
S8 S9 S10 S10 0 Start S8 S9 0 0
S9 S10 S10 S10 0 Start S9 S10 0 0
S10 S10 S10 S10 S10 Start Start Start T C

 Design Decision for the Tea and Coffee Machine


The design for the Drink machine exploits the minimal requirement of the system. The idea of the design is to
observe the smallest amount. Perception is, What if customer inserted five’s or ten’s 5p’s or inserted 20ps only
or inserted insufficient amount or inserted more than the required amount. These are the constraints are required
to investigate. Also machine required service every two hours, where service providers will fill the product and
empty the money box from the machine. In an emergency the machine will indicate with the lights, such as
more the product is not available for the customer.
The machine could be in any of the 10 states is Si =1…10 + start, where the Start is the state when the machine
collect the pee, the machine begins with the Start state and moved to state Si as per customer inputs. Let's have
an example that a user has inserted 10p,5p,10p in the slot 2 and choose Tea as product, the machine will count
the amount in each and every changing state from S1 to S5 and check the condition where the amount is >=25,
finally the Tea product will be dispatched else the machine will wait for the next input for a few seconds,
otherwise the machine will cancel the transaction if customer unable to provide a sufficient amount. Moreover,
the machine has no return policy at this moment, therefore, if the amount is >25 or >50 then the machine will
ignore and will not return the inserted amount instead product.

 Simulation of Test Cases


The simulation test result of the following figures is clearly defined, the drink machine has been tested with the
following below Inputs, where few inputs are rejected. The rejections are due to incorrect inputs found in the
machine. The first highlighted rejection is because the customer inserted 20p and asking for tea where tea
comes in 25p, so 5p is missing, in second and third rejections have similar inputs.

Copyright © 2014, De Montfort University. All Rights Reserved


8
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Drink Machine Results

Fig. 5: Tea, Coffee Vending Machine Test Results

The following below simulation is based on the string 10p5p10pT.


Let V = ({5p10p10p,T}, {n, d, q}, {Start, S5, Start}, δ, ω, 0S}.

Copyright © 2014, De Montfort University. All Rights Reserved


9
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Fig 6: Simulation for the input: a10p5p10pT

Let V = ({50p,C}, {n, d, q}, {Start, S10,Start}, δ, ω, 0S}

Copyright © 2014, De Montfort University. All Rights Reserved


10
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Fig 7:Simulation for the input: 50pC

Draw a state diagram for milk and Sugar Machine


The milk and sugar machine is very simple with the three states one is initialized and the other is milk or sugar
product state, where the machine will check the product availability, if the product is available then the product
will deliver through delivery box, or else it will wait for the input.
Flow start:

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

The Milk and Sugar State Machine:


The following below machines are deterministic finite automatons have the ability to change states in a way that
is only partially determined by the current state and input symbol. So possible next_States for a given
combination of current state and input symbols. The automation reads the input string and go to any one of
these next states according to input.
On these below machines we worked on binary relationship in order to make sure that the maximum 1 product
is dispatched, otherwise, the machine will reset for the next customer. In the below machines the machine will

Copyright © 2014, De Montfort University. All Rights Reserved


11
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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,0, Init), (Init,1,Sug),


(Sug,1,Init)}

Fig 9: Milk Machine Fig 10: Sugar Machine

Formally, a non-deterministic -NFSM is:


M = (states, input, transaction, initial, accept)
Where the transaction is:
Transaction*: states x input* -> p(state)
= transaction* (q,w)=
{q} if w = 1
{ q transaction*(q,u) transaction (q,a) if w= uˆa
So the language is=
L(M) = { w  inputs*: transaction * (initial,w)  accept = 0
L(M) = { w  10: 10 (Start,w)  accept = 0
Let say, w=1, according to the above diagram
So the tree is:

init 1
e
car
tt
dis e
p

Copyright © 2014, De Montfort University. All Rights Reserved


12
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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)

Symbolic state table


Make the function of F: S x I -> S and g: S x I->0 explicit
Milk State Table
Present State Input Next State Output/Open
=0 =1
Init 0 1 Cart 0
Carton - 1 init 1 Carton

Sugar State Table


Present State Input Next State Output/Open
=0 =1
Init 0 1 Sug 0
Sug - 1 init 1 portion of Sug

 Design Decision for the Milk and Sugar Machine


The Milk and Sugar machine is so simple, it has only one button to press and it dispense a milk-carton or/and a
portion of sugar. These machines carried two states and one transaction, finally the product dispensed. The
finite state mechanism adopted deterministic quantiple using the binary number in order to make sure the only 1
carton is dispensed even more than one button pressed.
The proof is:
init=1=Carton,
init =0=init,
cart1 =1=init.
Where,
(init =1=Carton)  (carton =1=init)

 Simulation of Test Cases


The milk and sugar machine has almost same function except the dispense of product. As per the following
below tests, the Milk machine as two rejections and one acceptance. Milk machine should do anything if Sugar
button pressed or Milk button pressed twice. The rejection came in the second lane where customer press button
twice therefore machine rejected the second input and drive to the initial stage.

Copyright © 2014, De Montfort University. All Rights Reserved


13
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Milk Machine Result Sugar Machine Results

Fig. 11:Simulation for the input: Milk or Suger

Let V = ({M}, {n, d, q}, {Start, Disp}, δ, ω, 0S}.

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.

 Specification Of the Model


Draw a state diagram:

Copyright © 2014, De Montfort University. All Rights Reserved


14
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

The methodology of the combined drink-milk machine as Start


demonstrated in the flow diagram on the left hand side. The process is INIT
similar to above diagrams. Where two slots for different pee. Once the Input
pee inserted by using either slot, the customer required to input their penny

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;
}

Fig. 13: Combined Drink-Milk Machine Flow Chart

 Finite State Machine Model


This machine is nondeterministic finite automatons which have the power to change the state partially
determined by the current status and input symbol. The machine derived to the valid states as per inputs
otherwise wait for few seconds for the correct input. Once the approval indicated the state change to disp state
and the product is dispensed, afterwards a carton-milk dispense for free and machine derived to the initial stage.
This machine makes sure that the 1 product has been dispatched for a transaction.
Formally, these machines are FSM transition M= (K, , , s, F), M, where: M an element of K :
K= {Start, s1,s2,s3,s4,s5,s6, s7, s8, s9, s10, disp, Sug},
= {si},
s  K = {Start},
F  = {Sug}}
M accept the language L(M = {w  {Start…..Carton}*
And
 = {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),
(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10), (S1,T,S1),(S1,C,S1),
(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10), (S2,T,S2),(S1,C,S2),

Copyright © 2014, De Montfort University. All Rights Reserved


15
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), (S3,T,S3),(S1,C,S3),


(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), (S4,T,S4),(S4,C,S4)
(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10),(S5,T,Disp),(S5,C,S5),
(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10),(S7,T, Disp),(S7,C,S7)
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10),(S8,T, Disp),(S8,C,S8)
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10),(S9,T, Disp),(S9,C,S9)
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10),(S10,T, Disp),(S10,C, Disp),
(Disp,λ,Carton)
(Carton,λ,Start)

Fig.14: Vending State Machine with Product and Milk-Carton is Free

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

Copyright © 2014, De Montfort University. All Rights Reserved


16
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

Let V = ({10p20p,T}, {n, d, q}, {Start, S6, Start}, δ, ω, s}.

Copyright © 2014, De Montfort University. All Rights Reserved


17
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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.

 Specification Of the Model


Draw a state diagram:

Copyright © 2014, De Montfort University. All Rights Reserved


18
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

 Deterministic Finite State Machine Model


This machine is deterministic finite automatons, the automaton M picks its next stage are encoded into the
transaction function, therefore if M is in state q  k and the symbol read from the input tape is a a  , then
(q,a)  k is a unique determination state to which K is passed.
Formally, these machines are FSM transition M= (K, , , s, F), M, where: M an element of K :
K= {Start, s1,s2,s3,s4,s5,s6, s7, s8, s9, s10, disp, Sug},
= {si},
s  K = {Start},
F  = {Sug}}
M accept the language L(M = {w  {Start…..Sug}*
And
 = {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),
(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10), (S1,T,S1),(S1,C,S1),

Copyright © 2014, De Montfort University. All Rights Reserved


19
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10), (S2,T,S2),(S1,C,S2),


(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), (S3,T,S3),(S1,C,S3),
(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), (S4,T,S4),(S4,C,S4)
(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10),(S5,T,Disp),(S5,C,S5),
(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10),(S7,T, Disp),(S7,C,S7)
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10),(S8,T, Disp),(S8,C,S8)
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10),(S9,T, Disp),(S9,C,S9)
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10),(S10,T, Disp),(S10,C, Disp),
(Disp,λ,Sug)
(Sug,λ,Start)}

Fig. 18: A combined Vending Machine for Tea-Coffee and A portion-Sug

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

Copyright © 2014, De Montfort University. All Rights Reserved


20
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

Let V = ({10p20p,T}, {n, d, q}, {Start, S6, Start}, δ, ω, s}

Copyright © 2014, De Montfort University. All Rights Reserved


21
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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.

 Specification Of the Model


Draw a state diagram:

Copyright © 2014, De Montfort University. All Rights Reserved


22
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

Call collect_money; If Product


}else Available
N
{ Y
Wait; N
If the right Y Drink
} Wait
amount inserted Dispensed
Call Start;
A Milk-Carton
Dispensed

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
.

 Nondeterministic Finite State Machine Model


This model is a non-deterministic NFAs automation process because this model satisfying one condition of
NFA that this model has two λ -transactions from the same Disp state reads the empty string for input, that
means the next state function (s, λ) moves to both of the state, state-cart1 and state-cart2.
Formally, these machines are NFSM transition M= (K, , ∆, s, F), where:
K= {Start, s1,s2,s3,s4,s5,s6, s7, s8, s9, s10, disp, Cart1, Cart2, init},
= {si},
s  K = {Start},
F  = {init}}
M accept the language L(M = {w  {Start…..crt1, cart2, init}*
Note: please refer exercise two for definition.
And

Copyright © 2014, De Montfort University. All Rights Reserved


23
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

∆= {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),


(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10), (S1,T,S1),(S1,C,S1),
(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10), (S2,T,S2),(S1,C,S2),
(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), (S3,T,S3),(S1,C,S3),
(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), (S4,T,S4),(S4,C,S4)
(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10),(S5,T,Disp),(S5,C,S5),
(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10),(S7,T, Disp),(S7,C,S7)
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10),(S8,T, Disp),(S8,C,S8)
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10),(S9,T, Disp),(S9,C,S9)
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10),(S10,T, Disp),(S10,C, Disp),
(Disp,λ,Cart1),(Disp,λ,Cart2)
(Car1,λ,Init),
(Cart2,λ,init),
(init,λ,start)}

Fig. 22: A combined Vending Machine for Milk-Drink with 2 Milk-Carton

(START, 10p5p5p10p20pC) ├ M (Start, 10p5p5p10p20pC)


├ M (S2, 5p5p10p20pC)
├ M (S3, 5p10p20pC)
├ M (S4,10p20pC)
├ M (S6,20pC)
├ M (S10,C)
├ M (Disp, λ)
├ M (Cart1, λ )
├ M (Cart2, λ)
├ M (Init, λ)
├ M (Start)

 State table
Present Inputs Next Output Open
State State

Copyright © 2014, De Montfort University. All Rights Reserved


24
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

5p 10p 20p 50p λ T C Tea Coffee Carton-1 Carton-2


Start S1 S2 S4 S10 - Start Start S1 0 0 0 0
S1 S2 S3 S5 0 - S1 S1 S2 0 0 0 0
S2 S3 S4 S6 0 - S2 S2 S3 0 0 0 0
S3 S4 S5 S7 0 - S3 S3 S4 0 0 0 0
S4 S5 S6 S8 0 - S4 S4 S5 0 0 0 0
S5 S6 S7 S9 0 - Disp S5 S6 0 0 0 0
S6 S7 S8 S10 0 - Disp S6 S7 0 0 0 0
S7 S8 S9 S10 0 - Disp S7 S8 0 0 0 0
S8 S9 S10 S10 0 - Disp S8 S9 0 0 0 0
S9 S10 S10 S10 0 - Disp S9 S10 0 0 0 0
S10 S10 S10 S10 S10 - Disp Disp Disp 0 0 0 0
Disp 0 0 0 0 λ - - Cart1 T C 0 0
Disp 0 0 0 0 λ - - Cart2 0 0 0 0
Cart1 0 0 0 0 λ - - Init 0 0 Cart1 0
Cart1 0 0 0 0 λ - - Init 0 0 0 Cart2
Init 0 0 0 0 λ - - Start 0 0 0 0

 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

Let V = ({20p5p10p5p10p,C}, {n, d, q}, {Start, S10, Start}, δ, ω, s}

Copyright © 2014, De Montfort University. All Rights Reserved


25
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Copyright © 2014, De Montfort University. All Rights Reserved


26
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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.

 Specification Of the Model


Draw a state diagram:

Copyright © 2014, De Montfort University. All Rights Reserved


27
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

 Nondeterministic Finite State Machine Model


This model is a nondeterministic NFAs automation process because this model satisfying one condition of NFA
that this model has two λ -transactions from the same Disp state reads the empty string for input, that means the
next state function (s, λ) moves to both of the state, state-sug1 and state-sug2.
Formally, these machines are NFSM transition M= (K, , ∆, s, F), where:
K= {Start, s1,s2,s3,s4,s5,s6, s7, s8, s9, s10, disp, Cart1, Cart2, init},
= {si},
s  K = {Start},
F  = {init}}
M accept the language L(M = {w  {Start…..sug1, sug2, init}*
Note: please refer exercise two for definition.

And

Copyright © 2014, De Montfort University. All Rights Reserved


28
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

∆ = {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),


(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10), (S1,T,S1),(S1,C,S1),
(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10), (S2,T,S2),(S1,C,S2),
(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), (S3,T,S3),(S1,C,S3),
(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), (S4,T,S4),(S4,C,S4)
(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10),(S5,T,Disp),(S5,C,S5),
(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10),(S7,T, Disp),(S7,C,S7)
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10),(S8,T, Disp),(S8,C,S8)
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10),(S9,T, Disp),(S9,C,S9)
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10),(S10,T, Disp),(S10,C, Disp),
(Disp,λ,Cart1),(Disp,λ,Cart2)
(Sug1,λ,Init),
(Sug2,λ,init),
(init,λ,start)}

 Fig. 26: A combined Vending Machine for Sweet-Drink

(START, 10p5p5p10pT) ├ M (Start, 10p5p5p10pT)


├ M (S2, 5p5p10pT)
├ M (S3, 5p10pT)
├ M (S4,10pT)
├ M (S6,T)
├ M (Disp)
├ M (Sug1,λ)
├ M (Sug2,λ)
├ M (Init, λ)
├ M (Start)

State table
Present Inputs Next Output Open
State State
5p 10p 20p 50p λ T C Tea Coffee Sugar-1 Sugar-2

Copyright © 2014, De Montfort University. All Rights Reserved


29
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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 Disp 0 0 0
Disp 0 0 0 0 λ - - Sug1 T C 0
Disp 0 0 0 0 λ - - Sug2
Sug1 0 0 0 0 λ - - Init 0 0 Sug1 0
Sug2 0 0 0 0 λ - - Init 0 0 0 Sug2
Init 0 0 0 0 λ - - Start 0 0 0 0

 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}

Copyright © 2014, De Montfort University. All Rights Reserved


30
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

10p5p5p10pT
Fig. 28: Simulation for a combined Vending Machine for Sweet-Drink with 2 Portion-Sugar

EX: 2. VI. A COMBIND DRINK-MILK-SUGAR MACHINES THAT DISPENSES A MILKY AND


SWEET-DRINK

 Specification Of the Model


Draw a state diagram:

Copyright © 2014, De Montfort University. All Rights Reserved


31
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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

Fig. 29: Drink-Milk-Sugar Machine

 Finite State Machine Model


Formally, these machines are NFSM transition M= (K, , ∆, s, F), where:
K= {Start, s1,s2,s3,s4,s5,s6, s7, s8, s9, s10, disp, Cart1, Cart2, init},
= {si},
s  K = {Start},
F  = {init}}
M accept the language L(M = {w  {Start…..sug1, sug2, init}*
And
∆ = {(Start,5,S1), (Start,10,S2), (Start, 20,S4), (Start,50,S10),(Start,T,Start),(Start,C,Start),
(S1, 5, S2 ),(S1, 10, S3), (S1,20, S4), (S1,50,S10), (S1,T,S1),(S1,C,S1),
(S2, 5, S3),(S2, 10, S4), (S2, 20, S5), (S2,50,S10), (S2,T,S2),(S1,C,S2),
(S3, 5, S4),(S3, 10, S5), (S3, 20, S5), (S3,50,S10), (S3,T,S3),(S1,C,S3),
(S4, 5, S5 ),(S4, 10, S5), (S4, 20, S5), (S4,50,S10), (S4,T,S4),(S4,C,S4)

Copyright © 2014, De Montfort University. All Rights Reserved


32
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

(S5, 5, S6), (S5, 10, S7), (S5, 20, S9), (S5,50,S10),(S5,T,Disp),(S5,C,S5),


(S6, 5, S7), (S6, 10, S8), (S6, 20, S10), (S6,50,S10),(S6,T, Disp),(S6,C,S6),
(S7, 5, S8), (S7, 10, S9), (S7, 20, S10), (S7,50,S10),(S7,T, Disp),(S7,C,S7)
(S8, 5, S9), (S8, 10, S10), (S7, 20, S10), (S7,50,S10),(S8,T, Disp),(S8,C,S8)
(S9, 5, S10), (S9, 10, S10), (S9, 20, S10), (S9,50,S10),(S9,T, Disp),(S9,C,S9)
(S10, 5, S10), (S10, 10, S10), (S10, 20, S10), (S10,50,S10),(S10,T, Disp),(S10,C, Disp),
(Disp,λ,Carton1),(Disp,λ,Sug1),
(Carton1,λ,Carton2),
(Sug1,λ,Sug2),
(Sug2,λ,init),
(Caton2,λ,init),
(init,λ,start)}
Note: please refer exercise two for definition.

Fig. 30: A combined Vending Machine for Drink-Milk-Sugar

(START, 20p20p10pC) ├ M (Start, 20p20p10pC)


├ M (S4, 20p10pC)
├ M (S8, 10pC)
├ M (S10,C)
├ M (Disp,λ)
├ M (Carton1,λ)
├ M (Sug1,λ)
├ M (Carton2,λ)
├ M (Sug2,λ)
├ M (Init, λ)
├ M (Start)

State table
Present Inputs Next Output Open
State State
5p 10p 20p 50p λ T C Tea Coffee Sugar-1 Sugar-2

Copyright © 2014, De Montfort University. All Rights Reserved


33
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Start S1 S2 S4 S10 - Start Start S1 0 0 0 0


S1 S2 S3 S5 0 - S1 S1 S2 0 0 0 0
S2 S3 S4 S6 0 - S2 S2 S3 0 0 0 0
S3 S4 S5 S7 0 - S3 S3 S4 0 0 0 0
S4 S5 S6 S8 0 - S4 S4 S5 0 0 0 0
S5 S6 S7 S9 0 - Disp S5 S6 0 0 0 0
S6 S7 S8 S10 0 - Disp S6 S7 0 0 0 0
S7 S8 S9 S10 0 - Disp S7 S8 0 0 0 0
S8 S9 S10 S10 0 - Disp S8 S9 0 0 0 0
S9 S10 S10 S10 0 - Disp S9 S10 0 0 0 0
S10 S10 S10 S10 S10 - Disp Disp Disp 0 0 0 0
Disp 0 0 0 0 λ - - Carton1 T C 0 0
Disp 0 0 0 0 λ - - Sug1 0 0 0 0
Carton1 0 0 0 0 λ - - Carton2 0 0 1 Carton 0
Sug1 0 0 0 0 λ - - Sug2 0 0 0 Sug1
Ctarton2 0 0 0 0 λ - - Init 0 0 Carton2 0
Sug2 0 0 0 0 λ - - init 0 0 0 Sug2
Init 0 0 0 0 λ - - Start 0 0 0 0

 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

Fig. 31: Test-Results for a combined Vending Machine for Drink-Milk-Sugar

Let V = ({20p20p10p,C}, {n, d, q}, {Start, S10, Start}, δ, ω, s}

Copyright © 2014, De Montfort University. All Rights Reserved


34
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

Fig. 32: Simulation for a combined Vending Machine for Drink-Milk-Sugar

EX: 2. VII. THE DEFINITION OF EQUAVALATION


The equivalent of notation might depict the relation of “friendship” among 2 or more states from the different
FSM diagrams. A relation R is antisymmetric if whenever (a,b)  R and a and b are distinct, then (b,a)  R. For
example, let P be the set of all persons. Then the below is antisymmetric.
{(a,b) : a, b  P and a is the father of b}
Formally, we say that two finite automata M1 and M2 are equivalent if and only if L(M1) = L(M2). Thus, two
automata are considered to be equivalent if they accept the same language, even though they may ‘use different
methods’ to do so.
Here, the (ii) and (iv) are required for proof, as equal or not.
Query: combined drink-milk machine produced = combined milky-drink machine produced

Copyright © 2014, De Montfort University. All Rights Reserved


35
Formal Methods Engineering
(CTEC5723_2015)
______________________________________________________________________________________

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)

Copyright © 2014, De Montfort University. All Rights Reserved


36
View publication stats

You might also like