Professional Documents
Culture Documents
Tutorial4a Answers
Tutorial4a Answers
Tutorial4a Answers
Exercise 1 – Answers
1. | Q |n[R | m[S]]
2. S | Q |n[R | m[]]
3. R | Q |n[ | m[S]]
4. u[ | Q |n[R | m[S]]]
5. ν n (S | Q |n[R | m[]])
6. ν n ν m (R | Q |n[ | m[S]])
7. n[Q | R] | m[S]
8. #recv(x).send(x).0 | n[@send(23).0] | recv(y).0
Exercise 2 – Answers
Give a context-expression to characterise each of the following statements (with respect to ambient hierarchy).
1. somewhere (n[true] | m[true])
2. somewhere m[n[true] | true].
3. somewhere n[ next (m[true] | true)]
4. somewhere n[ somewhere (m[true] | true)]
5. somewhere n[ somewhere (m[true] | u[true] | true)]
6. somewhere n[ somewhere (m[true] | true)] and somewhere n[ somewhere (u[true] | true)]
7. somewhere u[n[true] | m[true] | true]
8. not somewhere (m[n[true] | true] or u[n[true] | true])
9. somewhere u[m[true] | true] and somewhere m[n[true] | true]
10. somewhere m[n[true] | true] and somewhere n[m[true] | true]
Exercise 3 – Answers
1. I am located in m: somewhere m[ next (this | true)]
2. I am with m: somewhere (m[true] | next (this | true))
3. I am with m at u: somewhere u[m[true] | next (this | true)]
4. I am at m while m is at u: somewhere u[m[ next (this | true)] | true]
1
5. I have a least 2 child ambients: somewhere (this | next true | next true | true)
6. I have siblings: somewhere next (this | true) | next true | true)
7. m is my ancestor: somewhere m[ somewhere next (this | true)]
Exercise 4 – Answers
In the following “I” means the executing ambient.
1. this | true
Meaning: I am the root ambient.
Context model:
• | n[0]
• | skip
• | skip | skip
2. next (this | true)
Meaning: I have no parent (or my parent is the root ambient).
Context Model:
• n[ | send(5).0]
• n[ | skip]
• n[ | skip | skip]
3. next next (this | true)
Meaning: I have exactly one ancestor.
Context Model:
• m[n[ | send(5).0]]
• m[n[ | skip]]
• m[n[ | skip | skip]]
4. somewhere (this | true)
Meaning: I am the root ambient or its descent.
Context Model:
• | send(5).0
• n[ | skip]
• m[n[ | skip | skip]]
2
• n[] | skip | skip
6. next next this | true
Meaning: I have exactly one ancestor and execute a single thread (sequential process).
Context Model:
• m[n[]] | send(5).0
• m[n[] | send(5).0] | skip
• m[n[] | skip | send(5).0] | skip | skip
7. next (this | true) | n[true]
Meaning: I am with n and have no parent.
Context Model:
• m[ | send(5).0] | n[skip | send(5).0]
• m[ | skip] | n[skip]
• m[ | skip | skip] | n[send(5).0]
Exercise 5 – Answers
1. n[true] | m[true] | true
Meaning: n is with m and has no parent.
Context Model: m[0] | n[0]
2. next (n[true] | m[true] | true)
Meaning: n is with m and has exactly one ancestor parent.
Context Model: u[m[0] | n[0]]
3. somewhere (n[true] | m[true] | true)
Meaning: n is with m.
Context Model: m[0] | n[0]
4. n[true | m[true]] | true
Meaning: n has no parent and has a child m.
Context Model: n[m[0] | send(0).0]
5. n[true | somewhere m[true]] | true
Meaning: n an ancestor of m and has no parent.
Context Model: n[m[0] | u[0]]
6. this | somewhere m[true] | true
Meaning: I am the root ambient and an ancestor of m.
Context Model: | m[0]
7. somewhere (n[true | m[true]] | true)
Meaning: m is located at n.
Context Model: n[n[0]]
8. somewhere (n[true | somewhere m[true]] | true)
Meaning: n is an ancestor of m.
Context Model: n[u[m[0] | send(5).0]]
3
9. somewhere (this | somewhere m[true] | true)
Meaning: I am an ancestor of m.
Context Model: u[ | m[0]]
Exercise 6 – Answers
Consider three ambients n, m and u. Give the specification of the ambient n in each of the following cases.
1. n sends a hello message to a sibling m if u is located in n.
n[<has(u)>m :: send(hello).0]
or just
n[<at(m, u)>m#send(hello).0]
n[<with(m, u)>m@send(hello).0]
Exercise 7
Description
• Trip sensor is a type of motion detector that can detect movement across a laser beam.
• It can be used to alert a user of intrusion into a controlled area; e.g. by raising the alarm.
• The simple intrusion detection system comprises a trip sensor which is connected to a server (home
gateway) that raises the alarm when movement is detected.
Questions
1. Give a specification of the system in ccaPL.
2. Simulate your program and show the communication graph.
4
Answers: See Lesson 8 slides.
Exercise 8
Description
5
Exercise 9
Description
• The figure below shows a smart lamp system.
• The smart lamp is controlled by an Arduino-like micro-controller unit (MCU).
• The light sensor detects light when the light level is above a 20% threshold.
• The motion sensor detects movement.
• The controller turns the lamp on when no light is detected or a movement is detected; and off otherwise.
• The user can turn the system on or off using a push button.
Questions
1. How do you model the user interaction with the push button?
2. Give a specification of the system in ccaPL.
3. Simulate your program and show the communication graph.