+ All Categories
Home > Documents > Requirements from EX 4.3 R1. Clerk can display the current state of reservations on screen. R2. To...

Requirements from EX 4.3 R1. Clerk can display the current state of reservations on screen. R2. To...

Date post: 20-Dec-2015
Category:
View: 217 times
Download: 4 times
Share this document with a friend
Popular Tags:
12
Requirements from EX 4.3 R1. Clerk can display the current state of reservations on screen. R2. To book, client chooses a free seat and then gets a ticket. R3. Can’t double book. R4. Clients must have choice of all seats available, e.g., can’t divide seats between clerks. R5. Seat can appear to be free although being booked by another clerk. Strange note? How does this fit with R1? Inconsistent with textbook solution! Inconsistent with textbook solution!
Transcript
Page 1: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

Requirements from EX 4.3

R1. Clerk can display the current state of reservations on screen.

R2. To book, client chooses a free seat and then gets a ticket.

R3. Can’t double book. R4. Clients must have choice of all seats available,

e.g., can’t divide seats between clerks. R5. Seat can appear to be free although being

booked by another clerk. Strange note? How does this fit with R1?

Inconsistent with textbook solution!

Inconsistent with textbook solution!

Page 2: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

range Seats = 1..2range Clerks = 1..2

CLERK = (request[i:Seats]->{cancel,{s[i]}.reserve}->CLERK|s[i:Seats].release->CLERK).

SEAT = (reserve->release->SEAT).

||BOOKING = (c[j:Clerks]::s[i:Seats]:SEAT || c[j:Clerks]:CLERK).

Megen solution

?

I kind of like it. A clerk has a lock on a seat until he releases it. Cleaner than textbook? You can judge in a minute.

Requirements inconsistencies: !R1: clerk does not *always* show current seat states. !R2: client chooses but may not get seat/ticket: kind of put on queue. And can lock up system waiting for cancel.

?

Page 3: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const M = 5 //number of seatsrange P = 1..M //seat numbersconst N = 3 //number of terminalsrange T = 1..N //terminal numbers

SEAT = (book -> BOOKED),BOOKED = (na -> BOOKED). //na = not available

||SEATS = ([x:P]:SEAT)\{[x:P].na}. //hide the na's

TERMINAL = (book[P] -> TERMINAL).

||TERMINALS = ([x:T]:TERMINAL).

||TERM_SEATS = (TERMINALS||SEATS)/{[y:T].book[x:P]/[x].book}\{[y:T].book[x:P].[x:P]}.

||CINEMA = (TERM_SEATS). //deadlocks when all of the seats are booked

Daniel/Anthony solution

Page 4: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const M = 5 //number of seatsrange P = 1..M //seat numbersconst N = 3 //number of terminalsrange T = 1..N //terminal numbers

SEAT = (book -> BOOKED),BOOKED = (na -> BOOKED). //na = not available

||SEATS = ([x:P]:SEAT)\{[x:P].na}. //hide the na's

TERMINAL = (book[P] -> TERMINAL).

||TERMINALS = ([x:T]:TERMINAL).

||TERM_SEATS = (TERMINALS||SEATS)/{[y:T].book[x:P]/[x].book}\{[y:T].book[x:P].[x:P]}.

||CINEMA = (TERM_SEATS). //deadlocks when all of the seats are booked

Daniel/Anthony solutionRequirements inconsistencies: None that I can see R1-R4. R5. At abstraction level where it’s instantaneous?

Page 5: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const N = 4range T = 0..N //Modeled for five seats

set VarAlpha = {value.{read[T],write[T], acquire[T],release[T]}

}

SEAT = (read[u:T]->SEAT | write[v:T]->SEAT).

LOCK = (acquire[w:T]->release[w]->LOCK).||LOCKSEAT = (LOCK || SEAT).

TERMINAL = (go -> RUN),RUN = (chooses -> BOOK |close -> TERMINAL),BOOK = (value.acquire[x:T] -> value.read[x] -> value.write[x] -> value.release[x] -> RUN )+VarAlpha.

||GARDEN = (east:TERMINAL || west:TERMINAL || north:TERMINAL || south:TERMINAL || {east,west,north,south}::value:LOCKSEAT) /{go /{east,west,north,south}.go}.

Raihan solution

Page 6: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

SEAT = (read[u:T]->SEAT | write[v:T]->SEAT).

LOCK = (acquire[w:T]->release[w]->LOCK).||LOCKSEAT = (LOCK || SEAT).

TERMINAL = (go -> RUN),RUN = (chooses -> BOOK |close -> TERMINAL),BOOK = (value.acquire[x:T] -> value.read[x] -> value.write[x] -> value.release[x] -> RUN )+VarAlpha.

||GARDEN = (east:TERMINAL || west:TERMINAL || north:TERMINAL || south:TERMINAL || {east,west,north,south}::value:LOCKSEAT) /{go /{east,west,north,south}.go}.

Raihan solutionRequirements inconsistencies: !R1. does not show status. !R2. Don’t get ticket for seat. !R3. Can double book I believe. R5. Supports this. In general, has no memory of what tickets have been sold? Need SEAT[u:T]?

Page 7: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const SeatNumber = 3range Seats = 1..SeatNumberset Terminals = {t1,t2}

// If the concert starts, we allow dropins// A TAKEN seat can be released, a person can sit down or the concert can start// If a person sits down, they can leave anytime, but the seat will not become free until the concert ends (SEATED).// If the concert starts, we allow for late-comers that already have a ticket (STARTED)// If a person drops in, he/she cannot release his/her ticket. Therefore, "book" goes directly to STARTED.SEAT = FREE,FREE = ( book->TAKEN

| concertStarts->DROPIN| concertEnds->FREE),

