Search in sources :

Example 16 with InstructorConstraint

use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.

the class UniversalPerturbationsCounter method getPenalty.

@Override
protected double getPenalty(Assignment<Lecture, Placement> assignment, Placement assignedPlacement, Placement initialPlacement) {
    // assigned and initial value of the same lecture
    // assigned might be null
    Lecture lecture = initialPlacement.variable();
    double penalty = 0.0;
    if (iDifferentPlacement != 0.0)
        penalty += iDifferentPlacement;
    if (iAffectedStudentWeight != 0.0)
        penalty += iAffectedStudentWeight * lecture.classLimit(assignment);
    if (iAffectedInstructorWeight != 0.0)
        penalty += iAffectedInstructorWeight * lecture.getInstructorConstraints().size();
    if (assignedPlacement != null) {
        if ((iDifferentRoomWeight != 0.0 || iAffectedInstructorByRoomWeight != 0.0 || iAffectedStudentByRoomWeight != 0.0)) {
            int nrDiff = initialPlacement.nrDifferentRooms(assignedPlacement);
            penalty += nrDiff * iDifferentRoomWeight;
            penalty += nrDiff * iAffectedInstructorByRoomWeight * lecture.getInstructorConstraints().size();
            penalty += nrDiff * iAffectedStudentByRoomWeight * lecture.classLimit(assignment);
        }
        if ((iDifferentBuildingWeight != 0.0 || iAffectedInstructorByBldgWeight != 0.0 || iAffectedStudentByBldgWeight != 0.0)) {
            int nrDiff = initialPlacement.nrDifferentBuildings(assignedPlacement);
            penalty += nrDiff * iDifferentBuildingWeight;
            penalty += nrDiff * iAffectedInstructorByBldgWeight * lecture.getInstructorConstraints().size();
            penalty += nrDiff * iAffectedStudentByBldgWeight * lecture.classLimit(assignment);
        }
        if ((iDifferentTimeWeight != 0.0 || iAffectedInstructorByTimeWeight != 0.0 || iAffectedStudentByTimeWeight != 0.0) && !initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
            penalty += iDifferentTimeWeight;
            penalty += iAffectedInstructorByTimeWeight * lecture.getInstructorConstraints().size();
            penalty += iAffectedStudentByTimeWeight * lecture.classLimit(assignment);
        }
        if (iDifferentDayWeight != 0.0 && initialPlacement.getTimeLocation().getDayCode() != assignedPlacement.getTimeLocation().getDayCode())
            penalty += iDifferentDayWeight;
        if (iDifferentHourWeight != 0.0 && initialPlacement.getTimeLocation().getStartSlot() != assignedPlacement.getTimeLocation().getStartSlot())
            penalty += iDifferentHourWeight;
        if ((iTooFarForInstructorsWeight != 0.0 || iTooFarForStudentsWeight != 0.0) && !initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation())) {
            double distance = Placement.getDistanceInMeters(iDistanceMetric, initialPlacement, assignedPlacement);
            if (!lecture.getInstructorConstraints().isEmpty() && iTooFarForInstructorsWeight != 0.0) {
                if (distance > iDistanceMetric.getInstructorNoPreferenceLimit() && distance <= iDistanceMetric.getInstructorDiscouragedLimit()) {
                    penalty += Constants.sPreferenceLevelDiscouraged * iTooFarForInstructorsWeight * lecture.getInstructorConstraints().size();
                } else if (distance > iDistanceMetric.getInstructorDiscouragedLimit() && distance <= iDistanceMetric.getInstructorProhibitedLimit()) {
                    penalty += Constants.sPreferenceLevelStronglyDiscouraged * iTooFarForInstructorsWeight * lecture.getInstructorConstraints().size();
                } else if (distance > iDistanceMetric.getInstructorProhibitedLimit()) {
                    penalty += Constants.sPreferenceLevelProhibited * iTooFarForInstructorsWeight * lecture.getInstructorConstraints().size();
                }
            }
            if (iTooFarForStudentsWeight != 0.0 && distance > iDistanceMetric.minutes2meters(10))
                penalty += iTooFarForStudentsWeight * lecture.classLimit(assignment);
        }
        if (iDeltaStudentConflictsWeight != 0.0) {
            int newStudentConflicts = lecture.countStudentConflicts(assignment, assignedPlacement);
            int oldStudentConflicts = lecture.countInitialStudentConflicts();
            penalty += iDeltaStudentConflictsWeight * (newStudentConflicts - oldStudentConflicts);
        }
        if (iNewStudentConflictsWeight != 0.0) {
            Set<Student> newStudentConflicts = lecture.conflictStudents(assignment, assignedPlacement);
            Set<Student> initialStudentConflicts = lecture.initialStudentConflicts();
            for (Iterator<Student> i = newStudentConflicts.iterator(); i.hasNext(); ) if (!initialStudentConflicts.contains(i.next()))
                penalty += iNewStudentConflictsWeight;
        }
        if (iDeltaTimePreferenceWeight != 0.0) {
            penalty += iDeltaTimePreferenceWeight * (assignedPlacement.getTimeLocation().getNormalizedPreference() - initialPlacement.getTimeLocation().getNormalizedPreference());
        }
        if (iDeltaRoomPreferenceWeight != 0.0) {
            penalty += iDeltaRoomPreferenceWeight * (assignedPlacement.sumRoomPreference() - initialPlacement.sumRoomPreference());
        }
        if (iDeltaInstructorDistancePreferenceWeight != 0.0) {
            for (InstructorConstraint ic : lecture.getInstructorConstraints()) {
                for (Lecture lect : ic.variables()) {
                    if (lect.equals(lecture))
                        continue;
                    int initialPreference = (lect.getInitialAssignment() == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(initialPlacement, lect.getInitialAssignment()));
                    int assignedPreference = (assignment.getValue(lect) == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(assignedPlacement, assignment.getValue(lect)));
                    penalty += iDeltaInstructorDistancePreferenceWeight * (assignedPreference - initialPreference);
                }
            }
        }
    }
    return penalty;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Student(org.cpsolver.coursett.model.Student) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Example 17 with InstructorConstraint

