5.2. Schedule.rsl

module ScheduleModule;

from InstructorModule import InstructorDB;
from RoomModule import RoomDB;
from RoomModule import Room;
from RoomModule import Capacity;
from CourseModule import CourseDB;
from CourseModule import Course;

export Schedule;
export Section;

object Schedule is
   components: secs:Section*;
   operations: AddSection, ChangeSection, DeleteSection, FindSection, CreateSchedule;
   description : (*
      ViewSchedule contains a list of all the section being offered that 
      particular term.
   *);
end Schedule;

object Section is
   components: crs:ScheduleCourse and size:SectionSize and 
   prof:SectionInstructor and time:SectionTime and rm:SectionRoom 
   and com:Comments;
   description: (*
      Section contains all the things necessary for a section to be successful.
      The Identifier is the CourseId and SectionId.  Size is maximum number of 
      students allowed in the section.  Instructor is the name of the instructor 
      teaching this section.  Time is the days, begin and start time of the 
      section.  and room is where the section is meeting.
   *);
end Section;

object ScheduleCourse inherits from Course
   components: id:Identifier;
      description: (*
         Individual id for each section. 
      *);
end ScheduleCourse;

object Identifier is
   components: cid:CourseID and sid:SectionID;
   description: (* 
      Identifier is a two part object that identifies a unique Section.
   *);
end Identifier;

object CourseID is 
   components: did:DepartmentID and cnum:CourseNumber;
   description: (*
      This is a unique identifier of a Course (i.e. CPE 203, ART 112),
      Restriction - must corispond to a course in the current database.
   *);
end CourseID;

object SectionID is
   components: snum:SectionNumber and sabv:SectionDiscriptor;
   description: (*
      SectionID is a two digits number followed by a three character descriptor.
      Restriction - must corrispond to the information in the course database
      regarding section types.
   *);
end SectionID;

object SectionSize is integer
   description: (*
      Restriction - must be <= the size of the room that corrisponds to the 
      RoomNumber of that same section;
   *);
end SectionSize;

object SectionInstructor is
   components: last:InstrLastName and init:InstrFirstInit;
   description: (*
      SectionInstructor is the last name and first initial of the instructor
      teaching this section.
   *);
end SetionInstructor;   

object SectionTime is 
   components: days:Days and btime:BeginTime and etime:EndTime;
   description: (*
      SectionTime is the days of the week that the section meet on as well as
      the starting time and the ending time of the section on those days.
   *);
end SectionTime;

object SectionRoom inherits from Room
   components: num:RoomNumber;
      description: (*
         Individual room number for each Room.
      *);
end SectionRoom;

object RoomNumber is
   components: bid:BuildingID and rid:RoomID;
   description: (*
      SectionRoom is a two digit building number followed by a three charactor 
      string (usually digits) representing the room number wher the section will
      be held.
   *);
end RoomNumber;

object Comments is components: string;
   description: (* 
      Free form string. 
   *);
end Comments;
  
object DepartmentID is components: string;
   description: (* 
      Three character Department discriptor 
   *);
end DepartmentID;

object CourseNumber is components: integer;
   description: (* 
      A three digit integer 
   *);
end CourseNumber;
   
object SectionNumber is components: integer;
   description: (* 
      A two digit integer 
   *);
end SectionNumber;

object SectionDiscriptor is components: LEC or SEM or LB1 or LB2 or AC1 
   or AC2 or REC or IND;
   description: (* 
      The eight different types of section. 
   *);
end SectionDiscriptor;

object LEC;   
object SEM;   
object LB1;   
object LB2;   
object AC1;   
object AC2;   
object REC;   
object IND;   

object InstrLastName is components: string;
   description: (* 
      String of no more then 30 characters 
   *);
end InstrLastName;

object InstrFirstInit is components: string;
   description: (* 
      One character string 
*);
end InstrFirstInit;

object Days is
   components: DayInitial*;
   description: (*
      Days is any combonation of one of more Days, when the section meets. 
   *);
end Days;

object DayInitial is 
   components: M or T or W or R or F or S or U;
   description: (*
      M = Monday, T = Tuesday, W = Wendesday, R = Thursday, F = Friday,
      S = Saturday, U = Sunday.
   *);
end DayInitial;
   
object M;   
object T;   
object W;   
object R;   
object F;  
object S;   
object U;   

object BeginTime is 
   components: Time;
   description: (*
      BeginTime is when the section meeting starts.
   *);
end BeginTime;

object EndTime is 
   components: Time;
   description: (*
      BeginTime is when the section meeting ends.
   *);
end EndTime;

object Time is
   components: Hour and Minute and Meridiem;
   description: (*
      Time is of the form hh:mm A/PM.
   *);
end Time;

object Hour is components: integer; 
   description: (* 
      An integer between 1 and 12 
   *);
end Hour;

object Minute is components: integer;
   description: (* 
      An integer between 1 and 60 
   *);
end Minute;

object Meridiem is 
   components: AM or PM;
   description: (*
      Meridiem is for Ante Meridiem  or Post Meridiem  US standard time notation.
   *);
end Meridiem;

object AM;   
object PM;  

object BuildingID is components: string;
   description: (* 
      Two character string 
   *);
