本文整理匯總了Java中org.cpsolver.coursett.Constants.NR_DAYS屬性的典型用法代碼示例。如果您正苦於以下問題:Java Constants.NR_DAYS屬性的具體用法?Java Constants.NR_DAYS怎麽用?Java Constants.NR_DAYS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.cpsolver.coursett.Constants
的用法示例。
在下文中一共展示了Constants.NR_DAYS屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setNotAvailable
@SuppressWarnings("unchecked")
public void setNotAvailable(Placement placement) {
if (iAvailable == null) {
iAvailable = new List[Constants.SLOTS_PER_DAY * Constants.NR_DAYS];
for (int i = 0; i < iAvailable.length; i++)
iAvailable[i] = null;
}
for (Enumeration<Integer> e = placement.getTimeLocation().getSlots(); e.hasMoreElements();) {
int slot = e.nextElement();
if (iAvailable[slot] == null)
iAvailable[slot] = new ArrayList<Placement>(1);
iAvailable[slot].add(placement);
}
for (Lecture lecture: variables())
lecture.clearValueCache();
}
示例2: RoomConstraintContext
@SuppressWarnings("unchecked")
public RoomConstraintContext(Assignment<Lecture, Placement> assignment) {
iResource = new List[Constants.SLOTS_PER_DAY * Constants.NR_DAYS];
for (int i = 0; i < iResource.length; i++)
iResource[i] = new ArrayList<Placement>(3);
for (Lecture lecture: variables()) {
Placement placement = assignment.getValue(lecture);
if (placement != null && placement.hasRoomLocation(getResourceId())) {
for (Enumeration<Integer> e = placement.getTimeLocation().getSlots(); e.hasMoreElements();) {
int slot = e.nextElement();
iResource[slot].add(placement);
}
}
}
iLastUselessHalfHours = UselessHalfHours.countUselessSlotsHalfHours(this);
getModel().getCriterion(UselessHalfHours.class).inc(assignment, iLastUselessHalfHours);
iLastBrokenTimePatterns = BrokenTimePatterns.countUselessSlotsBrokenTimePatterns(this) / 6.0;
getModel().getCriterion(BrokenTimePatterns.class).inc(assignment, iLastBrokenTimePatterns);
}
示例3: countUselessSlotsHalfHours
/** Number of useless half hours for this room
* @param rc room constraint assignment context
* @param placement placement that is being considered
* @return number of useless slots caused by the given placement
**/
protected static int countUselessSlotsHalfHours(RoomConstraintContext rc, Placement placement) {
int ret = 0;
TimeLocation time = placement.getTimeLocation();
int slot = time.getStartSlot() % Constants.SLOTS_PER_DAY;
int days = time.getDayCode();
for (int d = 0; d < Constants.NR_DAYS; d++) {
if ((Constants.DAY_CODES[d] & days) == 0)
continue;
if (isUselessBefore(rc, d * Constants.SLOTS_PER_DAY + slot - 6, placement))
ret ++;
if (isUselessAfter(rc, d * Constants.SLOTS_PER_DAY + slot + time.getNrSlotsPerMeeting(), placement))
ret ++;
if (time.getNrSlotsPerMeeting() == 6 && isUseless(rc, d * Constants.SLOTS_PER_DAY + slot, placement))
ret --;
}
return ret;
}
示例4: isAvailable
public boolean isAvailable(TimeLocation timeLocation, Long departmentId) {
for (int d = 0; d < Constants.NR_DAYS; d++) {
if ((Constants.DAY_CODES[d] & timeLocation.getDayCode()) == 0)
continue;
int startTime = timeLocation.getStartSlot() / getStep();
int endTime = (timeLocation.getStartSlot() + timeLocation.getLength() - 1) / getStep();
for (int t = startTime; t <= endTime; t++) {
Long pref = iPreference[d][t];
if (pref.equals(sNotAvailablePref))
return false;
if (pref.equals(sFreeForAllPref))
continue;
if (departmentId != null && !departmentId.equals(pref))
return false;
}
}
return true;
}
示例5: MaxHalfDaysFlexibleConstraintContext
@SuppressWarnings("unchecked")
public MaxHalfDaysFlexibleConstraintContext(Assignment<Lecture, Placement> assignment) {
super();
iHalfDayAssignments = new Set[getNrHalfDays() * Constants.NR_DAYS];
for (int i = 0; i < iHalfDayAssignments.length; i++)
iHalfDayAssignments[i] = new HashSet<Lecture>();
for (Lecture variable: variables()) {
Placement value = assignment.getValue(variable);
if (value != null) {
for (int i = 0; i < Constants.DAY_CODES.length; i++)
if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0)
iHalfDayAssignments[i * getNrHalfDays() + getHalfDay(value.getTimeLocation())].add(value.variable());
}
}
if (!isHard()) {
Criterion<Lecture, Placement> criterion = getModel().getCriterion(FlexibleConstraintCriterion.class);
if (criterion != null) {
double pref = nrViolations(null, null);
if (pref == 0)
iLastPreference = -Math.abs(iPreference);
else
iLastPreference = Math.abs(iPreference) * pref;
criterion.inc(assignment, iLastPreference);
}
}
}
示例6: MaxDaysFlexibleConstraintContext
@SuppressWarnings("unchecked")
public MaxDaysFlexibleConstraintContext(Assignment<Lecture, Placement> assignment) {
super();
iDayAssignments = new Set[Constants.NR_DAYS];
for (int i = 0; i < iDayAssignments.length; i++)
iDayAssignments[i] = new HashSet<Lecture>();
for (Lecture variable: variables()) {
Placement value = assignment.getValue(variable);
if (value != null) {
for (int i = 0; i < iDayAssignments.length; i++)
if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0)
iDayAssignments[i].add(value.variable());
}
}
if (!isHard()) {
Criterion<Lecture, Placement> criterion = getModel().getCriterion(FlexibleConstraintCriterion.class);
if (criterion != null) {
double pref = nrViolations(null, null);
if (pref == 0)
iLastPreference = -Math.abs(iPreference);
else
iLastPreference = Math.abs(iPreference) * pref;
criterion.inc(assignment, iLastPreference);
}
}
}
示例7: getValue
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
double ret = 0.0;
if (value.getTimeLocation().getStartSlot() <= iLunchEnd && value.getTimeLocation().getStartSlot() + value.getTimeLocation().getLength() > iLunchStart) {
InstructorLunchBreakContext context = (InstructorLunchBreakContext)getContext(assignment);
for (InstructorConstraint constraint: value.variable().getInstructorConstraints()) {
InstructorConstraintContext icx = constraint.getContext(assignment);
CompactInfo compactInfo = context.getCompactInfo(constraint);
for (int i = 0; i < Constants.NR_DAYS; i++) {
// checks only days affected by the placement
if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0) {
int currentLunchStartSlot = Constants.SLOTS_PER_DAY * i + iLunchStart;
int currentLunchEndSlot = Constants.SLOTS_PER_DAY * i + iLunchEnd;
int semesterViolations = 0;
for (BitSet week : getWeeks()) {
int maxBreak = 0;
int currentBreak = 0;
for (int slot = currentLunchStartSlot; slot < currentLunchEndSlot; slot++) {
if (isEmpty(icx, slot, week, value)) {
currentBreak++;
if (maxBreak < currentBreak) {
maxBreak = currentBreak;
}
} else {
currentBreak = 0;
}
}
if (maxBreak < iLunchLength) {
semesterViolations++;
}
}
// add the difference to the result
ret += semesterViolations - compactInfo.getLunchDayViolations()[i];
}
}
}
}
return ret;
}
示例8: getInfo
@Override
public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
Set<String> violatedLunchBreaks = new TreeSet<String>();
int lunchViolations = 0;
for (InstructorConstraint c : ((TimetableModel)getModel()).getInstructorConstraints()) {
String days = "";
CompactInfo compactInfo = ((InstructorLunchBreakContext)getContext(assignment)).getCompactInfo(c);
for (int i = 0; i < Constants.NR_DAYS; i++) {
if (compactInfo.getLunchDayViolations()[i] > 0) {
if (iFullInfo)
days += (days.isEmpty() ? "" : ", ") + compactInfo.getLunchDayViolations()[i] + " × " + Constants.DAY_NAMES_SHORT[i];
lunchViolations += compactInfo.getLunchDayViolations()[i];
}
}
if (iFullInfo && !days.isEmpty())
violatedLunchBreaks.add(c.getName() + ": " + days);
}
if (lunchViolations > 0) {
info.put("Lunch breaks", getPerc(lunchViolations, 0, ((TimetableModel)getModel()).getInstructorConstraints().size() * Constants.NR_DAYS * getWeeks().size()) + "% (" + lunchViolations + ")");
if (iFullInfo && !violatedLunchBreaks.isEmpty()) {
String message = "";
for (String s: violatedLunchBreaks)
message += (message.isEmpty() ? "" : "<br>") + s;
info.put("Lunch break violations", message);
}
}
}
示例9: updateLunchPenalty
/**
* Method updates number of violations in days (Mo, Tue, Wed,..) considering
* each week in the semester separately. The current number of violations
* for a day is stored in the CompactInfo.lunchDayViolations of the
* constraint, which must be set properly before the calling of the method.
*
* @param assignment current assignment
* @param constraint
* the Instructor constraint of an instructor checked for a lunch
* break
* @param p
* placement of a lecture currently (un)assigned
*/
public void updateLunchPenalty(Assignment<Lecture, Placement> assignment, InstructorConstraint constraint, Placement p) {
// checks only placements in the lunch time
if (p.getTimeLocation().getStartSlot() <= iLunchEnd && p.getTimeLocation().getStartSlot() + p.getTimeLocation().getLength() > iLunchStart) {
CompactInfo compactInfo = getCompactInfo(constraint);
for (int i = 0; i < Constants.NR_DAYS; i++) {
// checks only days affected by the placement
if ((p.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0) {
int currentLunchStartSlot = Constants.SLOTS_PER_DAY * i + iLunchStart;
int currentLunchEndSlot = Constants.SLOTS_PER_DAY * i + iLunchEnd;
int semesterViolations = 0;
for (BitSet week : getWeeks()) {
int maxBreak = 0;
int currentBreak = 0;
for (int slot = currentLunchStartSlot; slot < currentLunchEndSlot; slot++) {
if (constraint.getContext(assignment).getPlacements(slot, week).isEmpty()) {
currentBreak++;
if (maxBreak < currentBreak) {
maxBreak = currentBreak;
}
} else {
currentBreak = 0;
}
}
if (maxBreak < iLunchLength) {
semesterViolations++;
}
}
// saving the result in the CompactInfo of the
// InstructorConstraint
compactInfo.getLunchDayViolations()[i] = semesterViolations;
}
}
}
}
示例10: computeLunchPenalty
/**
* Method computes number of violations in days (Mo, Tue, Wed,..) considering
* each week in the semester separately. Updates the compact infos accordingly.
* @param assignment current assignment
* @param constraint instructor constraint
* @return current penalty for the given instructor
*/
public double computeLunchPenalty(Assignment<Lecture, Placement> assignment, InstructorConstraint constraint) {
double violations = 0d;
CompactInfo compactInfo = getCompactInfo(constraint);
for (int i = 0; i < Constants.NR_DAYS; i++) {
int currentLunchStartSlot = Constants.SLOTS_PER_DAY * i + iLunchStart;
int currentLunchEndSlot = Constants.SLOTS_PER_DAY * i + iLunchEnd;
int semesterViolations = 0;
for (BitSet week : getWeeks()) {
int maxBreak = 0;
int currentBreak = 0;
for (int slot = currentLunchStartSlot; slot < currentLunchEndSlot; slot++) {
if (constraint.getContext(assignment).getPlacements(slot, week).isEmpty()) {
currentBreak++;
if (maxBreak < currentBreak) {
maxBreak = currentBreak;
}
} else {
currentBreak = 0;
}
}
if (maxBreak < iLunchLength) {
semesterViolations++;
}
}
// saving the result in the CompactInfo of the
// InstructorConstraint
compactInfo.getLunchDayViolations()[i] = semesterViolations;
violations += semesterViolations;
}
return Math.pow(violations, iMultiplier);
}
示例11: countUselessSlotsBrokenTimePatterns
/** Number of useless slots for this room
* @param rc room constraint
* @return current penalty for the given room
**/
public static int countUselessSlotsBrokenTimePatterns(RoomConstraintContext rc) {
int ret = 0;
for (int d = 0; d < Constants.NR_DAYS; d++) {
for (int s = 0; s < Constants.SLOTS_PER_DAY; s++) {
int slot = d * Constants.SLOTS_PER_DAY + s;
if (rc.getPlacements(slot).isEmpty()) {
switch (d) {
case 0:
if (!rc.getPlacements(2 * Constants.SLOTS_PER_DAY + s).isEmpty() && !rc.getPlacements(4 * Constants.SLOTS_PER_DAY + s).isEmpty())
ret++;
break;
case 1:
if (!rc.getPlacements(3 * Constants.SLOTS_PER_DAY + s).isEmpty())
ret++;
break;
case 2:
if (!rc.getPlacements(0 * Constants.SLOTS_PER_DAY + s).isEmpty() && !rc.getPlacements(4 * Constants.SLOTS_PER_DAY + s).isEmpty())
ret++;
break;
case 3:
if (!rc.getPlacements(1 * Constants.SLOTS_PER_DAY + s).isEmpty())
ret++;
break;
case 4:
if (!rc.getPlacements(0 * Constants.SLOTS_PER_DAY + s).isEmpty() && !rc.getPlacements(2 * Constants.SLOTS_PER_DAY + s).isEmpty())
ret++;
break;
}
}
}
}
return ret;
}
示例12: nrSharedDays
/** number of overlapping days
* @param anotherLocation another time
* @return number of days of the week that the two times share
**/
public int nrSharedDays(TimeLocation anotherLocation) {
int ret = 0;
for (int i = 0; i < Constants.NR_DAYS; i++) {
if ((iDayCode & Constants.DAY_CODES[i]) == 0)
continue;
if ((anotherLocation.iDayCode & Constants.DAY_CODES[i]) == 0)
continue;
ret++;
}
return ret;
}
示例13: getNrDays
public int getNrDays() {
return Constants.NR_DAYS;
}
示例14: getLunchPreference
/**
* Method uses the CompactInfo of the InstructorConstraint and returns the
* lunch preference for this constraint. Calculation formula does not use
* linear function, the number of violations is multiplied by a power of
* iMultiplier.
*
* @param instructorConstraint
* the Instructor constraint of an instructor checked for a lunch
* break
* @return the lunch preference for this constraint
*/
private double getLunchPreference(Assignment<Lecture, Placement> assignment, InstructorConstraint instructorConstraint) {
double violations = 0d;
CompactInfo info = getCompactInfo(instructorConstraint);
for (int i = 0; i < Constants.NR_DAYS; i++)
violations += info.getLunchDayViolations()[i];
return Math.pow(violations, iMultiplier);
}