Inteligencia Artificial - CLIPS regla no se ejecuta o se ejecuta en bucle

 
Vista:

CLIPS regla no se ejecuta o se ejecuta en bucle

Publicado por Tomás (1 intervención) el 17/12/2015 07:20:19
Buenas, llevo muchas horas dandome cabezasos contra una regla que no se ejecuta o lo hace en bucle.
La regla es "preciogamingoc" si la dejo como esta no se ejecuta aparentemente, pero si le quito los demás slots excepto tipo y oc se ejecuta pero lo hace en bucle y nunca salgo de la misma.

1
2
3
4
(defrule preciogamingoc
?A <- (pc (tipo g) (oc si))
=>
...

Os dejo el código completo, un saludo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
;;****TEMPLATES*****
 
(deftemplate pc
(slot tipo)
(slot oc)
(multislot procesador)
(multislot ram)
(multislot placabase)
(multislot discoduro)
(multislot grafica)
(multislot fuente)
(slot precio))
 
;;****FUNCTIONS*****
 
(deffunction pregunta (?pregunta $?respuestas-posibles)
   (printout t ?pregunta)
   (bind ?respuesta (read))
   (if (lexemep ?respuesta)
    then (bind ?respuesta (lowcase ?respuesta)))
   (while (not (member ?respuesta ?respuestas-posibles)) do
      (printout t ?pregunta)
      (bind ?respuesta (read))
      (if (lexemep ?respuesta)
          then (bind ?respuesta (lowcase ?respuesta))))
   ?respuesta)
 
(deffunction sino (?pregunta)
   (bind ?respuesta (pregunta ?pregunta si no s n))
   (if (or (eq ?respuesta si) (eq ?respuesta s))
       then TRUE
       else FALSE))
 
(deffunction tipo (?pregunta)
   (bind ?respuesta (pregunta ?pregunta g d o))
   (switch ?respuesta
        (case g then (return g))
        (case d then (return d))
        (case o then (return o))
        ))
 
 
;;******FACTS*******
 
(deffacts inicia
    (pc))
 
 
;;******RULES*******
 
 
(defrule tipopc
?A <- (pc (procesador)(ram)(placabase)(discoduro)(grafica)(fuente))
=>
(switch (tipo "Tipo (juegos:g/diseño:d/otros:o)? ")
    (case g then ( modify ?A (tipo g)(oc nose)(procesador "i5 4690_Intel")
    (ram "2x4GB 2133 cl9")
    (placabase "Gigabyte_H97M-HD3 ejemplo")
    (discoduro "1Tb")
    (grafica "GTX 960")
    (fuente "700W+ silver")
    (precio 550)))
    (case d then ( modify ?A (tipo d)(oc nose)(procesador "i7 4790_Intel")
    (ram "2x8GB 2133 cl9")
    (placabase "Gigabyte_H97M-HD3 ejemplo")
    (discoduro "1Tb HDD + 120gb SSD")
    (grafica "kuadro k620")
    (fuente "700W+ silver")
    (precio 700)))
    (case o then ( modify ?A (tipo o)(oc nose)(procesador "i3 6100_Intel")
    (ram "2x4GB 2400 cl12 DDR4")
    (placabase "Msi H110M PRO-VH")
    (discoduro "1Tb")
    (grafica "no incluida")
    (fuente "450W+ bronze")
    (precio 300)))))
 
(defrule oc
    ?A <- (pc(tipo g)(oc nose))
    =>
    (if (sino "Hará overclock al procesador (si/no)?: ")
    then ( modify ?A (oc si)))
)
 
(defrule preciogamingoc
?A <- (pc (tipo g) (oc si) (procesador) (ram) (placabase) (discoduro) (grafica) (fuente))
=>
    (printout t "Veo que su sistema será destinado a juegos y que además se le podrá hacer overclock." crlf
    "Ahora debe introducir el presupuesto medio para que podamos darle una configuración mas concreta." crlf
    "Introduzca su presupuesto máximo de referencia(>= 750): ")
    (bind ?precio (read))
    (if (and(>= ?precio 750)(< ?precio 850))
    ;;then ((printout t "bien"crlf))
    then (modify ?A (procesador "i5 4690K_Intel")
    (ram "2x8GB 2133 cl9")
    (placabase "Gigabyte_Z97X gaming 3 ejemplo")
    (discoduro "1Tb")
    (grafica "GTX 970")
    (fuente "700W+ silver")
    (precio 750)))
    ;;(else (if (>= ?precio 850)
    ;;then (modify ?C (procesador "i7 4790K_Intel")
    ;;(ram "2x8GB 2133 cl9")
    ;;(placabase "Gigabyte_Z97X gaming 5 ejemplo")
    ;;(discoduro "1Tb HDD")
    ;;(grafica "GTX 970")
    ;;(fuente "700W+ silver")
    ;;(precio 850))))
)
 
 
;;*******MAIN*******
 
(defrule inicio
  (declare (salience 1))
  =>
  (printout t crlf)
  (printout t "Sistema Experto de Configuracion de Ordenadores")
  (printout t crlf crlf))
 
  (defrule presupuesto
   (declare (salience -1))
   (pc (procesador ?A)(ram ?F)(placabase ?B)(discoduro ?M)(grafica ?G)(fuente ?P)(precio ?O))
   =>
   (printout t crlf crlf "-.PRESUPUESTO.-" crlf crlf)
   (printout t "PROCESADOR: " ?A crlf)
   (printout t "RAM: " ?F crlf)
   (printout t "PLACA BASE: " ?B crlf)
   (printout t "DISCO DURO:" ?M crlf)
   (printout t "GRAFICA: " ?G crlf)
   (printout t "FUENTE: " ?P crlf crlf)
   (printout t "PRECIO: " ?O crlf)
   )
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder