Search in sources :

Example 26 with Lecture

use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.

the class InstructorConstraint method computeConflicts.

@Override
public void computeConflicts(Assignment<Lecture, Placement> assignment, Placement placement, Set<Placement> conflicts) {
    Lecture lecture = placement.variable();
    Placement current = assignment.getValue(lecture);
    BitSet weekCode = placement.getTimeLocation().getWeekCode();
    InstructorConstraintContext context = getContext(assignment);
    for (Enumeration<Integer> e = placement.getTimeLocation().getSlots(); e.hasMoreElements(); ) {
        int slot = e.nextElement();
        for (Placement p : context.getPlacements(slot)) {
            if (!p.equals(current) && p.getTimeLocation().shareWeeks(weekCode)) {
                if (p.canShareRooms(placement) && p.sameRooms(placement))
                    continue;
                conflicts.add(p);
            }
        }
    }
    if (!iIgnoreDistances) {
        for (Enumeration<Integer> e = placement.getTimeLocation().getStartSlots(); e.hasMoreElements(); ) {
            int startSlot = e.nextElement();
            int prevSlot = startSlot - 1;
            if (prevSlot >= 0 && (prevSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
                for (Placement c : context.getPlacements(prevSlot, placement)) {
                    if (lecture.equals(c.variable()))
                        continue;
                    if (c.canShareRooms(placement) && c.sameRooms(placement))
                        continue;
                    if (Placement.getDistanceInMeters(getDistanceMetric(), placement, c) > getDistanceMetric().getInstructorProhibitedLimit())
                        conflicts.add(c);
                }
            }
            int nextSlot = startSlot + placement.getTimeLocation().getLength();
            if ((nextSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
                for (Placement c : context.getPlacements(nextSlot, placement)) {
                    if (lecture.equals(c.variable()))
                        continue;
                    if (c.canShareRooms(placement) && c.sameRooms(placement))
                        continue;
                    if (Placement.getDistanceInMeters(getDistanceMetric(), placement, c) > getDistanceMetric().getInstructorProhibitedLimit())
                        conflicts.add(c);
                }
            }
            if (getDistanceMetric().doComputeDistanceConflictsBetweenNonBTBClasses()) {
                TimeLocation t1 = placement.getTimeLocation();
                for (Lecture other : variables()) {
                    Placement otherPlacement = assignment.getValue(other);
                    if (otherPlacement == null || other.equals(placement.variable()))
                        continue;
                    TimeLocation t2 = otherPlacement.getTimeLocation();
                    if (t1 == null || t2 == null || !t1.shareDays(t2) || !t1.shareWeeks(t2))
                        continue;
                    if (t1.getStartSlot() + t1.getLength() < t2.getStartSlot()) {
                        if (Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement) > t1.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t2.getStartSlot() - t1.getStartSlot() - t1.getLength()))
                            conflicts.add(otherPlacement);
                    } else if (t2.getStartSlot() + t2.getLength() < t1.getStartSlot()) {
                        if (Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement) > t2.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t1.getStartSlot() - t2.getStartSlot() - t2.getLength()))
                            conflicts.add(otherPlacement);
                    }
                }
            }
        }
    }
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) BitSet(java.util.BitSet)

Example 27 with Lecture

use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.

the class InstructorConstraint method getPreference.

/** Back-to-back preference of the given placement 
     * @param assignment current assignment
     * @param value placement under consideration
     * @return distance preference for the given placement 
     **/
