(deftemplate path
(slot start)
(slot end)
(multislot path)
(slot cost(type NUMBER)))
(deftemplate info
(slot start)
(slot end)
(multislot path)
(slot cost))
(deftemplate startend
(slot start)
(slot end))
(deffacts variable_table
(path (start A)(end B)(path A,a,b,B) (cost 7))
(path (start A)(end C)(path A,a,b,c,C) (cost 10))
(path (start A)(end D)(path A,a,m,n,d,D) (cost 8.5))
(path (start A)(end E)(path A,a,m,n,E) (cost 5.5))
(path (start A)(end F)(path A,a,m,n,k,g,f,F) (cost 9.4))
(path (start A)(end CS) (path A,a,m,n,k,CS) (cost 6.7))
(path (start A)(end G)(path A,a,m,n,k,g,G) (cost 8))
(path (start A)(end H)(path A,a,m,n,d,e,H) (cost 10.3))
(path (start A)(end I)(path A,a,m,I) (cost 3.5))
(path (start B)(end A) (path B,b,a,A) (cost 7 ))
(path (start B)(end C) (path B,b,c,C) (cost 4))
(path (start B)(end D) (path B,b,c,d,D) (cost 7 ))
(path (start B)(end E) (path B,b,g,k,n,E) (cost 5.8 ))
(path (start B)(end F) (path B,b,g,f,F) (cost 4.7))
(path (start B)(end CS)(path B,b,g,k,CS) (cost 4.6))
(path (start B)(end G) (path NG2,b,g,G) (cost 3.3))
(path (start B)(end H) (path NG2,b,g,f,e,H) (cost 6.5 ))
(path (start B)(end I) (path NG2,b,g,k,n,m,I)(cost 7.8 ))
(path (start C)(end A) (path C,c,b,a,A) (cost 10))
(path (start C)(end B) (path C,c,b,B) (cost 5))
(path (start C)(end D) (path C,c,d,D) (cost 4))
(path (start C)(end E) (path C,c,d,n,E) (cost 5.3))
(path (start C)(end F) (path C,c,d,e,f,F) (cost 7.6))
(path (start C)(end CS)(path C,c,b,g,k,CS) (cost 7.6))
(path (start C)(end G) (path C,c,b,g,G) (cost 6.3))
(path (start C)(end H) (path C,c,d,e,H) (cost 5.8))
(path (start C)(end I) (path C,c,d,n,m,I) (cost 9))
(path (start D)(end A) (path D,d,n,m,a,A) (cost 8.5))
(path (start D)(end B) (path D,d,c,b,B) (cost 7))
(path (start D)(end C) (path D,d,c,C) (cost 4))
(path (start D)(end E) (path D,d,n,E) (cost 5))
(path (start D)(end F) (path D,d,e,f,F) (cost 5.6))
(path (start D)(end CS)(path D,d,n,k,CS) (cost 6.2))
(path (start D)(end G) (path D,d,e,f,g,G) (cost 6))
(path (start D)(end H) (path D,d,e,H) (cost 3.8))
(path (start D)(end I) (path D,d,n,m,I) (cost 7))
(path (start E)(end A) (path E,n,m,a,A) (cost 5.5))
(path (start E)(end B) (path E,n,k,g,b,B) (cost 5.8))
(path (start E)(end C) (path E,n,d,c,C) (cost 7))
(path (start E)(end D) (path E,n,d,D) (cost 5))
(path (start E)(end F) (path E,n,k,g,f,F) (cost 5.9))
(path (start E)(end CS)(path E,n,k,CS) (cost 3.2))
(path (start E)(end G) (path E,n,k,g,G) (cost 4.5))
(path (start E)(end H) (path E,n,d,e,H) (cost 6.8))
(path (start E)(end I) (path E,n,m,I) (cost 4))
(path (start F)(end A) (path F,f,g,k,n,m,a,A)(cost 9.4))
(path (start F)(end B) (path F,f,g,b,B) (cost 4.7))
(path (start F)(end C) (path F,f,e,d,c,C) (cost 7.6))
(path (start F)(end D) (path F,f,e,d,D) (cost 5.6))
(path (start F)(end E) (path F,f,g,k,n,E) (cost 5.9))
(path (start F)(end CS)(path F,f,g,k,CS) (cost 4.7))
(path (start F)(end G) (path F,f,g,G) (cost 3.4))
(path (start F)(end H) (path F,f,e,H) (cost 3.8))
(path (start F)(end I) (path F,f,g,k,n,m,I) (cost 7.9))
(path (start CS)(end A) (path CS,k,n,m,a,A) (cost 6.7))
(path (start CS)(end B) (path CS,k,g,b,B) (cost 4.6))
(path (start CS)(end C) (path CS,K,g,b,c,C) (cost 7.6))
(path (start CS)(end D) (path CS,k,n,d,D) (cost 6.2))
(path (start CS)(end E) (path CS,K,N,E) (cost 3.2))
(path (start CS)(end F) (path CS,k,g,f,F) (cost 4.7))
(path (start CS)(end G) (path CS,k,g,G) (cost 3.3))
(path (start CS)(end H) (path CS,k,g,f,e,H) (cost 6.5))
(path (start CS)(end I)(path CS,k,n,m,I) (cost 5.2))
(path (start G)(end A) (path G,g,k,n,m,a,A) (cost 8))
(path (start G)(end B) (path G,g,b,B) (cost 3.3))
(path (start G)(end C) (path G,g,b,c,C) (cost 6.3))
(path (start G)(end D) (path G,g,f,e,d,D) (cost 6))
(path (start G)(end E) (path G,g,k,n,E) (cost 4.5))
(path (start G)(end F) (path G,g,f,F) (cost 3.4))
(path (start G)(end CS)(path G,g,k,CS) (cost 3.3))
(path (start G)(end H) (path G,g,f,e,H) (cost 5.2))
(path (start G)(end I) (path G,g,k,n,m,I) (cost 6.5))
(path (start H)(end A) (path H,e,d,n,m,a,A) (cost 10.3))
(path (start H)(end B) (path H,e,f,g,B) (cost 6.5))
(path (start H)(end C) (path H,e,d,C) (cost 3.8))
(path (start H)(end D) (path H,e,d,c,D) (cost 5.8))
(path (start H)(end E) (path H,e,d,n,E) (cost 6.8))
(path (start H)(end F) (path H,e,f,F) (cost 3.8))
(path (start H)(end CS)(path H,e,f,g,k,CS) (cost 6.5))
(path (start H)(end H) (path H,e,f,g,H) (cost 5.2))
(path (start H)(end I) (path H,e,d,n,m,I) (cost 8.8))
(path (start I)(end A) (path I,m,a,A) (cost 3.5))
(path (start I)(end B) (path I,m,n,k,g,b,B) (cost 7.8))
(path (start I)(end C) (path I,m,n,d,c,C) (cost 9))
(path (start I)(end D) (path I,m,n,d,D) (cost 7))
(path (start I)(end E) (path I,m,n,E) (cost 4))
(path (start I)(end F) (path I,m,n,k,g,f,F) (cost 7.9))
(path (start I)(end CS)(path I,m,m,k,CS) (cost 5.2))
(path (start I)(end G) (path I,m,n,k,g,G) (cost 6.5))
(path (start I)(end H) (path I,m,n,d,e,I) (cost 8.8)))
(defrule lancesaisiepoint
?f1 <- (debut node)
=>
(retract ?f1)
(printout t "how many node start")
(bind ?x (read))
(assert (startnode ?x))
)
(defrule saisiepoint
?f <- (startnode ?a)
(test (> ?a 0))
=>
(printout t " Enter nbr node start" crlf)
(printout t "start node name ")
(bind ?start (read))
(printout t "node start value ")
(bind ?y1 (read))
(assert (startnode ?start ?y1))
(retract ?f)
(assert (startnode (- ?a 1)))
)
(defrule lancesaisiemoins
?f1 <- (startnode 0)
=>
(retract ?f1)
(printout t "how many node end ")
(bind ?x (read))
(assert (endnode ?x))
)
(defrule saisiemoins
?f <- (endnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node end" crlf)
(printout t "end node name ")
(bind ?end (read))
(printout t "node end value ")
(bind ?y2 (read))
(assert (endnode ?end ?y2))
(retract ?f)
(assert (endnode (- ?a 1))))
(defrule supprnbrpoint ;compter
?x<- (startnode 0)
=>
(retract ?x)
)
(defrule supprnbrmoins
?x<- (endnode 0)
=>
(retract ?x)
)
(defrule info
?M <- (startnode ?start ?y1)
?K <- (endnode ?end ?y2)
=>
(assert (start ?start end ?end)))
(defrule var
?e1 <-(startnode ?start ?)
?f1 <-(endnode ?end ?)
(path (start ?start) (end ?end) (path $?path) (cost ?cost))
(not (and (startnode ?start$? ?)
(path (start ?start$?) (end ?end) (cost ?cost?&:(< ?cost? ?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))))
(defrule var1
?e2 <-(startnode ?start ?)
?f2 <-(endnode ?end ?)
(path (start ?start) (end ?end) (path $?path) (cost ?cost))
(not (and (endnode ?end$? ?)
(path (start ?start) (end ?end$?) (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))))
this pict show the result if i have the number of start node equal to the number of end node
this pict show the result when we have the number of start node greedy than the end node
so when i applied the rule given by #GRAY i have the same 3 result combinaison for any number superior of 3 .
what i expect is to have all combinaison of the number of input ( between nmr start node and end node) of corse withe the lowest cost .
i tried with the retract but it give a different result may be i place it rong in the code.
and what if i use a different solution ,for example a class or a function ??? but i am still new in this field so i don t know what i can do , thank you very much for your help .
If you have multiple rules detecting the shortest paths, you need to add a pattern to each of the rules to exclude the paths detected by the other rules.
In this case, you can add the pattern "(not (info (start ?start) (end ?end)))" to the var and var1 rules to exclude the previously detected patterns:
(defrule var
?e1 <- (startnode ?start ?)
?f1 <- (endnode ?end ?)
(path (start ?start) (end ?end) (path $?path) (cost ?cost))
(not (and (startnode ?start$? ?)
(path (start ?start$?) (end ?end) (cost ?cost?&:(< ?cost? ?cost)))))
(not (info (start ?start) (end ?end)))
=>
(printout t " PATH " ?start " to " ?end " by " ?path " with a cost of " ?cost crlf)
(assert (info (start ?start) (end ?end) (path $?path) (cost ?cost))))
(defrule var1
?e2 <- (startnode ?start ?)
?f2 <- (endnode ?end ?)
(path (start ?start) (end ?end) (path $?path) (cost ?cost))
(not (and (endnode ?end$? ?)
(path (start ?start) (end ?end$?) (cost ?cost2&:(< ?cost2 ?cost)))))
(not (info (start ?start) (end ?end)))
=>
(printout t " PATH " ?start " to " ?end " by " ?path " with a cost of " ?cost crlf)
(assert (info (start ?start) (end ?end) (path $?path) (cost ?cost))))
Related
So I get the program to say enter name. However, once I enter the name it doesn't output any other information. I'm trying to get it to print out the name, class, magnitude, and distance. Where am I going wrong?
(deftemplate stars
(slot name)
(slot class)
(slot magnitude)
(slot dist)
)
(deffacts star
(stars (name Sirius) (class A) (magnitude 1) (dist 8.8))
(stars (name Canopus) (class F) (magnitude -3) (dist 98))
(stars (name Arcturus) (class K) (magnitude 0) (dist 36))
(stars (name Vega) (class A) (magnitude 1) (dist 26))
(stars (name Capella) (class G) (magnitude -1) (dist 46))
(stars (name Rigel) (class B) (magnitude -7) (dist 880))
(stars (name Procyon) (class F) (magnitude 3) (dist 11))
(stars (name Betelgeuse) (class M) (magnitude -5) (dist 490))
(stars (name Altair) (class A) (magnitude 2) (dist 16))
(stars (name Aldebaran) (class K) (magnitude -1) (dist 68))
(stars (name Spica) (class B) (magnitude -3) (dist 300))
(stars (name Antares) (class M) (magnitude -4) (dist 250))
(stars (name Pollux) (class K) (magnitude 1) (dist 35))
(stars (name Deneb) (class A) (magnitude -7) (dist 1630))
)
(defrule start-up
?i <- (initial-fact)
=>
(printout t "Enter name: ")
(bind ?y (read))
(assert (name ?y))
(retract ?i)
)
(defrule S1
?char <- (stars (name ?n) (class ?c) (magnitude ?m) (dist ?d))
(name ?y)
(test ( eq ?n ?y))
=>
(printout t ?n " " ?c" " ?m " " ?d crlf)
(retract ?char)
(assert (found))
)
I got the initial output of enter name but didn't get the second output of name, class, magnitude, and distance.
Can someone explain me how can I import the WEKA created rules in CLIPS and evaluate its efficience in TRS and TES data?
The data I use
I have written 7 rules out of 20 from WEKA tree. I include also 3 instances from the glass datasheet
small test code
(deftemplate glass
(slot n(type FLOAT))
(slot m(type FLOAT))
(slot a(type FLOAT))
(slot b(type FLOAT))
(slot r(type FLOAT))
(slot s(type FLOAT))
(slot k(type FLOAT))
(slot c(type FLOAT)))
(deftemplate Type
(slot type))
(deffacts instances1
(glass (n 13.00)
(m 2.28)
(a 1.00)
(b 0.00)))
(deffacts instances2
(glass (n 13.70)
(m 1.80)
(a 1.40)
(b 0.00)))
(deffacts instances3
(glass (n 13.70)
(m 1.90)
(a 1.40)
(b 0.00)))
(defrule R1
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (<= ?m 2.41))
(glass (n ?n))
(test (<= ?n 13.78))
(glass (a ?a))
(test (<= ?a 1.38))
=>
(assert (Type (type buildwindnonfloat1)))
(printout t "buildwindnonfloat1 detected" crlf))
(defrule R2
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (<= ?m 2.41))
(glass (n ?n))
(test (<= ?n 13.78))
(glass (a ?a))
(test (> ?a 1.38))
(glass (m ?m))
(test (<= ?m 1.88))
=>
(assert (Type (type containers2)))
(printout t "containers2 detected" crlf))
(defrule R3
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (<= ?m 2.41))
(glass (n ?n))
(test (<= ?n 13.78))
(glass (a ?a))
(test (> ?a 1.38))
(glass (m ?m))
(test (> ?m 1.88))
=>
(assert (Type (type buildwindnonfloat3)))
(printout t "buildwindnonfloat3 detected" crlf))
(defrule R4
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (<= ?m 2.41))
(glass (n ?n))
(test (> ?n 13.78))
=>
(assert (Type (type tableware4)))
(printout t "tableware detected" crlf))
(defrule R5
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (> ?m 2.41))
(glass (a ?a))
(test (<= ?a 1.4))
(glass (m ?m))
(test (<= ?m 3.34))
(glass (a ?a))
(test (<= ?a 1.25))
=>
(assert (Type (type buildwindnonfloat5)))
(printout t "buildwindnonfloat5 detected" crlf))
(defrule R6
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (> ?m 2.41))
(glass (a ?a))
(test (<= ?a 1.4))
(glass (m ?m))
(test (<= ?m 3.34))
(glass (a ?a))
(test (> ?a 1.25))
=>
(assert (Type (type buildwindfloat6)))
(printout t "buildwindfloat6 detected" crlf))
(defrule R7
(glass (b ?b))
(test (<= ?b 0.27))
(glass (m ?m))
(test (> ?m 2.41))
(glass (a ?a))
(test (<= ?a 1.4))
(glass (m ?m))
(test (> ?m 3.34))
(glass (m ?m))
(test (<= ?m 3.82))
(glass (r ?r))
(test (<= ?r 1.51707))
(glass (r ?r))
(test (<= ?r 51596))
=>
(assert (Type (type buildwindfloat7)))
(printout t "buildwindfloat7 detected" crlf))
To convert your data, it's easiest to read the data from the file when your program is running and directly assert the facts. So if your data looks like the following with each entry on its own line
1.5159,13.24,3.34,1.47,73.1,0.39,8.22,0,0,'build wind non-float'
1.5167,13.24,3.57,1.38,72.7,0.56,8.44,0,0.1,'vehic wind float'
then your can read your data by reading each line as a single string, replacing the commas with spaces, and then splitting the string into multiple values. You can then have a separate rule map the values from your file to the appropriate slots in your deftemplate facts.
Store the expected result with each glass fact and then you can compare that value to the value that your rule is proposing.
CLIPS (6.31 6/12/19)
CLIPS>
(deftemplate glass
(slot n (type FLOAT))
(slot m (type FLOAT))
(slot a (type FLOAT))
(slot b (type FLOAT))
(slot r (type FLOAT))
(slot s (type FLOAT))
(slot k (type FLOAT))
(slot c (type FLOAT))
(slot f (type FLOAT))
(slot type))
CLIPS>
(deftemplate input
(multislot data))
CLIPS>
(deffunction str-rpl (?str ?find ?replace)
(if (eq ?find "")
then
(return ?str))
(bind ?rs "")
(bind ?fl (str-length ?find))
(bind ?i (str-index ?find ?str))
(while (neq ?i FALSE)
(bind ?rs (str-cat ?rs (sub-string 1 (- ?i 1) ?str) ?replace))
(bind ?str (sub-string (+ ?i ?fl) (str-length ?str) ?str))
(bind ?i (str-index ?find ?str)))
(bind ?rs (str-cat ?rs ?str))
?rs)
CLIPS>
(defrule get-data
=>
(printout t "Input File? ")
(bind ?file (readline))
(if (not (open ?file data))
then
(printout t "Unable to open file" crlf)
(return))
(bind ?line (readline data))
(while (neq ?line EOF)
(bind ?line (str-rpl ?line "," " "))
(bind ?line (str-rpl ?line "'" "\""))
(assert (input (data (explode$ ?line))))
(bind ?line (readline data)))
(close data))
CLIPS>
(defrule convert-data
?i <- (input (data ?r ?n ?m ?a ?s ?k ?c ?b ?f ?type))
=>
(retract ?i)
(assert (glass (r ?r) (n ?n) (m ?m) (a ?a) (s ?s) (k ?k) (c ?c) (b ?b) (f ?f) (type ?type))))
CLIPS>
(defrule R1
(glass (b ?b)
(m ?m)
(n ?n)
(a ?a)
(type ?type))
(test (<= ?b 0.27))
(test (<= ?m 2.41))
(test (<= ?n 13.78))
(test (<= ?a 1.38))
=>
(printout t "buildwindnonfloat1 detected type = " ?type crlf))
CLIPS>
(defrule R2
(glass (b ?b)
(m ?m)
(n ?n)
(a ?a)
(type ?type))
(test (<= ?b 0.27))
(test (<= ?m 2.41))
(test (<= ?n 13.78))
(test (> ?a 1.38))
(test (<= ?m 1.88))
=>
(printout t "containers2 detected type = " ?type crlf))
CLIPS>
(defrule R3
(glass (b ?b)
(m ?m)
(n ?n)
(a ?a)
(type ?type))
(test (<= ?b 0.27))
(test (<= ?m 2.41))
(test (<= ?n 13.78))
(test (> ?a 1.38))
(test (> ?m 1.88))
=>
(printout t "buildwindnonfloat3 detected type = " ?type crlf))
CLIPS>
(defrule R4
(glass (b ?b)
(m ?m)
(n ?n)
(type ?type))
(test (<= ?b 0.27))
(test (<= ?m 2.41))
(test (> ?n 13.78))
=>
(printout t "tableware detected type = " ?type crlf))
CLIPS>
(defrule R5
(glass (b ?b)
(m ?m)
(a ?a)
(type ?type))
(test (<= ?b 0.27))
(test (> ?m 2.41))
(test (<= ?a 1.4))
(test (<= ?m 3.34))
(test (<= ?a 1.25))
=>
(printout t "buildwindnonfloat5 detected type = " ?type crlf))
CLIPS>
(defrule R6
(glass (b ?b)
(m ?m)
(a ?a)
(type ?type))
(test (<= ?b 0.27))
(test (> ?m 2.41))
(test (<= ?a 1.4))
(test (<= ?m 3.34))
(test (> ?a 1.25))
=>
(printout t "buildwindfloat6 detected type = " ?type crlf))
CLIPS>
(defrule R7
(glass (b ?b)
(m ?m)
(a ?a)
(r ?r)
(type ?type))
(test (<= ?b 0.27))
(test (> ?m 2.41))
(test (<= ?a 1.4))
(test (> ?m 3.34))
(test (<= ?m 3.82))
(test (<= ?r 1.51707))
(test (<= ?r 51596))
=>
(printout t "buildwindfloat7 detected type = " ?type crlf))
CLIPS> (reset)
CLIPS> (run)
Input File? weka.txt
buildwindfloat7 detected type = vehic wind float
CLIPS>
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 the case where I have the number of input is equal to output, the rule must help me choose between several combinations (start and end nodes) the shortest path for each combination.
Another rule can be added with the same rule before, if I have the number of input is greater than the number of output or the opposite. After selecting between the combination it is also necessary to take into consideration the input or the output and to derive it towards the nearest point?
(deftemplate path
(slot start)
(slot end)
(multislot path)
(slot cost(type NUMBER)))
(deftemplate info
(slot start)
(slot end)
(multislot path)
(slot cost))
(deffacts variable_table
(path (start A)(end B)(path A,a,b,B) (cost 7))
(path (start A)(end C)(path A,a,b,c,C) (cost 10))
(path (start A)(end D)(path A,a,m,n,d,D) (cost 8.5))
(path (start A)(end E)(path A,a,m,n,E) (cost 5.5))
(path (start A)(end F)(path A,a,m,n,k,g,f,F) (cost 9.4))
(path (start A)(end CS) (path A,a,m,n,k,CS) (cost 6.7))
(path (start A)(end G)(path A,a,m,n,k,g,G) (cost 8))
(path (start A)(end H)(path A,a,m,n,d,e,H) (cost 10.3))
(path (start A)(end I)(path A,a,m,I) (cost 3.5))
(path (start B)(end A) (path B,b,a,A) (cost 7 ))
(path (start B)(end C) (path B,b,c,C) (cost 4))
(path (start B)(end D) (path B,b,c,d,D) (cost 7 ))
(path (start B)(end E) (path B,b,g,k,n,E) (cost 5.8 ))
(path (start B)(end F) (path B,b,g,f,F) (cost 4.7))
(path (start B)(end CS)(path B,b,g,k,CS) (cost 4.6))
(path (start B)(end G) (path NG2,b,g,G) (cost 3.3))
(path (start B)(end H) (path NG2,b,g,f,e,H) (cost 6.5 ))
(path (start B)(end I) (path NG2,b,g,k,n,m,I)(cost 7.8 ))
(path (start C)(end A) (path C,c,b,a,A) (cost 10))
(path (start C)(end B) (path C,c,b,B) (cost 5))
(path (start C)(end D) (path C,c,d,D) (cost 4))
(path (start C)(end E) (path C,c,d,n,E) (cost 5.3))
(path (start C)(end F) (path C,c,d,e,f,F) (cost 7.6))
(path (start C)(end CS)(path C,c,b,g,k,CS) (cost 7.6))
(path (start C)(end G) (path C,c,b,g,G) (cost 6.3))
(path (start C)(end H) (path C,c,d,e,H) (cost 5.8))
(path (start C)(end I) (path C,c,d,n,m,I) (cost 9))
(path (start D)(end A) (path D,d,n,m,a,A) (cost 8.5))
(path (start D)(end B) (path D,d,c,b,B) (cost 7))
(path (start D)(end C) (path D,d,c,C) (cost 4))
(path (start D)(end E) (path D,d,n,E) (cost 5))
(path (start D)(end F) (path D,d,e,f,F) (cost 5.6))
(path (start D)(end CS)(path D,d,n,k,CS) (cost 6.2))
(path (start D)(end G) (path D,d,e,f,g,G) (cost 6))
(path (start D)(end H) (path D,d,e,H) (cost 3.8))
(path (start D)(end I) (path D,d,n,m,I) (cost 7))
(path (start E)(end A) (path E,n,m,a,A) (cost 5.5))
(path (start E)(end B) (path E,n,k,g,b,B) (cost 5.8))
(path (start E)(end C) (path E,n,d,c,C) (cost 7))
(path (start E)(end D) (path E,n,d,D) (cost 5))
(path (start E)(end F) (path E,n,k,g,f,F) (cost 5.9))
(path (start E)(end CS)(path E,n,k,CS) (cost 3.2))
(path (start E)(end G) (path E,n,k,g,G) (cost 4.5))
(path (start E)(end H) (path E,n,d,e,H) (cost 6.8))
(path (start E)(end I) (path E,n,m,I) (cost 4))
(path (start F)(end A) (path F,f,g,k,n,m,a,A)(cost 9.4))
(path (start F)(end B) (path F,f,g,b,B) (cost 4.7))
(path (start F)(end C) (path F,f,e,d,c,C) (cost 7.6))
(path (start F)(end D) (path F,f,e,d,D) (cost 5.6))
(path (start F)(end E) (path F,f,g,k,n,E) (cost 5.9))
(path (start F)(end CS)(path F,f,g,k,CS) (cost 4.7))
(path (start F)(end G) (path F,f,g,G) (cost 3.4))
(path (start F)(end H) (path F,f,e,H) (cost 3.8))
(path (start F)(end I) (path F,f,g,k,n,m,I) (cost 7.9))
(path (start CS)(end A) (path CS,k,n,m,a,A) (cost 6.7))
(path (start CS)(end B) (path CS,k,g,b,B) (cost 4.6))
(path (start CS)(end C) (path CS,K,g,b,c,C) (cost 7.6))
(path (start CS)(end D) (path CS,k,n,d,D) (cost 6.2))
(path (start CS)(end E) (path CS,K,N,E) (cost 3.2))
(path (start CS)(end F) (path CS,k,g,f,F) (cost 4.7))
(path (start CS)(end G) (path CS,k,g,G) (cost 3.3))
(path (start CS)(end H) (path CS,k,g,f,e,H) (cost 6.5))
(path (start CS)(end I)(path CS,k,n,m,I) (cost 5.2))
(path (start G)(end A) (path G,g,k,n,m,a,A) (cost 8))
(path (start G)(end B) (path G,g,b,B) (cost 3.3))
(path (start G)(end C) (path G,g,b,c,C) (cost 6.3))
(path (start G)(end D) (path G,g,f,e,d,D) (cost 6))
(path (start G)(end E) (path G,g,k,n,E) (cost 4.5))
(path (start G)(end F) (path G,g,f,F) (cost 3.4))
(path (start G)(end CS)(path G,g,k,CS) (cost 3.3))
(path (start G)(end H) (path G,g,f,e,H) (cost 5.2))
(path (start G)(end I) (path G,g,k,n,m,I) (cost 6.5))
(path (start H)(end A) (path H,e,d,n,m,a,A) (cost 10.3))
(path (start H)(end B) (path H,e,f,g,B) (cost 6.5))
(path (start H)(end C) (path H,e,d,C) (cost 3.8))
(path (start H)(end D) (path H,e,d,c,D) (cost 5.8))
(path (start H)(end E) (path H,e,d,n,E) (cost 6.8))
(path (start H)(end F) (path H,e,f,F) (cost 3.8))
(path (start H)(end CS)(path H,e,f,g,k,CS) (cost 6.5))
(path (start H)(end H) (path H,e,f,g,H) (cost 5.2))
(path (start H)(end I) (path H,e,d,n,m,I) (cost 8.8))
(path (start I)(end A) (path I,m,a,A) (cost 3.5))
(path (start I)(end B) (path I,m,n,k,g,b,B) (cost 7.8))
(path (start I)(end C) (path I,m,n,d,c,C) (cost 9))
(path (start I)(end D) (path I,m,n,d,D) (cost 7))
(path (start I)(end E) (path I,m,n,E) (cost 4))
(path (start I)(end F) (path I,m,n,k,g,f,F) (cost 7.9))
(path (start I)(end CS)(path I,m,m,k,CS) (cost 5.2))
(path (start I)(end G) (path I,m,n,k,g,G) (cost 6.5))
(path (start I)(end H) (path I,m,n,d,e,I) (cost 8.8)))
(defrule lancesaisiepoint
?f1 <- (debut node)
=>
(retract ?f1)
(printout t "how many node start")
(bind ?x (read))
(assert (startnode ?x))
)
(defrule saisiepoint
?f <- (startnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node start " crlf)
(printout t "start node name ")
(bind ?start (read))
(printout t "node start value ")
(bind ?y1 (read))
(assert (startnode ?start ?y1))
(retract ?f)
(assert (startnode (- ?a 1)))
)
(defrule lancesaisiemoins
?f1 <- (startnode 0)
=>
(retract ?f1)
(printout t "how many node end ")
(bind ?x (read))
(assert (endnode ?x))
)
(defrule saisiemoins
?f <- (endnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node end" crlf)
(printout t "end node name ")
(bind ?end (read))
(printout t "node end value ")
(bind ?y2 (read))
(assert (endnode ?end ?y2))
(retract ?f)
(assert (endnode (- ?a 1))))
(defrule supprnbrpoint ;compter
?x<- (startnode 0)
=>
(retract ?x)
)
(defrule supprnbrmoins
?x<- (endnode 0)
=>
(retract ?x)
)
(defrule info
?M <- (startnode ?start ?y1)
?K <- (endnode ?end ?y2)
=>
(assert (start ?start end ?end))
)
(defrule varvar
?L<- (start ?start end ?end)
(path (start ?start)(end ?end)(path $?path)(cost ?cost))
=>
(retract ?L)
(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 combination result if i have 3 startnode and 2 endnode
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
and then As final result i hope to get
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) */
I hope that it is clear ??
thank you for your help
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.
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 the case where I have the number of input is equal to output, the rule must help me choose between several combinations (start and end nodes) the shortest path for each combination.
Another rule can be added with the same rule before, if I have the number of input is greater than the number of output or the opposite. After selecting between the combination it is also necessary to take into consideration the input or the output and to derive it towards the nearest point?
(deftemplate path
(slot start)
(slot end)
(multislot path)
(slot cost(type NUMBER)))
(deftemplate info
(slot start)
(slot end)
(multislot path)
(slot cost))
(deffacts variable_table
(path (start A)(end B)(path A,a,b,B) (cost 7))
(path (start A)(end C)(path A,a,b,c,C) (cost 10))
(path (start A)(end D)(path A,a,m,n,d,D) (cost 8.5))
(path (start A)(end E)(path A,a,m,n,E) (cost 5.5))
(path (start A)(end F)(path A,a,m,n,k,g,f,F) (cost 9.4))
(path (start A)(end CS) (path A,a,m,n,k,CS) (cost 6.7))
(path (start A)(end G)(path A,a,m,n,k,g,G) (cost 8))
(path (start A)(end H)(path A,a,m,n,d,e,H) (cost 10.3))
(path (start A)(end I)(path A,a,m,I) (cost 3.5))
(path (start B)(end A) (path B,b,a,A) (cost 7 ))
(path (start B)(end C) (path B,b,c,C) (cost 4))
(path (start B)(end D) (path B,b,c,d,D) (cost 7 ))
(path (start B)(end E) (path B,b,g,k,n,E) (cost 5.8 ))
(path (start B)(end F) (path B,b,g,f,F) (cost 4.7))
(path (start B)(end CS)(path B,b,g,k,CS) (cost 4.6))
(path (start B)(end G) (path NG2,b,g,G) (cost 3.3))
(path (start B)(end H) (path NG2,b,g,f,e,H) (cost 6.5 ))
(path (start B)(end I) (path NG2,b,g,k,n,m,I)(cost 7.8 ))
(path (start C)(end A) (path C,c,b,a,A) (cost 10))
(path (start C)(end B) (path C,c,b,B) (cost 5))
(path (start C)(end D) (path C,c,d,D) (cost 4))
(path (start C)(end E) (path C,c,d,n,E) (cost 5.3))
(path (start C)(end F) (path C,c,d,e,f,F) (cost 7.6))
(path (start C)(end CS)(path C,c,b,g,k,CS) (cost 7.6))
(path (start C)(end G) (path C,c,b,g,G) (cost 6.3))
(path (start C)(end H) (path C,c,d,e,H) (cost 5.8))
(path (start C)(end I) (path C,c,d,n,m,I) (cost 9))
(path (start D)(end A) (path D,d,n,m,a,A) (cost 8.5))
(path (start D)(end B) (path D,d,c,b,B) (cost 7))
(path (start D)(end C) (path D,d,c,C) (cost 4))
(path (start D)(end E) (path D,d,n,E) (cost 5))
(path (start D)(end F) (path D,d,e,f,F) (cost 5.6))
(path (start D)(end CS)(path D,d,n,k,CS) (cost 6.2))
(path (start D)(end G) (path D,d,e,f,g,G) (cost 6))
(path (start D)(end H) (path D,d,e,H) (cost 3.8))
(path (start D)(end I) (path D,d,n,m,I) (cost 7))
(path (start E)(end A) (path E,n,m,a,A) (cost 5.5))
(path (start E)(end B) (path E,n,k,g,b,B) (cost 5.8))
(path (start E)(end C) (path E,n,d,c,C) (cost 7))
(path (start E)(end D) (path E,n,d,D) (cost 5))
(path (start E)(end F) (path E,n,k,g,f,F) (cost 5.9))
(path (start E)(end CS)(path E,n,k,CS) (cost 3.2))
(path (start E)(end G) (path E,n,k,g,G) (cost 4.5))
(path (start E)(end H) (path E,n,d,e,H) (cost 6.8))
(path (start E)(end I) (path E,n,m,I) (cost 4))
(path (start F)(end A) (path F,f,g,k,n,m,a,A)(cost 9.4))
(path (start F)(end B) (path F,f,g,b,B) (cost 4.7))
(path (start F)(end C) (path F,f,e,d,c,C) (cost 7.6))
(path (start F)(end D) (path F,f,e,d,D) (cost 5.6))
(path (start F)(end E) (path F,f,g,k,n,E) (cost 5.9))
(path (start F)(end CS)(path F,f,g,k,CS) (cost 4.7))
(path (start F)(end G) (path F,f,g,G) (cost 3.4))
(path (start F)(end H) (path F,f,e,H) (cost 3.8))
(path (start F)(end I) (path F,f,g,k,n,m,I) (cost 7.9))
(path (start CS)(end A) (path CS,k,n,m,a,A) (cost 6.7))
(path (start CS)(end B) (path CS,k,g,b,B) (cost 4.6))
(path (start CS)(end C) (path CS,K,g,b,c,C) (cost 7.6))
(path (start CS)(end D) (path CS,k,n,d,D) (cost 6.2))
(path (start CS)(end E) (path CS,K,N,E) (cost 3.2))
(path (start CS)(end F) (path CS,k,g,f,F) (cost 4.7))
(path (start CS)(end G) (path CS,k,g,G) (cost 3.3))
(path (start CS)(end H) (path CS,k,g,f,e,H) (cost 6.5))
(path (start CS)(end I)(path CS,k,n,m,I) (cost 5.2))
(path (start G)(end A) (path G,g,k,n,m,a,A) (cost 8))
(path (start G)(end B) (path G,g,b,B) (cost 3.3))
(path (start G)(end C) (path G,g,b,c,C) (cost 6.3))
(path (start G)(end D) (path G,g,f,e,d,D) (cost 6))
(path (start G)(end E) (path G,g,k,n,E) (cost 4.5))
(path (start G)(end F) (path G,g,f,F) (cost 3.4))
(path (start G)(end CS)(path G,g,k,CS) (cost 3.3))
(path (start G)(end H) (path G,g,f,e,H) (cost 5.2))
(path (start G)(end I) (path G,g,k,n,m,I) (cost 6.5))
(path (start H)(end A) (path H,e,d,n,m,a,A) (cost 10.3))
(path (start H)(end B) (path H,e,f,g,B) (cost 6.5))
(path (start H)(end C) (path H,e,d,C) (cost 3.8))
(path (start H)(end D) (path H,e,d,c,D) (cost 5.8))
(path (start H)(end E) (path H,e,d,n,E) (cost 6.8))
(path (start H)(end F) (path H,e,f,F) (cost 3.8))
(path (start H)(end CS)(path H,e,f,g,k,CS) (cost 6.5))
(path (start H)(end H) (path H,e,f,g,H) (cost 5.2))
(path (start H)(end I) (path H,e,d,n,m,I) (cost 8.8))
(path (start I)(end A) (path I,m,a,A) (cost 3.5))
(path (start I)(end B) (path I,m,n,k,g,b,B) (cost 7.8))
(path (start I)(end C) (path I,m,n,d,c,C) (cost 9))
(path (start I)(end D) (path I,m,n,d,D) (cost 7))
(path (start I)(end E) (path I,m,n,E) (cost 4))
(path (start I)(end F) (path I,m,n,k,g,f,F) (cost 7.9))
(path (start I)(end CS)(path I,m,m,k,CS) (cost 5.2))
(path (start I)(end G) (path I,m,n,k,g,G) (cost 6.5))
(path (start I)(end H) (path I,m,n,d,e,I) (cost 8.8)))
(defrule lancesaisiepoint
?f1 <- (debut node)
=>
(retract ?f1)
(printout t "how many node start")
(bind ?x (read))
(assert (startnode ?x))
)
(defrule saisiepoint
?f <- (startnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node start " crlf)
(printout t "start node name ")
(bind ?start (read))
(printout t "node start value ")
(bind ?y1 (read))
(assert (startnode ?start ?y1))
(retract ?f)
(assert (startnode (- ?a 1)))
)
(defrule lancesaisiemoins
?f1 <- (startnode 0)
=>
(retract ?f1)
(printout t "how many node end ")
(bind ?x (read))
(assert (endnode ?x))
)
(defrule saisiemoins
?f <- (endnode ?a)
(test (> ?a 0))
=>
(printout t "Enter nbr node end" crlf)
(printout t "end node name ")
(bind ?end (read))
(printout t "node end value ")
(bind ?y2 (read))
(assert (endnode ?end ?y2))
(retract ?f)
(assert (endnode (- ?a 1))))
(defrule supprnbrpoint ;compter
?x<- (startnode 0)
=>
(retract ?x)
)
(defrule supprnbrmoins
?x<- (endnode 0)
=>
(retract ?x)
)
(defrule info
?M <- (startnode ?start ?y1)
?K <- (endnode ?end ?y2)
=>
(assert (start ?start end ?end))
)
(defrule varvar
?L<- (start ?start end ?end)
(path (start ?start)(end ?end)(path $?path)(cost ?cost))
=>
(retract ?L)
(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 combination result if i have 3 startnode and 2 endnode
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
and then As final result i hope to get
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) */
I hope that it is clear ??
thank you for your help
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.
I'm trying to change the design of an expert system to work carried out by my rules.
Topic - processing of different parts on different machines. Naturally, each kind of items processed at different times on different machines.
The system consists of three rules. The first rule - load machines work. The second rule - unloads machines. The third rule - performs the movement of time.
I added in the first rule of a function call, which seeks item with maximum processing time. However, the expert system stopped working. Simply displays "1". That's all.
(defglobal ?*time* = 0)
(deftemplate details
(field det (type SYMBOL))
(field oper (type INTEGER))
(field count (type INTEGER))
)
(deftemplate route
(field det (type SYMBOL))
(field oper (type INTEGER))
(field machine (type INTEGER))
(field time (type INTEGER))
)
(deftemplate machine
(field num (type INTEGER))
(field count (type INTEGER)(default 0))
(field det (type SYMBOL)(default A))
(field oper (type INTEGER)(default 0))
(field time (type INTEGER)(default 0))
)
(deffacts details
(details (det A) (oper 0) (count 100))
(details (det B) (oper 0) (count 150))
(details (det C) (oper 0) (count 200))
(details (det D) (oper 0) (count 300))
(details (det E) (oper 0) (count 200))
(details (det A) (oper 1) (count 0))
(details (det B) (oper 1) (count 0))
(details (det C) (oper 1) (count 0))
(details (det D) (oper 1) (count 0))
(details (det E) (oper 1) (count 0))
....
)
(deffacts route
(route (det A) (oper 1) (machine 1) (time 10))
(route (det A) (oper 2) (machine 2) (time 5))
(route (det A) (oper 2) (machine 2) (time 2))
(route (det A) (oper 3) (machine 3) (time 4))
(route (det A) (oper 3) (machine 4) (time 3))
(route (det A) (oper 4) (machine 4) (time 8))
(route (det A) (oper 4) (machine 1) (time 8))
(route (det B) (oper 1) (machine 1) (time 8))
(route (det B) (oper 2) (machine 5) (time 4))
(route (det B) (oper 2) (machine 2) (time 6))
(route (det B) (oper 3) (machine 6) (time 3))
(route (det B) (oper 3) (machine 5) (time 2))
(route (det B) (oper 4) (machine 7) (time 2))
(route (det B) (oper 4) (machine 2) (time 3))
...
)
(deffacts machines
(machine (num 1))
(machine (num 2))
(machine (num 3))
(machine (num 4))
(machine (num 5))
(machine (num 6))
(machine (num 7))
(machine (num 8))
)
(deffunction my-predicate (?fact1 ?fact2)
(< (fact-slot-value ?fact1 time) (fact-slot-value ?fact2 time)))
(deffunction find-max2 (?template1 ?predicate1 ?operation ?template2 ?max)
(bind ?max FALSE)
(do-for-all-facts ((?f2 ?template2)) (eq (fact-slot-value ?f2 count) 0)
(do-for-all-facts ((?f1 ?template1)) (eq (fact-slot-value ?f1 oper) ?operation) (eq (fact-slot-value ?f1 oper)(fact-slot-value ?f2 oper))
(if (or (not ?max) (funcall ?predicate1 ?f1 ?max))
then
(bind ?max ?f1)))
)
)
;--------------------------------------------------------------------------------------------------
(defrule work_on_1
(declare (salience 10000))
(machine (num ?num1)(count ?count1) (time ?time1))
(test (eq ?count1 0))
(test (eq ?time1 0))
?node1 <- (machine (num ?num1)(count ?count1) (time ?time1))
(details (det ?detail) (oper ?operation1) (count ?count2))
(test (not (eq ?count2 0)))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2))
; add this code
(funcall find-max2 route my-predicate ?operation1 details ?max)
(test (eq ?operation1(fact-slot-value ?max oper )))
(route (machine ?num1) (det ?detail) (oper ?operation2) (time ?time2))
(test (eq ?operation2 (+ ?operation1 1)))
=>
(if (> ?count2 30)
then
(modify ?node1 (count 30) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 30)))
(printout t ?*time*" ," ?num1 " 30 деталей типа "?detail " , " ?operation2 " , " ?time2 crlf)
else
(modify ?node1 (count ?count2) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 ?count2)))
(printout t ?*time*" , " ?num1 " " ?count2 " , "?detail " , " ?operation2 " , " ?time2 crlf)
)
)
There are numerous issues with the code. First it's unclear why there’s redundant pattern matching for the machine and details facts:
(machine (num ?num1)(count ?count1) (time ?time1))
(test (eq ?count1 0))
(test (eq ?time1 0))
?node1 <- (machine (num ?num1)(count ?count1) (time ?time1))
(details (det ?detail) (oper ?operation1) (count ?count2))
(test (not (eq ?count2 0)))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2))
The following code is sufficient to achieve the same task:
?node1 <- (machine (num ?num1) (count ?count1&0) (time ?time1&0))
?node2 <- (details (det ?detail) (oper ?operation1) (count ?count2&~0))
Second, it looks like you're expecting the funcall pattern to invoke a function call and place the result of that function call in the variable ?max:
(funcall find-max2 route my-predicate ?operation1 details ?max)
There is no funcall conditional element that has this type of behavior. In this case, you've just created a pattern conditional element that's looking for an ordered fact with the relation name funcall. If you wanted to invoke funcall from the conditions of a rule you'd use the test conditional element:
(test (funcall find-max2 route my-predicate ?operation1 details))
Since the function being invoked is a literal, find-max2, there's really no point in using funcall since you can just call the function directly:
(test (find-max2 route my-predicate ?operation1 details))
Third, there's not much point to using the query functions within the conditions of a rule since you can directly pattern match on the facts instead. In addition, the placement of the query function you've used within the conditions will cause it to be executed once there are matching machine/details facts, but possibly before there are any route facts, so it will likely not even return the correct results.
The following rule shows how to find the maximum values without using query functions:
(defrule find-max
(route (oper ?oper1) (time ?time1))
(exists (details (count 0) (oper ?oper1)))
(not (and (route (oper ?oper2) (time ?time2&:(> ?time2 ?time1)))
(exists (details (count 0) (oper ?oper2)))))
=>
(printout t "Maximum time is " ?time1 crlf))
(defrule work_on_1
(declare (salience 10000))
?node1 <- (machinegun (num ?num1) (count ?count1&0) (time ?time1&0))
?node2 <- (store (det ?detail) (oper ?operation1) (count ?count2&~0))
(tex_route (oper ?oper1) (time ?time2))
(exists (store (count 0) (oper ?oper1)))
(not (and (tex_route (oper ?oper2) (time ?time3&:(> ?time3 ?time2)))
(exists (store (count 0) (oper ?oper2)))))
(test (eq ?time1 ?time2))
(route (machine ?num1) (det ?detail) (oper ?operation2) (time ?time2))
(test (eq ?operation2 (+ ?operation1 1)))
=>
(if (> ?count2 30)
then
(modify ?node1 (count 30) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 30)))
(printout t ?*time*" ," ?num1 " 30 деталей типа "?detail " , " ?operation2 " , " ?time2 crlf)
else
(modify ?node1 (count ?count2) (time ?time2) (oper ?operation2) (det ?detail))
(modify ?node2 (count (- ?count2 ?count2)))
(printout t ?*time*" , " ?num1 " " ?count2 " , "?detail " , " ?operation2 " , " ?time2 crlf)
)
)
It is new rule, but when the expert system stopped working - simply displays "1".