Anda di halaman 1dari 9

Instruction 5: Colored Petri nets (data)

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

Original model of the pharmacist

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

An organisation wishes to build a simple information system to retrieve phone numbers


of employees, for which it has built the following incomplete CPN model.
1`("John",(A,12))++
1`("Rafael",(D,2))++
1`("Susan",(F,10))++
1`("Tony",(C,1))
personnel db
1`((A,12),2330)++
1`((D,2),2350)++
1`((F,10),2342)++
1`((C,1),2139)

NameAddress

phone db

number
PhoneDB

Phone

1`"John"++1`"Pete"
query
Name

Place query models a request for an (internal) phone number of an employee. A


phonenumber is number consisting of four digits, ranging from 2000 to 2999. Place
personnel db models a database which contains the office address of each employee. An
office address consists of a corridor and a room number. Each corridor is is labelled with
letters A upto F, and room numbers are labelled 1 upto 20. Place phonedb specifies for
each office address the phone number. Both databases are not yet complete.
a) Give a correct specification of all color sets used in the incomplete model that
matches the tokens in the places such that constraints mentioned in the text are
met. You may use your own defined color sets.
Solution:
colset Name = string;
colset Corridor = with A| B | C | D | E | F;
colset Phone = int with 2000 .. 2999;
colset Room = int with 1 .. 20;
colset Address = product Corridor * Room;
colset PhoneDB = product Address * Phone;
colset NameAdress= product Name * Address;
b) Add to the incomplete model in a) one ore more transitions, arcs, variables and
arc inscriptions, such that for an arbitrary employee in place query the
corresponding phone number is delivered in place number.
Solution:

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:

Note that new place count needs to have a token.


e) The company wants to extend the information system such that also email
addresses of employees can be retrieved. Sketch how the model can be extended
to support this. Clearly indicate which color sets you modify.
Solution:
Change the color set of NameAddress, for instance
colset NameAddress = product Name * Address * STRING;
where the last element of type STRING models the email address.
Replace the color set Phone with new color set
colset PhoneEmail = product Phone * STRING;
Add a variable s
var s: STRING;

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.

e. Repair the deadlock described at d) by extending the model of c).


Solution:

Anda mungkin juga menyukai