Bse Datos
MATERIA: INTELIGENCIA ARTIFICIAL SIGLA: INF-424 GRUPO: 1
DOC: ING.LUDMILA N. BENITEZ MONTERO
Guía Nº 5
Ej. 1 Semaforo
PASO 1 Dar (clear)
PASO 2Guardar en un archivo .clp
(defrule No_Cruzar_Calle
(semaforo ~verde)
=>
(printout t "No puedo cruzar" crlf)
)
(defrule Cruzar_Calle
(semaforo ~rojo & ~amarillo)
=>
(printout t "Puedo cruzar" crlf))
(defrule Cruzar_Arriesgando
(semaforo amarillo)
=>
(printout t "Cruzar es peligroso" crlf)
)
PASO 3 Cargar el programa
(load "")
PASO 4 Insertar el hecho que dispara la regla
(deffactsCruces
(semaforo rojo)
)
PASO 5
(reset)
(run)
Otras alternativas
(deffacts Cruces
(semaforo verde)
)
(deffacts Cruces
(semaforo amarillo)
)
Variables. Se captura el valor de un campomediante una variable.
?x variable unicampo
$?y variable multicampo
Ej.2 Variable Unicampo
PASO 1 Dar (clear)
PASO 2 Guardar en un archivo .clp
(deftemplate Persona
(slot nombre)
(slot apellido)(slot edad)
(multislot amigos)
)
UNIVERSIDAD AUTONOMA JUAN MISAEL SARACHO
MATERIA: INTELIGENCIA ARTIFICIAL SIGLA: INF-424 GRUPO: 1
DOC: ING.LUDMILA N. BENITEZ MONTERO
(defrule ImprimeNombre(Apellido-a-buscar ?x)
(Persona (nombre ?y)(apellido ?x))
=>
(printout t ?y "--se apellida--" ?x crlf)
)
(deffacts lista_personas
(Persona (nombre Juan)(apellido Perez)(edad 23)
)
(Persona(nombre Agustin)(apellido Perez)(edad 27)
)
(Persona(nombre Julia)(apellido Arce)(edad 20)
)
(Apellido-a-buscar Perez)
)
PASO 3 Cargar el programa (load " ")
(reset)
(run)
Ej.3 VariableMulticampo
PASO 1 Correr en el entorno
(defrule ImprimeAmigos
(Buscar-Amigos-de ?x)
(Persona
(nombre ?x)
(amigos $?n)
)
=>
(printout t ?x " es amigo de " ?n crlf)
)
PASO 2
(reset)
PASO 3Insertar el hecho que dispara la regla
(assert (Buscar-Amigos-de Maria) )
UNIVERSIDAD AUTONOMA JUAN MISAEL SARACHO
MATERIA: INTELIGENCIA ARTIFICIAL SIGLA: INF-424 GRUPO: 1
DOC: ING.LUDMILA N....
Regístrate para leer el documento completo.