public int getPreference(Assignment<Lecture, Placement> assignment, Placement value) {
    Lecture lecture = value.variable();
    Placement placement = value;
    int pref = 0;
    HashSet<Placement> checked = new HashSet<Placement>();
    InstructorConstraintContext context = getContext(assignment);
    for (Enumeration<Integer> e = placement.getTimeLocation().getStartSlots(); e.hasMoreElements(); ) {
        int startSlot = e.nextElement();
        int prevSlot = startSlot - 1;
        if (prevSlot >= 0 && (prevSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
            for (Placement c : context.getPlacements(prevSlot, placement)) {
                if (lecture.equals(c.variable()) || !checked.add(c))
                    continue;
                double dist = Placement.getDistanceInMeters(getDistanceMetric(), placement, c);
                if (dist > getDistanceMetric().getInstructorNoPreferenceLimit() && dist <= getDistanceMetric().getInstructorDiscouragedLimit())
                    pref += Constants.sPreferenceLevelDiscouraged;
                if (dist > getDistanceMetric().getInstructorDiscouragedLimit() && (dist <= getDistanceMetric().getInstructorProhibitedLimit() || iIgnoreDistances))
                    pref += Constants.sPreferenceLevelStronglyDiscouraged;
                if (!iIgnoreDistances && dist > getDistanceMetric().getInstructorProhibitedLimit())
                    pref += Constants.sPreferenceLevelProhibited;
            }
        }
        int nextSlot = startSlot + placement.getTimeLocation().getLength();
        if ((nextSlot / Constants.SLOTS_PER_DAY) == (startSlot / Constants.SLOTS_PER_DAY)) {
            for (Placement c : context.getPlacements(nextSlot, placement)) {
                if (lecture.equals(c.variable()) || !checked.add(c))
                    continue;
                double dist = Placement.getDistanceInMeters(getDistanceMetric(), placement, c);
                if (dist > getDistanceMetric().getInstructorNoPreferenceLimit() && dist <= getDistanceMetric().getInstructorDiscouragedLimit())
                    pref += Constants.sPreferenceLevelDiscouraged;
                if (dist > getDistanceMetric().getInstructorDiscouragedLimit() && (dist <= getDistanceMetric().getInstructorProhibitedLimit() || iIgnoreDistances))
                    pref += Constants.sPreferenceLevelStronglyDiscouraged;
                if (!iIgnoreDistances && dist > getDistanceMetric().getInstructorProhibitedLimit())
                    pref = Constants.sPreferenceLevelProhibited;
            }
        }
        if (getDistanceMetric().doComputeDistanceConflictsBetweenNonBTBClasses()) {
            TimeLocation t1 = placement.getTimeLocation();
            Placement before = null, after = null;
            for (Lecture other : variables()) {
                Placement otherPlacement = assignment.getValue(other);
                if (otherPlacement == null || other.equals(placement.variable()))
                    continue;
                TimeLocation t2 = otherPlacement.getTimeLocation();
                if (t1 == null || t2 == null || !t1.shareDays(t2) || !t1.shareWeeks(t2))
                    continue;
                if (t1.getStartSlot() + t1.getLength() < t2.getStartSlot()) {
                    int distanceInMinutes = Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement);
                    if (distanceInMinutes > t1.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t2.getStartSlot() - t1.getStartSlot() - t1.getLength()))
                        pref += (iIgnoreDistances ? Constants.sPreferenceLevelStronglyDiscouraged : Constants.sPreferenceLevelProhibited);
                    else if (distanceInMinutes > Constants.SLOT_LENGTH_MIN * (t2.getStartSlot() - t1.getStartSlot() - t1.getLength()))
                        pref += Constants.sPreferenceLevelDiscouraged;
                } else if (t2.getStartSlot() + t2.getLength() < t1.getStartSlot()) {
                    int distanceInMinutes = Placement.getDistanceInMinutes(getDistanceMetric(), placement, otherPlacement);
                    if (distanceInMinutes > t2.getBreakTime() + Constants.SLOT_LENGTH_MIN * (t1.getStartSlot() - t2.getStartSlot() - t2.getLength()))
                        pref += (iIgnoreDistances ? Constants.sPreferenceLevelStronglyDiscouraged : Constants.sPreferenceLevelProhibited);
                    else if (distanceInMinutes > Constants.SLOT_LENGTH_MIN * (t1.getStartSlot() - t2.getStartSlot() - t2.getLength()))
                        pref += Constants.sPreferenceLevelDiscouraged;
                }
                if (t1.getStartSlot() + t1.getLength() <= t2.getStartSlot()) {
                    if (after == null || t2.getStartSlot() < after.getTimeLocation().getStartSlot())
                        after = otherPlacement;
                } else if (t2.getStartSlot() + t2.getLength() <= t1.getStartSlot()) {
                    if (before == null || before.getTimeLocation().getStartSlot() < t2.getStartSlot())
                        before = otherPlacement;
                }
            }
            if (iUnavailabilities != null) {
                for (Placement c : iUnavailabilities) {
                    TimeLocation t2 = c.getTimeLocation();
                    if (t1 == null || t2 == null || !t1.shareDays(t2) || !t1.shareWeeks(t2))
                        continue;
                    if (t1.getStartSlot() + t1.getLength() <= t2.getStartSlot()) {
                        if (after == null || t2.getStartSlot() < after.getTimeLocation().getStartSlot())
                            after = c;
                    } else if (t2.getStartSlot() + t2.getLength() <= t1.getStartSlot()) {
                        if (before == null || before.getTimeLocation().getStartSlot() < t2.getStartSlot())
                            before = c;
                    }
                }
            }
            if (before != null && Placement.getDistanceInMinutes(getDistanceMetric(), before, placement) > getDistanceMetric().getInstructorLongTravelInMinutes())
                pref += Constants.sPreferenceLevelStronglyDiscouraged;
            if (after != null && Placement.getDistanceInMinutes(getDistanceMetric(), after, placement) > getDistanceMetric().getInstructorLongTravelInMinutes())
                pref += Constants.sPreferenceLevelStronglyDiscouraged;
            if (before != null && after != null && Placement.getDistanceInMinutes(getDistanceMetric(), before, after) > getDistanceMetric().getInstructorLongTravelInMinutes())
                pref -= Constants.sPreferenceLevelStronglyDiscouraged;
        }
    }
    return pref;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) HashSet(java.util.HashSet)

