160 likes | 176 Views
A system for registering students at a university. Only registered students are considered legal. Each student has a unique ID. Students with the same major and registered at the same university are regarded as classmates.
E N D
RigorousSoftwareEngineering Assignment3 (exercise2,3.3,3.5)
Exercise2 abstractsigStudent{} sigGraduateextendsStudent{} sigUndergraduateextendsStudent{} sigID{} sigMajor{} sigUniversity{}
abstractsigStudent{ id:oneID, major:oneMajor, university:loneUniversity, isLegal:Bool, classmates:setStudent, }
Descriptions Descriptions Astudentshouldregisteratauniversity,andonlyregisteredstudentsarelegalstudents. EverystudenthasauniquestudentID. Alloy Alloy factlegal_in_university{ alls:Student|(s.university!=none)iff(s.isLegal=True) } factunique_ids{ alldisjs,t:Student|s.id!=t.id } factno_id_without_student{ alli:ID|ones:Student|s.id=i }
Descriptions Studentswiththesamemajorwhoareregisteredatthesameuniversityareregardedasclassmates. Graduatesandundergraduatesareneverclassmates. Alloy factclassmates_have_same_major_and_uni{ alldisjs,t:Student|(s.major=t.majorands.university=t.university and(sinUndergraduateandtinUndergraduateorsinGraduateandtinGraduate) iff(sint.classmates) }
Descriptions Descriptions Theclassmaterelationisnotreflexive(astudentcannotbehis/herownclassmate). Visualizethemodelfor2Universities,3Majors,3Studentsand3IDs. Alloy Alloy factno_self_classmate{ alls:Student|snotins.classmates } predshow{} runshowfor2University,3Major,3Student,3ID
Exercise3.3DorisDay’ssong “Everybody loves my baby but my baby don’t love nobody but me” David Gries has pointed out that, from a strictly logical point of view, this implies ‘I am my baby’. Everybodylovesmybaby(b) assert song { all p: Person| my_baby[p] implies Me = p } predmy_baby[b: Person] { (all p: Person | b inp.loves) and b.loves = Me } Mybabydon’tlovenobodybutme
Exercise3.3DorisDay’ssong “Everybody loves my baby but my baby don’t love nobody but me” David Gries has pointed out that, from a strictly logical point of view, this implies ‘I am my baby’. assert song { all p: Person| my_baby[p] implies Me = p } predmy_baby[b: Person] { (all p: Person | b inp.loves) and b.loves = Me } +b
Exercise3.5ModelingtheTube Station: the set of all stations JubileeStation, CentralStation, CircleStation: for each line, a subset of Station jubliee, central, circle: binary relations relating stations on each line to one another if they are directly connected sig Station {} sigJubileeStationin Station { jubilee: set JubileeStation } sigCentralStationin Station { central: set CentralStation } sigCircleStationin Station { circle: set CircleStation }
Exercise3.5ModelingtheTube Stanmore, BakerStreet, Epping:singleton subsets of Station for individual stations one sig Stanmore, BakerStreet, Epping extends Station {}
Exercise3.5ModelingtheTube (a)Namedstationsareonexactlythelinesasshowningraphic Centralline Jubileeline Circleline Stanmore in (JubileeStation - CentralStation) - CircleStation BakerStreetin (JubileeStation & CircleStation) - CentralStation Epping in (CentralStation - JubileeStation) - CircleStation
Exercise3.5ModelingtheTube (b)Nostation(includingthoseunnamed)isonallthreelines Centralline Jubileeline Circleline no (JubileeStation & CentralStation & CircleStation)
Exercise3.5ModelingtheTube (c)TheCirclelineformsacircle Centralline Jubileeline Circleline ^circle:(s1,s2),(s1,s3),…,(s1,sn),…,(sn-1,sn) all s: CircleStation { ones.circle CircleStationins.^circle } Everystationhasone“next”station,includingthe“last”station. Allstationsthatcanbereachedstartingfroms
Exercise3.5ModelingtheTube (d)JubileeisastraightlinestartingatStanmore Centralline Jubileeline Circleline Stanmoreisthestartingstation,otherstationinJubileecanbereachedfromStanmore JubileeStationin Stanmore.*jubilee all s: JubileeStation { lones.jubilee s not in s.^jubilee } Everystationhasoneorzero“next”station Allstationsthatcanbereachedstartingfroms
Exercise3.5ModelingtheTube (e)there’sastationbetweenStanmoreandBakerStreet Centralline Jubileeline Circleline All(A,B)tuplesthatonecantravelfromAtoBonJubilee let reach = ^jubilee | someStanmore.reach & reach.BakerStreet AllstationsthatcanreachBakerStreet AllstationsthatcanbereachedstartingfromStanmore
Exercise3.5ModelingtheTube (f)ItispossibletotravelfromBakerStreettoEpping Centralline Jubileeline Circleline Epping inBakerStreet.^(jubilee + central + circle) All(A,B)tuplesthatonecantravelfromAtoB AllstationsthatcanbereachedstartingfromBakerStreet