0% found this document useful (0 votes)
26 views3 pages

Controling The Angenda

This document discusses controlling the agenda and conflict resolution in the expert system shell Jess. It describes how salience values can be used to determine the order of rule firing, and the two conflict resolution strategies of depth and breadth. The depth strategy fires more recently activated rules first, while breadth fires rules in the order they were activated. Constraints and wildcards can be used to match patterns in facts and bind variables. The run command can be used to step through rule firings one at a time for debugging.

Uploaded by

olivukovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Controling The Angenda

This document discusses controlling the agenda and conflict resolution in the expert system shell Jess. It describes how salience values can be used to determine the order of rule firing, and the two conflict resolution strategies of depth and breadth. The depth strategy fires more recently activated rules first, while breadth fires rules in the order they were activated. Constraints and wildcards can be used to match patterns in facts and bind variables. The run command can be used to step through rule firings one at a time for debugging.

Uploaded by

olivukovic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

More JESS

Controlling the Agenda, Combining Constraints & Actions

1. Controlling the agenda

The declare(salience) command allows you to have control over which rules are put on the
agenda but you need to use it carefully. Salience is a kind of rule priority.

Activated rules of the highest salience will fire first, followed by rules of lower salience. You
include the salience declaration in the definition of the rule.

The example below defines 3 rules with varying salience to fire when the object light-is has a
value red. Play around with your traffic-light example.

Jess> (defrule (traffic-light


(declare (salience 100))
(light-is red)
=>
(printout t "STOP" crlf)
)
)

Jess> (defrule traffic-light1


(declare (salience 150))
(light-is red)
=>
(printout t "STOP NOW!!!!" crlf)
)
TRUE

Jess> (defrule traffic-light3


(declare (salience 120))
(light-is red)
=>
(printout t "STOP STOP" crlf)
)
TRUE

Jess> (watch rules)


TRUE

Jess> (assert (light-is red))


<Fact-0>

Jess> (agenda)
[Activation: MAIN::traffic-light1 f-1 ; time=2 ; salience=150]
[Activation: MAIN::traffic-light3 f-1 ; time=2 ; salience=120]
[Activation: MAIN::traffic-light f-1 ; time=2 ; salience=100]
For a total of 3 activations.

Jess> (run)
FIRE 1 MAIN::traffic-light1 f-1
STOP NOW!!!!
FIRE 2 MAIN::traffic-light3 f-1
STOP STOP
FIRE 1 MAIN::traffic-light f-1
STOP
3

2. Conflict Resolution
Jess offers two modes of conflict resolution : depth (last in first out) and breadth (first in first
out).
When depth strategy is in effect, this is the default, more recently activated rules will be fired
before less recently activated rules of the same salience.
When breadth strategy is active, rules of the same salience fire in the order in which they
were activated.

The command set-strategy allows you specify the conflict resolution strategy Jess uses.

Experiment with your traffic lights example.

Usage
(set-strategy (depth))
(set-strategy (breadth))

3. More about running


It is possible to debug using the run command. E.g. (run 15) tells jess to run the program but
stop after 15 rule firings. (run 1) allows you to step through a program firing a rule at a time.

E.g From example in section 1.


Jess> (reset)
TRUE
Jess> (assert (light-is red))
<Fact-1>
Jess> (run 1)
FIRE 1 MAIN::traffic-light1 f-1
STOP NOW!!!!
1
Jess> (run 1)
FIRE 1 MAIN::traffic-light3 f-1
STOP STOP
1
Jess> (run 1)
FIRE 1 MAIN::traffic-light f-1
STOP
1

4. wildcards
A question mark ?
matches any single field within a fact
multi-field wildcard $?
matches zero or more fields in a fact

5. Constraints
not constraint ~
the field can take any value except the one specified
or constraint |
specifies alternative values, one of which must match
and constraint &
the value of the field must match all specified values
mostly used to place constraints on the binding of a variable
basic operators (+,-,*,/) and many functions (trigonometric, logarithmic, exponential) are
supported

E.g more complex rule


(deftemplate person "personal details"
(slot name)
(slot eye-color)
(slot hair-color)
)
TRUE
Jess>(defrule find-blue-eyes
(person (name ?name)
(eye-color blue))
=>
(printout t ?name " has blue eyes."
crlf))
Jess> (assert (person (name "Dave") (hair-color brown) (eye-color brown)))
<Fact-0>

Jess> (assert (person (name "Carol") (hair-color black) (eye-color blue)))


<Fact-1>

Jess> (assert (person (name "Tom") (hair-color blonde) (eye-color blue)))


<Fact-2>
Jess> (run)
Tom has blue eyes.
Carol has blue eyes.
2

E.g. Much more complex


Jess> (reset)
Jess> (assert (person (name "Dave") (hair-color brown) (eye-color brown)))
Jess> (assert (person (name "Carol") (hair-color black) (eye-color blue)))
Jess> (assert (person (name "Tom") (hair-color blonde) (eye-color blue)))
Jess> (assert (person (name "Tony") (hair-color red) (eye-color green)))
Jess> (assert (person (name "Susan") (hair-color black) (eye-color green)))

Jess>
(defrule silly-eye-hair-match
(person (name ?name1)
(eye-color ?eyes1&blue|green)
(hair-color ?hair1&~black))
(person (name ?name2&~?name1)
(eye-color ?eyes2&~eyes1)
(hair-color ?hair2&brown|hair1))
=>
(printout t ?name1 " has "?eyes1 " eyes and " ?hair1 " hair." crlf)
(printout t ?name2 " has "?eyes2 " eyes and " ?hair2 " hair." crlf))

Jess> (run)
Tony has green eyes and red hair.
Dave has brown eyes and brown hair.
Tom has blue eyes and blonde hair.
Dave has brown eyes and brown hair.
(if previous rule also exists also get)
Tom has blue eyes.
Carol has blue eyes.

You might also like