Transcript Solutions
1.
Assignment 4 - FSP
A variable store values in the range actions
read 0..N
and supports the and
write
. Model the variable as a process, VARIABLE, using FSP. The process’s LTS graph for N=2 shown below. Your FSP model must produce an identical graph.
is
Assignment 4 - FSP
1.
Solution.
const N = ...
range R = 0..N
VARIABLE = VAR[0], VAR[i:R] = (read[i] -> VAR[i] |write[v:R] -> VAR[v] ).
Assignment 4 - FSP
2. A drinks dispensing machine charges 15p for a can of Sugarola. The machine accepts coins with denominations 5p, 10p and 20p and gives change. Using the alphabet
{can, in.coin[10], in.coin[20], in.coin[5], out.coin[10], out.coin[5] }
model the machine as an FSP process, DRINKS. A sample trace is shown below.
Assignment 4 - FSP
2. Solution.
DRINKS = CREDIT[0], CREDIT[0] = (in.coin[5] -> CREDIT[5] |in.coin[10] -> CREDIT[10] |in.coin[20] -> CHANGE[5]), CREDIT[5] = (in.coin[5] -> CREDIT[10] |in.coin[10] -> CHANGE[0] |in.coin[20] -> CHANGE[10]), CREDIT[10] = (in.coin[5] -> CHANGE[0] |in.coin[10] -> CHANGE[5] |in.coin[20] -> CHANGE[15]), CHANGE[0] = (can -> DRINKS), CHANGE[5] = (can -> out.coin[5] -> DRINKS), CHANGE[10] = (can -> out.coin[10] -> DRINKS), CHANGE[15] = (can -> out.coin[5] -> out.coin[10] -> DRINKS).
Assignment 4 - FSP
3. Consider the following scenario. There are n bees and a hungry bear. They share a pot of honey. The pot is initially empty; its capacity is H portions of honey. The bear waits until the pot is full, eats all the honey and waits until the pot is full again: this pattern repeats forever. Each bee repeatedly gathers one portion of honey and puts it into the pot; if the pot is full when a bee arrives it must wait until the bear has eaten the honey before adding its portion: this pattern repeats forever.
Model this scenario using FSP. The LTS graph for 4 bees is shown below. Your FSP model must produce an identical graph.
3. continued.
Assignment 4 - FSP
Assignment 4 - FSP
3. Solution.
const H=4 const N=3 BEE = (addhoney -> BEE).
BEAR = (eat -> BEAR).
POT = POT[0], POT[i:0..H] = (when (i
||HONEYBEAR = ([i:0..N]:BEE || BEAR || POT).
Assignment 4 - FSP
3. A, S and J work in a bar. A washes the dirty glasses one at a time and places each on a workspace. The workspace can hold a maximum of 10 glasses. S and J remove the glasses from the workspace one at a time and dry them. [You can ignore what happens to a glass after it is dried.] Unfortunately, there is only one drying cloth so S and J have to take turns at using it. However, as J is able to dry faster he dries two glasses at each turn while S only dries one. S takes the first turn at drying.
Model the concurrent activity in the bar by completing the following FSP template.
Assignment 4 - FSP
3. continued.
S = (sdry -> S).
J = (jdry -> jdry -> J).
A = (wash -> A).
// gw is the number of glasses washed.
// j is the number of glasses washed by J in this turn.
// turn indicates whose turn it is to wash.
WORKSPACE(N=5) = WS[0][0][0], WS[gw:0..N][j:0..1][turn:0..1] = (..).
||BAR = (S || J || A || WORKSPACE(10)).
Assignment 4 - FSP
3. continued. A sample trace is shown below.
Assignment 4 - FSP
3. Solution.
S = (sdry -> S).
J = (jdry -> jdry -> J).
A = (wash -> A).
WORKSPACE(N=5) = WS[0][0][0], WS[gw:0..N][j:0..1][turn:0..1] = (gw[gw]-> WS[gw][j][turn] |when (gw
||BAR = (S || J || A || WORKSPACE(20)).