(* This file defines objects and operation related to constraints. See Section 2.6.2 of the requirements. Module Constraints defines the objects and operations related to scheduling constraints. *) module Constraints; from Time import TimePeriod; from Database import all; export all; object ConstraintsList is components: pres: Preferred*; description: (*This object is a collection of the preferred constraints*); end ConstraintsList; object OverlapConstraint inherits from Absolute components: NonOverlapSpec*; description: (*The overlap constraint indicates to the scheduler if there are two courses scheduled in the same classroom at the same time. The scheduler checks the list of NonOverlapSpecs for two of the same course patterns. If this happens, the scheduler will prevent that course from being scheduled.*); end OverlapConstraint; object NonOverlapSpec is components: CoursePattern and CoursePattern; description: (*Two course patterns are used to make sure they are not conflicting with eachother.*); end NonOverlapSpec; object CoursePattern is components: string and string; description: (*The course patterns are represented by Strings, which describe the classroom and time of a course.*); end CoursePattern; object Absolute description: (*Absolute constraints are fulfilled first and foremost before preferred constraints when generating a schedule.*); end Absolute; object Preferred components: pr:Priority; description: (*Preferred constraints do not necessarily have to be met when generating a schedule. They are prioritized in order. The higher priority constraints will try to be fulfilled by the scheduler as long as they do not conflict with absolute constraints. *); end Preferred; object Distance inherits from Preferred components: Meters; description: (*The distance constraint is a preferred constraint that contains how many meters the constraint is set at, which indicates to the scheduler how many meters away to schedule the next class*); end Distance; object Meters is integer; object TimeConstraint inherits from Preferred components: p:PreferenceLevel; description: (*The time constraint object is a time period with a preference of 0-10.*); end TimeConstraint; object PreferenceLevel is integer; object TimeConstraints components: TimeConstraint*; description: (*The time constraints is a list of all the TimeConstraint objects that are preferred to have.*); end TimeConstraints; object Priority is integer description: (* The integer in the priority object tells the scheduler the order of priority in the constraints. A lower priority will be scheduled first when generating a schedule.*); end Priority; operation SetTimeConstraints is inputs: tc:TimeConstraint*; outputs: tc':TimeConstraints; description: (* This operation takes the time periods and their corresponding time preferences entered and lists them as a collection of TimeConstraints*); precondition: (*the time constraints are not nil and the time constraints preferences must be between 0 and 10*) (forall (i:integer | (i >= 1) and (i < #tc)) (tc[i] != nil) and (tc'[i].p >= 0) and (tc'[i].p <= 10)); postcondition:(*All of the TimeConstraint objects are in the TimeConstraints object. The oder of the items is highest preference to lowest.*) (forall (i:integer | (i >= 1) and (i < #tc)) (tc'[i].p >= tc'[i+1].p)); end SetTimeConstraints; object CourseConstraint inherits from Preferred components: p:PreferenceLevel; description: (*The course constraint object is a course name with a preference of 0-10.*); end CourseConstraint; object CourseConstraints is components: CourseConstraint*; description: (*The course constraints object is a list of all the CourseConstraint objects that have a preference greater than 0*); end CourseConstraints; operation SetCourseConstraints is inputs: cc:CourseConstraint*; outputs: cc':CourseConstraints; description: (* This operation takes the course names and their corresponding course preferences entered and lists them as a collection of CourseConstraints*); precondition: (*The CourseConstraints have a preference greater than zero and not more than 10 and the CourseConstraints object is not nil.*) (forall (i:integer | (i >= 1) and (i < #cc)) (cc[i] != nil) and (cc[i].p > 0) and (cc[i].p <= 10)); postcondition:(*All of the CourseConstraint objects are in the CourseConstraints object. The oder of the items is highest preference to lowest.*) (forall (i:integer | (i >= 1) and (i < #cc)) (cc'[i].p >= cc'[i+1].p)); end SetCourseConstraints; operation SetPriorities is inputs: cl:ConstraintsList; outputs: cl':ConstraintsList; description: (* This operation adds the constraints to a list and orders the constraints in the oder of priority from lowest first to highest last*); precondition: (*None*); postcondition:(*integer value of priorities are in numerical order*) (forall (i:integer | (i >= 1) and (i < #cl')) (cl'.pres[i].pr < cl'.pres[i+1].pr)); end SetPriorities; end Constraints;