« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
| 公告 |

|
Blog信息 |
blog名称:彼岸·花 日志总数:39 评论数量:115 留言数量:-16 访问次数:403560 建立时间:2005年8月6日 |

| |
[一路前行]专家系统JESS实例教程 文章收藏
子轩 发表于 2006/12/5 9:55:25 |
我们假设有一个交易系统,客户提出要买的东西,卖家提供要买的东西,如果有符合的,就成交。这是一个很简单的系统,用一般程序语言也可以实现,但是我们看看专家系统开发更简单的方法。
1第一条规则
如果来了新的客户,取得这个客户所有需要的商品,并产生新的事实。
(defrule query-buyer ?fact <- (new-buyer ?buyer) ; if there is a new a buyer...=> (retract ?fact) (foreach ?i (nth$ 2 (send ?buyer "GetProducts")) (assert (requires ?buyer ?i)) ; get the products the buyer requires ; and for each one create a fact ; associating the buyer and the product ))
例如,来了一个客户Danny,我们先assert(new-buyer danny) ,jess发现了这条事实后,触发query-buyer这个规则,注意所有的规则之间没有顺序性。query-buyer这条规则先撤销刚才的事实,避免死循环,然后调用一个函数取得用户所有需要的商品Send ?buyer "GetProducts".例如得到的结果是(Computer Keyboard Mouse),然后规则遍历这个结果集,每一个商品都产生一个新的事实,例如assert requires Danny Computer等等。
2 第二个规则,出现一个新卖家,原理和刚才一样
(defrule query-seller ?fact <- (new-seller ?seller) ; if there is a new seller...=> (retract ?fact) (foreach ?i (nth$ 2 (send ?seller "GetProducts")) (assert (provides ?seller ?i)) ; get the products the seller provides ; and for each one create a fact ; associating the seller and the product ))
3 最后一个是交易的规则
当有买家购买一个商品,卖家卖一个商品,并且两者相同的事实时候,告诉卖家有人要买该物品,同时也告诉买家有卖家投递该物品
(defrule match-buyer-and-seller (requires ?buyer ?product1) ; the buyer requires product1 (provides ?seller ?product2) ; the seller provides product2 (test (eq ?product1 ?product2)) ; product1 and product2 are the same=> (send ?seller "Order" ?product2) ; order from the seller (send ?buyer "Delivery" ?product1) ; deliver to the buyer)
从这个规则中,我们看到,实现这样一个交易市场的系统,没有任何遍历所有买家和卖家进行比较的操作。这些匹配是JESS自动模式匹配完成的,大大简化了开发。
使用专家系统,我们可以通过定义规则的方式来积累经验,而不是通过If else这样的代码来积累经验。
转载自: http://blog.csdn.net/danny_xcz/archive/2005/11/17/531463.aspx |
|
回复:专家系统JESS实例教程 文章收藏
suzie(游客)发表评论于2009/9/3 10:39:09 |
|
回复:专家系统JESS实例教程 文章收藏
RGES(游客)发表评论于2009/3/31 10:22:28 |
金属软管、北京金属软管、不锈钢金属软管、不锈钢软管、波纹补偿器、波纹管、四氟软管、治疗近视、近视治疗、喷码机 广告 广告机、液晶广告机、网络广告机、框架广告机、展架、货架展架、铁艺展架、展柜、工作服 |
|
回复:专家系统JESS实例教程 文章收藏
jiajia(游客)发表评论于2007/11/26 16:00:34 |
很好的入门的例子,我还有个规则自己看不懂,能请教一下吗,我的QQ:623589023 |
|
» 1 »
|