end BuildingID;

object RoomID is components: string;
   description: (* 
      Three character string 
   *);
end RoomID;

operation AddSection is
   inputs: sdb:Schedule, sc:Section, cs:Course, cdb:CourseDB;
   outputs: sdb':Schedule, cdb':CourseDB;

   precondition: 
      (*
       * A CourseDB needs to be added to the inputs and the new section
       * must be in the CouseDB (crs in cdb)
       *)
      (cs in cdb)
   
         and

      (* 
       * There is no sec in the input Schedule with the same Identifier.
       *)
      (not (exists (sc' in sdb) sc'.crs.id = sc.crs.id))

         and

      (*
       * The Size is not empty and is not greater that 99.
       *)
      ((sc.size != nil) and (sc.size < 100));

    postcondition: 
      (*
       * A section is in the output sdb if and only if it is the new section
       * to be added or it is in the input Schedule
       *)
      forall (sc': Section)
         (sc' in sdb') iff ((sc' = sc) or (sc' in sdb));

end AddSection;

operation ChangeSection is
   inputs: sdb:Schedule, old_sc:Section, new_sc:Section;
   outputs: sdb':Schedule;

   precondition:
      (*
       * The old and new sections have the same Identifier and they 
       * are not the same.
       *)
      ((old_sc.crs.id = new_sc.crs.id) and (old_sc != new_sc))

         and

      (*
       * The old section is in the givin Schedule.
       *)
      (old_sc in sdb)

        and

      (*
       * The Size is not empty and is not greater that 99.
       *)
      ((new_sc.size != nil) and (new_sc.size < 100));

   postcondition:
      (*
       * A section is in the output Schedule if and only if is the new
       * section to be added or it is in the input Schedule, and it
       * is not the old section.
       *)
      forall (sc':Section)
         (sc' in sdb') iff (((sc' = new_sc) or (sc' in sdb)) and
         (sc' != old_sc));

end ChangeSection;

operation DeleteSection is
   inputs: sc:Section, sdb:Schedule;
   outputs: sdb':Schedule;

   precondition:
      (*
       * The given Section is in the given Schedule.
       *)
      sc in sdb;

   postcondition:
      (*
       * A section os in the output Schedule if and only if it is
       * not the record to be deleted and it is in the input Schedule.
       *)
      (forall (sc':Section)
         (sc' in sdb') iff ((sc' != sc) or (sc' in sdb)));

end DeleteSection;

operation FindSection is
   inputs: sdb:Schedule, n:SectionInstructor;
   outputs: secl:Section*;

   precondition: ;

   postcondition:
      (*
       * The output list consists of all sections taught by the givin
       * Instructor.
       *)
      (forall (sec' in secl) (sec' in sdb) and (sec'.prof = n))
 
         and

      (*
       * The output list is sorted by course Identifier.
       *)
      (forall (i:integer | (i >= 1) and (i < #secl))
         secl[i].crs.id < secl[i+1].crs.id);

   description: (*
      Find a section or sections by instructor name.  If more than one is found,
      the output list is sorted by section id.
   *);
end FindSection;

operation FindSection is
   inputs: sdb:Schedule, n:SectionRoom;
   outputs: secl:Section*;

   precondition: ;

   postcondition:
      (*
       * The output list consists of all sections taught in a givin
       * Room.
       *)
      (forall (room' in secl) (room' in sdb) and (room'.rm = n))
 
         and

      (*
       * The output list is sorted by course Identifier.
       *)
      (forall (i:integer | (i >= 1) and (i < #secl))
         secl[i].rm.num < secl[i+1].rm.num);

   description: (*
      Find a section or sections by Room number.  If more than one is found,
      the output list is sorted by room number.
   *);
end FindSection;

operation CreateSchedule is
   inputs: sdb:Schedule, idb:InstructorDB, cdb:CourseDB, rdb:RoomDB;
   outputs: sdb':Schedule;

   precondition: ;

   postcondition:
      (*
       * Basic Instuctor Constraints - An instructor can only be assigned to one 
       * section at a specific time
       *)
      (forall (i:integer | (i >= 1) and (i < #sdb))
         forall (j:integer | (j >= 1) and (j < #sdb))
            if (sdb.secs[i].prof = sdb.secs[j].prof)
            then sdb.secs[i].time != sdb.secs[j].time)
        
         and

      (*
       * Basic Room Constraints - A Room can only be assigned to one section
       * at a specific time
       *)
      (forall (i:integer | (i >= 1) and (i < #sdb))
         forall (j:integer | (j >= 1) and (j < #sdb))
            if (sdb.secs[i].rm = sdb.secs[j].rm)
            then sdb.secs[i].time != sdb.secs[j].time)
         
         and

      (*
       * Basic Room Constraints - Room size is at least as big as the section size 
       *)
      (forall (i:integer | (i >= 1) and (i < #sdb))
         (sdb.secs[i].size = sdb.secs[i].rm.capac))


      (*
       * Advanced Constriants - Instructor Course Preferences 
       *)

      (*
       * Advanced Constraints - Instructor Time Preferences 
       *);
end CreateSchedule;

end ScheduleModule;

Prev: Project.rsl | Next: InstructorListing.rsl | Up: Specification | Top: index