【问题标题】:To satisfy x out of y constraints满足 x out of y 约束
【发布时间】:2012-03-26 14:21:30
【问题描述】:

我正在制作一个时间表程序,它一对一匹配从SubjectTeacherPeriod(计划实体)到Period。有一种情况我需要:“对于 y 个周期,SubjectTeacherPeriod 中的至少 x 个必须匹配 match_condition

例如,我想限制 3 个特定时期,其中至少两个由与 asst prof 匹配的教师教授。

这是持有这种约束的数据结构:

Class XOfYPeriods
  SomeType match_condition 
  int x
  List<Period> Periods //problem 

SubjectTeacherPeriod 当然有Period

class SubjectTeacherPeriod
  int id
  SomeType attrib
  Period period

如何编写一个规则来评估 列表 中的单个 Periods 以检查分配给这些 Periods 的 x 个 SubjectTeacherPeriods 是否满足匹配条件?

如果我以错误的形式定义我的类,请纠正我。

为了举例,这里有一个要评估以确定匹配的语句:eval(matches($stp_attrib,$match_condition))


很抱歉使用伪代码,如果它混淆了多于澄清。 SomeType 实际上是 List ,因此使用 Collections.disjoint 检查匹配条件

【问题讨论】:

    标签: drools drools-planner


    【解决方案1】:

    我会试一试,但不确定我是否完全理解您的问题陈述:

    rule "X of Y Periods"
    when
        $c : XOfYPeriods( )
        $list : List( size > $c.x ) from
            accumulate( $stp : SubjectTeacherPeriod( matches(attrib, $c.match_condition),
                                                     period memberOf $c.periods ),
                        collectList( $stp ) )
    then
        // $list of STP that match the condition and 
        // whose period matches one of the periods in the list
    end
    

    希望对你有帮助。

    【讨论】:

    • 是的,我需要使用accumulatememberOf
    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 2016-11-01
    • 2015-08-24
    • 2018-04-11
    相关资源
    最近更新 更多