【问题标题】:How to update state of list so that Rete picks up the objects added therein for rules re-evaluation如何更新列表的状态,以便 Rete 拾取其中添加的对象以重新评估规则
【发布时间】:2019-01-28 20:38:05
【问题描述】:

我使用的是 IBM 8.9.2,我们有一个场景,我需要根据列表 Y 中的值创建一个列表 X,同时对这些值进行分组。
例如,假设我有一个城市列表,并且每个 City 对象(在 cityList 列表中)都有一个属性 - 国家。现在我想反转关系并创建一个 countries 列表,该列表由具有 containedCities 列表的 Country 对象组成。

我的规则是

definitions
    set 'cities' to all cities in cityList;
    set 'a city' to a city in 'cities'
    set 'countries' to all countries in countryList;
    set 'a country' to a country in 'countries'

if 
    the country code of 'a city' is the country code of 'a country'
then
     add 'a city' to the contained cities of 'a country' ; (** Assume B2X/XOM has method for adding the city to the country list)
else
      create country for 'a city' and add it to countryList ; (** Assume appropriate B2X/XOM)

将国家添加到 countryList 不会更新其对象状态,因此不会在为 cityList 的第一个城市运行规则后将其重新引入议程以重新评估规则。
因此,结果是一个国家列表,其中为每个城市创建了一个新的 Country 对象,而不是计划的分组。
我的目标是在内存中插入 cityList 和 countryList 并打开 Rete 以便模式匹配可以在内存中即时发生。

寻找有关如何实现这一目标的指示。

【问题讨论】:

    标签: ibm-odm rete


    【解决方案1】:

    我会写两个单独的规则。 一个将每个城市的国家添加到国家列表中。 另一个将每个城市添加到相应的国家。 两种 BOM 的“添加”方法都应选中“更新对象状态”。 注意:我已将 cmets 添加到 ODM 不允许的规则中。

    第一条规则

    definitions
        set 'the city' to a city in cityList ;
    
    if 
        the country code of 'the city' is not one of the country codes of countryList // Assume BOM method exists
    then
         add the country code of 'the city' to the country codes of countryList ; // Assume BOM method exists
    

    第二条规则

    definitions
        set 'the city' to a city in cityList ;
        set 'the country' to a country in countryList 
            where the country code of this country is the country code of 'the city';
    
    if 
        'the city' is not one of the cities of 'the country' // Requires City.equals method
    then
         add 'the city' to the cities of 'the country' ; // Assume BOM method exists
    

    【讨论】:

    • 谢谢@Greg。这完全符合我的期望。一个小提示——规则1的国家列表和城市列表应该属于同一个对象,这样对象状态更新通知才有效。
    猜你喜欢
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    相关资源
    最近更新 更多