Conditional or selective rule using Clips

前端 未结 1 1511
时光取名叫无心
时光取名叫无心 2021-01-26 12:22

I hope you are doing very well? I am a beginner in regards to CLIPS. I have a graph of several nodes (start nodes (input) and of end nodes (output). I want to create a rule in t

1条回答
  •  [愿得一人]
    2021-01-26 12:52

    Try combining rules info and varvar to the following:

    (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))))
    

    The results you'll get are:

     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
    

    It's not clear why you're expecting path E to B to be selected since path E to I has a lower cost.

    0 讨论(0)
提交回复
热议问题