Example 28 with Lecture

use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.

the class MinimizeNumberOfUsedGroupsOfTime method toString.

@Override
public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("Minimize Use Of " + (Constants.SLOT_LENGTH_MIN * (iGroupsOfTime[0].getEndSlot() - iGroupsOfTime[0].getStartSlot())) + "min Groups between ");
    for (Iterator<Lecture> e = variables().iterator(); e.hasNext(); ) {
        Lecture v = e.next();
        sb.append(v.getName());
        if (e.hasNext())
            sb.append(", ");
    }
    return sb.toString();
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture)

Example 29 with Lecture

use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.

the class MinimizeNumberOfUsedRoomsConstraint method toString.

@Override
public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("Minimize Number Of Rooms Used between ");
    for (Iterator<Lecture> e = variables().iterator(); e.hasNext(); ) {
        Lecture v = e.next();
        sb.append(v.getName());
        if (e.hasNext())
            sb.append(", ");
    }
    return sb.toString();
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture)

Example 30 with Lecture

use of org.cpsolver.coursett.model.Lecture in project cpsolver by UniTime.

the class GroupConstraint method nrSlotsADay.

private int nrSlotsADay(Assignment<Lecture, Placement> assignment, int dayCode, BitSet week, HashMap<Lecture, Placement> assignments, Set<Placement> conflicts) {
    Set<Integer> slots = new HashSet<Integer>();
    for (Lecture lecture : variables()) {
        Placement placement = null;
        if (assignments != null && assignments.containsKey(lecture))
            placement = assignments.get(lecture);
        else if (assignment != null)
            placement = assignment.getValue(lecture);
        if (placement == null || placement.getTimeLocation() == null)
            continue;
        if (conflicts != null && conflicts.contains(placement))
            continue;
        TimeLocation t = placement.getTimeLocation();
        if (t == null || (t.getDayCode() & dayCode) == 0 || (week != null && !t.shareWeeks(week)))
            continue;
        for (int i = 0; i < t.getLength(); i++) slots.add(i + t.getStartSlot());
    }
    return slots.size();
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Placement(org.cpsolver.coursett.model.Placement) WeakeningConstraint(org.cpsolver.ifs.model.WeakeningConstraint) Constraint(org.cpsolver.ifs.model.Constraint) GlobalConstraint(org.cpsolver.ifs.model.GlobalConstraint) 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