gpt4 book ai didi

syntax-error - 有条件的情况下如何正确使用加法?片段

转载 作者:行者123 更新时间:2023-12-03 08:11:05 29 4
gpt4 key购买 nike

我正在尝试检查汽车前面是否有任何障碍物。假设汽车在位置“2”。我的目标是检查位置“3”处是否有障碍物。
可能没有明确的障碍事实,这意味着在特定位置没有障碍。我检查使用是否存在有条件。但是在规则 r6 中,对于这部分(+?location_car 1),我收到CLIPS语法错误 [PRNTUTIL2] 。如果我放弃添加,它会起作用。我可以使用什么替代方法?或者我只是缺少一些语法方面的东西?

  (deftemplate car
(slot location)
)
(deftemplate obstacles
(slot location) ; location of road segment
(slot tlights) ; number of red traffic lights
(slot cars) ; number of cars which have priority drive through
(slot pedestrians) ; number of pedestrians crossing the road
(slot spec_service) ; number of spec service vehicles passing by
)

(deffacts faktu-inicializavimas
(car (location 0))
(obstacles (location 9) (tlights 1) (cars 2) (pedestrians 5) (spec_service 2))
)

(defrule r6 "Drive to location"
?fact-id1 <- (car (location ?location_car))
(or
(exists (obstacles (location (+ ?location_car 1)) (tlights 0) (cars 0) (pedestrians 0) (spec_service 0)))
(not
(exists (obstacles (location (+ ?location_car 1)) ))
)
)
=>
(printout t "Drive to location")
(modify ?fact-id1 (location (+ ?location_car 2)))
)

最佳答案

使用返回值约束(等号=)将字段约束为函数调用的返回值。

(defrule r6 "Drive to location"
?fact-id1 <- (car (location ?location_car))
(or
(exists (obstacles (location =(+ ?location_car 1))
(tlights 0)
(cars 0)
(pedestrians 0)
(spec_service 0)))
(not
(exists (obstacles (location =(+ ?location_car 1)) ))
)
)
=>
(printout t "Drive to location")
(modify ?fact-id1 (location (+ ?location_car 2)))
)

关于syntax-error - 有条件的情况下如何正确使用加法?片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42321832/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com