OptaPlanner 中的 Count 与 CountDistinct
Count vs. CountDistinct in OptaPlanner
the docs 中关于 ConstraintCollectors
' count()
和 countDistinct()
的例子不是很清楚:
The ConstraintCollectors.count(…)
counts all elements in a group.
The ConstraintCollectors.countDistinct(…)
counts any element in a group once, regardless of how many times it occurs.
我看不出两者之间的区别。当与 groupBy()
组合时,它们不都是 return 一个 BiConstraintStream<A, Integer>
表示 A
及其对应计数的组的元组吗?
这些方法缺少 javadoc 和一些示例:https://issues.redhat.com/browse/PLANNER-2241
计数:
from([
Person("Ann", "Cole", 20),
Person("Beth", "Cole", 20),
Person("Carl", "Cole", 22),
Person("Dan", "Jones", 20)
]).groupBy(Person::getLastName, count())
returns [{"Cole", 3}, {"Jones", 1}]
countDistinct:
from([
Person("Ann", "Cole", 20),
Person("Beth", "Cole", 20),
Person("Carl", "Cole", 30),
Person("Dan", "Jones", 20)
]).groupBy(Person::getLastName, countDistinct(Person::getAge))
returns [{"Cole", 2}, {"Jones", 1}]
这些例子是否说明了区别?
the docs 中关于 ConstraintCollectors
' count()
和 countDistinct()
的例子不是很清楚:
The
ConstraintCollectors.count(…)
counts all elements in a group.
TheConstraintCollectors.countDistinct(…)
counts any element in a group once, regardless of how many times it occurs.
我看不出两者之间的区别。当与 groupBy()
组合时,它们不都是 return 一个 BiConstraintStream<A, Integer>
表示 A
及其对应计数的组的元组吗?
这些方法缺少 javadoc 和一些示例:https://issues.redhat.com/browse/PLANNER-2241
计数:
from([
Person("Ann", "Cole", 20),
Person("Beth", "Cole", 20),
Person("Carl", "Cole", 22),
Person("Dan", "Jones", 20)
]).groupBy(Person::getLastName, count())
returns [{"Cole", 3}, {"Jones", 1}]
countDistinct:
from([
Person("Ann", "Cole", 20),
Person("Beth", "Cole", 20),
Person("Carl", "Cole", 30),
Person("Dan", "Jones", 20)
]).groupBy(Person::getLastName, countDistinct(Person::getAge))
returns [{"Cole", 2}, {"Jones", 1}]
这些例子是否说明了区别?