use of org.cpsolver.coursett.model.Placement in project cpsolver by UniTime.
the class SpreadConstraint method getAdept.
public Placement getAdept(Assignment<Lecture, Placement> assignment, Placement placement, int[][] nrCourses, Set<Placement> conflicts) {
Placement adept = null;
int improvement = 0;
// take uncommitted placements first
for (Lecture lect : variables()) {
if (lect.isCommitted())
continue;
Placement plac = assignment.getValue(lect);
if (plac == null || plac.equals(placement) || placement.variable().equals(plac.variable()) || conflicts.contains(plac))
continue;
int imp = getPenaltyIfUnassigned(assignment, plac, nrCourses);
if (imp == 0)
continue;
if (adept == null || imp > improvement) {
adept = plac;
improvement = imp;
}
}
if (adept != null)
return adept;
// no uncommitted placement found -- take committed one
for (Lecture lect : variables()) {
if (!lect.isCommitted())
continue;
Placement plac = assignment.getValue(lect);
if (plac == null || plac.equals(placement) || conflicts.contains(plac))
continue;
int imp = getPenaltyIfUnassigned(assignment, plac, nrCourses);
if (imp == 0)
continue;
if (adept == null || imp > improvement) {
adept = plac;
improvement = imp;
}
}
return adept;
}
use of org.cpsolver.coursett.model.Placement in project cpsolver by UniTime.
the class BrokenTimePatterns method getValue.
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
double ret = 0;
Set<RoomConstraint> constraints = new HashSet<RoomConstraint>();
for (Lecture lect : variables) {
Placement placement = assignment.getValue(lect);
if (placement == null)
continue;
if (placement.isMultiRoom()) {
for (RoomLocation r : placement.getRoomLocations()) {
if (r.getRoomConstraint() != null && constraints.add(r.getRoomConstraint()))
ret += penalty(r.getRoomConstraint().getContext(assignment));
}
} else if (placement.getRoomLocation().getRoomConstraint() != null && constraints.add(placement.getRoomLocation().getRoomConstraint())) {
ret += penalty(placement.getRoomLocation().getRoomConstraint().getContext(assignment));
}
}
return ret;
}
use of org.cpsolver.coursett.model.Placement in project cpsolver by UniTime.
the class FlexibleConstraintCriterion method getValue.
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
HashMap<Lecture, Placement> assignments = new HashMap<Lecture, Placement>();
assignments.put(value.variable(), value);
double ret = 0.0;
for (FlexibleConstraint gc : value.variable().getFlexibleGroupConstraints()) ret += gc.getCurrentPreference(assignment, conflicts, assignments);
assignments.put(value.variable(), null);
for (FlexibleConstraint gc : value.variable().getFlexibleGroupConstraints()) ret -= gc.getCurrentPreference(assignment, conflicts, assignments);
return ret;
}
use of org.cpsolver.coursett.model.Placement 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", new Double(weighted ? iDifferentPlacement * perts : perts));
if (includeZero || iAffectedStudentWeight != 0.0)
info.put("Affected students", new Double(weighted ? iAffectedStudentWeight * affectedStudents : affectedStudents));
if (includeZero || iAffectedInstructorWeight != 0.0)
info.put("Affected instructors", new Double(weighted ? iAffectedInstructorWeight * affectedInstructors : affectedInstructors));
if (includeZero || iAffectedStudentByTimeWeight != 0.0)
info.put("Affected students [time]", new Double(weighted ? iAffectedStudentByTimeWeight * affectedStudentsByTime : affectedStudentsByTime));
if (includeZero || iAffectedInstructorByTimeWeight != 0.0)
info.put("Affected instructors [time]", new Double(weighted ? iAffectedInstructorByTimeWeight * affectedInstructorsByTime : affectedInstructorsByTime));
if (includeZero || iAffectedStudentByRoomWeight != 0.0)
info.put("Affected students [room]", new Double(weighted ? iAffectedStudentByRoomWeight * affectedStudentsByRoom : affectedStudentsByRoom));
if (includeZero || iAffectedInstructorByRoomWeight != 0.0)
info.put("Affected instructors [room]", new Double(weighted ? iAffectedInstructorByRoomWeight * affectedInstructorsByRoom : affectedInstructorsByRoom));
if (includeZero || iAffectedStudentByBldgWeight != 0.0)
info.put("Affected students [bldg]", new Double(weighted ? iAffectedStudentByBldgWeight * affectedStudentsByBldg : affectedStudentsByBldg));
if (includeZero || iAffectedInstructorByBldgWeight != 0.0)
info.put("Affected instructors [bldg]", new Double(weighted ? iAffectedInstructorByBldgWeight * affectedInstructorsByBldg : affectedInstructorsByBldg));
if (includeZero || iDifferentRoomWeight != 0.0)
info.put("Different room", new Double(weighted ? iDifferentRoomWeight * differentRoom : differentRoom));
if (includeZero || iDifferentBuildingWeight != 0.0)
info.put("Different building", new Double(weighted ? iDifferentBuildingWeight * differentBuilding : differentBuilding));
if (includeZero || iDifferentTimeWeight != 0.0)
info.put("Different time", new Double(weighted ? iDifferentTimeWeight * differentTime : differentTime));
if (includeZero || iDifferentDayWeight != 0.0)
info.put("Different day", new Double(weighted ? iDifferentDayWeight * differentDay : differentDay));
if (includeZero || iDifferentHourWeight != 0.0)
info.put("Different hour", new Double(weighted ? iDifferentHourWeight * differentHour : differentHour));
if (includeZero || iTooFarForInstructorsWeight != 0.0)
info.put("New placement too far for initial [instructors]", new Double(weighted ? iTooFarForInstructorsWeight * tooFarForInstructors : tooFarForInstructors));
if (includeZero || iTooFarForStudentsWeight != 0.0)
info.put("New placement too far for initial [students]", new Double(weighted ? iTooFarForStudentsWeight * tooFarForStudents : tooFarForStudents));
if (includeZero || iDeltaStudentConflictsWeight != 0.0)
info.put("Delta student conflicts", new Double(weighted ? iDeltaStudentConflictsWeight * deltaStudentConflicts : deltaStudentConflicts));
if (includeZero || iNewStudentConflictsWeight != 0.0)
info.put("New student conflicts", new Double(weighted ? iNewStudentConflictsWeight * newStudentConflicts : newStudentConflicts));
if (includeZero || iDeltaTimePreferenceWeight != 0.0)
info.put("Delta time preferences", new Double(weighted ? iDeltaTimePreferenceWeight * deltaTimePreferences : deltaTimePreferences));
if (includeZero || iDeltaRoomPreferenceWeight != 0.0)
info.put("Delta room preferences", new Double(weighted ? iDeltaRoomPreferenceWeight * deltaRoomPreferences : deltaRoomPreferences));
if (includeZero || iDeltaInstructorDistancePreferenceWeight != 0.0)
info.put("Delta instructor distance preferences", new Double(weighted ? iDeltaInstructorDistancePreferenceWeight * deltaInstructorDistancePreferences : deltaInstructorDistancePreferences));
return info;
}
use of org.cpsolver.coursett.model.Placement 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) + ")");
}
Aggregations