public class Exam extends Variable<Exam,ExamPlacement>
ExamPeriod
that is long
enough (see ExamPeriod.getLength()
) and that is available for the
exam (see getPeriodPlacements()
). ExamRoom.isAvailable(ExamPeriod)
,
ExamRoomPlacement.isAvailable(ExamPeriod)
), and which together cover
the size of exam (number of students attending the exam) has to be assigned
to an exam. Based on the type of seating (see hasAltSeating()
),
either room sizes (see ExamRoom.getSize()
) or alternative seating
sizes (see ExamRoom.getAltSize()
) are used. An exam has a list of
available rooms with their penalties assiciated with (see
getRoomPlacements()
). ExamPlacement
for more details. Modifier and Type | Field and Description |
---|---|
protected static DecimalFormat |
sDoubleFormat |
Constructor and Description |
---|
Exam(long id,
String name,
int length,
boolean altSeating,
int maxRooms,
int minSize,
List<ExamPeriodPlacement> periodPlacements,
List<ExamRoomPlacement> roomPlacements)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addContstraint(Constraint<Exam,ExamPlacement> constraint)
Adds a constraint.
|
void |
allowAllStudentConflicts(Assignment<Exam,ExamPlacement> assignment,
ExamPeriod period)
Allow all direct student conflict for the given period (see
ExamStudent.canConflict(Exam, Exam) ). |
boolean |
checkDistributionConstraints(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period)
Check all distribution constraint that this exam is involved in
|
boolean |
checkDistributionConstraints(Assignment<Exam,ExamPlacement> assignment,
ExamRoomPlacement room)
Check all distribution constraint that this exam is involved in
|
int |
compareTo(Exam o)
An exam with more correlated exams is preferred (
nrStudentCorrelatedExams() ). |
int |
countInstructorConflicts(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period)
Number of instructor of this exam (that does not have direct conflicts
allowed, see
ExamInstructor.canConflict(Exam, Exam) ) that attend
some other exam in the given period. |
int |
countStudentConflicts(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period)
Number of students of this exam (that does not have direct conflicts
allowed, see
ExamStudent.canConflict(Exam, Exam) ) that attend
some other exam in the given period. |
Set<ExamRoomPlacement> |
findBestAvailableRooms(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period)
Find best available rooms for the exam in the given period.
|
Set<ExamRoomPlacement> |
findRoomsRandom(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period)
Randomly find a set of available rooms for the exam in the given period.
|
Set<ExamRoomPlacement> |
findRoomsRandom(Assignment<Exam,ExamPlacement> assignment,
ExamPeriodPlacement period,
boolean checkConflicts)
Randomly find a set of available rooms for the exam in the given period.
|
int |
getAveragePeriod()
Average period.
|
int |
getDistributionConstraintPenalty(Assignment<Exam,ExamPlacement> assignment,
ExamRoomPlacement room)
Check all soft distribution constraint that this exam is involved in
|
List<ExamDistributionConstraint> |
getDistributionConstraints()
List of distribution constraints that this exam is involved in
|
List<ExamInstructor> |
getInstructors()
List of instructors that are assigned to this exam
|
Map<Exam,List<ExamStudent>> |
getJointEnrollments()
Joint enrollments
|
int |
getLength()
Length of the exam in minutes.
|
int |
getMaxRooms()
Maximal number of rooms that can be assigned to the exam
|
int |
getMinSize()
Minimal exam size, see
getSize() |
String |
getName()
Exam name
|
List<ExamOwner> |
getOwners()
Courses and/or sections that are having this exam
|
Collection<ExamOwner> |
getOwners(ExamInstructor instructor)
Courses/sections of this exam into which the given instructor is enrolled
into
|
Collection<ExamOwner> |
getOwners(ExamStudent student)
Courses/sections of this exam into which the given student is enrolled
into
|
ExamPeriodPlacement |
getPeriodPlacement(ExamPeriod period)
Returns appropriate
ExamPeriodPlacement for the given period, if
it is available for this exam, null otherwise. |
ExamPeriodPlacement |
getPeriodPlacement(Long periodId)
Returns appropriate
ExamPeriodPlacement for the given period, if
it is available for this exam, null otherwise. |
List<ExamPeriodPlacement> |
getPeriodPlacements()
Return list of possible period placements.
|
List<ExamRoomPlacement> |
getPreferredRoomPlacements()
Return list of possible room placements that are strongly preferred.
|
Integer |
getPrintOffset()
Print offset -- for reporting purposes
|
ExamRoomPlacement |
getRoomPlacement(ExamRoom room)
Returns appropriate
ExamRoomPlacement for the given room, if it
is available for this exam, null otherwise. |
ExamRoomPlacement |
getRoomPlacement(long roomId)
Returns appropriate
ExamRoomPlacement for the given room, if it
is available for this exam, null otherwise. |
List<ExamRoomPlacement> |
getRoomPlacements()
Return list of possible room placements.
|
int |
getSize()
Exam size, it is bigger from
getMinSize() and the number of
students enrolled into the exam getStudents() . |
Integer |
getSizeOverride()
Override exam size with given value (revert to default when null)
|
HashSet<Exam> |
getStudentConflicts(Assignment<Exam,ExamPlacement> assignment,
ExamPeriod period)
List of exams that are assigned to the given period and share one or more
students with this exam (that does not have direct conflicts allowed, see
ExamStudent.canConflict(Exam, Exam) ). |
Set<Exam> |
getStudentCorrelatedExams()
Exams that are correlated with this exam (there is at least one
student attending both exams).
|
List<ExamStudent> |
getStudents()
List of students that are enrolled in the exam
|
boolean |
hasAltSeating()
True if alternative seating is required (
ExamRoom.getAltSize() is
to be used), false if normal seating is required (
ExamRoom.getSize() is to be used). |
boolean |
hasAveragePeriod()
True if there is an average period assigned to the exam.
|
boolean |
hasName()
Exam name
|
boolean |
hasStudentConflictWithPreAssigned(Assignment<Exam,ExamPlacement> assignment,
ExamPeriod period)
True, if there is a student of this exam (that does not have direct
conflicts allowed, see
ExamStudent.canConflict(Exam, Exam) ) that
attends some other exam in the given period. |
boolean |
hasValues()
Return true if there are some values in the domain of this variable
|
boolean |
isAllowDirectConflicts()
True if a direct student conflict is allowed, see
ExamStudent.canConflict(Exam, Exam) |
int |
nrStudentCorrelatedExams()
Number of exams that are correlated with this exam (there is at least one
student attending both exams).
|
void |
removeContstraint(Constraint<Exam,ExamPlacement> constraint)
Removes a constraint.
|
void |
setAllowDirectConflicts(boolean allowDirectConflicts)
Set whether a direct student conflict is allowed, see
ExamStudent.canConflict(Exam, Exam) |
void |
setAveragePeriod(int period)
Set average period.
|
void |
setMaxRooms(int maxRooms)
Set maximal number of rooms that can be assigned to the exam
|
void |
setMinSize(int minSize)
Minimal exam size, see
getSize() |
void |
setName(String name)
Exam name
|
void |
setPrintOffset(Integer printOffset)
Print offset -- for reporting purposes
|
void |
setSizeOverride(Integer size)
Override exam size with given value (revert to default when null)
|
String |
toString()
String representation
|
List<ExamPlacement> |
values(Assignment<Exam,ExamPlacement> assignment)
Values (assignment of a period and a set of rooms)
|
void |
variableAssigned(Assignment<Exam,ExamPlacement> assignment,
long iteration,
ExamPlacement placement)
A value was assigned to this variable
|
addVariableListener, assign, constraints, constraintVariables, equals, getAssignment, getAssignment, getAssignments, getBestAssignment, getBestAssignmentIteration, getDescription, getExtra, getId, getIndex, getInitialAssignment, getLastIteration, getModel, getVariableListeners, hardConstraints, hasAssignment, hasAssignment, hashCode, hasInitialAssignment, removeInitialValue, removeValue, removeVariableListener, setAssignment, setBestAssignment, setExtra, setIndex, setInitialAssignment, setLastIteration, setModel, setValues, softConstraints, unassign, values, variableUnassigned
protected static DecimalFormat sDoubleFormat
public Exam(long id, String name, int length, boolean altSeating, int maxRooms, int minSize, List<ExamPeriodPlacement> periodPlacements, List<ExamRoomPlacement> roomPlacements)
id
- exam unique idname
- exam namelength
- exam length in minutesaltSeating
- true if alternative seating is requestedmaxRooms
- maximum number of rooms to be usedminSize
- minimal size of rooms into which an exam can be assigned (see
getSize()
)periodPlacements
- list of periods and their penalties
ExamPeriodPlacement
into which an exam can be assignedroomPlacements
- list of rooms and their penalties ExamRoomPlacement
into which an exam can be assignedpublic int getSize()
getMinSize()
and the number of
students enrolled into the exam getStudents()
. If
getMaxRooms()
is greater than zero, an exam must be assigned
into rooms which overall size (or alternative seating size if
hasAltSeating()
) must be equal or greater than this size.public void setSizeOverride(Integer size)
size
- examination size overridepublic Integer getSizeOverride()
public Integer getPrintOffset()
public void setPrintOffset(Integer printOffset)
printOffset
- print offset in minutespublic int getMinSize()
getSize()
public void setMinSize(int minSize)
getSize()
minSize
- minimal examination sizepublic List<ExamPlacement> values(Assignment<Exam,ExamPlacement> assignment)
values
in class Variable<Exam,ExamPlacement>
assignment
- current assignment (if the domain is dependent on the current assignment)ExamPlacement
public List<ExamRoomPlacement> getRoomPlacements()
ExamRoomPlacement
public List<ExamRoomPlacement> getPreferredRoomPlacements()
ExamRoomPlacement
public List<ExamPeriodPlacement> getPeriodPlacements()
ExamPeriodPlacement
public boolean hasAltSeating()
ExamRoom.getAltSize()
is
to be used), false if normal seating is required (
ExamRoom.getSize()
is to be used).public int getLength()
public void setAveragePeriod(int period)
ExamRotationPenalty
in order to put more weight on
exams that were badly assigned last time(s) and ensuring some form of
fairness.period
- average periodpublic int getAveragePeriod()
ExamRotationPenalty
in order to put more weight on
exams that were badly assigned last time(s) and ensuring some form of
fairness.public boolean hasAveragePeriod()
ExamRotationPenalty
in order to put more weight on
exams that were badly assigned last time(s) and ensuring some form of
fairness.public boolean isAllowDirectConflicts()
ExamStudent.canConflict(Exam, Exam)
public void setAllowDirectConflicts(boolean allowDirectConflicts)
ExamStudent.canConflict(Exam, Exam)
allowDirectConflicts
- true if a direct student conflict is allowedpublic void addContstraint(Constraint<Exam,ExamPlacement> constraint)
Model.addConstraint(Constraint)
is called.addContstraint
in class Variable<Exam,ExamPlacement>
constraint
- added constraintpublic void removeContstraint(Constraint<Exam,ExamPlacement> constraint)
Model.removeConstraint(Constraint)
is
called.removeContstraint
in class Variable<Exam,ExamPlacement>
constraint
- added constraintpublic List<ExamStudent> getStudents()
ExamStudent
public List<ExamDistributionConstraint> getDistributionConstraints()
ExamDistributionConstraint
public List<ExamInstructor> getInstructors()
ExamInstructor
public boolean checkDistributionConstraints(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period)
assignment
- current assignmentperiod
- a period to be assigned to this exampublic boolean checkDistributionConstraints(Assignment<Exam,ExamPlacement> assignment, ExamRoomPlacement room)
assignment
- current assignmentroom
- a room to be assigned to this exampublic int getDistributionConstraintPenalty(Assignment<Exam,ExamPlacement> assignment, ExamRoomPlacement room)
assignment
- current assignmentroom
- a room to be assigned to this exampublic int getMaxRooms()
public void setMaxRooms(int maxRooms)
maxRooms
- maximal number of rooms that can be assigned to the exampublic Set<ExamRoomPlacement> findBestAvailableRooms(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period)
assignment
- current assignmentperiod
- given period.public Set<ExamRoomPlacement> findRoomsRandom(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period)
assignment
- current assignmentperiod
- given period.public Set<ExamRoomPlacement> findRoomsRandom(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period, boolean checkConflicts)
assignment
- current assignmentperiod
- given period.checkConflicts
- if false, room and distribution conflicts are not checkedpublic int nrStudentCorrelatedExams()
public Set<Exam> getStudentCorrelatedExams()
public int compareTo(Exam o)
nrStudentCorrelatedExams()
). If it is the same, ratio number
of students / number of available periods is used. If the same, exam ids
are used.compareTo
in interface Comparable<Exam>
compareTo
in class Variable<Exam,ExamPlacement>
public boolean hasStudentConflictWithPreAssigned(Assignment<Exam,ExamPlacement> assignment, ExamPeriod period)
ExamStudent.canConflict(Exam, Exam)
) that
attends some other exam in the given period.assignment
- current assignmentperiod
- a periodpublic int countStudentConflicts(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period)
ExamStudent.canConflict(Exam, Exam)
) that attend
some other exam in the given period.assignment
- current assignmentperiod
- a periodpublic int countInstructorConflicts(Assignment<Exam,ExamPlacement> assignment, ExamPeriodPlacement period)
ExamInstructor.canConflict(Exam, Exam)
) that attend
some other exam in the given period.assignment
- current assignmentperiod
- a periodpublic HashSet<Exam> getStudentConflicts(Assignment<Exam,ExamPlacement> assignment, ExamPeriod period)
ExamStudent.canConflict(Exam, Exam)
).assignment
- current assignmentperiod
- a periodExam
(other than this exam, that are placed in
the given period and create prohibited direct conflicts)public void allowAllStudentConflicts(Assignment<Exam,ExamPlacement> assignment, ExamPeriod period)
ExamStudent.canConflict(Exam, Exam)
).assignment
- current assignmentperiod
- a periodpublic String toString()
toString
in class Variable<Exam,ExamPlacement>
public String getName()
getName
in class Variable<Exam,ExamPlacement>
public boolean hasName()
public Map<Exam,List<ExamStudent>> getJointEnrollments()
public List<ExamOwner> getOwners()
ExamOwner
public Collection<ExamOwner> getOwners(ExamStudent student)
student
- a student that is enrolled into this examExamOwner
which are having this
exam with the given student enrolled inpublic Collection<ExamOwner> getOwners(ExamInstructor instructor)
instructor
- an instructor that is enrolled into this examExamOwner
which are having this
exam with the given instructor enrolled inpublic ExamPeriodPlacement getPeriodPlacement(Long periodId)
ExamPeriodPlacement
for the given period, if
it is available for this exam, null otherwise.periodId
- period unique idpublic ExamRoomPlacement getRoomPlacement(long roomId)
ExamRoomPlacement
for the given room, if it
is available for this exam, null otherwise.roomId
- room unique idpublic ExamPeriodPlacement getPeriodPlacement(ExamPeriod period)
ExamPeriodPlacement
for the given period, if
it is available for this exam, null otherwise.period
- period in questionpublic ExamRoomPlacement getRoomPlacement(ExamRoom room)
ExamRoomPlacement
for the given room, if it
is available for this exam, null otherwise.room
- room in questionpublic boolean hasValues()
hasValues
in class Variable<Exam,ExamPlacement>
public void variableAssigned(Assignment<Exam,ExamPlacement> assignment, long iteration, ExamPlacement placement)
Variable
variableAssigned
in class Variable<Exam,ExamPlacement>
assignment
- current assignmentiteration
- current iterationplacement
- assigned value