use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.

the class UniversalPerturbationsCounter method getCompactInfo.

public Map<String, Double> getCompactInfo(Assignment<Lecture, Placement> assignment, TimetableModel model, Placement assignedPlacement, boolean includeZero, boolean weighted) {
    Map<String, Double> info = new HashMap<String, Double>();
    if (!iMPP)
        return info;
    Lecture lecture = assignedPlacement.variable();
    Placement initialPlacement = lecture.getInitialAssignment();
    if (initialPlacement == null || initialPlacement.equals(assignedPlacement))
        return info;
    int perts = 1;
    long affectedStudents = lecture.classLimit(assignment);
    int affectedInstructors = lecture.getInstructorConstraints().size();
    long affectedStudentsByTime = (initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation()) ? 0 : lecture.classLimit(assignment));
    int affectedInstructorsByTime = (initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation()) ? 0 : lecture.getInstructorConstraints().size());
    int differentRoom = initialPlacement.nrDifferentRooms(assignedPlacement);
    int affectedInstructorsByRoom = differentRoom * lecture.getInstructorConstraints().size();
    long affectedStudentsByRoom = differentRoom * lecture.classLimit(assignment);
    int differentBuilding = initialPlacement.nrDifferentBuildings(initialPlacement);
    int affectedInstructorsByBldg = differentBuilding * lecture.getInstructorConstraints().size();
    long affectedStudentsByBldg = differentBuilding * lecture.classLimit(assignment);
    int deltaRoomPreferences = assignedPlacement.sumRoomPreference() - initialPlacement.sumRoomPreference();
    int differentTime = (initialPlacement.getTimeLocation().equals(assignedPlacement.getTimeLocation()) ? 0 : 1);
    int differentDay = (initialPlacement.getTimeLocation().getDayCode() != assignedPlacement.getTimeLocation().getDayCode() ? 1 : 0);
    int differentHour = (initialPlacement.getTimeLocation().getStartSlot() != assignedPlacement.getTimeLocation().getStartSlot() ? 1 : 0);
    int tooFarForInstructors = 0;
    int tooFarForStudents = 0;
    int deltaStudentConflicts = lecture.countStudentConflicts(assignment, assignedPlacement) - lecture.countInitialStudentConflicts();
    int newStudentConflicts = 0;
    double deltaTimePreferences = (assignedPlacement.getTimeLocation().getNormalizedPreference() - initialPlacement.getTimeLocation().getNormalizedPreference());
    int deltaInstructorDistancePreferences = 0;
    double distance = Placement.getDistanceInMeters(iDistanceMetric, initialPlacement, assignedPlacement);
    if (!lecture.getInstructorConstraints().isEmpty()) {
        if (distance > iDistanceMetric.getInstructorNoPreferenceLimit() && distance <= iDistanceMetric.getInstructorDiscouragedLimit()) {
            tooFarForInstructors += lecture.getInstructorConstraints().size();
        } else if (distance > iDistanceMetric.getInstructorDiscouragedLimit() && distance <= iDistanceMetric.getInstructorProhibitedLimit()) {
            tooFarForInstructors += 2 * lecture.getInstructorConstraints().size();
        } else if (distance > iDistanceMetric.getInstructorProhibitedLimit()) {
            tooFarForInstructors += 10 * lecture.getInstructorConstraints().size();
        }
    }
    if (distance > iDistanceMetric.minutes2meters(10))
        tooFarForStudents = lecture.classLimit(assignment);
    Set<Student> newStudentConflictsVect = lecture.conflictStudents(assignment, assignedPlacement);
    Set<Student> initialStudentConflicts = lecture.initialStudentConflicts();
    for (Iterator<Student> e = newStudentConflictsVect.iterator(); e.hasNext(); ) if (!initialStudentConflicts.contains(e.next()))
        newStudentConflicts++;
    for (InstructorConstraint ic : lecture.getInstructorConstraints()) {
        for (Lecture lect : ic.variables()) {
            if (lect.equals(lecture))
                continue;
            int initialPreference = (lect.getInitialAssignment() == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(initialPlacement, lect.getInitialAssignment()));
            int assignedPreference = (assignment.getValue(lect) == null ? Constants.sPreferenceLevelNeutral : ic.getDistancePreference(assignedPlacement, assignment.getValue(lect)));
            deltaInstructorDistancePreferences += (assignedPreference - initialPreference);
        }
    }
    if (includeZero || iDifferentPlacement != 0.0)
        info.put("Different placement", Double.valueOf(weighted ? iDifferentPlacement * perts : perts));
    if (includeZero || iAffectedStudentWeight != 0.0)
        info.put("Affected students", Double.valueOf(weighted ? iAffectedStudentWeight * affectedStudents : affectedStudents));
    if (includeZero || iAffectedInstructorWeight != 0.0)
        info.put("Affected instructors", Double.valueOf(weighted ? iAffectedInstructorWeight * affectedInstructors : affectedInstructors));
    if (includeZero || iAffectedStudentByTimeWeight != 0.0)
        info.put("Affected students [time]", Double.valueOf(weighted ? iAffectedStudentByTimeWeight * affectedStudentsByTime : affectedStudentsByTime));
    if (includeZero || iAffectedInstructorByTimeWeight != 0.0)
        info.put("Affected instructors [time]", Double.valueOf(weighted ? iAffectedInstructorByTimeWeight * affectedInstructorsByTime : affectedInstructorsByTime));
    if (includeZero || iAffectedStudentByRoomWeight != 0.0)
        info.put("Affected students [room]", Double.valueOf(weighted ? iAffectedStudentByRoomWeight * affectedStudentsByRoom : affectedStudentsByRoom));
    if (includeZero || iAffectedInstructorByRoomWeight != 0.0)
        info.put("Affected instructors [room]", Double.valueOf(weighted ? iAffectedInstructorByRoomWeight * affectedInstructorsByRoom : affectedInstructorsByRoom));
    if (includeZero || iAffectedStudentByBldgWeight != 0.0)
        info.put("Affected students [bldg]", Double.valueOf(weighted ? iAffectedStudentByBldgWeight * affectedStudentsByBldg : affectedStudentsByBldg));
    if (includeZero || iAffectedInstructorByBldgWeight != 0.0)
        info.put("Affected instructors [bldg]", Double.valueOf(weighted ? iAffectedInstructorByBldgWeight * affectedInstructorsByBldg : affectedInstructorsByBldg));
    if (includeZero || iDifferentRoomWeight != 0.0)
        info.put("Different room", Double.valueOf(weighted ? iDifferentRoomWeight * differentRoom : differentRoom));
    if (includeZero || iDifferentBuildingWeight != 0.0)
        info.put("Different building", Double.valueOf(weighted ? iDifferentBuildingWeight * differentBuilding : differentBuilding));
    if (includeZero || iDifferentTimeWeight != 0.0)
        info.put("Different time", Double.valueOf(weighted ? iDifferentTimeWeight * differentTime : differentTime));
    if (includeZero || iDifferentDayWeight != 0.0)
        info.put("Different day", Double.valueOf(weighted ? iDifferentDayWeight * differentDay : differentDay));
    if (includeZero || iDifferentHourWeight != 0.0)
        info.put("Different hour", Double.valueOf(weighted ? iDifferentHourWeight * differentHour : differentHour));
    if (includeZero || iTooFarForInstructorsWeight != 0.0)
        info.put("New placement too far for initial [instructors]", Double.valueOf(weighted ? iTooFarForInstructorsWeight * tooFarForInstructors : tooFarForInstructors));
    if (includeZero || iTooFarForStudentsWeight != 0.0)
        info.put("New placement too far for initial [students]", Double.valueOf(weighted ? iTooFarForStudentsWeight * tooFarForStudents : tooFarForStudents));
    if (includeZero || iDeltaStudentConflictsWeight != 0.0)
        info.put("Delta student conflicts", Double.valueOf(weighted ? iDeltaStudentConflictsWeight * deltaStudentConflicts : deltaStudentConflicts));
    if (includeZero || iNewStudentConflictsWeight != 0.0)
        info.put("New student conflicts", Double.valueOf(weighted ? iNewStudentConflictsWeight * newStudentConflicts : newStudentConflicts));
    if (includeZero || iDeltaTimePreferenceWeight != 0.0)
        info.put("Delta time preferences", Double.valueOf(weighted ? iDeltaTimePreferenceWeight * deltaTimePreferences : deltaTimePreferences));
    if (includeZero || iDeltaRoomPreferenceWeight != 0.0)
        info.put("Delta room preferences", Double.valueOf(weighted ? iDeltaRoomPreferenceWeight * deltaRoomPreferences : deltaRoomPreferences));
    if (includeZero || iDeltaInstructorDistancePreferenceWeight != 0.0)
        info.put("Delta instructor distance preferences", Double.valueOf(weighted ? iDeltaInstructorDistancePreferenceWeight * deltaInstructorDistancePreferences : deltaInstructorDistancePreferences));
    return info;
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) HashMap(java.util.HashMap) Student(org.cpsolver.coursett.model.Student) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) Placement(org.cpsolver.coursett.model.Placement)

