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());
}
}
}
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;
}
Aggregations