24.11.2014 Views

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6. Anatomy of a <strong>flex</strong> Program 57<br />

The frames<br />

The rules<br />

The ruleset<br />

First we define the data structures, which means declaring a frame for a<br />

cinema and a frame for a cinema-goer. Each will have a single slot, or<br />

attribute, which contains the number of seats for a cinema and the number<br />

of tickets required by a viewer.<br />

frame cinema<br />

default seats is 500.<br />

frame viewer<br />

default tickets_required is 3.<br />

We will define one rule, which describes how the cinema seats will be<br />

allocated to the viewer. We will call this rule allocate_tickets. The<br />

condition under which the rule will be fired is simply that the viewer requires<br />

some tickets!<br />

rule allocate_tickets<br />

if the tickets_required of viewer is greater than 0<br />

then the seats of the cinema becomes<br />

the seats of the cinema<br />

minus the tickets_required of viewer and<br />

the tickets_required of viewer becomes 0.<br />

Next, a ruleset must be defined to say what rules are to be considered.<br />

We will call our ruleset seating; in this case we only have one rule, called<br />

allocate_tickets.<br />

ruleset seating<br />

contains allocate_tickets.<br />

The action<br />

Finally, to set this going we invoke these rules, defining an action to do<br />

so.<br />

action go ;<br />

do invoke ruleset seating.<br />

Starting The Forward Chaining Engine<br />

<strong>flex</strong> toolkit<br />

We now have a complete <strong>flex</strong> program. To start the <strong>flex</strong> forward chaining<br />

engine, we simply run the Prolog query go (type go at the Prolog command<br />

line).<br />

?- go.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!