[rust-021]如何把production加入到规则引擎的网络

Production,产生式规则。

在开源框架,对应的代码如下:

    pub fn add_production(&mut self, production: Production) {
        let log = self.log.new(o!("production_id" => production.id.0));
        trace!(log, "add production"; "production" => ?production);

        if production.conditions.is_empty() {
            error!(log, "production has no conditions");
            return;
        }

        //dummy node是整个网络的root节点。获取dummy node id,以遍历整个网络
        // rete网络参考《Production Matching for Large Learning Systems》第10页。
        let mut current_node_id = self.dummy_node_id;

        //每个产生式规则,if conditions then actoion。
        // 每个产生式规则,有一个或者多个condtion,逐个condition遍历,加入网络
        for i in 0..production.conditions.len() {
            //处理第N个条件
            let condition = production.conditions[i];
            trace!(log, "add condition"; "condition" => ?condition);

            // build or share alpha memory
            // 从condition生成alpha test
            let alpha_test = AlphaTest::from(condition);
            // Returns either an existing id or generates a new one.
            // 如果alpha test的id是已存的,返回id,如果不存在,生成新id,以便创建新alpha memory
            let alpha_memory_id = self
                .alpha_tests
                .get(&alpha_test)
                .cloned()
                .unwrap_or_else(|| AlphaMemoryId(self.id_generator.next()));
            // If we need a new alpha memory, create it.
            // 如果没有alpha memory,创建一个
            if !self.alpha_network.contains_key(&alpha_memory_id) {
                // Collect the WMEs that should already be in this
                // memory.
                // 创造一个alpha memory,需要将符合这个alpha test的wme找出来,存储到alpha memory
                let wmes &
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值