我如何从所有数据中找到我在 CLIPS 中添加的最低价格
how can i find from all data i have add one lowest price in CLIPS
我需要从我输入的所有数据中找到最低价格。例如,我已经测试了规则包含(defrule lowest 并且它有效但在这里它在循环中工作)。我该如何解决这种情况?
启动程序
;; enter how many point you need to add ;;
(defrule lancesaisiepoint
?f1 <- (debut point)
=>
(retract ?f1)
(printout t "Combien de point ");; type number;;
(bind ?x (read))
(assert (point ?x))
)
(defrule saisiepoint
?f <- (point ?a)
(test (> ?a 0))
=>
(printout t "Entrer nbr point " crlf)
(printout t "nom point ")
(bind ?x1 (read))
(printout t "Valeur point ")
(bind ?y1 (read))
(assert (point ?x1 ?y1))
(retract ?f)
(assert (point (- ?a 1)))
)
;;enter how manu moins(a variable) you need to add;;
(defrule lancesaisiemoins
?f1 <- (point 0)
=>
(retract ?f1)
(printout t "Combien de moins ");; type number ;;
(bind ?x (read))
(assert (moins ?x))
)
(defrule saisiemoins
?f <- (moins ?a)
(test (> ?a 0))
=>
(printout t "Entrer nbr moins" crlf)
(printout t "nom moins ")
(bind ?x2 (read))
(printout t "Valeur moins ")
(bind ?y2 (read))
(assert (moins ?x2 ?y2))
(retract ?f)
(assert (moins(- ?a 1))))
(defrule supprnbrpoint ;compter
?x<- (point 0)
=>
(retract ?x)
)
(defrule supprnbrmoins
?x<- (moins 0)
=>
(retract ?x)
)
;; add information like path and cost ;;
(defrule table
?M <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
=>
(printout t "donner les infos du chemin " ?x1 ?x2 crlf)
(printout t "path : ")
(bind ?p (readline))
(printout t "distance ")
(bind ?d (readline))
(assert (infos ?x1 to ?x2 path ?p distance ?d ))
)
(defrule path
?P <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
?Z <- (infos ?x1 to ?x2 path ?p distance ?d )
=>
(printout t " path de " ?x1 ?x2 " est: " ?p " avec une distance de " ?d crlf)
)
(defrule lowest
(infos ?x1 to ?x2 path ?p distance ?d )
(not (distance ?d2&:(< ?d2 ?d)))
=>
(printout t "le chemin de " ?x1 " vers " ?x2 "," ?p " has the lowest price: " ?d crlf))
对您的规则进行以下修改:
(defrule table
?M <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
=>
(printout t "donner les infos du chemin " ?x1 ?x2 crlf)
(printout t "path : ")
(bind ?p (readline))
(printout t "distance ")
(bind ?d (read)) ;; Use read not readline
(assert (infos ?x1 to ?x2 path ?p distance ?d)))
(defrule lowest
(declare (salience -10)) ;; Rule needs to execute last
(infos ?x1 to ?x2 path ?p distance ?d)
(not (infos ? to ? path ? distance ?d2&:(< ?d2 ?d))) ;; Need to match infos facts
=>
(printout t "le chemin de " ?x1 " vers " ?x2 "," ?p " has the lowest price: " ?d crlf))
你会得到这个行为:
CLIPS> (assert (debut point))
<Fact-1>
CLIPS> (run)
Combien de point 2
Entrer nbr point
nom point A
Valeur point 23
Entrer nbr point
nom point B
Valeur point 34
Combien de moins 1
Entrer nbr moins
nom moins C
Valeur moins 43
donner les infos du chemin AC
path : ABC
distance 3
path de AC est: ABC avec une distance de 3
donner les infos du chemin BC
path : BDC
distance 23
path de BC est: BDC avec une distance de 23
le chemin de A vers C,ABC has the lowest price: 3
CLIPS>
我需要从我输入的所有数据中找到最低价格。例如,我已经测试了规则包含(defrule lowest 并且它有效但在这里它在循环中工作)。我该如何解决这种情况?
启动程序
;; enter how many point you need to add ;;
(defrule lancesaisiepoint
?f1 <- (debut point)
=>
(retract ?f1)
(printout t "Combien de point ");; type number;;
(bind ?x (read))
(assert (point ?x))
)
(defrule saisiepoint
?f <- (point ?a)
(test (> ?a 0))
=>
(printout t "Entrer nbr point " crlf)
(printout t "nom point ")
(bind ?x1 (read))
(printout t "Valeur point ")
(bind ?y1 (read))
(assert (point ?x1 ?y1))
(retract ?f)
(assert (point (- ?a 1)))
)
;;enter how manu moins(a variable) you need to add;;
(defrule lancesaisiemoins
?f1 <- (point 0)
=>
(retract ?f1)
(printout t "Combien de moins ");; type number ;;
(bind ?x (read))
(assert (moins ?x))
)
(defrule saisiemoins
?f <- (moins ?a)
(test (> ?a 0))
=>
(printout t "Entrer nbr moins" crlf)
(printout t "nom moins ")
(bind ?x2 (read))
(printout t "Valeur moins ")
(bind ?y2 (read))
(assert (moins ?x2 ?y2))
(retract ?f)
(assert (moins(- ?a 1))))
(defrule supprnbrpoint ;compter
?x<- (point 0)
=>
(retract ?x)
)
(defrule supprnbrmoins
?x<- (moins 0)
=>
(retract ?x)
)
;; add information like path and cost ;;
(defrule table
?M <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
=>
(printout t "donner les infos du chemin " ?x1 ?x2 crlf)
(printout t "path : ")
(bind ?p (readline))
(printout t "distance ")
(bind ?d (readline))
(assert (infos ?x1 to ?x2 path ?p distance ?d ))
)
(defrule path
?P <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
?Z <- (infos ?x1 to ?x2 path ?p distance ?d )
=>
(printout t " path de " ?x1 ?x2 " est: " ?p " avec une distance de " ?d crlf)
)
(defrule lowest
(infos ?x1 to ?x2 path ?p distance ?d )
(not (distance ?d2&:(< ?d2 ?d)))
=>
(printout t "le chemin de " ?x1 " vers " ?x2 "," ?p " has the lowest price: " ?d crlf))
对您的规则进行以下修改:
(defrule table
?M <- (point ?x1 ?y1)
?K <- (moins ?x2 ?y2)
=>
(printout t "donner les infos du chemin " ?x1 ?x2 crlf)
(printout t "path : ")
(bind ?p (readline))
(printout t "distance ")
(bind ?d (read)) ;; Use read not readline
(assert (infos ?x1 to ?x2 path ?p distance ?d)))
(defrule lowest
(declare (salience -10)) ;; Rule needs to execute last
(infos ?x1 to ?x2 path ?p distance ?d)
(not (infos ? to ? path ? distance ?d2&:(< ?d2 ?d))) ;; Need to match infos facts
=>
(printout t "le chemin de " ?x1 " vers " ?x2 "," ?p " has the lowest price: " ?d crlf))
你会得到这个行为:
CLIPS> (assert (debut point))
<Fact-1>
CLIPS> (run)
Combien de point 2
Entrer nbr point
nom point A
Valeur point 23
Entrer nbr point
nom point B
Valeur point 34
Combien de moins 1
Entrer nbr moins
nom moins C
Valeur moins 43
donner les infos du chemin AC
path : ABC
distance 3
path de AC est: ABC avec une distance de 3
donner les infos du chemin BC
path : BDC
distance 23
path de BC est: BDC avec une distance de 23
le chemin de A vers C,ABC has the lowest price: 3
CLIPS>