Example 18 with InstructorConstraint

use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.

the class Lecture method removeContstraint.

@Override
public void removeContstraint(Constraint<Lecture, Placement> constraint) {
    super.removeContstraint(constraint);
    if (constraint instanceof WeakeningConstraint)
        iWeakeningConstraints.remove(constraint);
    if (constraint instanceof FlexibleConstraint)
        iFlexibleGroupConstraints.remove(constraint);
    if (constraint instanceof JenrlConstraint) {
        JenrlConstraint jenrl = (JenrlConstraint) constraint;
        Lecture another = jenrl.another(this);
        if (another != null) {
            iJenrlConstraints.remove(jenrl);
            another.iJenrlConstraints.remove(jenrl);
            iJenrlConstraintsHash.remove(another);
            another.iJenrlConstraintsHash.remove(this);
        }
    } else if (constraint instanceof GroupConstraint) {
        iCanShareRoomGroupConstraints.remove(constraint);
        iHardGroupSoftConstraints.remove(constraint);
        iGroupConstraints.remove(constraint);
    } else if (constraint instanceof DepartmentSpreadConstraint)
        iDeptSpreadConstraint = null;
    else if (constraint instanceof SpreadConstraint)
        iSpreadConstraints.remove(constraint);
    else if (constraint instanceof InstructorConstraint)
        iInstructorConstraints.remove(constraint);
    else if (constraint instanceof ClassLimitConstraint)
        iClassLimitConstraint = null;
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) ClassLimitConstraint(org.cpsolver.coursett.constraint.ClassLimitConstraint) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) WeakeningConstraint(org.cpsolver.ifs.model.WeakeningConstraint) GroupConstraint(org.cpsolver.coursett.constraint.GroupConstraint) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) SpreadConstraint(org.cpsolver.coursett.constraint.SpreadConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Example 19 with InstructorConstraint

use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.

the class Lecture method computeValues.

/**
 * Domain -- all combinations of room and time locations
 * @param assignment current assignment
 * @param allowBreakHard breaking of hard constraints is allowed
 * @return list of possible placements
 */
public List<Placement> computeValues(Assignment<Lecture, Placement> assignment, boolean allowBreakHard) {
    List<Placement> values = new ArrayList<Placement>(iRoomLocations.size() * iTimeLocations.size());
    for (TimeLocation timeLocation : iTimeLocations) {
        if (!allowBreakHard && Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(timeLocation.getPreference())))
            continue;
        if (timeLocation.getPreference() > 500)
            continue;
        boolean notAvailable = false;
        for (InstructorConstraint ic : getInstructorConstraints()) {
            if (!ic.isAvailable(this, timeLocation) && ic.isHard()) {
                notAvailable = true;
                break;
            }
        }
        if (notAvailable)
            continue;
        if (iNrRooms == 0) {
            Placement p = new Placement(this, timeLocation, (RoomLocation) null);
            for (InstructorConstraint ic : getInstructorConstraints()) {
                if (!ic.isAvailable(this, p) && ic.isHard()) {
                    notAvailable = true;
                    break;
                }
            }
            if (notAvailable)
                continue;
            p.setVariable(this);
            if (sSaveMemory && !isValid(p))
                continue;
            if (getInitialAssignment() != null && p.equals(getInitialAssignment()))
                setInitialAssignment(p);
            // if (getAssignment() != null && getAssignment().equals(p)) iValue = getAssignment();
            if (getBestAssignment() != null && getBestAssignment().equals(p))
                setBestAssignment(p, getBestAssignmentIteration());
            values.add(p);
        } else if (iNrRooms == 1) {
            rooms: for (RoomLocation roomLocation : iRoomLocations) {
                if (!allowBreakHard && Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(roomLocation.getPreference())))
                    continue;
                if (roomLocation.getPreference() > 500)
                    continue;
                if (roomLocation.getRoomConstraint() != null && !roomLocation.getRoomConstraint().isAvailable(this, timeLocation, getScheduler()))
                    continue;
                Placement p = new Placement(this, timeLocation, roomLocation);
                p.setVariable(this);
                for (InstructorConstraint ic : getInstructorConstraints()) if (!ic.isAvailable(this, p) && ic.isHard())
                    continue rooms;
                if (sSaveMemory && !isValid(p))
                    continue;
                if (getInitialAssignment() != null && p.equals(getInitialAssignment()))
                    setInitialAssignment(p);
                if (getBestAssignment() != null && getBestAssignment().equals(p))
                    setBestAssignment(p, getBestAssignmentIteration());
                values.add(p);
            }
        } else {
            if (getMaxRoomCombinations() > 0 && ToolBox.binomial(iRoomLocations.size(), iNrRooms) > getMaxRoomCombinations()) {
                if (getInitialAssignment() != null && getInitialAssignment().getNrRooms() == getNrRooms()) {
                    boolean av = true;
                    for (RoomLocation room : iRoomLocations) {
                        if (room.getRoomConstraint() != null && !room.getRoomConstraint().isAvailable(this, timeLocation, getScheduler())) {
                            av = false;
                            break;
                        }
                        if (room.getPreference() > 500) {
                            av = false;
                            break;
                        }
                        if (!allowBreakHard && Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(room.getPreference()))) {
                            av = false;
                            break;
                        }
                    }
                    Placement p = new Placement(this, timeLocation, new ArrayList<RoomLocation>(getInitialAssignment().getRoomLocations()));
                    for (InstructorConstraint ic : getInstructorConstraints()) if (!ic.isAvailable(this, p) && ic.isHard()) {
                        av = false;
                        break;
                    }
                    if (av && (!sSaveMemory || isValid(p))) {
                        p.setVariable(this);
                        if (p.equals(getInitialAssignment()))
                            setInitialAssignment(p);
                        if (getBestAssignment() != null && getBestAssignment().equals(p))
                            setBestAssignment(p, getBestAssignmentIteration());
                        values.add(p);
                    }
                }
                List<RoomLocation> available = new ArrayList<RoomLocation>(iRoomLocations.size());
                List<RoomLocation> other = new ArrayList<RoomLocation>(iRoomLocations.size());
                rooms: for (RoomLocation room : iRoomLocations) {
                    if (room.getRoomConstraint() != null && !room.getRoomConstraint().isAvailable(this, timeLocation, getScheduler()))
                        continue;
                    if (room.getPreference() > 500)
                        continue;
                    if (!allowBreakHard && Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(room.getPreference())))
                        continue;
                    for (InstructorConstraint ic : getInstructorConstraints()) if (!ic.isAvailable(this, new Placement(this, timeLocation, room)) && ic.isHard())
                        continue rooms;
                    if (assignment != null && room.getRoomConstraint() != null && !room.getRoomConstraint().getContext(assignment).inConflict(this, timeLocation) && !Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(room.getPreference()))) {
                        available.add(room);
                    } else {
                        other.add(room);
                    }
                }
                if (available.size() + other.size() < iNrRooms)
                    continue;
                for (Enumeration<Collection<RoomLocation>> e = ToolBox.sample(available, other, iNrRooms, getMaxRoomCombinations()); e.hasMoreElements(); ) {
                    Placement p = new Placement(this, timeLocation, new ArrayList<RoomLocation>(e.nextElement()));
                    if (getInitialAssignment() != null && p.sameRooms(getInitialAssignment()))
                        continue;
                    p.setVariable(this);
                    if (sSaveMemory && !isValid(p))
                        continue;
                    if (getBestAssignment() != null && getBestAssignment().equals(p))
                        setBestAssignment(p, getBestAssignmentIteration());
                    values.add(p);
                }
            } else {
                List<RoomLocation> rooms = new ArrayList<RoomLocation>(iRoomLocations.size());
                rooms: for (RoomLocation room : iRoomLocations) {
                    if (!allowBreakHard && Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(room.getPreference())))
                        continue;
                    if (room.getPreference() > 500)
                        continue;
                    if (room.getRoomConstraint() != null && !room.getRoomConstraint().isAvailable(this, timeLocation, getScheduler()))
                        continue;
                    for (InstructorConstraint ic : getInstructorConstraints()) if (!ic.isAvailable(this, new Placement(this, timeLocation, room)) && ic.isHard())
                        continue rooms;
                    rooms.add(room);
                }
                if (rooms.size() < iNrRooms)
                    continue;
                for (Enumeration<Collection<RoomLocation>> e = ToolBox.permutations(rooms, iNrRooms); e.hasMoreElements(); ) {
                    Placement p = new Placement(this, timeLocation, new ArrayList<RoomLocation>(e.nextElement()));
                    p.setVariable(this);
                    if (sSaveMemory && !isValid(p))
                        continue;
                    if (getInitialAssignment() != null && p.equals(getInitialAssignment()))
                        setInitialAssignment(p);
                    if (getBestAssignment() != null && getBestAssignment().equals(p))
                        setBestAssignment(p, getBestAssignmentIteration());
                    values.add(p);
                }
            }
        }
    }
    return values;
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Example 20 with InstructorConstraint

