Exercise 51:
Pharmacy
Consider the following model of a pharmacy, which is simplified and not yet complete.
Patients arrive at the pharmacists desk (also known as counter) with a recipe, stating
their name and their medicine (also known as drug). The required drug is identified by
a number. If available in the stockroom, the client receives the drug from the pharmacist.
colset Drug = int with 1..500;
colset Patient = string;
colset Recipe = product Patient * Drug;
1`3++10`20++1`50++2`500
Stockroom
Drug
Counter
1`("Kerremans",50)++1`("Quaglini",300)
Orders
Delivery
Recipe
Drug
The following questions are all related to this simple model and should introduce as few
adjustments to the model as necessary.
a) Extend and/or adapt the initial model in such a way that it delivers the right drug for
each recipe. Do not add any tokens.
Solution:
Remark 1. Note that the arc from Counter to Stockroom has been removed. To explain
why, consider the following alternative solution on the right.
On the right, each token represents a drug (type) that is is tagged with an amount that
specifies how many instances of the drug type are in stock. On the left, each token
corresponds to one specific drug instance. For instance, on the left there are 10 tokens of
drug type 20, while on the right there is one token (20,10), specifying that there are 10
instances of drug type 20.
Remark 2. Note that you need to declare the variables (leftside of the pane)!
Alternative solution using multiple variables and a guard:
The guard condition [d1=d2] ensures that the value for d1 equals the value for d2.
Without the guard, it is possible that for instance d1=500 and d2=3.
Both solutions are correct and would get a full score for the exam.
b) Explain why patient "Quaglini" can't get her drug in the model you provided for a).
Solution: patient "Quaglini" wants to have drug 300, but this is not in stock (no token in
place Stockroom).
c) Due to new regulations, the pharmacist can only hand out drugs to patients who are
already registered in the client database of the pharmacy. Extend and/or adapt the
model you provided for a) to reflect this situation.
Solution:
d) Patients should also pay for their drugs. The pharmacy has a pricelist, which specifies
for each drug its price, for instance drug 50 costs 130 euro. Extend the model from a)
such that patient not only get their drug but also a bill, so a number specifiying the
cost.
Solution:
Exercise 52:
Phone numbers
NameAddress
phone db
number
PhoneDB
Phone
1`"John"++1`"Pete"
query
Name
c) Token "Pete" in place query can't be consumed. Explain why and sketch a
minimal extension such that token "Pete" can be consumed.
Solution:
Pete doesn't have an office according to personnel db. To repair, add for instance token
("Pete",(C,1)) to the place personnel db. Then Pete is located at the same room as Tony.
Token "Pete" then can be consumed because n="Pete", a=(C,1) and t=2139.
d) The company is interested how many times the information system is used.
Extend the model such that total number of queries is registered and updated
when a new query is made.
Solution:
Next, replace (n,a) with (n,a,s) and replace p (on the arc that points to place number) with
(p,s).
Exercise 53:
Bakery
Consider a small bakery with only one shop assistant attending customers. If a customer
enters the bakery, he has to draw a ticket with a number n, where n>0. The customer has
to wait until the shop assistant processes his number. After leaving the shop, the customer
can enter the shop again.
a. Model the process of a bakery in classical Petri. Make sure that you add a place
for the current number in the ticket machine and the current number being
processed. You may assume that each action (drawing a ticket, serving the
customer) can be modelled with one transition.
Solution:
last
given
number
current
number
UNIT
UNIT
() ()
() ()
customer
outside
bakery
()
UNIT
customer
enters
bakery
()
customer
without
number
()
customer
draws
number
()
UNIT
()
customer
with
number
()
serve
customer
()
serve
customer
UNIT
leave
shop
()
b. Extend the model from (a) with color such that you can model that customer
(black token) has a number. Make sure that for a customer with number n :
the next customer gets a ticket with the number n+1.
after the shop assistant served the customer, she serves the customer with
number n+1.
Execute the model in CPN Tools with 2 customers.
Solution:
UNIT
c. Some customers are fed up with waiting and disappear after a while before they
have been served. Extend the model from b) to incorporate disappearing
customers.
Solution:
d. The model from c) can result in dead parts: after some firing sequence, some
transitions are never fired anymore. Explain why and give an example of such a
firing sequence plus the transitions that cannot be fired anymore.
Solution:
If a customer with number n is leaving, the shop assistant still want to serve him after
processing number n-1. After firing sequence "customer enters bakery", "customer draws
number", "leave shop unserved", the transitions "service customer" and "leave shop" can't
be fired anymore.