use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class JenrlConstraint method computeConflicts.
@Override
public void computeConflicts(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
if (!getContext(assignment).isOverLimit() || value.variable().isCommitted())
return;
Lecture other = another(value.variable());
if (other == null)
return;
Placement otherPlacement = assignment.getValue(other);
if (otherPlacement != null && !other.isCommitted() && isInConflict(value, otherPlacement, getDistanceMetric()))
conflicts.add(otherPlacement);
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method assign.
/**
* Assign given solution
*/
public void assign(SctSolution solution) {
for (int index = 0; index < iStudents.size(); index++) {
SctStudent student = iStudents.get(index);
Configuration configuration = null;
SctEnrollment enrollment = solution.iEnrollments[index];
if (enrollment == null)
continue;
for (Lecture lecture : enrollment.getLectures()) {
if (configuration == null)
configuration = lecture.getConfiguration();
for (Lecture other : student.getStudent().getLectures()) incJenrl(getAssignment(), student.getStudent(), lecture, other);
lecture.addStudent(getAssignment(), student.getStudent());
student.getStudent().addLecture(lecture);
}
if (configuration != null)
student.getStudent().addConfiguration(configuration);
}
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method setConfiguration.
/**
* Select an offering for the model
*/
public void setConfiguration(Configuration config) {
iConfigurations = new ArrayList<Configuration>();
iConfigurations.add(config);
iOfferingId = config.getOfferingId();
if (config.getAltConfigurations() != null)
for (Configuration alt : config.getAltConfigurations()) if (!alt.equals(config))
iConfigurations.add(alt);
iStudents = new ArrayList<SctStudent>();
Set<Long> studentIds = new HashSet<Long>();
for (Configuration c : iConfigurations) for (Lecture l : c.getTopLectures(c.getTopSubpartIds().iterator().next())) {
for (Student s : l.students()) {
if (studentIds.add(s.getId()))
iStudents.add(new SctStudent(this, s));
}
}
for (Student student : getTimetableModel().getAllStudents()) if (student.hasOffering(getOfferingId()))
if (studentIds.add(student.getId()))
iStudents.add(new SctStudent(this, student));
Collections.sort(iStudents);
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method group.
/**
* Group weight of the given enrollments
*/
private double group(SctEnrollment[] enrollments) {
Map<Long, Map<Long, Match>> matches = new HashMap<Long, Map<Long, Match>>();
for (SctEnrollment enrollment : enrollments) {
if (enrollment == null)
continue;
for (StudentGroup group : enrollment.getStudent().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.getConfiguration());
match.put(lecture.getSchedulingSubpartId(), m);
}
m.inc(lecture);
}
}
}
double ret = 0.0;
for (Map<Long, Match> match : matches.values()) {
for (Match m : match.values()) ret += m.value();
}
return ret;
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method getSubparts.
/**
* List of scheduling subparts and their classes of the given configuration
*/
public Map<Long, Set<Lecture>> getSubparts(Configuration configuration) {
Map<Long, Set<Lecture>> subparts = iSubparts.get(configuration.getConfigId());
if (subparts == null) {
subparts = new HashMap<Long, Set<Lecture>>();
Queue<Lecture> queue = new LinkedList<Lecture>();
for (Map.Entry<Long, Set<Lecture>> e : configuration.getTopLectures().entrySet()) {
subparts.put(e.getKey(), e.getValue());
queue.addAll(e.getValue());
}
Lecture lecture = null;
while ((lecture = queue.poll()) != null) {
if (lecture.getChildren() != null)
for (Map.Entry<Long, List<Lecture>> e : lecture.getChildren().entrySet()) {
Set<Lecture> lectures = subparts.get(e.getKey());
if (lectures == null) {
lectures = new HashSet<Lecture>(e.getValue());
subparts.put(e.getKey(), lectures);
} else {
lectures.addAll(e.getValue());
}
queue.addAll(e.getValue());
}
}
iSubparts.put(configuration.getConfigId(), subparts);
}
return subparts;
}
Aggregations