使用剪辑的条件或选择性规则

2024-03-11

我希望你过得很好?我是 CLIPS 的初学者。我有一个包含多个节点(起始节点(输入)和结束节点(输出))的图表。我想在输入数量等于输出的情况下创建一个规则,该规则必须帮助我在几个节点之间进行选择组合(起始节点和结束节点)每个组合的最短路径。

如果我输入的数量大于输出的数量或相反,则可以添加与之前相同的规则的另一个规则。在组合之间进行选择后,还需要考虑输入或输出并将其推向最近的点?

(deftemplate path
(slot start) 
(slot end)
(multislot path) 
(slot cost(type NUMBER)))

(deftemplate info
(slot start) 
(slot end)
(multislot path) 
(slot cost))




(deffacts variable_table

(path (start A)(end B)(path A,a,b,B)         (cost  7))
(path (start A)(end C)(path A,a,b,c,C)       (cost   10))
(path (start A)(end D)(path A,a,m,n,d,D)     (cost 8.5))
(path (start A)(end E)(path A,a,m,n,E)       (cost 5.5))
(path (start A)(end F)(path A,a,m,n,k,g,f,F) (cost  9.4))
(path (start A)(end CS) (path A,a,m,n,k,CS)  (cost  6.7))
(path (start A)(end G)(path A,a,m,n,k,g,G)   (cost 8))
(path (start A)(end H)(path A,a,m,n,d,e,H)   (cost 10.3))
(path (start A)(end I)(path A,a,m,I)         (cost 3.5))

(path (start B)(end A) (path B,b,a,A)        (cost   7  ))
(path (start B)(end C) (path B,b,c,C)        (cost  4))
(path (start B)(end D) (path B,b,c,d,D)      (cost 7 ))
(path (start B)(end E) (path B,b,g,k,n,E)    (cost 5.8  ))
(path (start B)(end F) (path B,b,g,f,F)      (cost  4.7))
(path (start B)(end CS)(path B,b,g,k,CS)     (cost  4.6))
(path (start B)(end G) (path NG2,b,g,G)      (cost  3.3))
(path (start B)(end H) (path NG2,b,g,f,e,H)  (cost 6.5 ))
(path (start B)(end I) (path NG2,b,g,k,n,m,I)(cost 7.8 ))

(path (start C)(end A) (path C,c,b,a,A)      (cost   10))
(path (start C)(end B) (path C,c,b,B)        (cost   5))
(path (start C)(end D) (path C,c,d,D)        (cost   4))
(path (start C)(end E) (path C,c,d,n,E)      (cost   5.3))
(path (start C)(end F) (path C,c,d,e,f,F)    (cost   7.6))
(path (start C)(end CS)(path C,c,b,g,k,CS)   (cost   7.6))
(path (start C)(end G) (path C,c,b,g,G)      (cost  6.3))
(path (start C)(end H) (path C,c,d,e,H)      (cost   5.8))
(path (start C)(end I) (path C,c,d,n,m,I)    (cost  9))

(path (start D)(end A) (path D,d,n,m,a,A)    (cost  8.5))
(path (start D)(end B) (path D,d,c,b,B)      (cost  7))
(path (start D)(end C) (path D,d,c,C)        (cost  4))
(path (start D)(end E) (path D,d,n,E)        (cost  5))
(path (start D)(end F) (path D,d,e,f,F)      (cost  5.6))
(path (start D)(end CS)(path D,d,n,k,CS)     (cost  6.2))
(path (start D)(end G) (path D,d,e,f,g,G)    (cost  6))
(path (start D)(end H) (path D,d,e,H)        (cost  3.8))
(path (start D)(end I) (path D,d,n,m,I)      (cost  7))

(path (start E)(end A) (path E,n,m,a,A)      (cost  5.5))
(path (start E)(end B) (path E,n,k,g,b,B)    (cost  5.8))
(path (start E)(end C) (path E,n,d,c,C)      (cost  7))
(path (start E)(end D) (path E,n,d,D)        (cost  5))
(path (start E)(end F) (path E,n,k,g,f,F)    (cost  5.9))
(path (start E)(end CS)(path E,n,k,CS)       (cost  3.2))
(path (start E)(end G) (path E,n,k,g,G)      (cost  4.5))
(path (start E)(end H) (path E,n,d,e,H)      (cost  6.8))
(path (start E)(end I) (path E,n,m,I)        (cost  4))

(path (start F)(end A) (path F,f,g,k,n,m,a,A)(cost   9.4))
(path (start F)(end B) (path F,f,g,b,B)      (cost   4.7))
(path (start F)(end C) (path F,f,e,d,c,C)    (cost  7.6))
(path (start F)(end D) (path F,f,e,d,D)      (cost  5.6))
(path (start F)(end E) (path F,f,g,k,n,E)    (cost  5.9))
(path (start F)(end CS)(path F,f,g,k,CS)     (cost   4.7))
(path (start F)(end G) (path F,f,g,G)        (cost   3.4))
(path (start F)(end H) (path F,f,e,H)        (cost   3.8))
(path (start F)(end I) (path F,f,g,k,n,m,I)  (cost  7.9))


(path (start CS)(end A) (path CS,k,n,m,a,A)  (cost  6.7))
(path (start CS)(end B) (path CS,k,g,b,B)    (cost  4.6))
(path (start CS)(end C) (path CS,K,g,b,c,C)  (cost  7.6))
(path (start CS)(end D) (path CS,k,n,d,D)    (cost  6.2))
(path (start CS)(end E) (path CS,K,N,E)      (cost  3.2))
(path (start CS)(end F) (path CS,k,g,f,F)    (cost  4.7))
(path (start CS)(end G) (path CS,k,g,G)      (cost  3.3))
(path (start CS)(end H) (path CS,k,g,f,e,H)  (cost  6.5))
(path (start CS)(end I)(path CS,k,n,m,I)     (cost  5.2))

(path (start G)(end A) (path G,g,k,n,m,a,A)  (cost       8))
(path (start G)(end B) (path G,g,b,B)        (cost  3.3))
(path (start G)(end C) (path G,g,b,c,C)      (cost  6.3))
(path (start G)(end D) (path G,g,f,e,d,D)    (cost  6))
(path (start G)(end E) (path G,g,k,n,E)      (cost  4.5))
(path (start G)(end F) (path G,g,f,F)        (cost  3.4))
(path (start G)(end CS)(path G,g,k,CS)       (cost  3.3))
(path (start G)(end H) (path G,g,f,e,H)      (cost  5.2))
(path (start G)(end I) (path G,g,k,n,m,I)    (cost  6.5))

(path (start H)(end A) (path H,e,d,n,m,a,A)  (cost 10.3))
(path (start H)(end B) (path H,e,f,g,B)      (cost  6.5))
(path (start H)(end C) (path H,e,d,C)        (cost  3.8))
(path (start H)(end D) (path H,e,d,c,D)      (cost  5.8))
(path (start H)(end E) (path H,e,d,n,E)      (cost  6.8))
(path (start H)(end F) (path H,e,f,F)        (cost  3.8))
(path (start H)(end CS)(path H,e,f,g,k,CS)   (cost  6.5))
(path (start H)(end H) (path H,e,f,g,H)      (cost  5.2))
(path (start H)(end I) (path H,e,d,n,m,I)    (cost  8.8))

(path (start I)(end A) (path I,m,a,A)        (cost  3.5))
(path (start I)(end B) (path I,m,n,k,g,b,B)  (cost 7.8))
(path (start I)(end C) (path I,m,n,d,c,C)    (cost  9))
(path (start I)(end D) (path I,m,n,d,D)      (cost  7))
(path (start I)(end E) (path I,m,n,E)        (cost  4))
(path (start I)(end F) (path I,m,n,k,g,f,F)  (cost  7.9))
(path (start I)(end CS)(path I,m,m,k,CS)     (cost  5.2))
(path (start I)(end G) (path I,m,n,k,g,G)    (cost  6.5))
(path (start I)(end H) (path I,m,n,d,e,I)    (cost 8.8)))

 (defrule lancesaisiepoint
?f1 <-  (debut node)
=>
    (retract ?f1)
    (printout t "how many node start")
    (bind ?x (read))
    (assert (startnode ?x))
 )

