当前位置: 首页>>代码示例>>Java>>正文


Java Constants.DAY_CODES属性代码示例

本文整理汇总了Java中org.cpsolver.coursett.Constants.DAY_CODES属性的典型用法代码示例。如果您正苦于以下问题:Java Constants.DAY_CODES属性的具体用法?Java Constants.DAY_CODES怎么用?Java Constants.DAY_CODES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.cpsolver.coursett.Constants的用法示例。


在下文中一共展示了Constants.DAY_CODES属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNrViolations

@Override
public double getNrViolations(Assignment<Lecture, Placement> assignment, Set<Placement> conflicts, HashMap<Lecture, Placement> assignments){
    List<BitSet> weeks = getWeeks();

    int violatedDays = 0;
    for (int dayCode : Constants.DAY_CODES) {
        weekIteration: for (BitSet week : weeks) {
            Set<Placement> adepts = new HashSet<Placement>();
            List<Block> blocks = getBreakBlocks(assignment, dayCode, null, null, assignments, week);
            getAdeptsLunchBreak(blocks, adepts);
            if (!adepts.isEmpty())
                violatedDays++;
            break weekIteration;
        }
    }
    return violatedDays;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:17,代码来源:BreakFlexibleConstraint.java

示例2: candidates

public Set<Lecture> candidates(Placement value, Set<Placement> conflicts) {
    int bestCnt = 0;
    List<Integer> bestWeeks = new ArrayList<Integer>();
    for (int i = 0; i < iDayAssignments.length; i++) {
        if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0) continue;
        int cnt = iDayAssignments[i].size();
        if (iDayAssignments[i].contains(value.variable())) cnt --;
        for (Placement conflict: conflicts) {
            if (conflict.variable().equals(value.variable())) continue;
            if (iDayAssignments[i].contains(conflict.variable())) cnt --;
        }
        if (cnt <= 0) continue;
        if (bestWeeks.isEmpty() || bestCnt > cnt) {
            bestWeeks.clear(); bestWeeks.add(i); bestCnt = cnt;
        } else if (bestCnt == cnt) {
            bestWeeks.add(i);
        }
    }
    return bestWeeks.isEmpty() ? null : iDayAssignments[ToolBox.random(bestWeeks)];
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:20,代码来源:MaxDaysFlexibleConstraint.java

示例3: getNrViolations

/**
 * Count violations, that is weekly average free time that is over the limit in hours.
 * @param assignment current assignment
 * @param conflicts placements to be unassigned
 * @param assignments placements of variables
 * @return weekly average free time that is over the limit in hours
 */
@Override
public double getNrViolations(Assignment<Lecture, Placement> assignment, Set<Placement> conflicts, HashMap<Lecture, Placement> assignments) {
    double penalty = 0;
    // constraint is checked for every day in week
    for (int dayCode : Constants.DAY_CODES) {
        // constraint is checked for every week in semester (or for the whole semester)
        for (BitSet week : getWeeks()) {
            // count holes in the week and day
            int holes = countHoles(assignment, dayCode, conflicts, null, assignments, week);
            if (holes > iMaxHolesOnADay)
                penalty += (holes - iMaxHolesOnADay);
        }
    }
    // return average holes in a week, in hours
    return penalty / (12.0 * getWeeks().size());
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:23,代码来源:MaxHolesFlexibleConstraint.java

示例4: nrHalfDays

public int nrHalfDays(Placement value, Set<Placement> conflicts) {
    int ret = 0;
    for (int i = 0; i < Constants.DAY_CODES.length; i++) {
        for (int j = 0; j < getNrHalfDays(); j++) {
            int idx = i * getNrHalfDays() + j;
            int cnt = iHalfDayAssignments[idx].size();
            if (value != null) {
                if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0 && j == getHalfDay(value.getTimeLocation())) cnt ++;
                if (iHalfDayAssignments[idx].contains(value.variable())) cnt --; 
            }
            if (conflicts != null) {
                for (Placement conflict: conflicts) {
                    if (value != null && conflict.variable().equals(value.variable())) continue;
                    if (iHalfDayAssignments[idx].contains(conflict.variable())) cnt --;
                }
            }
            if (cnt > 0) ret++;                    
        }
    }
    return ret;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:21,代码来源:MaxHalfDaysFlexibleConstraint.java

示例5: getPenaltyIfUnassigned

private int getPenaltyIfUnassigned(Assignment<Lecture, Placement> assignment, Placement placement, int[][] nrCourses) {
    SpreadConstraintContext context = getContext(assignment);
    int firstSlot = placement.getTimeLocation().getStartSlot();
    if (firstSlot > iLastDaySlot)
        return 0;
    int endSlot = firstSlot + placement.getTimeLocation().getNrSlotsPerMeeting() - 1;
    if (endSlot < iFirstDaySlot)
        return 0;
    int penalty = 0;
    for (int i = Math.max(firstSlot, iFirstDaySlot); i <= Math.min(endSlot, iLastDaySlot); i++) {
        for (int j = iFirstWorkDay; j <= iLastWorkDay; j++) {
            int dayCode = Constants.DAY_CODES[j % 7];
            if ((dayCode & placement.getTimeLocation().getDayCode()) != 0 && nrCourses[i - iFirstDaySlot][j - iFirstWorkDay] > context.getMaxCourses(i, j))
                penalty++;
        }
    }
    return penalty;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:18,代码来源:SpreadConstraint.java

示例6: tryUnassign

private int tryUnassign(Assignment<Lecture, Placement> assignment, Placement placement, int[][] nrCourses) {
    SpreadConstraintContext context = getContext(assignment);
    // sLogger.debug("  -- trying to unassign "+placement);
    int firstSlot = placement.getTimeLocation().getStartSlot();
    if (firstSlot > iLastDaySlot)
        return 0;
    int endSlot = firstSlot + placement.getTimeLocation().getNrSlotsPerMeeting() - 1;
    if (endSlot < iFirstDaySlot)
        return 0;
    int improvement = 0;
    for (int i = Math.max(firstSlot, iFirstDaySlot); i <= Math.min(endSlot, iLastDaySlot); i++) {
        for (int j = iFirstWorkDay; j <= iLastWorkDay; j++) {
            int dayCode = Constants.DAY_CODES[j % 7];
            if ((dayCode & placement.getTimeLocation().getDayCode()) != 0) {
                if (nrCourses[i - iFirstDaySlot][j - iFirstWorkDay] > context.getMaxCourses(i, j))
                    improvement++;
                nrCourses[i - iFirstDaySlot][j - iFirstWorkDay]--;
            }
        }
    }
    // sLogger.debug("  -- penalty is decreased by "+improvement);
    return improvement;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:23,代码来源:SpreadConstraint.java

示例7: unassigned

@Override
public void unassigned(Assignment<Lecture, Placement> assignment, Placement placement) {
    int firstSlot = placement.getTimeLocation().getStartSlot();
    if (firstSlot > iLastDaySlot)
        return;
    int endSlot = firstSlot + placement.getTimeLocation().getNrSlotsPerMeeting() - 1;
    if (endSlot < iFirstDaySlot)
        return;
    getCriterion().inc(assignment, -iCurrentPenalty);
    for (int i = Math.max(firstSlot, iFirstDaySlot); i <= Math.min(endSlot, iLastDaySlot); i++) {
        for (int j = iFirstWorkDay; j <= iLastWorkDay; j++) {
            int dayCode = Constants.DAY_CODES[j % 7];
            if ((dayCode & placement.getTimeLocation().getDayCode()) != 0) {
                if (iCourses[i - iFirstDaySlot][j - iFirstWorkDay].size() > iMaxCourses[i - iFirstDaySlot][j - iFirstWorkDay])
                    iCurrentPenalty--;
                iCourses[i - iFirstDaySlot][j - iFirstWorkDay].remove(placement);
            }
        }
    }
    getCriterion().inc(assignment, iCurrentPenalty);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:21,代码来源:SpreadConstraint.java

示例8: nrViolations

public int nrViolations(HashMap<Lecture, Placement> assignments, Set<Placement> conflicts) {
    int halfDays = 0;
    for (int i = 0; i < Constants.DAY_CODES.length; i++) {
        for (int j = 0; j < getNrHalfDays(); j++) {
            int idx = i * getNrHalfDays() + j;
            int cnt = iHalfDayAssignments[idx].size();
            if (assignments != null) {
                for (Map.Entry<Lecture, Placement> entry: assignments.entrySet()) {
                    Placement assignment = entry.getValue();
                    if (assignment != null && (assignment.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0 && j == getHalfDay(assignment.getTimeLocation())) cnt ++;
                }
            }
            if (conflicts != null)
                for (Placement conflict: conflicts) {
                    if (assignments != null && assignments.containsKey(conflict.variable())) continue;
                    if (iHalfDayAssignments[idx].contains(conflict.variable())) cnt --;
                }
            if (cnt > 0) halfDays ++;
        }
    }
    return (halfDays <= iMaxHalfDays ? 0 : halfDays - iMaxHalfDays);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:22,代码来源:MaxHalfDaysFlexibleConstraint.java

示例9: 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;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:15,代码来源:TimeLocation.java

示例10: nrDays

public int nrDays() {
    int ret = 0;
    for (int i = 0; i < Constants.DAY_CODES.length; i++) {
        if ((getDays() & Constants.DAY_CODES[i]) != 0)
            ret++;
    }
    return ret;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:8,代码来源:MinimizeNumberOfUsedGroupsOfTime.java

示例11: 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;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:39,代码来源:InstructorLunchBreak.java

示例12: isPrecedence

private boolean isPrecedence(Placement p1, Placement p2, boolean firstGoesFirst, boolean considerDatePatterns) {
    int ord1 = variables().indexOf(p1.variable());
    int ord2 = variables().indexOf(p2.variable());
    TimeLocation t1 = null, t2 = null;
    if (ord1 < ord2) {
        if (firstGoesFirst) {
            t1 = p1.getTimeLocation();
            t2 = p2.getTimeLocation();
        } else {
            t2 = p1.getTimeLocation();
            t1 = p2.getTimeLocation();
        }
    } else {
        if (!firstGoesFirst) {
            t1 = p1.getTimeLocation();
            t2 = p2.getTimeLocation();
        } else {
            t2 = p1.getTimeLocation();
            t1 = p2.getTimeLocation();
        }
    }
    if (considerDatePatterns && iPrecedenceConsiderDatePatterns) {
        boolean sameDatePattern = (t1.getDatePatternId() != null ? t1.getDatePatternId().equals(t2.getDatePatternId()) : t1.getWeekCode().equals(t2.getWeekCode()));
        if (!sameDatePattern) {
        	int m1 = t1.getFirstMeeting(iDayOfWeekOffset), m2 = t2.getFirstMeeting(iDayOfWeekOffset);
            if (m1 != m2) return m1 < m2;
        }
    }
    if (iFirstWorkDay != 0) {
        for (int i = 0; i < Constants.DAY_CODES.length; i++) {
            int idx = (i + iFirstWorkDay) % 7;
            boolean a = (t1.getDayCode() & Constants.DAY_CODES[idx]) != 0;
            boolean b = (t2.getDayCode() & Constants.DAY_CODES[idx]) != 0;
            if (b && !a) return false; // second start first
            if (a && !b) return true;  // first start first
            if (a && b) return t1.getStartSlot() + t1.getLength() <= t2.getStartSlot(); // same day: check times
        }
    }
    return t1.getStartSlots().nextElement() + t1.getLength() <= t2.getStartSlots().nextElement();
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:40,代码来源:GroupConstraint.java

示例13: getDayHeader

/** Days for printing purposes 
 * @return day header (e.g., MWF for Monday - Wednesday - Friday time)
 **/
public String getDayHeader() {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < Constants.DAY_CODES.length; i++)
        if ((iDayCode & Constants.DAY_CODES[i]) != 0)
            sb.append(Constants.DAY_NAMES_SHORT[i]);
    return sb.toString();
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:10,代码来源:TimeLocation.java

示例14: isFollowingDay

private boolean isFollowingDay(Placement p1, Placement p2, boolean firstGoesFirst) {
    int ord1 = variables().indexOf(p1.variable());
    int ord2 = variables().indexOf(p2.variable());
    TimeLocation t1 = null, t2 = null;
    if (ord1 < ord2) {
        if (firstGoesFirst) {
            t1 = p1.getTimeLocation();
            t2 = p2.getTimeLocation();
        } else {
            t2 = p1.getTimeLocation();
            t1 = p2.getTimeLocation();
        }
    } else {
        if (!firstGoesFirst) {
            t1 = p1.getTimeLocation();
            t2 = p2.getTimeLocation();
        } else {
            t2 = p1.getTimeLocation();
            t1 = p2.getTimeLocation();
        }
    }
    int f1 = -1, f2 = -1, e1 = -1;
    for (int i = 0; i < Constants.DAY_CODES.length; i++) {
        int idx = (i + iFirstWorkDay) % 7;
        if ((t1.getDayCode() & Constants.DAY_CODES[idx]) != 0) {
            if (f1 < 0)
                f1 = i;
            e1 = i;
        }
        if ((t2.getDayCode() & Constants.DAY_CODES[idx]) != 0) {
            if (f2 < 0)
                f2 = i;
        }
    }
    return ((e1 + 1) % iNrWorkDays == f2);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:36,代码来源:GroupConstraint.java

示例15: assigned

@Override
public void assigned(Assignment<Lecture, Placement> assignment, Placement value) {
    for (int i = 0; i < iDayAssignments.length; i++)
        if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0)
            iDayAssignments[i].add(value.variable());
    updateCriterion(assignment);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:7,代码来源:MaxDaysFlexibleConstraint.java


注:本文中的org.cpsolver.coursett.Constants.DAY_CODES属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。