Search in sources :

Example 31 with Lecture

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

Example 32 with Lecture

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

Example 33 with Lecture

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

Example 34 with Lecture

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

Example 35 with Lecture

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

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