Search in sources :

Example 81 with Lecture

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;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) HashMap(java.util.HashMap) Student(org.cpsolver.coursett.model.Student) JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) StudentGroup(org.cpsolver.coursett.model.StudentGroup) HashSet(java.util.HashSet)

Example 82 with Lecture

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);
    }
}
Also used : GroupBasedInitialSectioning(org.cpsolver.coursett.sectioning.SctSectioning.GroupBasedInitialSectioning) Lecture(org.cpsolver.coursett.model.Lecture) TreeSet(java.util.TreeSet)

Example 83 with Lecture

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

Example 84 with Lecture

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

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

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