use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class StudentSwapSectioning method gp.
/**
* Student group percentage of a solution subset
*/
public static double gp(TimetableModel model, Collection<Lecture> variables) {
if (model.getStudentGroups().isEmpty())
return 0.0;
double ret = 0;
int count = 0;
for (StudentGroup group : model.getStudentGroups()) {
Map<Long, Match> match = new HashMap<Long, Match>();
Set<Long> offeringIds = new HashSet<Long>();
for (Student student : group.getStudents()) for (Lecture lecture : student.getLectures()) {
if (variables != null && !variables.contains(lecture))
continue;
offeringIds.add(lecture.getConfiguration().getOfferingId());
Match m = match.get(lecture.getSchedulingSubpartId());
if (m == null) {
m = new Match(group, lecture.getConfiguration());
match.put(lecture.getSchedulingSubpartId(), m);
}
m.inc(lecture);
}
if (match.isEmpty())
continue;
double value = 0.0;
for (Match m : match.values()) value += m.value();
ret += value / offeringIds.size();
count++;
}
return 100.0 * ret / count;
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class StudentSwapSectioning method studentsToLectures.
@Override
protected Group[] studentsToLectures(Long offeringId, Collection<Student> students, Collection<Lecture> lectures) {
if (hasStudentGroups(students)) {
Set<Lecture> sortedLectures = new TreeSet<Lecture>(new Comparator<Lecture>() {
@Override
public int compare(Lecture l1, Lecture l2) {
return l1.getClassId().compareTo(l2.getClassId());
}
});
sortedLectures.addAll(lectures);
GroupBasedInitialSectioning sect = new GroupBasedInitialSectioning(getProgress(), offeringId, sortedLectures, students);
return sect.getGroups();
} else {
return super.studentsToLectures(offeringId, students, lectures);
}
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class TimeSwap method resolve.
@Override
public Double resolve(Solution<Lecture, Placement> solution, double total, long startTime, Map<Lecture, Placement> assignments, List<Placement> conflicts, int index) {
Assignment<Lecture, Placement> assignment = solution.getAssignment();
if (index == conflicts.size())
return solution.getModel().getTotalValue(assignment) - total;
Placement conflict = conflicts.get(index);
Lecture variable = conflict.variable();
List<TimeLocation> values = variable.timeLocations();
if (values.isEmpty())
return null;
int valIdx = ToolBox.random(values.size());
int attempts = 0;
for (int i = 0; i < values.size(); i++) {
TimeLocation time = values.get((i + valIdx) % values.size());
if (time.getPreference() > 50)
continue;
if (time.equals(conflict.getTimeLocation()))
continue;
Placement value = null;
if (variable.getNrRooms() == 0)
value = new Placement(variable, time, (RoomLocation) null);
else if (variable.getNrRooms() == 1)
value = new Placement(variable, time, conflict.getRoomLocation());
else
value = new Placement(variable, time, conflict.getRoomLocations());
if (!value.isValid() || solution.getModel().inConflict(assignment, value))
continue;
assignment.assign(solution.getIteration(), value);
Double v = resolve(solution, total, startTime, assignments, conflicts, 1 + index);
assignment.unassign(solution.getIteration(), variable);
attempts++;
if (v != null && (!iHC || v <= 0)) {
assignments.put(variable, value);
return v;
}
if (attempts >= iMaxAttempts || isTimeLimitReached(startTime))
break;
}
return null;
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method decEnrollment.
/**
* Decrement enrollment of all classes of the given classes
*/
private void decEnrollment(SctStudent student, SctEnrollment enrollment, Map<Long, Double> limits, Map<Long, Map<Long, Match>> matches) {
for (Lecture lecture : enrollment.getLectures()) incEnrollment(lecture, limits, -student.getOfferingWeight());
for (StudentGroup group : student.getStudent().getGroups()) {
Map<Long, Match> match = matches.get(group.getId());
if (match == null) {
match = new HashMap<Long, Match>();
matches.put(group.getId(), match);
}
for (Lecture lecture : enrollment.getLectures()) {
Match m = match.get(lecture.getSchedulingSubpartId());
if (m == null) {
m = new Match(group, lecture);
match.put(lecture.getSchedulingSubpartId(), m);
}
m.dec(lecture);
}
}
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class StudentSwap method initMove.
/**
* Compute student move and its validity
*/
private boolean initMove(Assignment<Lecture, Placement> assignment, Collection<Lecture> lectures) {
double w = 0.0;
iFirstLectures = new HashSet<Lecture>();
iSecondLectures = new HashSet<Lecture>();
for (Lecture lecture : lectures) {
if (lecture.getConfiguration() == null)
return false;
if (!iFirstStudent.getLectures().contains(lecture)) {
if (iSecondConfig == null) {
iSecondConfig = lecture.getConfiguration();
w = iFirstStudent.getOfferingWeight(iSecondConfig);
}
iSecondLectures.add(lecture);
if (lecture.nrWeightedStudents() + w > sEps + lecture.classLimit(assignment))
return false;
}
}
if (iSecondLectures.isEmpty())
return false;
iFirstLectures = new HashSet<Lecture>();
for (Lecture lecture : iFirstStudent.getLectures()) {
if (lecture.getConfiguration() == null)
return false;
if (lecture.getConfiguration().getOfferingId().equals(iSecondConfig.getOfferingId()) && !lectures.contains(lecture)) {
iFirstLectures.add(lecture);
if (iFirstConfig == null) {
iFirstConfig = lecture.getConfiguration();
}
if (lecture.getClassLimitConstraint() != null && lecture.nrWeightedStudents() < sEps + lecture.minClassLimit())
return false;
}
}
if (iFirstLectures.isEmpty())
return false;
return true;
}
Aggregations