use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.
the class InstructorFairness method getValue.
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
double ret = 0.0;
InstructorFairnessContext context = (InstructorFairnessContext) getContext(assignment);
if (context.allInstructorsAssigned(assignment) && !value.variable().getInstructorConstraints().isEmpty()) {
List<InstructorConstraint> insConstraints = value.variable().getInstructorConstraints();
ret = (context.getDiffInstrValue(insConstraints, context.fairnessDouble(assignment, value))) / insConstraints.size();
if (conflicts != null) {
for (Placement conflict : conflicts) {
if (!conflict.variable().getInstructorConstraints().isEmpty()) {
List<InstructorConstraint> insConstraints2 = conflict.variable().getInstructorConstraints();
ret -= (context.getDiffInstrValue(insConstraints2, context.fairnessDouble(assignment, conflict))) / insConstraints2.size();
}
}
}
}
return ret;
}
use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.
the class UniversalPerturbationsCounter method getInfo.
public void getInfo(Assignment<Lecture, Placement> assignment, TimetableModel model, Map<String, String> info, List<Lecture> variables) {
if (variables == null)
super.getInfo(assignment, model, info);
else
super.getInfo(assignment, model, info, variables);
if (!iMPP)
return;
int perts = 0;
long affectedStudents = 0;
int affectedInstructors = 0;
long affectedStudentsByTime = 0;
int affectedInstructorsByTime = 0;
long affectedStudentsByRoom = 0;
int affectedInstructorsByRoom = 0;
long affectedStudentsByBldg = 0;
int affectedInstructorsByBldg = 0;
int differentRoom = 0;
int differentBuilding = 0;
int differentTime = 0;
int differentDay = 0;
int differentHour = 0;
int tooFarForInstructors = 0;
int tooFarForStudents = 0;
int deltaStudentConflicts = 0;
int newStudentConflicts = 0;
double deltaTimePreferences = 0;
int deltaRoomPreferences = 0;
int deltaInstructorDistancePreferences = 0;
for (Lecture lecture : (variables == null ? model.perturbVariables(assignment) : model.perturbVariables(assignment, variables))) {
if (assignment.getValue(lecture) == null || lecture.getInitialAssignment() == null || assignment.getValue(lecture).equals(lecture.getInitialAssignment()))
continue;
perts++;
Placement assignedPlacement = assignment.getValue(lecture);
Placement initialPlacement = lecture.getInitialAssignment();
affectedStudents += lecture.classLimit(assignment);
affectedInstructors += lecture.getInstructorConstraints().size();
int nrDiff = initialPlacement.nrDifferentRooms(assignedPlacement);
differentRoom += nrDiff;
affectedInstructorsByRoom += nrDiff * lecture.getInstructorConstraints().size();
affectedStudentsByRoom += nrDiff * lecture.classLimit(assignment);
nrDiff = initialPlacement.nrDifferentBuildings(assignedPlacement);
differentBuilding += nrDiff;
affectedInstructorsByBldg += nrDiff * lecture.getInstructorConstraints().size();
affectedStudentsByBldg += nrDiff * lecture.classLimit(assignment);
deltaRoomPreferences += assignedPlacement.sumRoomPreference() - initialPlacement.sumRoomPreference();
if (!initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
differentTime++;
affectedInstructorsByTime += lecture.getInstructorConstraints().size();
affectedStudentsByTime += lecture.classLimit(assignment);
}
if (initialPlacement.getTimeLocation().getDayCode() != assignedPlacement.getTimeLocation().getDayCode())
differentDay++;
if (initialPlacement.getTimeLocation().getStartSlot() != assignedPlacement.getTimeLocation().getStartSlot())
differentHour++;
if (!initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
double distance = Placement.getDistanceInMeters(iDistanceMetric, initialPlacement, assignedPlacement);
if (!lecture.getInstructorConstraints().isEmpty()) {
if (distance > iDistanceMetric.getInstructorNoPreferenceLimit() && distance <= iDistanceMetric.getInstructorDiscouragedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelDiscouraged * lecture.getInstructorConstraints().size();
} else if (distance > iDistanceMetric.getInstructorDiscouragedLimit() && distance <= iDistanceMetric.getInstructorProhibitedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelStronglyDiscouraged * lecture.getInstructorConstraints().size();
} else if (distance > iDistanceMetric.getInstructorProhibitedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelProhibited * lecture.getInstructorConstraints().size();
}
}
if (distance > iDistanceMetric.minutes2meters(10))
tooFarForStudents += lecture.classLimit(assignment);
}
deltaStudentConflicts += lecture.countStudentConflicts(assignment, assignedPlacement) - lecture.countInitialStudentConflicts();
Set<Student> newStudentConflictsSet = lecture.conflictStudents(assignment, assignedPlacement);
Set<Student> initialStudentConflicts = lecture.initialStudentConflicts();
for (Iterator<Student> e1 = newStudentConflictsSet.iterator(); e1.hasNext(); ) if (!initialStudentConflicts.contains(e1.next()))
newStudentConflicts++;
deltaTimePreferences += assignedPlacement.getTimeLocation().getNormalizedPreference() - initialPlacement.getTimeLocation().getNormalizedPreference();
for (InstructorConstraint ic : lecture.getInstructorConstraints()) {
for (Lecture lect : ic.variables()) {
if (lect.equals(lecture))
continue;
int initialPreference = (lect.getInitialAssignment() == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(initialPlacement, lect.getInitialAssignment()));
int assignedPreference = (assignedPlacement == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(assignedPlacement, assignedPlacement));
deltaInstructorDistancePreferences += assignedPreference - initialPreference;
}
}
}
if (perts != 0)
info.put("Perturbations: Different placement", String.valueOf(perts) + " (weighted " + sDoubleFormat.format(iDifferentPlacement * perts) + ")");
if (affectedStudents != 0)
info.put("Perturbations: Number of affected students", String.valueOf(affectedStudents) + " (weighted " + sDoubleFormat.format(iAffectedStudentWeight * affectedStudents) + ")");
if (affectedInstructors != 0)
info.put("Perturbations: Number of affected instructors", String.valueOf(affectedInstructors) + " (weighted " + sDoubleFormat.format(iAffectedInstructorWeight * affectedInstructors) + ")");
if (affectedStudentsByTime != 0)
info.put("Perturbations: Number of affected students [time]", String.valueOf(affectedStudentsByTime) + " (weighted " + sDoubleFormat.format(iAffectedStudentByTimeWeight * affectedStudentsByTime) + ")");
if (affectedInstructorsByTime != 0)
info.put("Perturbations: Number of affected instructors [time]", String.valueOf(affectedInstructorsByTime) + " (weighted " + sDoubleFormat.format(iAffectedInstructorByTimeWeight * affectedInstructorsByTime) + ")");
if (affectedStudentsByRoom != 0)
info.put("Perturbations: Number of affected students [room]", String.valueOf(affectedStudentsByRoom) + " (weighted " + sDoubleFormat.format(iAffectedStudentByRoomWeight * affectedStudentsByRoom) + ")");
if (affectedInstructorsByRoom != 0)
info.put("Perturbations: Number of affected instructors [room]", String.valueOf(affectedInstructorsByRoom) + " (weighted " + sDoubleFormat.format(iAffectedInstructorByRoomWeight * affectedInstructorsByRoom) + ")");
if (affectedStudentsByBldg != 0)
info.put("Perturbations: Number of affected students [bldg]", String.valueOf(affectedStudentsByBldg) + " (weighted " + sDoubleFormat.format(iAffectedStudentByBldgWeight * affectedStudentsByBldg) + ")");
if (affectedInstructorsByBldg != 0)
info.put("Perturbations: Number of affected instructors [bldg]", String.valueOf(affectedInstructorsByBldg) + " (weighted " + sDoubleFormat.format(iAffectedInstructorByBldgWeight * affectedInstructorsByBldg) + ")");
if (differentRoom != 0)
info.put("Perturbations: Different room", String.valueOf(differentRoom) + " (weighted " + sDoubleFormat.format(iDifferentRoomWeight * differentRoom) + ")");
if (differentBuilding != 0)
info.put("Perturbations: Different building", String.valueOf(differentBuilding) + " (weighted " + sDoubleFormat.format(iDifferentBuildingWeight * differentBuilding) + ")");
if (differentTime != 0)
info.put("Perturbations: Different time", String.valueOf(differentTime) + " (weighted " + sDoubleFormat.format(iDifferentTimeWeight * differentTime) + ")");
if (differentDay != 0)
info.put("Perturbations: Different day", String.valueOf(differentDay) + " (weighted " + sDoubleFormat.format(iDifferentDayWeight * differentDay) + ")");
if (differentHour != 0)
info.put("Perturbations: Different hour", String.valueOf(differentHour) + " (weighted " + sDoubleFormat.format(iDifferentHourWeight * differentHour) + ")");
if (tooFarForInstructors != 0)
info.put("Perturbations: New placement too far from initial [instructors]", String.valueOf(tooFarForInstructors) + " (weighted " + sDoubleFormat.format(iTooFarForInstructorsWeight * tooFarForInstructors) + ")");
if (tooFarForStudents != 0)
info.put("Perturbations: New placement too far from initial [students]", String.valueOf(tooFarForStudents) + " (weighted " + sDoubleFormat.format(iTooFarForStudentsWeight * tooFarForStudents) + ")");
if (deltaStudentConflicts != 0)
info.put("Perturbations: Delta student conflicts", String.valueOf(deltaStudentConflicts) + " (weighted " + sDoubleFormat.format(iDeltaStudentConflictsWeight * deltaStudentConflicts) + ")");
if (newStudentConflicts != 0)
info.put("Perturbations: New student conflicts", String.valueOf(newStudentConflicts) + " (weighted " + sDoubleFormat.format(iNewStudentConflictsWeight * newStudentConflicts) + ")");
if (deltaTimePreferences != 0)
info.put("Perturbations: Delta time preferences", String.valueOf(deltaTimePreferences) + " (weighted " + sDoubleFormat.format(iDeltaTimePreferenceWeight * deltaTimePreferences) + ")");
if (deltaRoomPreferences != 0)
info.put("Perturbations: Delta room preferences", String.valueOf(deltaRoomPreferences) + " (weighted " + sDoubleFormat.format(iDeltaRoomPreferenceWeight * deltaRoomPreferences) + ")");
if (deltaInstructorDistancePreferences != 0)
info.put("Perturbations: Delta instructor distance preferences", String.valueOf(deltaInstructorDistancePreferences) + " (weighted " + sDoubleFormat.format(iDeltaInstructorDistancePreferenceWeight * deltaInstructorDistancePreferences) + ")");
}
use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.
the class UniversalPerturbationsCounter method getCompactInfo.
public Map<String, Double> getCompactInfo(Assignment<Lecture, Placement> assignment, TimetableModel model, boolean includeZero, boolean weighted) {
Map<String, Double> info = new HashMap<String, Double>();
if (!iMPP)
return info;
int perts = 0;
long affectedStudents = 0;
int affectedInstructors = 0;
long affectedStudentsByTime = 0;
int affectedInstructorsByTime = 0;
long affectedStudentsByRoom = 0;
int affectedInstructorsByRoom = 0;
long affectedStudentsByBldg = 0;
int affectedInstructorsByBldg = 0;
int differentRoom = 0;
int differentBuilding = 0;
int differentTime = 0;
int differentDay = 0;
int differentHour = 0;
int tooFarForInstructors = 0;
int tooFarForStudents = 0;
int deltaStudentConflicts = 0;
int newStudentConflicts = 0;
double deltaTimePreferences = 0;
int deltaRoomPreferences = 0;
int deltaInstructorDistancePreferences = 0;
for (Lecture lecture : model.perturbVariables(assignment)) {
if (assignment.getValue(lecture) == null || lecture.getInitialAssignment() == null || assignment.getValue(lecture).equals(lecture.getInitialAssignment()))
continue;
perts++;
Placement assignedPlacement = assignment.getValue(lecture);
Placement initialPlacement = lecture.getInitialAssignment();
affectedStudents += lecture.classLimit(assignment);
affectedInstructors += lecture.getInstructorConstraints().size();
int nrDiff = initialPlacement.nrDifferentRooms(assignedPlacement);
differentRoom += nrDiff;
affectedInstructorsByRoom += nrDiff * lecture.getInstructorConstraints().size();
affectedStudentsByRoom += nrDiff * lecture.classLimit(assignment);
nrDiff = initialPlacement.nrDifferentBuildings(initialPlacement);
differentBuilding += nrDiff;
affectedInstructorsByBldg += nrDiff * lecture.getInstructorConstraints().size();
affectedStudentsByBldg += nrDiff * lecture.classLimit(assignment);
deltaRoomPreferences += assignedPlacement.sumRoomPreference() - initialPlacement.sumRoomPreference();
if (!initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
differentTime++;
affectedInstructorsByTime += lecture.getInstructorConstraints().size();
affectedStudentsByTime += lecture.classLimit(assignment);
}
if (initialPlacement.getTimeLocation().getDayCode() != assignedPlacement.getTimeLocation().getDayCode())
differentDay++;
if (initialPlacement.getTimeLocation().getStartSlot() != assignedPlacement.getTimeLocation().getStartSlot())
differentHour++;
if (!initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
double distance = Placement.getDistanceInMeters(iDistanceMetric, initialPlacement, assignedPlacement);
if (!lecture.getInstructorConstraints().isEmpty()) {
if (distance > iDistanceMetric.getInstructorNoPreferenceLimit() && distance <= iDistanceMetric.getInstructorDiscouragedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelDiscouraged;
} else if (distance > iDistanceMetric.getInstructorDiscouragedLimit() && distance <= iDistanceMetric.getInstructorProhibitedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelStronglyDiscouraged;
} else if (distance > iDistanceMetric.getInstructorProhibitedLimit()) {
tooFarForInstructors += Constants.sPreferenceLevelProhibited;
}
}
if (distance > iDistanceMetric.minutes2meters(10))
tooFarForStudents += lecture.classLimit(assignment);
}
deltaStudentConflicts += lecture.countStudentConflicts(assignment, assignedPlacement) - lecture.countInitialStudentConflicts();
Set<Student> newStudentConflictsSet = lecture.conflictStudents(assignment, assignedPlacement);
Set<Student> initialStudentConflicts = lecture.initialStudentConflicts();
for (Iterator<Student> e1 = newStudentConflictsSet.iterator(); e1.hasNext(); ) if (!initialStudentConflicts.contains(e1.next()))
newStudentConflicts++;
deltaTimePreferences += assignedPlacement.getTimeLocation().getNormalizedPreference() - initialPlacement.getTimeLocation().getNormalizedPreference();
for (InstructorConstraint ic : lecture.getInstructorConstraints()) {
if (ic != null)
for (Lecture lect : ic.variables()) {
if (lect.equals(lecture))
continue;
int initialPreference = (lect.getInitialAssignment() == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(initialPlacement, lect.getInitialAssignment()));
int assignedPreference = (assignedPlacement == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(assignedPlacement, assignedPlacement));
deltaInstructorDistancePreferences += assignedPreference - initialPreference;
}
}
}
if (includeZero || iDifferentPlacement != 0.0)
info.put("Different placement", Double.valueOf(weighted ? iDifferentPlacement * perts : perts));
if (includeZero || iAffectedStudentWeight != 0.0)
info.put("Affected students", Double.valueOf(weighted ? iAffectedStudentWeight * affectedStudents : affectedStudents));
if (includeZero || iAffectedInstructorWeight != 0.0)
info.put("Affected instructors", Double.valueOf(weighted ? iAffectedInstructorWeight * affectedInstructors : affectedInstructors));
if (includeZero || iAffectedStudentByTimeWeight != 0.0)
info.put("Affected students [time]", Double.valueOf(weighted ? iAffectedStudentByTimeWeight * affectedStudentsByTime : affectedStudentsByTime));
if (includeZero || iAffectedInstructorByTimeWeight != 0.0)
info.put("Affected instructors [time]", Double.valueOf(weighted ? iAffectedInstructorByTimeWeight * affectedInstructorsByTime : affectedInstructorsByTime));
if (includeZero || iAffectedStudentByRoomWeight != 0.0)
info.put("Affected students [room]", Double.valueOf(weighted ? iAffectedStudentByRoomWeight * affectedStudentsByRoom : affectedStudentsByRoom));
if (includeZero || iAffectedInstructorByRoomWeight != 0.0)
info.put("Affected instructors [room]", Double.valueOf(weighted ? iAffectedInstructorByRoomWeight * affectedInstructorsByRoom : affectedInstructorsByRoom));
if (includeZero || iAffectedStudentByBldgWeight != 0.0)
info.put("Affected students [bldg]", Double.valueOf(weighted ? iAffectedStudentByBldgWeight * affectedStudentsByBldg : affectedStudentsByBldg));
if (includeZero || iAffectedInstructorByBldgWeight != 0.0)
info.put("Affected instructors [bldg]", Double.valueOf(weighted ? iAffectedInstructorByBldgWeight * affectedInstructorsByBldg : affectedInstructorsByBldg));
if (includeZero || iDifferentRoomWeight != 0.0)
info.put("Different room", Double.valueOf(weighted ? iDifferentRoomWeight * differentRoom : differentRoom));
if (includeZero || iDifferentBuildingWeight != 0.0)
info.put("Different building", Double.valueOf(weighted ? iDifferentBuildingWeight * differentBuilding : differentBuilding));
if (includeZero || iDifferentTimeWeight != 0.0)
info.put("Different time", Double.valueOf(weighted ? iDifferentTimeWeight * differentTime : differentTime));
if (includeZero || iDifferentDayWeight != 0.0)
info.put("Different day", Double.valueOf(weighted ? iDifferentDayWeight * differentDay : differentDay));
if (includeZero || iDifferentHourWeight != 0.0)
info.put("Different hour", Double.valueOf(weighted ? iDifferentHourWeight * differentHour : differentHour));
if (includeZero || iTooFarForInstructorsWeight != 0.0)
info.put("New placement too far for initial [instructors]", Double.valueOf(weighted ? iTooFarForInstructorsWeight * tooFarForInstructors : tooFarForInstructors));
if (includeZero || iTooFarForStudentsWeight != 0.0)
info.put("New placement too far for initial [students]", Double.valueOf(weighted ? iTooFarForStudentsWeight * tooFarForStudents : tooFarForStudents));
if (includeZero || iDeltaStudentConflictsWeight != 0.0)
info.put("Delta student conflicts", Double.valueOf(weighted ? iDeltaStudentConflictsWeight * deltaStudentConflicts : deltaStudentConflicts));
if (includeZero || iNewStudentConflictsWeight != 0.0)
info.put("New student conflicts", Double.valueOf(weighted ? iNewStudentConflictsWeight * newStudentConflicts : newStudentConflicts));
if (includeZero || iDeltaTimePreferenceWeight != 0.0)
info.put("Delta time preferences", Double.valueOf(weighted ? iDeltaTimePreferenceWeight * deltaTimePreferences : deltaTimePreferences));
if (includeZero || iDeltaRoomPreferenceWeight != 0.0)
info.put("Delta room preferences", Double.valueOf(weighted ? iDeltaRoomPreferenceWeight * deltaRoomPreferences : deltaRoomPreferences));
if (includeZero || iDeltaInstructorDistancePreferenceWeight != 0.0)
info.put("Delta instructor distance preferences", Double.valueOf(weighted ? iDeltaInstructorDistancePreferenceWeight * deltaInstructorDistancePreferences : deltaInstructorDistancePreferences));
return info;
}
use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.
the class BackToBackInstructorPreferences method getBounds.
@Override
public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
double[] bounds = new double[] { 0.0, 0.0 };
Set<InstructorConstraint> constraints = new HashSet<InstructorConstraint>();
for (Lecture lect : variables) {
for (InstructorConstraint ic : lect.getInstructorConstraints()) {
if (!constraints.add(ic))
continue;
bounds[1] += ic.getWorstPreference();
}
}
return bounds;
}
use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.
the class BackToBackInstructorPreferences method getValue.
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
double ret = 0;
Set<InstructorConstraint> constraints = new HashSet<InstructorConstraint>();
for (Lecture lect : variables) {
for (InstructorConstraint ic : lect.getInstructorConstraints()) {
if (!constraints.add(ic))
continue;
ret += ic.getPreference(assignment);
}
}
return ret;
}
Aggregations