如何在存在条件下正确使用加法?剪辑
How to use addition correctly within exists conditional? CLIPS
我正在检查车前是否有任何障碍物。假设汽车位于位置“2”。我的目标是检查位置“3”是否有障碍物。
可能没有明确的障碍物事实,这意味着在那个特定位置没有任何障碍物。我检查使用 exists 条件。但是我在规则 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)))
)
使用 return 值约束(等号 =)将字段约束为函数调用的 return 值。
(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)))
)
我正在检查车前是否有任何障碍物。假设汽车位于位置“2”。我的目标是检查位置“3”是否有障碍物。 可能没有明确的障碍物事实,这意味着在那个特定位置没有任何障碍物。我检查使用 exists 条件。但是我在规则 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)))
)
使用 return 值约束(等号 =)将字段约束为函数调用的 return 值。
(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)))
)