2020-04-14 17:29:33 +02:00
|
|
|
|
%
|
|
|
|
|
% VM.mcrl2
|
|
|
|
|
%
|
|
|
|
|
% A Simple Vending Machine.
|
|
|
|
|
%
|
|
|
|
|
% Copyright (c) 2019-2019 HS Emden-Leer
|
|
|
|
|
% All Rights Reserved.
|
|
|
|
|
%
|
|
|
|
|
% @version 1.00 - 01 Apr 2019 - GJV - initial version
|
|
|
|
|
%
|
|
|
|
|
|
|
|
|
|
% -----------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
%
|
|
|
|
|
% Definition of the coins
|
|
|
|
|
%
|
|
|
|
|
sort
|
|
|
|
|
Coin = struct _5c | _10c | _20c | _50c | Euro;
|
|
|
|
|
|
|
|
|
|
map
|
|
|
|
|
value: Coin -> Int; % the value of a coin as an integer
|
2020-04-30 14:40:28 +02:00
|
|
|
|
next: Coin -> Int; %n<>chst gr<67><72>erer Betrag
|
2020-04-14 17:29:33 +02:00
|
|
|
|
|
|
|
|
|
eqn
|
|
|
|
|
value(_5c) = 5;
|
|
|
|
|
value(_10c) = 10;
|
|
|
|
|
value(_20c) = 20;
|
|
|
|
|
value(_50c) = 50;
|
|
|
|
|
value(Euro) = 100;
|
|
|
|
|
|
2020-04-30 14:40:28 +02:00
|
|
|
|
next(Euro) = 500;
|
2020-04-25 10:57:28 +02:00
|
|
|
|
next(_50c) = 100;
|
|
|
|
|
next(_20c) = 50;
|
|
|
|
|
next(_10c) = 20;
|
|
|
|
|
next(_5c) = 10;
|
2020-04-21 11:04:32 +02:00
|
|
|
|
|
2020-04-14 17:29:33 +02:00
|
|
|
|
|
|
|
|
|
% -----------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
%
|
|
|
|
|
% Definition of the products
|
|
|
|
|
%
|
|
|
|
|
sort
|
|
|
|
|
Product = struct tea | coffee | cake | apple;
|
|
|
|
|
|
|
|
|
|
map
|
|
|
|
|
price: Product -> Int; % the price of a product as an integer
|
|
|
|
|
|
|
|
|
|
eqn
|
2020-04-21 11:04:32 +02:00
|
|
|
|
price(tea) = 10;
|
|
|
|
|
price(coffee) = 25;
|
|
|
|
|
price(cake) = 60;
|
|
|
|
|
price(apple) = 80;
|
2020-04-14 17:29:33 +02:00
|
|
|
|
|
|
|
|
|
% -----------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
%
|
|
|
|
|
% Definition of the actions
|
|
|
|
|
%
|
|
|
|
|
act
|
|
|
|
|
accept: Coin; % accept a coin inserted into the machine
|
|
|
|
|
return: Coin; % returns change
|
|
|
|
|
offer: Product; % offer the possibility to order a certain product
|
|
|
|
|
serve: Product; % serve a certain product
|
|
|
|
|
returnChange: Int; % request to return the current credit as change
|
|
|
|
|
|
|
|
|
|
%
|
|
|
|
|
% Definition of the processes
|
|
|
|
|
%
|
|
|
|
|
proc
|
|
|
|
|
|
|
|
|
|
VM(credit : Int) =
|
2020-05-08 19:42:15 +02:00
|
|
|
|
(credit < 200) ->
|
|
|
|
|
sum c : Coin
|
|
|
|
|
.accept(c).VM(credit + value(c)) %Coins akzeptieren, solange credit < 2<>
|
2020-04-27 17:42:44 +02:00
|
|
|
|
|
2020-05-08 19:42:15 +02:00
|
|
|
|
+ (credit > 0) ->
|
|
|
|
|
returnChange(credit).ReturnChange(credit)%Geld zur<75>ckgeben wenn credit > 0
|
2020-04-27 17:42:44 +02:00
|
|
|
|
|
2020-04-14 17:29:33 +02:00
|
|
|
|
+ sum p : Product.(
|
2020-05-08 19:42:15 +02:00
|
|
|
|
(credit >= price(p)) ->
|
|
|
|
|
offer(p).serve(p).VM(credit - price(p))%Produkt anbieten, wenn genug credit
|
|
|
|
|
);
|
2020-04-14 17:29:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReturnChange(credit : Int) =
|
2020-05-08 19:42:15 +02:00
|
|
|
|
sum c : Coin.(
|
|
|
|
|
(credit >= value(c) && credit < next(c)) -> %gr<67><72>t m<>glichen Coin ermitteln
|
|
|
|
|
return(c).( %diesen zur<75>ckgeben
|
|
|
|
|
((credit - value(c)) > 0) %wenn noch Geld <20>brig
|
|
|
|
|
-> ReturnChange(credit - value(c)) %dieses zur<75>ckgeben
|
|
|
|
|
<> VM(credit - value(c)) % oder nur abziehen
|
2020-04-14 17:29:33 +02:00
|
|
|
|
));
|
|
|
|
|
|
2020-04-27 17:42:44 +02:00
|
|
|
|
|
|
|
|
|
|
2020-04-14 17:29:33 +02:00
|
|
|
|
% -----------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
init
|
2020-04-27 17:42:44 +02:00
|
|
|
|
VM(0)
|
2020-04-14 17:29:33 +02:00
|
|
|
|
;
|