我希望你做得很好?我是CLIPS的初学者。我有几个节点的图形(起始节点(输入)和结束节点(输出)。我想在我输入的数量等于输出的情况下创建规则,规则必须帮助我在几个节点之间进行选择组合(开始和结束节点)每个组合的最短路径。
如果输入数量大于输出数量或相反,则可以使用相同的规则添加另一个规则。在组合之间进行选择之后,还需要考虑输入或输出并将其导出到最近的点?
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
组合结果如果我有3个startnode和2个endnode
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) */
然后作为最终结果我希望得到
case class Person(batch: Long, age: Long, name: String)
val df = spark.read.json("/home/white/tmp/a.json").as[Person]
我希望很清楚? 谢谢你的帮助
答案 0 :(得分:0)
尝试将规则信息和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的成本较低。