Skip to main content Skip to navigation

LSD account for a cat flap (Ian Bridge)

LSD account for a Cat Flap

/*******************************************************************
file : catflap.lsd
date : 07.08.91
author : I.Bridge (as 'modernised' by wmb 11/11/97)
notes : description of agents for a 'catflap' system
********************************************************************/

TYPE
flapPosTyp = ENUM (fpOut, fpVert, fpIn)
lockPosTyp = SET OF ENUM (lpOut, lpIn)
catIntTyp = ENUM (ciGoOut, ciStayPut, ciGoIn)
pushDirTyp = ENUM (pdOut, pdIn)

AGENT flap {
STATE
lockPos : lockPosTyp
flapPos : flapPosTyp
ORACLE
lockPos
pushDir
HANDLE
flapPos
PROTOCOL
(pushDir == pdOut) AND NOT (lpOut IN lockPos)
-> flapPos = fpOut /* open out */
(pushDir == pdIn) AND NOT (lpIn IN lockPos)
-> flapPos = fpIn /* open in */
(pushDir == pdNone)
-> flapPos = fpVert /* close */
}

AGENT man {
ORACLE
flapPos
HANDLE
lockPos
PROTOCOL
(flapPos = fpVert) /* change lock */
-> lockPos IN power_set(lockPosTyp) /* See Notes */
}

AGENT cat {
STATE
catInt : catIntTyp
catPos : INTEGER // > 0 : outside
// = 0 : at flap
// < 0 : inside
pushDir : pushDirTyp
ORACLE
flapPos
HANDLE
pushDir
DERIVATE
catEngag is (catPos >= 1) && (catPos <= 1);
catObstr is (flapPos == fpVert)
PROTOCOL
(catInt = ciGoIn) AND catObstr /* push in */
-> pushDir = pdIn
(catInt = ciGoIn) AND NOT catObstr /* walk in */
-> catPos = catPos - 1
(catInt = ciGoOut) AND catObstr /* push out */
-> pushDir = pdOut
(catInt = ciGoOut) AND NOT catObstr /* walk out */
-> catPos = catPos + 1
NOT catEngag /* no push */
-> pushDir = pdNone
TRUE /* decide intention */
-> intent IN catIntTyp
}

Notes :

The cat is engaged in getting through the flap when it is at or within a unit distance from the entrance (at position 0). Whilst engaged in the flap the cat must push in the direction required to open the flap or to keep it open. The feature of cat length has not been modelled.

Cat behaviour is totally non-deterministic (modelling an extremely fickle cat). The model is sufficiently realistic to encompass the eventuality that the cat changes its intentions whilst engaged in the flap (guaranteeing a safe outcome for the cat).

The function 'power_set' is assumed to return an instance of the power set of a set of values defined by a type.