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 &