Search in sources :

Example 36 with Lecture

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);
        }
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) StudentGroup(org.cpsolver.coursett.model.StudentGroup)

Example 37 with 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);
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Set(java.util.Set) HashSet(java.util.HashSet) Configuration(org.cpsolver.coursett.model.Configuration)

Example 38 with Lecture

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;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 39 with 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(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);
        }
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture)

Example 40 with 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;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) RoomLocation(org.cpsolver.coursett.model.RoomLocation)

Aggregations

Lecture (org.cpsolver.coursett.model.Lecture)96 Placement (org.cpsolver.coursett.model.Placement)55 HashSet (java.util.HashSet)35 TimetableModel (org.cpsolver.coursett.model.TimetableModel)17 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)17 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)14 TimeLocation (org.cpsolver.coursett.model.TimeLocation)14 Constraint (org.cpsolver.ifs.model.Constraint)14 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)13 Student (org.cpsolver.coursett.model.Student)13 BitSet (java.util.BitSet)11 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)10 GlobalConstraint (org.cpsolver.ifs.model.GlobalConstraint)9 RoomLocation (org.cpsolver.coursett.model.RoomLocation)8 Set (java.util.Set)7 TreeSet (java.util.TreeSet)7 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)7 StudentGroup (org.cpsolver.coursett.model.StudentGroup)7 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)6