TAKEN = ( release->FREE| sit -> SEATED| concertStarts->STARTED),

SEATED = ( concertEnds->FREE),

STARTED = ( sit->SEATED| concertEnds->FREE),

DROPIN = ( book->STARTED| concertEnds->FREE)\{sit}.

CONCERT = ( concertStarts->concertEnds->CONCERT | cancel->CONCERT)\{cancel}. //Why this?

TERMINAL = (book->TERMINAL).

||BOOKING = (CONCERT || Terminals:TERMINAL || Terminals::s[Seats]:SEAT)/{concertStarts/Terminals.s[Seats].concertStarts,concertEnds/Terminals.s[Seats].concertEnds,Terminals.s[Seats].book/Terminals.book}.

// A note: The concert can start without anyone reserving a seat. I don't know if this is normal practice.// Maybe the orchestra can use it as a rehearsal if there is no one to watch them :-)// Another note: If a ticket is booked at terminal 1, it can still be release at e.g. terminal 2.

David solution

Page 8: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

SEAT = FREE,FREE = ( book->TAKEN

| concertStarts->DROPIN| concertEnds->FREE),

TAKEN = ( release->FREE| sit -> SEATED| concertStarts->STARTED),

SEATED = ( concertEnds->FREE),

STARTED = ( sit->SEATED| concertEnds->FREE),

DROPIN = ( book->STARTED| concertEnds->FREE)\{sit}.

CONCERT = ( concertStarts->concertEnds->CONCERT | cancel->CONCERT)\{cancel}.

TERMINAL = (book->TERMINAL).

||BOOKING = (CONCERT || Terminals:TERMINAL || Terminals::s[Seats]:SEAT)/{concertStarts/Terminals.s[Seats].concertStarts,concertEnds/Terminals.s[Seats].concertEnds,Terminals.s[Seats].book/Terminals.book}.

David solutionRequirements inconsistencies: R1-R4 ok. !R5. Obvious given R1 != R5 and R1 is true. Nice that either can release.

Page 9: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

range Bool = 0..1 const False = 0 const True = 1 const N = 3 range T = 1..N

SEAT = SEAT[True], SEAT[x:Bool] = ( check[x] -> SEAT[x]

|book -> SEAT[False] |when (x==False) book -> ERROR ).

||SEATS = (seat[T]:SEAT). LOCK = (acquire -> release -> LOCK).

TERMINAL = (choose[s:T] -> acquire -> seat[s].check[x:Bool] -> if (x==True)

then (seat[s].book -> release -> ticket -> TERMINAL) else (release -> TERMINAL)).

||RESERVATION = (a:TERMINAL || b:TERMINAL || {a,b}::SEATS || {a,b}::LOCK).

Fan solution

Page 10: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const N = 3 range T = 1..N

SEAT = SEAT[True], SEAT[x:Bool] = ( check[x] -> SEAT[x]

|book -> SEAT[False] |when (x==False) book -> ERROR ).

||SEATS = (seat[T]:SEAT). LOCK = (acquire -> release -> LOCK).

TERMINAL = (choose[s:T] -> acquire -> seat[s].check[x:Bool] -> if (x==True)

then (seat[s].book -> release -> ticket -> TERMINAL) else (release -> TERMINAL)).

||RESERVATION = (a:TERMINAL || b:TERMINAL || {a,b}::SEATS || {a,b}::LOCK).

Fan solutionRequirements inconsistencies: !R1. Shows seats that are not available. !R2. Can choose seat and not get ticket. R5. Does support this (anti-R1). System locks while in booking phase.

Page 11: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const False = 0const True = 1range Bool = False..True

SEAT = SEAT[False],SEAT[reserved:Bool] = ( reserve -> SEAT[True] | query[reserved] -> SEAT[reserved] | when (reserved) reserve -> ERROR //error if reserved twice ).

range Seats = 0..1||SEATS = (seat[Seats]:SEAT).

LOCK = (acquire -> release -> LOCK).

BROKENLOCK = ({acquire,release}->BROKENLOCK).

TERMINAL = (choose[s:Seats] -> acquire -> seat[s].query[reserved:Bool] -> if (!reserved) then (seat[s].reserve -> release-> TERMINAL) else (release -> TERMINAL) ).

set Terminals = {a,b}||CONCERT = (Terminals:TERMINAL || Terminals::SEATS || Terminals::LOCK).

Textbook solution Requirements inconsistencies: !R1: clerk does not show current seat states. Always shows all seats as choosable. !R2: client chooses but may not get seat/ticket. Frustrating!

Page 12: Requirements from EX 4.3  R1. Clerk can display the current state of reservations on screen.  R2. To book, client chooses a free seat and then gets a.

const False = 0const True = 1range Bool = False..True

SEAT = SEAT[False],SEAT[reserved:Bool] = ( reserve -> SEAT[True] | query[reserved] -> SEAT[reserved] | when (reserved) reserve -> ERROR //error if reserved twice ).

range Seats = 0..1||SEATS = (seat[Seats]:SEAT).

LOCK = (acquire -> release -> LOCK).

BROKENLOCK = ({acquire,release}->BROKENLOCK).

TERMINAL = (choose[s:Seats] -> acquire -> seat[s].query[reserved:Bool] -> if (!reserved) then (seat[s].reserve -> release-> TERMINAL) else (release -> TERMINAL) ).

set Terminals = {a,b}||CONCERT = (Terminals:TERMINAL || Terminals::SEATS || Terminals::LOCK).

/* use this system to demonstrate how lack of mutual exclusion leads to double reservation*/

||UNSAFECONCERT = (Terminals:TERMINAL || Terminals::SEATS || Terminals::BROKENLOCK).

Textbook solution – broken lock


Recommended