Search in sources :

Example 21 with JenrlConstraint

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

the class StudentSwapSectioning method objective.

/**
 * Student conflict weight of a solution
 */
protected double objective(Solution<Lecture, Placement> solution) {
    List<StudentConflict> criteria = getStudentConflictCriteria();
    if (criteria == null) {
        double value = 0.0;
        for (JenrlConstraint constraint : ((TimetableModel) solution.getModel()).getJenrlConstraints()) {
            if (constraint.isInConflict(solution.getAssignment()))
                value += constraint.jenrl();
        }
        return value;
    }
    double value = 0.0;
    for (StudentConflict criterion : criteria) value += criterion.getWeightedValue(solution.getAssignment());
    return value;
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) StudentConflict(org.cpsolver.coursett.criteria.StudentConflict) TimetableModel(org.cpsolver.coursett.model.TimetableModel)

Example 22 with JenrlConstraint

use of org.cpsolver.coursett.constraint.JenrlConstraint 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 23 with JenrlConstraint

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

the class Lecture method getInitialStudentConflicts.

/**
 * Table of student conflicts caused by the initial assignment of this
 * lecture in format (another lecture, number)
 * @return table of student conflicts with the initial assignment of this class
 */
public Map<Lecture, Long> getInitialStudentConflicts() {
    Placement value = getInitialAssignment();
    if (value == null)
        return null;
    Map<Lecture, Long> ret = new HashMap<Lecture, Long>();
    for (JenrlConstraint jenrl : jenrlConstraints()) {
        Lecture another = jenrl.another(this);
        if (another.getInitialAssignment() != null)
            if (JenrlConstraint.isInConflict(value, another.getInitialAssignment(), getDistanceMetric(), getStudentWorkDayLimit()))
                ret.put(another, jenrl.getJenrl());
    }
    return ret;
}
Also used : JenrlConstraint(org.cpsolver.coursett.constraint.JenrlConstraint) HashMap(java.util.HashMap)

Example 24 with JenrlConstraint

use of org.cpsolver.coursett.constraint.JenrlConstraint 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

JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)24 HashSet (java.util.HashSet)11 Lecture (org.cpsolver.coursett.model.Lecture)9 DepartmentSpreadConstraint (org.cpsolver.coursett.constraint.DepartmentSpreadConstraint)7 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)7 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)7 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)7 TimetableModel (org.cpsolver.coursett.model.TimetableModel)7 ClassLimitConstraint (org.cpsolver.coursett.constraint.ClassLimitConstraint)5 RoomConstraint (org.cpsolver.coursett.constraint.RoomConstraint)5 Placement (org.cpsolver.coursett.model.Placement)5 Constraint (org.cpsolver.ifs.model.Constraint)5 HashMap (java.util.HashMap)4 FlexibleConstraint (org.cpsolver.coursett.constraint.FlexibleConstraint)4 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)4 ArrayList (java.util.ArrayList)3 StudentConflict (org.cpsolver.coursett.criteria.StudentConflict)3 Student (org.cpsolver.coursett.model.Student)3 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2