(defrule saisiepoint
?f <-   (startnode ?a)
    (test (> ?a 0))
=>
 (printout t "Enter nbr node start  " crlf)
(printout t "start node name ")
(bind ?start (read))
(printout t "node start value ")
(bind ?y1 (read))
(assert (startnode ?start ?y1))
(retract ?f)
(assert (startnode (- ?a 1)))
)

(defrule lancesaisiemoins
?f1 <-  (startnode 0)
=>
(retract ?f1)
(printout t "how many node end ")
(bind ?x (read))
(assert (endnode ?x))
 )

(defrule saisiemoins
?f <-   (endnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node end" crlf)
(printout t "end node name ")
(bind ?end (read))
(printout t "node end value ")
(bind ?y2 (read))
(assert (endnode ?end ?y2))
(retract ?f)
(assert (endnode (- ?a 1))))


(defrule supprnbrpoint ;compter
?x<-    (startnode 0)
=>
    (retract ?x)
    )

(defrule supprnbrmoins
?x<-    (endnode 0)
=>
    (retract ?x)
    )

(defrule info

 ?M <- (startnode ?start ?y1)
 ?K <- (endnode ?end ?y2)
  =>
(assert (start ?start end ?end)) 
)

(defrule varvar   

?L<- (start ?start end ?end)

(path (start ?start)(end ?end)(path $?path)(cost ?cost))
  =>
(retract ?L)
(printout t " PATH  " ?start " to " ?end " by " ?path " with a cost of  " ?cost  crlf)
(assert (info (start ?start) (end ?end) (path $?path)
(cost ?cost)))
)

如果我有 3 个起始节点和 2 个结束节点,则组合结果

how many node start 3
Enter nbr node start  
start node name A
node start value 3
Enter nbr node start  
start node name C
node start value 5
Enter nbr node start  
start node name E
node start value 5
how many node end 2
Enter nbr node end
end node name B
node end value -5
Enter nbr node end
end node name I
node end value -5
 PATH  A to I by (A,a,m,I) with a cost of  3.5
 PATH  C to I by (C,c,d,n,m,I) with a cost of  9
 PATH  E to I by (E,n,m,I) with a cost of  4
 PATH  A to B by (A,a,b,B) with a cost of  7
 PATH  C to B by (C,c,b,B) with a cost of  5
 PATH  E to B by (E,n,k,g,b,B) with a cost of  5.8

然后作为最终结果我希望得到

PATH  A to I by (A,a,m,I) with a cost of  3.5 */ because it is the low cost between the 3 first combinaison */
PATH  E to B by (E,n,k,g,b,B) with a cost of  5.8 */ because it is the low cost between the 3 second combinaison */
PATH  C to B by (C,c,b,B) with a cost of  5  */ because it is the low cost between (C to B) and (C to I) */

我希望它是清楚的? 感谢您的帮助


尝试将规则 info 和 varvar 组合为以下内容:

(defrule varvar   
   (startnode ?start ?)
   (endnode ?end ?)
   (path (start ?start) (end ?end) (path $?path) (cost ?cost))
   (not (and (endnode ?end2 ?) 
             (path (start ?start) (end ?end2) (cost ?cost2&:(< ?cost2 ?cost)))))
   =>
   (printout t " PATH  " ?start " to " ?end " by " ?path " with a cost of  " ?cost  crlf)
   (assert (info (start ?start) (end ?end) (path $?path) (cost ?cost))))

您将得到的结果是:

 PATH  A to I by (A,a,m,I) with a cost of  3.5
 PATH  E to I by (E,n,m,I) with a cost of  4
 PATH  C to B by (C,c,b,B) with a cost of  5

目前尚不清楚为什么您期望选择路径 E 到 B,因为路径 E 到 I 的成本较低。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用剪辑的条件或选择性规则 的相关文章

随机推荐

  • 如何修复 GMail SMTP 错误:“SMTP 服务器需要安全连接或客户端未经身份验证。”

    下面是我正在使用的代码 请告知如何纠正此问题 using System using System Collections Generic using System Linq using System Web using System Web
  • 参数类型“Stream”无法分配给参数类型“Stream?”

    我想使用 Streams 使用 firebase 身份验证 但是我在网上收到上述错误stream FirebaseAuth instance authStateChanges 我努力了onAuthStateChange 那也行不通 clas
  • Abaqus Surface getSequenceFromMask

    我正在 Abaqus 中编写脚本 我用切圆 像奶酪 压碎圆形和正方形 我需要在部件之间放置接触 所以我需要 Surface 宏管理器生成 s1 a instances kolo 1 edges side1Edges1 s1 getSeque
  • 在 Codeigniter 中加密时避免使用特定字符?

    我需要通过 URL 传递一些加密值 有什么办法可以避免加密后得到的值中出现一些字符 例如斜杠 因为在codeigniter中 斜杠等字符用于分隔URL中的参数 请注意 我不希望任何建议不要在 URL 中传递加密字符串 使用PHPurlenc
  • 用于索引和搜索的 Lucene 分析器

    我有一个正在使用 Lucene 建立索引的字段 如下所示 Field name hungerState index Index TOKENIZED store Store YES public HungerState getHungerSt
  • 如何更新角度材质

    将项目中的角度材料更新到最新版本的最佳方法是什么 email protected cdn cgi l email protection I tried npm install save angular material angular cd
  • 我应该使用字符串表来提高数据库效率吗?

    假设您有一个包含单个表的数据库 例如 Name FavoriteFood Alice Pizza Mark Sushi Jack Pizza 如果有一个名为 St
  • 在 git bash 中找不到 sudo/apt-get 命令

    我在我的机器上使用 Windows 10 当前安装了 git bash 我想为我的应用程序安装 Node 和 npm 当我尝试时 apt get安装nodejs 找不到 apt get 命令 我尝试谷歌并得到 须藤安装nodejs 未找到
  • 页面重新加载时 Jquery 显示/隐藏重置

    我是 jquery 的新手 但我正在尝试使用它来创建多步骤选项卡式表单 在其中一页 我有单选按钮 将根据所选的选择显示多个字段 我发现的问题是 如果用户在选择单选按钮后刷新页面 页面将重新加载并隐藏所有 div 但它会记住所选的单选按钮选项
  • 将项目推送到 STL 容器后出现段错误

    typedef struct temp int a b char c temp c char malloc 10 temp free c temp int main temp a list
  • 插入行以用标题分隔数据组

    有人可以帮我写这个脚本吗 就目前情况而言 一旦值 文本发生更改并插入新行 当前的宏就会分离数据 但我只是无法弄清楚如何在插入行后包含标题 Sub Insert Row Dim ws As Worksheet Dim lr As Long D
  • 无法使用 VS 代码从 Node js 中的控制台读取

    我正在 VS code 中使用 Node js 的核心模块 但无法让它与 readline 模块一起工作 我在 js 文件中有以下代码 const readline require readline const rl readline cr
  • 使用布尔索引数组过滤列表

    如何在不使用 numpy 的情况下使用布尔索引数组来过滤列表 例如 gt gt gt l a b c gt gt gt b True False False gt gt gt l b 结果应该是 a 我知道 numpy 支持它 但想知道如何
  • ruby 打印 2 个字符串之间选定的文本行

    我试图在 ruby 中的两个字符串之间获取一组文本 但我似乎无法获得正确的方法或使用正确的正则表达式 text h1 all kinds of html h1 p blah blah p p i ve been working on thi
  • MVC 软件架构中验证逻辑的放置位置

    我其实已经开始学习mvc架构了 我很困惑是否将用户名注册验证逻辑放在模型中或控制器中 我有某种状态消息 可以告诉用户要注册的新用户名是否可用 我开始感到困惑 因为大多数消息来源说它应该在模型中 因为它涉及在将用户名数据放入数据库之前进行验证
  • IPC 的共享内存和线程的共享内存有什么区别?

    让我们使用 POSIX 共享内存 例如 shmget 协调进程间通信的常见调用 调用 shmget 并协调共享内存段上的通信与 Linux 在单个进程中实现共享内存和线程之间的同步有何不同 其中之一更轻吗 SHM适用于多进程中的IPC 在现
  • postgresql 中的 regexp \Q...\E 等价于什么?

    我有以下查询 SELECT field FROM myTable WHERE field Qprefix E 它不会找到类似的值prefix foo 我该如何更换 Q E 这种形式的正则表达式带有 Q E仅支持不带引号的子字符串PCRE h
  • 从 shell 脚本中提取 YAML 中的变量

    我有一个由以下内容组成的 YAML 文件 acceleration matrix 1ere row x 20 0 0 15 15 2eme row y 0 15 0 0 0 3eme row z 0 0 30 15 15 4eme row
  • NLTK 中 Text.similar() 和 ContextIndex.similar_words() 生成的单词按频率排序?

    我使用这两个函数来查找相似的单词 它们返回不同的列表 我想知道这些函数是否按最频繁关联到最不频繁关联排序 ContextIndex similar words word http nltk org modules nltk text htm
  • 使用剪辑的条件或选择性规则

    我希望你过得很好 我是 CLIPS 的初学者 我有一个包含多个节点 起始节点 输入 和结束节点 输出 的图表 我想在输入数量等于输出的情况下创建一个规则 该规则必须帮助我在几个节点之间进行选择组合 起始节点和结束节点 每个组合的最短路径 如