use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctModel method incEnrollment.
/**
* Increment enrollment of all classes of the given classes
*/
private void incEnrollment(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.inc(lecture);
}
}
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctStudent method computeEnrollments.
/**
* Compute all possible enrollments
*/
private void computeEnrollments() {
iEnrollments = new ArrayList<SctEnrollment>();
if (isInstructing()) {
double conflictWeight = 0.0;
for (Lecture lecture : getInstructingLectures()) {
for (Lecture other : getStudent().getLectures()) if (!getModel().getOfferingId().equals(other.getConfiguration().getOfferingId()))
conflictWeight += getJenrConflictWeight(lecture, other);
}
iEnrollments.add(new SctEnrollment(0, this, getInstructingLectures(), conflictWeight));
return;
}
for (Configuration configuration : getModel().getConfigurations()) {
Map<Long, Set<Lecture>> subparts = getModel().getSubparts(configuration);
List<Long> subpartIds = getSubpartIds(configuration);
computeEnrollments(configuration, subparts, subpartIds, new HashSet<Lecture>(), 0.0);
}
Collections.sort(iEnrollments);
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctStudent method getSubpartIds.
/**
* All scheduling subpart ids of a configuration.
*/
private List<Long> getSubpartIds(Configuration configuration) {
List<Long> subpartIds = new ArrayList<Long>();
Queue<Lecture> queue = new LinkedList<Lecture>();
for (Map.Entry<Long, Set<Lecture>> e : configuration.getTopLectures().entrySet()) {
subpartIds.add(e.getKey());
queue.add(e.getValue().iterator().next());
}
Lecture lecture = null;
while ((lecture = queue.poll()) != null) {
if (lecture.getChildren() != null)
for (Map.Entry<Long, List<Lecture>> e : lecture.getChildren().entrySet()) {
subpartIds.add(e.getKey());
queue.add(e.getValue().iterator().next());
}
}
return subpartIds;
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class SctStudent method computeEnrollments.
/**
* Compute all possible enrollments
*/
private void computeEnrollments(Configuration configuration, Map<Long, Set<Lecture>> subparts, List<Long> subpartIds, Set<Lecture> enrollment, double conflictWeight) {
if (enrollment.size() == subpartIds.size()) {
iEnrollments.add(new SctEnrollment(iEnrollments.size(), this, enrollment, conflictWeight));
iTotalEnrollmentWeight += conflictWeight;
} else {
Set<Lecture> lectures = subparts.get(subpartIds.get(enrollment.size()));
for (Lecture lecture : lectures) {
if (lecture.getParent() != null && !enrollment.contains(lecture.getParent()))
continue;
if (!getStudent().canEnroll(lecture))
continue;
double delta = 0.0;
for (Lecture other : getStudent().getLectures()) if (!configuration.getOfferingId().equals(other.getConfiguration().getOfferingId()))
delta += getJenrConflictWeight(lecture, other);
for (Lecture other : enrollment) delta += getJenrConflictWeight(lecture, other);
enrollment.add(lecture);
computeEnrollments(configuration, subparts, subpartIds, enrollment, conflictWeight + delta);
enrollment.remove(lecture);
}
}
}
use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.
the class RoomSwap 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();
if (conflict.getNrRooms() != 1)
return null;
List<RoomLocation> values = variable.roomLocations();
if (values.isEmpty())
return null;
int valIdx = ToolBox.random(values.size());
int attempts = 0;
for (int i = 0; i < values.size(); i++) {
RoomLocation room = values.get((i + valIdx) % values.size());
if (room.getPreference() > 50)
continue;
if (room.equals(conflict.getRoomLocation()))
continue;
Placement value = new Placement(variable, conflict.getTimeLocation(), room);
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;
}
Aggregations