use of org.cpsolver.coursett.constraint.InstructorConstraint in project cpsolver by UniTime.

the class Lecture method addContstraint.

@Override
public void addContstraint(Constraint<Lecture, Placement> constraint) {
    super.addContstraint(constraint);
    if (constraint instanceof WeakeningConstraint)
        iWeakeningConstraints.add(constraint);
    if (constraint instanceof FlexibleConstraint)
        iFlexibleGroupConstraints.add((FlexibleConstraint) constraint);
    if (constraint instanceof JenrlConstraint) {
        JenrlConstraint jenrl = (JenrlConstraint) constraint;
        Lecture another = jenrl.another(this);
        if (another != null) {
            iJenrlConstraints.add(jenrl);
            another.iJenrlConstraints.add(jenrl);
            iJenrlConstraintsHash.put(another, (JenrlConstraint) constraint);
            another.iJenrlConstraintsHash.put(this, (JenrlConstraint) constraint);
        }
    } else if (constraint instanceof DepartmentSpreadConstraint)
        iDeptSpreadConstraint = (DepartmentSpreadConstraint) constraint;
    else if (constraint instanceof SpreadConstraint)
        iSpreadConstraints.add((SpreadConstraint) constraint);
    else if (constraint instanceof InstructorConstraint) {
        InstructorConstraint ic = (InstructorConstraint) constraint;
        if (ic.getResourceId() != null && ic.getResourceId().longValue() > 0)
            iInstructorConstraints.add(ic);
    } else if (constraint instanceof ClassLimitConstraint)
        iClassLimitConstraint = (ClassLimitConstraint) constraint;
    else if (constraint instanceof GroupConstraint) {
        GroupConstraint gc = (GroupConstraint) constraint;
        if (gc.canShareRoom()) {
            iCanShareRoomGroupConstraints.add((GroupConstraint) constraint);
        } else {
            iGroupConstraints.add((GroupConstraint) constraint);
            if (Constants.sPreferenceProhibited.equals(Constants.preferenceLevel2preference(gc.getPreference())) || Constants.sPreferenceRequired.equals(Constants.preferenceLevel2preference(gc.getPreference())))
                iHardGroupSoftConstraints.add((GroupConstraint) constraint);
        }
    }
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) ClassLimitConstraint(org.cpsolver.coursett.constraint.ClassLimitConstraint) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) WeakeningConstraint(org.cpsolver.ifs.model.WeakeningConstraint) GroupConstraint(org.cpsolver.coursett.constraint.GroupConstraint) DepartmentSpreadConstraint(org.cpsolver.coursett.constraint.DepartmentSpreadConstraint) SpreadConstraint(org.cpsolver.coursett.constraint.SpreadConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Aggregations

InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)21 Lecture (org.cpsolver.coursett.model.Lecture)14 HashSet (java.util.HashSet)10 Placement (org.cpsolver.coursett.model.Placement)8 Student (org.cpsolver.coursett.model.Student)8 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)7 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)7 HashMap (java.util.HashMap)5 TreeSet (java.util.TreeSet)5 DepartmentSpreadConstraint (org.cpsolver.coursett.constraint.DepartmentSpreadConstraint)5 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ClassLimitConstraint (org.cpsolver.coursett.constraint.ClassLimitConstraint)4 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)4 SoftInstructorConstraint (org.cpsolver.coursett.constraint.SoftInstructorConstraint)4 Constraint (org.cpsolver.ifs.model.Constraint)4 BitSet (java.util.BitSet)3 FlexibleConstraint (org.cpsolver.coursett.constraint.FlexibleConstraint)3 RoomLocation (org.cpsolver.coursett.model.RoomLocation)3