public String determinePlanningEntityTooltip(Object planningEntity) { Indictment indictment = solutionBusiness.getIndictmentMap().get(planningEntity); if (indictment == null) { return "<html>No indictment</html>"; } StringBuilder s = new StringBuilder("<html>Indictment: ").append(indictment.getScore().toShortString()); for (ConstraintMatch constraintMatch : indictment.getConstraintMatchSet()) { s.append("<br/> ").append(constraintMatch.getConstraintName()) .append(" = ").append(constraintMatch.getScore().toShortString()); } s.append("</html>"); return s.toString(); }
protected void registerConstraintMatch(RuleContext kcontext, final Runnable constraintUndoListener, Supplier<Score_> scoreSupplier) { AgendaItem<?> agendaItem = (AgendaItem) kcontext.getMatch(); ConstraintActivationUnMatchListener constraintActivationUnMatchListener = new ConstraintActivationUnMatchListener(constraintUndoListener); agendaItem.setCallback(constraintActivationUnMatchListener); if (constraintMatchEnabled) { List<Object> justificationList = extractJustificationList(kcontext); // Not needed in fast code: Add ConstraintMatch constraintActivationUnMatchListener.constraintMatchTotal = findConstraintMatchTotal(kcontext); ConstraintMatch constraintMatch = constraintActivationUnMatchListener.constraintMatchTotal .addConstraintMatch(justificationList, scoreSupplier.get()); List<Indictment> indictmentList = justificationList.stream() .distinct() // One match might have the same justification twice .map(justification -> { Indictment indictment = indictmentMap.computeIfAbsent(justification, k -> new Indictment(justification, zeroScore)); indictment.addConstraintMatch(constraintMatch); return indictment; }).collect(Collectors.toList()); constraintActivationUnMatchListener.constraintMatch = constraintMatch; constraintActivationUnMatchListener.indictmentList = indictmentList; } }
.limit(INDICTMENT_LIMIT) .forEach(indictment -> { Set<ConstraintMatch> constraintMatchSet = indictment.getConstraintMatchSet(); scoreExplanation .append(" ").append(indictment.getScore().toShortString()) .append(": justification (").append(indictment.getJustification()) .append(") has ").append(constraintMatchSet.size()).append(" matches:\n"); constraintMatchSet.stream()
/** * @return never null * @deprecated in favor of {@link #getScore()} */ @Deprecated public Score getScoreTotal() { return getScore(); }
@Test public void getScoreTotal() { TestdataEntity e1 = new TestdataEntity("e1"); TestdataEntity e2 = new TestdataEntity("e2"); TestdataEntity e3 = new TestdataEntity("e3"); Indictment indictment = new Indictment(e1, SimpleScore.ZERO); assertEquals(SimpleScore.ZERO, indictment.getScore()); ConstraintMatch match1 = new ConstraintMatch("package1", "constraint1", asList(e1), SimpleScore.of(-1)); indictment.addConstraintMatch(match1); assertEquals(SimpleScore.of(-1), indictment.getScore()); // Different constraintName ConstraintMatch match2 = new ConstraintMatch("package1", "constraint2", asList(e1), SimpleScore.of(-20)); indictment.addConstraintMatch(match2); assertEquals(SimpleScore.of(-21), indictment.getScore()); indictment.addConstraintMatch(new ConstraintMatch("package1", "constraint3", asList(e1, e2), SimpleScore.of(-300))); assertEquals(SimpleScore.of(-321), indictment.getScore()); // Different justification indictment.addConstraintMatch(new ConstraintMatch("package1", "constraint3", asList(e1, e3), SimpleScore.of(-4000))); assertEquals(SimpleScore.of(-4321), indictment.getScore()); // Almost duplicate, but e2 and e1 are in reverse order, so different justification indictment.addConstraintMatch(new ConstraintMatch("package1", "constraint3", asList(e2, e1), SimpleScore.of(-50000))); assertEquals(SimpleScore.of(-54321), indictment.getScore()); indictment.removeConstraintMatch(match2); assertEquals(SimpleScore.of(-54301), indictment.getScore()); indictment.removeConstraintMatch(match1); assertEquals(SimpleScore.of(-54300), indictment.getScore()); }
/** * @return {@code >= 0} */ public int getConstraintMatchCount() { return getConstraintMatchSet().size(); }
@Test public void compareTo() { PlannerAssert.assertCompareToOrder( new Indictment("a", SimpleScore.ZERO), new Indictment("aa", SimpleScore.ZERO), new Indictment("ab", SimpleScore.ZERO), new Indictment("b", SimpleScore.ZERO), new Indictment("c", SimpleScore.ZERO), new Indictment("d", SimpleScore.ZERO) ); }
void nextMeetingAssignmentListCell(List<MeetingAssignment> meetingAssignmentList, Function<MeetingAssignment, String> stringFunction, List<String> filteredConstraintNames) { if (meetingAssignmentList == null) { meetingAssignmentList = Collections.emptyList(); } HardMediumSoftScore score = meetingAssignmentList.stream() .map(indictmentMap::get).filter(Objects::nonNull) .flatMap(indictment -> indictment.getConstraintMatchSet().stream()) // Filter out filtered constraints .filter(constraintMatch -> filteredConstraintNames == null || filteredConstraintNames.contains(constraintMatch.getConstraintName())) .map(constraintMatch -> (HardMediumSoftScore) constraintMatch.getScore()) // Filter out positive constraints .filter(indictmentScore -> !(indictmentScore.getHardScore() >= 0 && indictmentScore.getSoftScore() >= 0)) .reduce(Score::add).orElse(HardMediumSoftScore.ZERO); XSSFCell cell = getXSSFCellOfScore(score); if (!meetingAssignmentList.isEmpty()) { ClientAnchor anchor = creationHelper.createClientAnchor(); anchor.setCol1(cell.getColumnIndex()); anchor.setCol2(cell.getColumnIndex() + 4); anchor.setRow1(currentRow.getRowNum()); anchor.setRow2(currentRow.getRowNum() + 4); Comment comment = currentDrawing.createCellComment(anchor); String commentString = getMeetingAssignmentListString(meetingAssignmentList); comment.setString(creationHelper.createRichTextString(commentString)); cell.setCellComment(comment); } cell.setCellValue(meetingAssignmentList.stream().map(stringFunction).collect(joining("\n"))); currentRow.setHeightInPoints(Math.max(currentRow.getHeightInPoints(), meetingAssignmentList.size() * currentSheet.getDefaultRowHeightInPoints())); }
@Test public void equalsAndHashCode() { PlannerAssert.assertObjectsAreEqual( new Indictment("e1", SimpleScore.ZERO), new Indictment("e1", SimpleScore.ZERO), new Indictment("e1", SimpleScore.of(-7)) ); PlannerAssert.assertObjectsAreNotEqual( new Indictment("a", SimpleScore.ZERO), new Indictment("aa", SimpleScore.ZERO), new Indictment("b", SimpleScore.ZERO), new Indictment("c", SimpleScore.ZERO) ); }
commentString.append("\n").append(indictment.getScore().toShortString()) .append(" total"); Set<ConstraintMatch> constraintMatchSet = indictment.getConstraintMatchSet(); List<String> constraintNameList = constraintMatchSet.stream() .map(ConstraintMatch::getConstraintName).distinct().collect(toList());
public List<RotationViolationPenalty> getRotationViolationPenaltyList(Indictment indictment) { if (indictment == null) { return Collections.emptyList(); } return indictment.getConstraintMatchSet().stream() .filter(cm -> cm.getConstraintPackage().equals(CONSTRAINT_MATCH_PACKAGE) && cm.getConstraintName().equals("Employee is not rotation employee")) .map(cm -> new RotationViolationPenalty((Shift) cm.getJustificationList().get(0), (HardMediumSoftLongScore) cm.getScore())) .collect(Collectors.toList()); }
@Override public Map<Object, Indictment> getIndictmentMap() { if (!isConstraintMatchEnabled()) { throw new IllegalStateException("When constraintMatchEnabled (" + isConstraintMatchEnabled() + ") is disabled in the constructor, this method should not be called."); } Map<Object, Indictment> incrementalIndictmentMap = ((ConstraintMatchAwareIncrementalScoreCalculator<Solution_>) incrementalScoreCalculator) .getIndictmentMap(); if (incrementalIndictmentMap != null) { return incrementalIndictmentMap; } Map<Object, Indictment> indictmentMap = new LinkedHashMap<>(); // TODO use entitySize Score zeroScore = getScoreDefinition().getZeroScore(); for (ConstraintMatchTotal constraintMatchTotal : getConstraintMatchTotals()) { for (ConstraintMatch constraintMatch : constraintMatchTotal.getConstraintMatchSet()) { constraintMatch.getJustificationList().stream() .distinct() // One match might have the same justification twice .forEach(justification -> { Indictment indictment = indictmentMap.computeIfAbsent(justification, k -> new Indictment(justification, zeroScore)); indictment.addConstraintMatch(constraintMatch); }); } } return indictmentMap; }
.map(indictmentMap::get) .filter(Objects::nonNull) .flatMap(indictment -> indictment.getConstraintMatchSet().stream()) Indictment indictment = indictmentMap.get(talk); if (indictment != null) { commentString.append("\n").append(indictment.getScore().toShortString()) .append(" total"); Set<ConstraintMatch> constraintMatchSet = indictment.getConstraintMatchSet().stream() .filter(constraintMatch -> filteredConstraintNameList == null || filteredConstraintNameList.contains(constraintMatch.getConstraintName()))
protected void preparePlanningEntityColors(List<?> planningEntityList) { if (useIndictmentColor) { indictmentMinimumLevelNumbers = null; for (Object planningEntity : planningEntityList) { Indictment indictment = solutionBusiness.getIndictmentMap().get(planningEntity); if (indictment != null) { Number[] levelNumbers = indictment.getScore().toLevelNumbers(); if (indictmentMinimumLevelNumbers == null) { indictmentMinimumLevelNumbers = new double[levelNumbers.length]; for (int i = 0; i < levelNumbers.length; i++) { indictmentMinimumLevelNumbers[i] = levelNumbers[i].doubleValue(); } } else { for (int i = 0; i < levelNumbers.length; i++) { double levelNumber = levelNumbers[i].doubleValue(); if (levelNumber < indictmentMinimumLevelNumbers[i]) { indictmentMinimumLevelNumbers[i] = levelNumber; } } } } } } else { normalColorFactory = new TangoColorFactory(); } }
public List<RequiredSkillViolation> getRequiredSkillViolationList(Indictment indictment) { if (indictment == null) { return Collections.emptyList(); } return indictment.getConstraintMatchSet().stream() .filter(cm -> cm.getConstraintPackage().equals(CONSTRAINT_MATCH_PACKAGE) && cm.getConstraintName().equals("Required skill for a shift")) .map(cm -> new RequiredSkillViolation((Shift) cm.getJustificationList().get(0), (HardMediumSoftLongScore) cm.getScore())) .collect(Collectors.toList()); }
public String determinePlanningEntityTooltip(Object planningEntity) { Indictment indictment = solutionBusiness.getIndictmentMap().get(planningEntity); if (indictment == null) { return "<html>No indictment</html>"; } StringBuilder s = new StringBuilder("<html>Indictment: ").append(indictment.getScore().toShortString()); for (ConstraintMatch constraintMatch : indictment.getConstraintMatchSet()) { s.append("<br/> ").append(constraintMatch.getConstraintName()) .append(" = ").append(constraintMatch.getScore().toShortString()); } s.append("</html>"); return s.toString(); }
public Color determinePlanningEntityColor(Object planningEntity, Object normalColorObject) { if (useIndictmentColor) { Indictment indictment = solutionBusiness.getIndictmentMap().get(planningEntity); if (indictment != null) { Number[] levelNumbers = indictment.getScore().toLevelNumbers(); for (int i = 0; i < levelNumbers.length; i++) { if (i > INDICTMENT_COLORS.length) { return TangoColorFactory.ALUMINIUM_3; } double levelNumber = levelNumbers[i].doubleValue(); if (levelNumber < 0.0) { return TangoColorFactory.buildPercentageColor( INDICTMENT_COLORS[i][0], INDICTMENT_COLORS[i][1], 1.0 - (levelNumber / indictmentMinimumLevelNumbers[i])); } } } return Color.WHITE; } else { return normalColorFactory.pickColor(normalColorObject); } }
public List<UnassignedShiftPenalty> getUnassignedShiftPenaltyList(Indictment indictment) { if (indictment == null) { return Collections.emptyList(); } return indictment.getConstraintMatchSet().stream() .filter(cm -> cm.getConstraintPackage().equals(CONSTRAINT_MATCH_PACKAGE) && cm.getConstraintName().equals("Assign every shift")) .map(cm -> new UnassignedShiftPenalty((Shift) cm.getJustificationList().get(0), (HardMediumSoftLongScore) cm.getScore())) .collect(Collectors.toList()); } }