Search in sources :

Example 6 with FlexibleConstraint

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

the class FlexibleConstraintCriterion method getInfo.

@Override
public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
    TimetableModel m = (TimetableModel) getModel();
    if (m.getFlexibleConstraints().isEmpty())
        return;
    for (FlexibleConstraintType type : FlexibleConstraintType.values()) {
        StringBuilder debug = null;
        int violated = 0, constraints = 0;
        for (FlexibleConstraint c : m.getFlexibleConstraints()) {
            if (type.equals(c.getType())) {
                constraints++;
                if (c.getContext(assignment).getPreference() > 0) {
                    violated++;
                    if (iDebug) {
                        if (debug == null)
                            debug = new StringBuilder(c.getOwner() + " (" + sDoubleFormat.format(c.getNrViolations(assignment, new HashSet<Placement>(), null)) + ")");
                        else
                            debug.append("; " + c.getOwner() + " (" + sDoubleFormat.format(c.getNrViolations(assignment, new HashSet<Placement>(), null)) + ")");
                    }
                }
            }
        }
        if (constraints > 0) {
            info.put(type.getName() + " Constraints", getPerc(violated, 0, constraints) + "% (" + violated + ")");
            if (iDebug && violated > 0)
                info.put(type.getName() + " Violations", debug.toString());
        }
    }
}
Also used : FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) Placement(org.cpsolver.coursett.model.Placement) FlexibleConstraintType(org.cpsolver.coursett.constraint.FlexibleConstraint.FlexibleConstraintType) TimetableModel(org.cpsolver.coursett.model.TimetableModel) FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) HashSet(java.util.HashSet)

Example 7 with FlexibleConstraint

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

the class FlexibleConstraintCriterion method getValue.

@Override
public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    Set<FlexibleConstraint> flexibleConstraints = new HashSet<FlexibleConstraint>();
    for (Lecture lecture : variables) {
        flexibleConstraints.addAll(lecture.getFlexibleGroupConstraints());
    }
    int ret = 0;
    for (FlexibleConstraint gc : flexibleConstraints) {
        ret += gc.getContext(assignment).getPreference();
    }
    return ret;
}
Also used : FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) Lecture(org.cpsolver.coursett.model.Lecture) FlexibleConstraint(org.cpsolver.coursett.constraint.FlexibleConstraint) HashSet(java.util.HashSet)

Aggregations

FlexibleConstraint (org.cpsolver.coursett.constraint.FlexibleConstraint)7 HashSet (java.util.HashSet)4 Lecture (org.cpsolver.coursett.model.Lecture)4 ClassLimitConstraint (org.cpsolver.coursett.constraint.ClassLimitConstraint)3 GroupConstraint (org.cpsolver.coursett.constraint.GroupConstraint)3 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)3 SpreadConstraint (org.cpsolver.coursett.constraint.SpreadConstraint)3 Placement (org.cpsolver.coursett.model.Placement)3 HashMap (java.util.HashMap)2 DepartmentSpreadConstraint (org.cpsolver.coursett.constraint.DepartmentSpreadConstraint)2 FlexibleConstraintType (org.cpsolver.coursett.constraint.FlexibleConstraint.FlexibleConstraintType)2 JenrlConstraint (org.cpsolver.coursett.constraint.JenrlConstraint)2 WeakeningConstraint (org.cpsolver.ifs.model.WeakeningConstraint)2 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1